diff options
| author | Yong He <yonghe@outlook.com> | 2023-07-26 12:23:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-26 12:23:53 -0700 |
| commit | b8ade05df10a2774d3da5ef1fb2c7479ff48989a (patch) | |
| tree | a7fefd7dc494cd6ce2f01c24b0d0379a74edfe9d | |
| parent | 727245a67443447aeec6f7281e8e65834974fbd1 (diff) | |
Fix scalar swizzle causes invalid glsl output. (#3028)
* Fix -fvk-u-shift not applying to RWStructuredBuffer on glsl output.
* Add `transpose` to `ObjectToWorld4x3`.
* Fix scalar swizzle causes invalid glsl output.
Fixes #3026.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | source/slang/slang-ir-peephole.cpp | 25 | ||||
| -rw-r--r-- | tests/bugs/glsl-int-swizzle.slang | 14 | ||||
| -rw-r--r-- | tests/bugs/glsl-int-swizzle.slang.expected.txt | 4 |
3 files changed, 43 insertions, 0 deletions
diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp index ac026b563..600361b2f 100644 --- a/source/slang/slang-ir-peephole.cpp +++ b/source/slang/slang-ir-peephole.cpp @@ -759,6 +759,31 @@ struct PeepholeContext : InstPassBase break; case kIROp_swizzle: { + // If we see a swizzle(scalar), we replace it with makeVectorFromScalar. + if (as<IRBasicType>(inst->getOperand(0)->getDataType())) + { + auto vectorType = as<IRVectorType>(inst->getDataType()); + IRIntegerValue vectorSize = 1; + if (vectorType) + { + auto sizeLit = as<IRIntLit>(vectorType->getElementCount()); + if (!sizeLit) + vectorSize = 0; + vectorSize = sizeLit->getValue(); + } + if (vectorSize == 1) + { + inst->replaceUsesWith(inst->getOperand(0)); + maybeRemoveOldInst(inst); + break; + } + IRBuilder builder(module); + builder.setInsertBefore(inst); + auto newInst = builder.emitMakeVectorFromScalar(vectorType, inst->getOperand(0)); + inst->replaceUsesWith(newInst); + maybeRemoveOldInst(inst); + break; + } // If we see a swizzle(makeVector) then we can replace it with the values from makeVector. auto makeVector = inst->getOperand(0); if (makeVector->getOp() != kIROp_MakeVector) diff --git a/tests/bugs/glsl-int-swizzle.slang b/tests/bugs/glsl-int-swizzle.slang new file mode 100644 index 000000000..6dccf69f0 --- /dev/null +++ b/tests/bugs/glsl-int-swizzle.slang @@ -0,0 +1,14 @@ +// glsl-int-swizzle.slang + +//TEST(compute):COMPARE_COMPUTE:-vk -shaderobj + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name gBuffer +RWStructuredBuffer<int> gBuffer; + +int getX(int4 v) { return v.x; } + +[numthreads(4,1,1)] +void computeMain(uint3 tid : SV_DispatchThreadID) +{ + gBuffer[tid.x] = getX((1).xxxx); +} diff --git a/tests/bugs/glsl-int-swizzle.slang.expected.txt b/tests/bugs/glsl-int-swizzle.slang.expected.txt new file mode 100644 index 000000000..98fb6a686 --- /dev/null +++ b/tests/bugs/glsl-int-swizzle.slang.expected.txt @@ -0,0 +1,4 @@ +1 +1 +1 +1 |
