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 /source/slang/slang-ir-peephole.cpp | |
| 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>
Diffstat (limited to 'source/slang/slang-ir-peephole.cpp')
| -rw-r--r-- | source/slang/slang-ir-peephole.cpp | 25 |
1 files changed, 25 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) |
