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-compiler-tu.cpp | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'source/slang/slang-compiler-tu.cpp') diff --git a/source/slang/slang-compiler-tu.cpp b/source/slang/slang-compiler-tu.cpp index fe778148b..57a1133fc 100644 --- a/source/slang/slang-compiler-tu.cpp +++ b/source/slang/slang-compiler-tu.cpp @@ -54,7 +54,7 @@ namespace Slang * Precompile the module for the given target. * * This function creates a target program and emits the precompiled blob as - * an embedded blob in the module IR, e.g. DXIL. + * an embedded blob in the module IR, e.g. DXIL, SPIR-V. * Because the IR for the Slang Module may violate the restrictions of the * target language, the emitted target blob may not be able to include the * full module, but rather only the subset that can be precompiled. For @@ -77,7 +77,7 @@ namespace Slang * in the linked IR which survived the additional pruning. * * Functions that are rejected after linking+legalization (inside - * emitPrecompiled*): + * emitPrecompiledDownstreamIR): * - (DXIL) Functions that return or take a HLSLStructuredBufferType * - (DXIL) Functions that return or take a Matrix type * @@ -86,17 +86,13 @@ namespace Slang * phase of filtering. * * The original module IR functions matching those are then marked with - * "AvailableIn*" (e.g. AvailableInDXILDecoration) to indicate to future + * "AvailableInDownstreamIRDecoration" to indicate to future * module users which functions are present in the precompiled blob. */ SLANG_NO_THROW SlangResult SLANG_MCALL Module::precompileForTarget( SlangCompileTarget target, slang::IBlob** outDiagnostics) { - if (target != SLANG_DXIL) - { - return SLANG_FAIL; - } CodeGenTarget targetEnum = CodeGenTarget(target); auto module = getIRModule(); @@ -130,10 +126,15 @@ namespace Slang { case CodeGenTarget::DXIL: tp.getOptionSet().add(CompilerOptionName::Profile, Profile::RawEnum::DX_Lib_6_6); - tp.getOptionSet().add(CompilerOptionName::EmbedDXIL, true); break; + case CodeGenTarget::SPIRV: + break; + default: + return SLANG_FAIL; } + tp.getOptionSet().add(CompilerOptionName::EmbedDownstreamIR, true); + CodeGenContext::EntryPointIndices entryPointIndices; entryPointIndices.setCount(entryPointCount); @@ -166,7 +167,7 @@ namespace Slang } ComPtr outArtifact; - SlangResult res = codeGenContext.emitPrecompiledDXIL(outArtifact); + SlangResult res = codeGenContext.emitPrecompiledDownstreamIR(outArtifact); sink.getBlobIfNeeded(outDiagnostics); if (res != SLANG_OK) @@ -183,7 +184,8 @@ namespace Slang for (const auto& mangledName : metadata->getExportedFunctionMangledNames()) { auto moduleInst = nameToFunction[mangledName]; - builder.addDecoration(moduleInst, kIROp_AvailableInDXILDecoration); + builder.addDecoration(moduleInst, kIROp_AvailableInDownstreamIRDecoration, + builder.getIntValue(builder.getIntType(), (int)targetReq->getTarget())); auto moduleDec = moduleInst->findDecoration(); moduleDec->removeAndDeallocate(); } @@ -207,12 +209,7 @@ namespace Slang // Add the precompiled blob to the module builder.setInsertInto(module); - switch (targetReq->getTarget()) - { - case CodeGenTarget::DXIL: - builder.emitEmbeddedDXIL(blob); - break; - } + builder.emitEmbeddedDownstreamIR(targetReq->getTarget(), blob); return SLANG_OK; } -- cgit v1.2.3