diff options
| author | cheneym2 <acheney@nvidia.com> | 2025-03-05 16:45:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-05 13:45:03 -0800 |
| commit | 0634684495f709fe3594fdcd483cfce7933e54eb (patch) | |
| tree | 7a5d99705475a885b0d22169a56678a399133d12 /source/compiler-core/slang-glslang-compiler.cpp | |
| parent | 5248a0254a48382d06ecb190c9f87c0ab62ff534 (diff) | |
Support SPIR-V deferred linking option (#6500)
The new option "SkipDownstreamLinking" will defer final downstream IR
linking to the user application. This option only has an effect if
there are modules that were precompiled to the target IR using
precompileForTarget().
Until now, the default behavior for SPIR-V was to use deferred linking, and
the default behavior for DXIL was to use immediate/internal linking in Slang.
This change only affects the SPIR-V behavior such that both deferred and
non-deferred linking is supported based on the new option.
To support the non-deferred option, Slang will internally call into
SPIRV-Tools-link to reconstitute a complete SPIR-V shader program when
necessary (due to modules having been precompiled to target IR).
Otherwise, if SkipDownstreamLinking is enabled, the shader returned by
e.g. getTargetCode() or getEntryPointCode() may have import linkage to
the SPIR-V embedded in the constituent modules.
Closes #4994
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/compiler-core/slang-glslang-compiler.cpp')
| -rw-r--r-- | source/compiler-core/slang-glslang-compiler.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/source/compiler-core/slang-glslang-compiler.cpp b/source/compiler-core/slang-glslang-compiler.cpp index b619f468f..540b437c5 100644 --- a/source/compiler-core/slang-glslang-compiler.cpp +++ b/source/compiler-core/slang-glslang-compiler.cpp @@ -49,6 +49,11 @@ public: validate(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE; virtual SLANG_NO_THROW SlangResult SLANG_MCALL disassemble(const uint32_t* contents, int contentsSize) SLANG_OVERRIDE; + int link( + const uint32_t** modules, + const uint32_t* moduleSizes, + const uint32_t moduleCount, + IArtifact** outArtifact) SLANG_OVERRIDE; /// Must be called before use SlangResult init(ISlangSharedLibrary* library); @@ -66,6 +71,7 @@ protected: glslang_CompileFunc_1_2 m_compile_1_2 = nullptr; glslang_ValidateSPIRVFunc m_validate = nullptr; glslang_DisassembleSPIRVFunc m_disassemble = nullptr; + glslang_LinkSPIRVFunc m_link = nullptr; ComPtr<ISlangSharedLibrary> m_sharedLibrary; @@ -80,6 +86,7 @@ SlangResult GlslangDownstreamCompiler::init(ISlangSharedLibrary* library) m_validate = (glslang_ValidateSPIRVFunc)library->findFuncByName("glslang_validateSPIRV"); m_disassemble = (glslang_DisassembleSPIRVFunc)library->findFuncByName("glslang_disassembleSPIRV"); + m_link = (glslang_LinkSPIRVFunc)library->findFuncByName("glslang_linkSPIRV"); if (m_compile_1_0 == nullptr && m_compile_1_1 == nullptr && m_compile_1_2 == nullptr) { @@ -323,6 +330,32 @@ SlangResult GlslangDownstreamCompiler::disassemble(const uint32_t* contents, int return SLANG_FAIL; } +SlangResult GlslangDownstreamCompiler::link( + const uint32_t** modules, + const uint32_t* moduleSizes, + const uint32_t moduleCount, + IArtifact** outArtifact) +{ + glslang_LinkRequest request; + memset(&request, 0, sizeof(request)); + + request.modules = modules; + request.moduleSizes = moduleSizes; + request.moduleCount = moduleCount; + + if (!m_link(&request)) + { + return SLANG_FAIL; + } + + auto artifact = ArtifactUtil::createArtifactForCompileTarget(SLANG_SPIRV); + artifact->addRepresentationUnknown( + Slang::RawBlob::create(request.linkResult, request.linkResultSize * sizeof(uint32_t))); + + *outArtifact = artifact.detach(); + return SLANG_OK; +} + bool GlslangDownstreamCompiler::canConvert(const ArtifactDesc& from, const ArtifactDesc& to) { // Can only disassemble blobs that are SPIR-V @@ -467,6 +500,14 @@ SlangResult SpirvDisDownstreamCompilerUtil::locateCompilers( return locateGlslangSpirvDownstreamCompiler(path, loader, set, SLANG_PASS_THROUGH_SPIRV_DIS); } +SlangResult SpirvLinkDownstreamCompilerUtil::locateCompilers( + const String& path, + ISlangSharedLibraryLoader* loader, + DownstreamCompilerSet* set) +{ + return locateGlslangSpirvDownstreamCompiler(path, loader, set, SLANG_PASS_THROUGH_SPIRV_LINK); +} + #else // SLANG_ENABLE_GLSLANG_SUPPORT /* static */ SlangResult GlslangDownstreamCompilerUtil::locateCompilers( |
