From 3979660d4fe1fd6c1f1d9b8956e96817e17c3f4e Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 13 Dec 2023 15:15:19 -0800 Subject: Fix GLSL static initialization bug. (#3409) * Fix GLSL static initialization bug. Fixes #3408. * Update comment. * Fold global var initializer as an expression if possible. --------- Co-authored-by: Yong He --- tests/bugs/gh-2959.slang | 16 ++++++++++++++++ tests/bugs/gh-3408.slang | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/bugs/gh-2959.slang create mode 100644 tests/bugs/gh-3408.slang (limited to 'tests/bugs') diff --git a/tests/bugs/gh-2959.slang b/tests/bugs/gh-2959.slang new file mode 100644 index 000000000..b478fa938 --- /dev/null +++ b/tests/bugs/gh-2959.slang @@ -0,0 +1,16 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +static uint g_values[2] = { 0, 1 }; + +[numthreads(2, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + + outputBuffer[tid] = g_values[tid]; + // BUF: 0 + // BUF: 1 +} diff --git a/tests/bugs/gh-3408.slang b/tests/bugs/gh-3408.slang new file mode 100644 index 000000000..a24befe91 --- /dev/null +++ b/tests/bugs/gh-3408.slang @@ -0,0 +1,21 @@ +//TEST:SIMPLE(filecheck=CHECK): -entry computeMain -stage compute -target glsl +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -shaderobj -vk + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + // CHECK-NOT: {{\b}}if{{\b}} + + int tid = dispatchThreadID.x; + + static int a[] = { 1, 2 }; + + outputBuffer[dispatchThreadID.x] = a[tid & 1]; + // BUF: 1 + // BUF: 2 + // BUF: 1 + // BUF: 2 +} -- cgit v1.2.3