From 313677160a186efebf83fab4df7d08dd119a5cd2 Mon Sep 17 00:00:00 2001 From: cheneym2 Date: Thu, 5 Sep 2024 14:59:28 -0400 Subject: 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 --- source/slang/slang-emit.cpp | 58 ++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'source/slang/slang-emit.cpp') 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(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(inst->getFullType()); + auto argCount = type->getOperandCount(); + for (UInt aa = 0; aa < argCount; ++aa) { - if (auto dec = inst->findDecoration()) + auto operand = type->getOperand(aa); + if (operand->getOp() == kIROp_HLSLStructuredBufferType || + operand->getOp() == kIROp_MatrixType) { - dec->removeAndDeallocate(); + remove = true; + break; } - if (auto dec = inst->findDecoration()) - { - dec->removeAndDeallocate(); - } - break; + } + } + else if (target == CodeGenTarget::SPIRV) + { + // SPIR-V does not allow exporting entry points + if (inst->findDecoration()) + { + remove = true; + } + } + if (remove) + { + if (auto dec = inst->findDecoration()) + { + dec->removeAndDeallocate(); + } + if (auto dec = inst->findDecoration()) + { + 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); -- cgit v1.2.3