summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-spirv.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-08-29 16:43:25 -0700
committerGitHub <noreply@github.com>2023-08-29 16:43:25 -0700
commit019f702e24d2d1d6ecf53d71f87776a83db96608 (patch)
treefc75001b121794b51d60a19d48b15f95797932a4 /source/slang/slang-emit-spirv.cpp
parentf3ecf978a07b02681a4d70a9d83991e6661bf753 (diff)
Wave intrinsics. (#3164)
* Wave intrinsics. * scalar intrinsics. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 462f408ab..a203f4a80 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -1454,6 +1454,8 @@ struct SPIRVEmitContext
return emitGetStringHash(inst);
default:
{
+ if (as<IRSPIRVAsmOperand>(inst))
+ return nullptr;
String e = "Unhandled global inst in spirv-emit:\n"
+ dumpIRToString(inst, {IRDumpOptions::Mode::Detailed, 0});
SLANG_UNIMPLEMENTED_X(e.begin());
@@ -1854,6 +1856,8 @@ struct SPIRVEmitContext
{
default:
{
+ if (as<IRSPIRVAsmOperand>(inst))
+ return nullptr;
String e = "Unhandled local inst in spirv-emit:\n"
+ dumpIRToString(inst, {IRDumpOptions::Mode::Detailed, 0});
SLANG_UNIMPLEMENTED_X(e.getBuffer());
@@ -2175,7 +2179,8 @@ struct SPIRVEmitContext
auto entryPointDecor = cast<IREntryPointDecoration>(decoration);
auto spvStage = mapStageToExecutionModel(entryPointDecor->getProfile().getStage());
auto name = entryPointDecor->getName()->getStringSlice();
- List<IRInst*> params;
+ List<SpvInst*> params;
+ HashSet<SpvInst*> paramsSet;
// `interface` part: reference all global variables that are used by this entrypoint.
// TODO: we may want to perform more accurate tracking.
for (auto globalInst : m_irModule->getModuleInst()->getChildren())
@@ -2184,10 +2189,27 @@ struct SPIRVEmitContext
{
case kIROp_GlobalVar:
case kIROp_GlobalParam:
- params.add(globalInst);
+ {
+ SpvInst* spvGlobalInst;
+ if (m_mapIRInstToSpvInst.tryGetValue(globalInst, spvGlobalInst))
+ {
+ paramsSet.add(spvGlobalInst);
+ params.add(spvGlobalInst);
+ }
+ break;
+ }
+ default:
break;
}
}
+
+ // Add remaining builtin variables that does not have a corresponding IR global var/param.
+ // These variables could be added from SPIRV ASM blocks.
+ for (auto builtinVar : m_builtinGlobalVars)
+ {
+ if (paramsSet.add(builtinVar.second))
+ params.add(builtinVar.second);
+ }
emitOpEntryPoint(
section,
decoration,
@@ -3838,6 +3860,18 @@ struct SPIRVEmitContext
}
};
+ switch (opcode)
+ {
+ case SpvOpCapability:
+ requireSPIRVCapability((SpvCapability)getIntVal(spvInst->getOperand(1)->getOperand(0)));
+ continue;
+ case SpvOpExtension:
+ ensureExtensionDeclaration(as<IRStringLit>(spvInst->getOperand(1)->getOperand(0))->getStringSlice());
+ continue;
+ default:
+ break;
+ }
+
last = emitInstCustomOperandFunc(
parentForOpCode(opcode, parent),
// We want the "result instruction" to refer to the top level
@@ -3922,6 +3956,20 @@ struct SPIRVEmitContext
emitOperand(id);
break;
}
+ case kIROp_SPIRVAsmOperandBuiltinVar:
+ {
+ const auto kind = (SpvBuiltIn)(getIntVal(operand->getOperand(0)));
+ IRBuilder builder(operand);
+ builder.setInsertBefore(operand);
+ auto varInst = getBuiltinGlobalVar(builder.getPtrType(kIROp_PtrType, operand->getDataType(), SpvStorageClassInput), kind);
+ emitOperand(varInst);
+ break;
+ }
+ case kIROp_SPIRVAsmOperandGLSL450Set:
+ {
+ emitOperand(getGLSL450ExtInst());
+ break;
+ }
default:
SLANG_UNREACHABLE("Unhandled case in emitSPIRVAsm");
}