From 537697d3aa21b418c348b1017005603668b6a4cb Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Thu, 16 Oct 2025 21:53:10 +0300 Subject: Inline global constants for shader style CPU targets (#8686) On the shader-host-callable target, test `gh-4874.slang` generates IR that contains global constants referencing global params. These need to get inlined into functions, as otherwise `introduceExplicitGlobalContext()` will fail with "no outer func at use site for global", making the test crash the compiler. --- source/slang/slang-emit.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index d5e89b1fe..bdd7dfe10 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -1270,7 +1270,13 @@ Result linkAndOptimizeIR( // For CUDA targets, always inline global constants to avoid dynamic initialization // of __device__ variables rejected by NVRTC. This runs independently of the broader // resource/existential type legalization, which remains disabled for CUDA. - if (target == CodeGenTarget::CUDASource || options.shouldLegalizeExistentialAndResourceTypes) + // + // We also need this pass on the CPU targets in shader mode, as global + // constants may reference global parameters, which can't be emitted as + // constants. + if (target == CodeGenTarget::CUDASource || + (isCPUTarget(targetRequest) && isKernelTarget(target)) || + options.shouldLegalizeExistentialAndResourceTypes) { inlineGlobalConstantsForLegalization(irModule); } -- cgit v1.2.3