diff --git a/include/slang.h b/include/slang.h index 3f503a611a..e4ae6b5227 100644 --- a/include/slang.h +++ b/include/slang.h @@ -958,8 +958,8 @@ extern "C" // precompiled modules if it is up-to-date with its source. EmbedDXIL, // bool - EmbedSPIRV, // bool ForceDXLayout, // bool + EmbedSPIRV, // bool CountOf, }; @@ -4932,9 +4932,9 @@ namespace slang virtual SLANG_NO_THROW void SLANG_MCALL setEmbedDXIL(bool value) = 0; - virtual SLANG_NO_THROW void SLANG_MCALL setEmbedSPIRV(bool value) = 0; - virtual SLANG_NO_THROW void SLANG_MCALL setTargetForceDXLayout(int targetIndex, bool value) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setEmbedSPIRV(bool value) = 0; }; #define SLANG_UUID_ICompileRequest ICompileRequest::getTypeGuid() diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 8f4501c2b2..be96357fc6 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3796,6 +3796,17 @@ struct SPIRVEmitContext } break; } + case kIROp_DownstreamModuleExportDecoration: + { + requireSPIRVCapability(SpvCapabilityLinkage); + auto name = decoration->getParent()->findDecoration()->getMangledName(); + emitInst(getSection(SpvLogicalSectionID::Annotations), + decoration, + SpvOpDecorate, + dstID, + SpvDecorationLinkageAttributes, name, SpvLinkageTypeExport); + break; + } // ... } @@ -6710,12 +6721,28 @@ SlangResult emitSPIRVFromIR( #endif auto shouldPreserveParams = codeGenContext->getTargetProgram()->getOptionSet().getBoolOption(CompilerOptionName::PreserveParameters); + auto generateWholeProgram = codeGenContext->getTargetProgram()->getOptionSet().getBoolOption(CompilerOptionName::GenerateWholeProgram); for (auto inst : irModule->getGlobalInsts()) { if (as(inst)) + { context.ensureInst(inst); + + } if (shouldPreserveParams && as(inst)) + { context.ensureInst(inst); + } + if (generateWholeProgram) + { + if (auto func = as(inst)) + { + if (func->findDecoration()) + { + context.ensureInst(inst); + } + } + } } // Emit source language info. diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 87c9158467..da83c50a65 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -449,8 +449,24 @@ static void unexportNonEmbeddableDXIL(IRModule* irModule) static void unexportNonEmbeddableSPIRV(IRModule* irModule) { - SLANG_UNUSED(irModule); - return; + for (auto inst : irModule->getGlobalInsts()) + { + if (inst->getOp() == kIROp_Func) + { + // SPIR-V does not allow exporting entry points + if (inst->findDecoration()) + { + if (auto dec = inst->findDecoration()) + { + dec->removeAndDeallocate(); + } + if (auto dec = inst->findDecoration()) + { + dec->removeAndDeallocate(); + } + } + } + } } Result linkAndOptimizeIR( @@ -1504,7 +1520,8 @@ Result linkAndOptimizeIR( } else if (targetProgram->getOptionSet().getBoolOption(CompilerOptionName::EmbedSPIRV)) { - // TBD what limitation SPIRV has. + // Honor SPIR-V library restrictions for embedded precompilation, such as + // not exporting entrypoints. unexportNonEmbeddableSPIRV(irModule); } diff --git a/tests/library/precompiled-module-library-resource.slang b/tests/library/precompiled-module-library-resource.slang index 79c3daaa10..f1ff6f5488 100644 --- a/tests/library/precompiled-module-library-resource.slang +++ b/tests/library/precompiled-module-library-resource.slang @@ -1,9 +1,11 @@ // precompiled-module-library-resource.slang -// Compile this library source with -embed-dxil option. Tests that modules can be -// precompiled to dxil despite having resource parameters or return types. +// Compile this library source with -embed-dxil and -embed-spirv options. +// Tests that modules can be precompiled to dxil despite having resource +// parameters or return types. -//TEST(windows):COMPILE: tests/library/precompiled-module-library-resource.slang -o tests/library/precompiled-module-library-resource.slang-module -embed-dxil -profile lib_6_6 -incomplete-library +//TEST(windows):COMPILE: tests/library/precompiled-module-library-resource.slang -o tests/library/precompiled-module-library-resource-dxil.slang-module -embed-dxil -profile lib_6_6 -incomplete-library +//TEST:COMPILE: tests/library/precompiled-module-library-resource.slang -o tests/library/precompiled-module-library-resource-spv.slang-module -embed-spirv -incomplete-library module "precompiled-module-library-resource";