yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1// for-break.slang 2 3// Test active mask synthesis for a `for` loop that 4// has no ordinary exit condition and can thus 5// only be exited via a (single) `break`. 6 7//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute 8//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute 9//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile cs_6_0 -xslang -DHACK 10//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -xslang -DHACK 11//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -capability cuda_sm_7_0 12 13//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 14RWStructuredBuffer<int> buffer; 15 16#define THREAD_COUNT 4 17#define LOC_COUNT 4 18#define ITER_COUNT THREAD_COUNT 19#define WRITE(LOC, ITER) buffer[tid + (LOC)*THREAD_COUNT + (ITER)*THREAD_COUNT*LOC_COUNT] = 0xA0000000 | (tid << 24) | (ITER << 16) | (LOC << 8) | WaveGetActiveMask() 20 21//TEST_INPUT:cbuffer(data=[0 1]):name C 22cbuffer C 23{ 24 int alwaysFalse; 25 int alwaysTrue; 26} 27 28void test(int tid) 29{ 30 int ii = 0; 31 for(;;) 32 { 33 WRITE(0, ii); 34 if(ii >= tid) 35 { 36 WRITE(1, ii); 37 38 // Note: This flag has been included to force 39 // D3D and Vulkan implementations to provide 40 // the expected/desired behavior for the active 41 // mask in the preceding code. 42 // 43 // It seems that without making the `break` 44 // conditional, some implementation will see that 45 // this block post-dominates the entire loop, 46 // and thus decide that the code is semantically 47 // "outside" the loop, despite the fact that 48 // it is clearly lexically *inside* the loop. 49 // 50 // Making the `break` conditional introduces 51 // a new control-flow edge that changes the 52 // post-dominator relationship and thus makes 53 // such implementations see this code as being 54 // "inside" the loop again. 55 // 56 #ifdef HACK 57 if(alwaysTrue) 58 #endif 59 break; 60 } 61 WRITE(2, ii); 62 ii++; 63 } 64 WRITE(3, ITER_COUNT); 65} 66 67[numthreads(THREAD_COUNT, 1, 1)] 68void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 69{ 70 test(dispatchThreadID.x); 71}