yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
768e62f6c
master
1// multi-level-break.slang 2 3//TEST(compute):COMPARE_COMPUTE: -shaderobj 4//DISABLE_TEST(compute):COMPARE_COMPUTE:-cpu -shaderobj 5 6int test(int r) 7{ 8 int result = 0; 9iLoop: 10 for (int i = 0; i < 2; i++) 11 { 12 jLoop: 13 for (int j = 0; j < 3; j++) 14 { 15 for (;;) 16 { 17 result++; 18 if (r == 0) 19 { 20 // When r == 0, we break out the outter most loop, 21 // resulting the inner most statement being run only once. 22 break iLoop; 23 } 24 else if (r == 1) 25 { 26 // When r == 1, we break out the `j` loop, 27 // resulting the inner most statement being run loop-i times. 28 break jLoop; 29 } 30 else 31 { 32 // When r takes other values, we break out the inner most loop p, 33 // resulting the inner most statement being run i*j times. 34 break; 35 } 36 } 37 } 38 } 39 return result; 40} 41 42//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 43RWStructuredBuffer<int> outputBuffer; 44 45[numthreads(1, 1, 1)] 46void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 47{ 48 outputBuffer[0] = test(0); 49 outputBuffer[1] = test(1); 50 outputBuffer[2] = test(2); 51 outputBuffer[3] = 0; 52}