From e8a5cc5e3b1f14452efce0d2474503f8766ca562 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Thu, 16 Jan 2025 12:08:11 +0200 Subject: [PATCH 1/2] Add test that reproduces the issue in #5986 --- tests/wgsl/global-call.slang | 20 ++++++++++++++++++++ tests/wgsl/global-call.slang.expected.txt | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 tests/wgsl/global-call.slang create mode 100644 tests/wgsl/global-call.slang.expected.txt diff --git a/tests/wgsl/global-call.slang b/tests/wgsl/global-call.slang new file mode 100644 index 0000000000..7b67f21398 --- /dev/null +++ b/tests/wgsl/global-call.slang @@ -0,0 +1,20 @@ +//TEST(compute):COMPARE_COMPUTE:-shaderobj + +//TEST_INPUT:ubuffer(data=[3 7 8 10], stride=4):name=inputBuffer +RWStructuredBuffer inputBuffer; + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +uint f(uint a) +{ + return a*inputBuffer[0]; +} + +static uint b = f(2); + +[numthreads(1,1,1)] +void computeMain() +{ + outputBuffer[0] = b; +} \ No newline at end of file diff --git a/tests/wgsl/global-call.slang.expected.txt b/tests/wgsl/global-call.slang.expected.txt new file mode 100644 index 0000000000..e20d75ba3b --- /dev/null +++ b/tests/wgsl/global-call.slang.expected.txt @@ -0,0 +1,4 @@ +6 +0 +0 +0 From f86e173800dc9c13bfe91734dbd25f36c695d072 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Thu, 16 Jan 2025 13:57:55 +0200 Subject: [PATCH 2/2] Call moveGlobalVarInitializationToEntryPoints for WGSL as well This closes #5986. --- source/slang/slang-emit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 176cd05586..4fee5c4407 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -1471,6 +1471,7 @@ Result linkAndOptimizeIR( default: break; case CodeGenTarget::GLSL: + case CodeGenTarget::WGSL: moveGlobalVarInitializationToEntryPoints(irModule); break; // For SPIR-V to SROA across 2 entry-points a value must not be a global