yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//DISABLED_TEST(compute, vulkan):COMPARE_COMPUTE_EX():-vk -compute -shaderobj -output-using-type -render-features wave-ops 2//DISABLED_TEST(compute):COMPARE_COMPUTE_EX():-dx12 -profile sm_6_5 -compute -shaderobj -output-using-type -render-features wave-ops 3//TEST:SIMPLE(filecheck=CHECK):-target hlsl -profile cs_6_5 -entry computeMain -line-directive-mode none 4//TEST:SIMPLE(filecheck=CHECK):-target glsl -profile cs_6_5 -entry computeMain -line-directive-mode none 5 6// 7// This test checks that we fuse calls to saturated cooperation, even with different input values 8// 9 10//TEST_INPUT:ubuffer(data=[0 3 2 2], stride=4):out,name=outputBuffer 11RWStructuredBuffer<int> outputBuffer; 12 13static int count = 0; 14 15int coopAdd(float x, int i) 16{ 17 count += i; 18 return int(x) * 2; 19} 20 21int fallback1(float x, int) 22{ 23 count = -1; 24 return -1; 25} 26 27int coopMul(float x, float f) 28{ 29 count *= int(f); 30 return int(x) * 2; 31} 32 33int fallback2(float x, float) 34{ 35 count = -1; 36 return -1; 37} 38 39int coopExp(float x, int i) 40{ 41 int c = count; 42 count = 1; 43 for(int j = 0; j < i; ++j) 44 count *= c; 45 return int(x) * 2; 46} 47 48// Make sure that we have enough invocations to saturate the first workgroup 49[numthreads(128, 1, 1)] 50void computeMain(uint tig : SV_GroupIndex) 51{ 52 // The values we're cooperating over are {0, 2, 3} 53 // We track the number of sets evaluated in the "count" variable, and write 54 // that at index 0 55 // 56 // If these are not fused, then we'd expect count to be incremented three 57 // times then doubled three times. What we want to see is 58 // 0, +1, *2, **2, +1, *2, **2, +1, *2, **2 = 40804 59 // If they're not interleaved then we'll see 60 // 0, +1, +1, +1, *2, *2, *2, **2, **2, **2 = -1593835520 (having overflowed) 61 let i = tig < 4 ? float(outputBuffer[tig]) : 0; 62 let j = i + 1; 63 let k = j + 1; 64 let y = saturated_cooperation(coopAdd, fallback1, i, 1); 65 let m = 2.f; 66 let x = saturated_cooperation(coopMul, fallback2, j, m); 67 // Put some calculation between the calls to check that the fusion still takes place 68 let e = min(m*100, 2); 69 let z = saturated_cooperation(coopExp, fallback1, k, int(e)); 70 71 // check that all the piping functions we invent during fusing is inlined away 72 // CHECK: = coopAdd 73 // CHECK-NEXT: = coopMul 74 // there is a tuple pack here 75 // CHECK-NEXT: Tuple 76 // CHECK-NEXT: = coopExp 77 78 // CHECK: = fallback1 79 // CHECK-NEXT: = fallback2 80 // CHECK-NEXT: Tuple 81 // CHECK-NEXT: = fallback1 82 83 if(tig < 4) 84 outputBuffer[tig] = tig == 0 ? count : z; 85}