yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Sai Praveen BangaruFix issue in multi-level break elimination by handling multi-level continue statements (#7953)5f8475bee

master
1.4 KiB45 linesraw
1//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-output-using-type -cpu
2
3// Regression test for issue #7748: Dictionary key collision in multi-level break processing
4// This test specifically exercises the case of "continue inside a switch that is inside a for loop"
5// which was identified as the root cause of the dictionary collision issue.
6
7int testContinueInSwitchInLoop(int value) {
8    int result = 0;
9
10    for (int i = 0; i < 3; ++i) {
11        switch (value) {
12            case 0:
13                result += 1;
14                continue; // This continue should go to the for loop
15            case 1:
16                result += 2;
17                break; // This break goes to the switch
18            default:
19                result += 3;
20                break;
21        }
22        result += 10; // This should be skipped when continue is used
23    }
24
25    return result;
26}
27
28int processValues() {
29    int sum = 0;
30    sum += testContinueInSwitchInLoop(0); // Should be 3 (1+1+1, no +10s due to continue)
31    sum += testContinueInSwitchInLoop(1); // Should be 36 (2+10, 2+10, 2+10)  
32    sum += testContinueInSwitchInLoop(2); // Should be 39 (3+10, 3+10, 3+10)
33    return sum;
34}
35
36//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
37RWStructuredBuffer<int> outputBuffer;
38
39[shader("compute")]
40[numthreads(1, 1, 1)]  
41void computeMain() {
42    int result = processValues();
43    outputBuffer[0] = result;
44    //CHECK: 78
45}