yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1// for-continue.slang 2 3// Test case of a `for` loop that 4// has multiple paths to continue 5// the loop (both the ordinary one 6// and an explicit `continue`) 7 8//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute 9//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute 10//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -xslang -DHACK 11//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -xslang -DHACK 12//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0 13 14//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name buffer 15RWStructuredBuffer<int> buffer; 16 17#define THREAD_COUNT 4 18#define LOC_COUNT 4 19#define ITER_COUNT THREAD_COUNT 20#define WRITE_VAL(LOC, ITER, VAL) buffer[tid + (LOC)*THREAD_COUNT + (ITER)*THREAD_COUNT*LOC_COUNT] = 0xA0000000 | (tid << 24) | (ITER << 16) | (LOC << 8) | VAL 21#define WRITE(LOC, ITER) WRITE_VAL(LOC, ITER, WaveGetActiveMask()) 22 23//TEST_INPUT:cbuffer(data=[0 1]):name C 24cbuffer C 25{ 26 int alwaysFalse; 27 int alwaysTrue; 28} 29 30// In order to make a test of `continue` behavior 31// adversarial, we need to observe the value of 32// the active mask during the code that executes 33// on a `continue`. 34// 35// We therefore define a subroutine that 36// will perform the increment action for an 37// ordinary counted loop, allowing us to 38// observe the value of the active mask inside 39// the function. 40// 41void inc(uint tid, in out int ii) 42{ 43 // NOTE: For our current HLSL and GLSL output 44 // strategies, we end up duplicating the 45 // "continue clause" of a `for` loop into 46 // each of the sites in the code where control 47 // flow continues the loop. Unsurprisingly, 48 // those copies mean that the active mask 49 // seen on those platforms is not the expected 50 // one. 51 // 52 // We will therefore write out the expected 53 // value directly instead of using `WaveGetActiveMask()` 54 // on those targets. 55 // 56#ifdef HACK 57 WRITE_VAL(3, ii, (0xE << ii) & 0xF); 58#else 59 WRITE(3, ii); 60#endif 61 ii++; 62} 63 64void test(uint tid) 65{ 66 for(int ii = 0; ii < tid; inc(tid, ii)) 67 { 68 WRITE(0, ii); 69 if((tid & 1) != 0) 70 { 71 WRITE(1, ii); 72 continue; 73 } 74 WRITE(2, ii); 75 } 76 WRITE(4, 0); 77} 78 79[numthreads(THREAD_COUNT, 1, 1)] 80void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 81{ 82 test(dispatchThreadID.x); 83}