summaryrefslogtreecommitdiffstats
path: root/tools/gfx
diff options
context:
space:
mode:
authorcheneym2 <acheney@nvidia.com>2025-03-05 16:45:03 -0500
committerGitHub <noreply@github.com>2025-03-05 13:45:03 -0800
commit0634684495f709fe3594fdcd483cfce7933e54eb (patch)
tree7a5d99705475a885b0d22169a56678a399133d12 /tools/gfx
parent5248a0254a48382d06ecb190c9f87c0ab62ff534 (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 'tools/gfx')
-rw-r--r--tools/gfx/renderer-shared.cpp10
-rw-r--r--tools/gfx/vulkan/vk-device.h3
-rw-r--r--tools/gfx/vulkan/vk-shader-program.cpp16
3 files changed, 22 insertions, 7 deletions
diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp
index ae4ea3eef..edd271ecb 100644
--- a/tools/gfx/renderer-shared.cpp
+++ b/tools/gfx/renderer-shared.cpp
@@ -1133,11 +1133,13 @@ Result ShaderProgramBase::compileShaders(RendererBase* device)
kernelCodes.add(downstreamIR);
}
- // If target precompilation was used, kernelCode may only represent the
- // glue code holding together the bits of precompiled target IR.
- // Collect those dependency target IRs too.
+ // If target precompilation with deferred downstream linking is enabled,
+ // kernelCode may only represent the glue code holding together the
+ // bits of precompiled target IR. It's the application's job to pull it
+ // together. Collect those dependency target IRs too.
ComPtr<slang::IModulePrecompileService_Experimental> componentPrecompileService;
- if (entryPointComponent->queryInterface(
+ if (this->desc.downstreamLinkMode == DownstreamLinkMode::Deferred &&
+ entryPointComponent->queryInterface(
slang::IModulePrecompileService_Experimental::getTypeGuid(),
(void**)componentPrecompileService.writeRef()) == SLANG_OK)
{
diff --git a/tools/gfx/vulkan/vk-device.h b/tools/gfx/vulkan/vk-device.h
index 27cc4c3ce..06e19ad7e 100644
--- a/tools/gfx/vulkan/vk-device.h
+++ b/tools/gfx/vulkan/vk-device.h
@@ -223,6 +223,9 @@ public:
VkSampler m_defaultSampler;
RefPtr<FramebufferImpl> m_emptyFramebuffer;
+
+ // If true, slang will skip downstream linking, so we need to do it ourselves
+ bool m_skipsDownstreamLinking = false;
};
} // namespace vk
diff --git a/tools/gfx/vulkan/vk-shader-program.cpp b/tools/gfx/vulkan/vk-shader-program.cpp
index 1627c95a7..2dd9b0326 100644
--- a/tools/gfx/vulkan/vk-shader-program.cpp
+++ b/tools/gfx/vulkan/vk-shader-program.cpp
@@ -74,10 +74,20 @@ Result ShaderProgramImpl::createShaderModule(
slang::EntryPointReflection* entryPointInfo,
List<ComPtr<ISlangBlob>>& kernelCodes)
{
- ComPtr<ISlangBlob> linkedKernel = m_device->m_glslang.linkSPIRV(kernelCodes);
- if (!linkedKernel)
+ ComPtr<ISlangBlob> linkedKernel;
+ ComPtr<slang::ISession> slangSession;
+ m_device->getSlangSession(slangSession.writeRef());
+ if (kernelCodes.getCount() == 1)
{
- return SLANG_FAIL;
+ linkedKernel = kernelCodes[0];
+ }
+ else
+ {
+ linkedKernel = m_device->m_glslang.linkSPIRV(kernelCodes);
+ if (!linkedKernel)
+ {
+ return SLANG_FAIL;
+ }
}
m_codeBlobs.add(linkedKernel);