summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-emit.cpp')
-rw-r--r--source/slang/slang-emit.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 103cd15ab..caa8ca8ea 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -58,6 +58,7 @@
#include "slang-ir-metadata.h"
#include "slang-ir-optix-entry-point-uniforms.h"
#include "slang-ir-pytorch-cpp-binding.h"
+#include "slang-ir-redundancy-removal.h"
#include "slang-ir-restructure.h"
#include "slang-ir-restructure-scoping.h"
#include "slang-ir-sccp.h"
@@ -415,6 +416,37 @@ bool checkStaticAssert(IRInst* inst, DiagnosticSink* sink)
return false;
}
+static void unexportNonEmbeddableDXIL(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)
+ {
+ auto operand = type->getOperand(aa);
+ if (operand->getOp() == kIROp_HLSLStructuredBufferType ||
+ operand->getOp() == kIROp_MatrixType)
+ {
+ if (auto dec = inst->findDecoration<IRPublicDecoration>())
+ {
+ dec->removeAndDeallocate();
+ }
+ if (auto dec = inst->findDecoration<IRDownstreamModuleExportDecoration>())
+ {
+ dec->removeAndDeallocate();
+ }
+ break;
+ }
+ }
+ }
+ }
+}
+
Result linkAndOptimizeIR(
CodeGenContext* codeGenContext,
LinkingAndOptimizationOptions const& options,
@@ -746,6 +778,11 @@ Result linkAndOptimizeIR(
break;
}
+ if (codeGenContext->removeAvailableInDXIL)
+ {
+ removeAvailableInDownstreamModuleDecorations(irModule);
+ }
+
if (targetProgram->getOptionSet().shouldRunNonEssentialValidation())
{
checkForRecursiveTypes(irModule, sink);
@@ -1453,6 +1490,13 @@ Result linkAndOptimizeIR(
auto metadata = new ArtifactPostEmitMetadata;
outLinkedIR.metadata = metadata;
+ if (targetProgram->getOptionSet().getBoolOption(CompilerOptionName::EmbedDXIL))
+ {
+ // 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);
+ }
+
collectMetadata(irModule, *metadata);
outLinkedIR.metadata = metadata;