summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-05-12 15:32:25 -0500
committerGitHub <noreply@github.com>2025-05-12 13:32:25 -0700
commit54ff7fd879e71f51ed3c0fda16224cbbcf0831eb (patch)
tree4136a3b3fcf762757a237504100f8c5b1aef5967 /source
parent4c76b275907cf2d764f3fc51468d1c58635a10c1 (diff)
Ensure to emit 32-bit type for bitfield operations for SPIRV (#7046)
Close #7014
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-spirv-legalize.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp
index 82b424daa..0287ae81a 100644
--- a/source/slang/slang-ir-spirv-legalize.cpp
+++ b/source/slang/slang-ir-spirv-legalize.cpp
@@ -1471,6 +1471,39 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
}
}
+ // TODO: Currently SPIRV doesn't support non-32-bit integer types for bitfield extract and
+ // insert. We will relax this restriction once this is done:
+ // https://github.com/shader-slang/slang/issues/7015.
+ void processBitFieldOp(IRInst* inst)
+ {
+ auto dataType = inst->getDataType();
+ IRVectorType* vectorType = as<IRVectorType>(dataType);
+ Slang::IRType* elementType = dataType;
+ if (vectorType)
+ elementType = vectorType->getElementType();
+
+ const IntInfo i = getIntTypeInfo(elementType);
+
+ // SPIRV doesn't support non-32bit integer types, so we need to convert
+ if (i.width < 32)
+ {
+ IRBuilder builder(inst);
+ builder.setInsertBefore(inst);
+ IRType* intType = i.isSigned ? builder.getIntType() : builder.getUIntType();
+ auto targetType = vectorType
+ ? builder.getVectorType(intType, vectorType->getElementCount())
+ : intType;
+ auto baseInst = builder.emitCast(targetType, inst->getOperand(0));
+ builder.replaceOperand(inst->getOperands(), baseInst);
+ if (inst->getOp() == kIROp_BitfieldInsert)
+ {
+ auto insertInst = builder.emitCast(targetType, inst->getOperand(1));
+ builder.replaceOperand(inst->getOperands() + 1, insertInst);
+ }
+ inst->setFullType(intType);
+ }
+ }
+
void legalizeSPIRVEntryPoint(IRFunc* func, IREntryPointDecoration* entryPointDecor)
{
auto stage = entryPointDecor->getProfile().getStage();
@@ -1704,6 +1737,11 @@ struct SPIRVLegalizationContext : public SourceEmitterBase
case kIROp_SPIRVAsm:
processSPIRVAsm(as<IRSPIRVAsm>(inst));
break;
+ case kIROp_BitfieldExtract:
+ case kIROp_BitfieldInsert:
+ processBitFieldOp(inst);
+ break;
+
case kIROp_DebugValue:
if (!isSimpleDataType(as<IRDebugValue>(inst)->getDebugVar()->getDataType()))
inst->removeAndDeallocate();