Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move global variable initialization into entry points for WGSL #6106

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading