summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit.cpp
diff options
context:
space:
mode:
authorcheneym2 <acheney@nvidia.com>2024-09-05 14:59:28 -0400
committerGitHub <noreply@github.com>2024-09-05 11:59:28 -0700
commit313677160a186efebf83fab4df7d08dd119a5cd2 (patch)
treee12e159846f0b7b0e3567d028ad4a57cd9f001aa /source/slang/slang-emit.cpp
parent33e8bfd43f66613f6f834fb0e1816ef43071f2e4 (diff)
Initial -embed-spirv support (#4974)
* Initial -embed-spirv support Add support for SPIR-V precompilation using the framework established for DXIL. Work on #4883 * SLANG_UNUSED * Add linkage attributes to exported spirv functions * Combine DXIL and SPIRV paths * Whitespace fix * Merge remaining precompiled spirv/dxil paths * Change inst accessors to return codegentarget * Add unit test for precompiled spirv --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-emit.cpp')
-rw-r--r--source/slang/slang-emit.cpp58
1 files changed, 36 insertions, 22 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index caa8ca8ea..ed9e90462 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -416,31 +416,47 @@ bool checkStaticAssert(IRInst* inst, DiagnosticSink* sink)
return false;
}
-static void unexportNonEmbeddableDXIL(IRModule* irModule)
+static void unexportNonEmbeddableIR(CodeGenTarget target, IRModule* irModule)
{
for (auto inst : irModule->getGlobalInsts())
{
if (inst->getOp() == kIROp_Func)
{
- // DXIL does not permit HLSLStructureBufferType in exported functions
- // or sadly Matrices (https://github.com/shader-slang/slang/issues/4880)
- auto type = as<IRFuncType>(inst->getFullType());
- auto argCount = type->getOperandCount();
- for (UInt aa = 0; aa < argCount; ++aa)
+ bool remove = false;
+ if (target == CodeGenTarget::HLSL)
{
- auto operand = type->getOperand(aa);
- if (operand->getOp() == kIROp_HLSLStructuredBufferType ||
- operand->getOp() == kIROp_MatrixType)
+ // DXIL does not permit HLSLStructureBufferType in exported functions
+ // or sadly Matrices (https://github.com/shader-slang/slang/issues/4880)
+ auto type = as<IRFuncType>(inst->getFullType());
+ auto argCount = type->getOperandCount();
+ for (UInt aa = 0; aa < argCount; ++aa)
{
- if (auto dec = inst->findDecoration<IRPublicDecoration>())
+ auto operand = type->getOperand(aa);
+ if (operand->getOp() == kIROp_HLSLStructuredBufferType ||
+ operand->getOp() == kIROp_MatrixType)
{
- dec->removeAndDeallocate();
+ remove = true;
+ break;
}
- if (auto dec = inst->findDecoration<IRDownstreamModuleExportDecoration>())
- {
- dec->removeAndDeallocate();
- }
- break;
+ }
+ }
+ else if (target == CodeGenTarget::SPIRV)
+ {
+ // SPIR-V does not allow exporting entry points
+ if (inst->findDecoration<IREntryPointDecoration>())
+ {
+ remove = true;
+ }
+ }
+ if (remove)
+ {
+ if (auto dec = inst->findDecoration<IRPublicDecoration>())
+ {
+ dec->removeAndDeallocate();
+ }
+ if (auto dec = inst->findDecoration<IRDownstreamModuleExportDecoration>())
+ {
+ dec->removeAndDeallocate();
}
}
}
@@ -778,9 +794,9 @@ Result linkAndOptimizeIR(
break;
}
- if (codeGenContext->removeAvailableInDXIL)
+ if (codeGenContext->removeAvailableInDownstreamIR)
{
- removeAvailableInDownstreamModuleDecorations(irModule);
+ removeAvailableInDownstreamModuleDecorations(target, irModule);
}
if (targetProgram->getOptionSet().shouldRunNonEssentialValidation())
@@ -1490,11 +1506,9 @@ Result linkAndOptimizeIR(
auto metadata = new ArtifactPostEmitMetadata;
outLinkedIR.metadata = metadata;
- if (targetProgram->getOptionSet().getBoolOption(CompilerOptionName::EmbedDXIL))
+ if (targetProgram->getOptionSet().getBoolOption(CompilerOptionName::EmbedDownstreamIR))
{
- // We need to make sure that we don't try to export any functions that can't
- // be part of a DXIL library interface, eg. with resources.
- unexportNonEmbeddableDXIL(irModule);
+ unexportNonEmbeddableIR(target, irModule);
}
collectMetadata(irModule, *metadata);