From 46529df2c4f73a4655bdd79d48004f29374a99a8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 6 Nov 2023 14:40:38 -0800 Subject: Fix ICE when lowering an associatedtype declref from an derived interface. (#3312) * Fix ICE when lowering an associatedtype declref from an derived interface. * Fixes. * Fix test. * Fix GLSL/SPIRV image subscript swizzle store regression. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-emit-spirv.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/slang/slang-emit-spirv.cpp') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index f26340969..19c46f373 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3827,17 +3827,31 @@ struct SPIRVEmitContext SpvInst* emitSwizzleSet(SpvInstParent* parent, IRSwizzleSet* inst) { + if (inst->getElementCount() == 1) + { + auto index = inst->getElementIndex(0); + if (auto intLit = as(index)) + return emitOpCompositeInsert(parent, inst, inst->getFullType(), inst->getSource(), inst->getBase(), makeArray(SpvLiteralInteger::from32((uint32_t)intLit->value.intVal))); + } auto resultVectorType = as(inst->getDataType()); List shuffleIndices; shuffleIndices.setCount((Index)getIntVal(resultVectorType->getElementCount())); for (Index i = 0; i < shuffleIndices.getCount(); i++) shuffleIndices[i] = SpvLiteralInteger::from32((int32_t)i); + for (UInt i = 0; i < inst->getElementCount(); i++) { auto destIndex = (int32_t)getIntVal(inst->getElementIndex(i)); SLANG_ASSERT(destIndex < shuffleIndices.getCount()); shuffleIndices[destIndex] = SpvLiteralInteger::from32((int32_t)(i + shuffleIndices.getCount())); } + auto source = inst->getSource(); + if (!as(source->getDataType())) + { + IRBuilder builder(inst); + builder.setInsertBefore(inst); + source = builder.emitMakeVectorFromScalar(resultVectorType, source); + } return emitOpVectorShuffle(parent, inst, inst->getFullType(), inst->getBase(), inst->getSource(), shuffleIndices.getArrayView()); } -- cgit v1.2.3