Skip to content

Commit

Permalink
Move global variable initialization into entry points for WGSL (#6106)
Browse files Browse the repository at this point in the history
* Add test that reproduces the issue in #5986

* Call moveGlobalVarInitializationToEntryPoints for WGSL as well

This closes #5986.

---------

Co-authored-by: Yong He <[email protected]>
  • Loading branch information
aleino-nv and csyonghe authored Jan 17, 2025
1 parent 1b7c242 commit dfb369e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/slang/slang-emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/wgsl/global-call.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//TEST(compute):COMPARE_COMPUTE:-shaderobj

//TEST_INPUT:ubuffer(data=[3 7 8 10], stride=4):name=inputBuffer
RWStructuredBuffer<uint> inputBuffer;

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<uint> outputBuffer;

uint f(uint a)
{
return a*inputBuffer[0];
}

static uint b = f(2);

[numthreads(1,1,1)]
void computeMain()
{
outputBuffer[0] = b;
}
4 changes: 4 additions & 0 deletions tests/wgsl/global-call.slang.expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
6
0
0
0

0 comments on commit dfb369e

Please sign in to comment.