yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
083eecee3
master
1//TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target spirv -O0 -g3 2RWStructuredBuffer<int> outputBuffer; 3 4// This tests the following use cases: 5// Inline single block function in multiple places. 6// Inline single block function into multi-block function(This also covers multiple blocks with a phi node.) 7// Inline single block function in multiple places in the same function. 8// Inline multi-block function into another function 9// Inline multi-block function multiple times 10// Recursive inlining use case. 11 12[ForceInline] 13int calculateAdjustment(int value) 14{ 15 return value * 3 / 2; 16} 17 18[ForceInline] 19int inlineMultipleBasicBlocks(int value) 20{ 21 int result = 0; 22 23 result = value * 2; 24 result = calculateAdjustment(result); 25 26 // Add another branch to create more basic blocks 27 if (result > 20) 28 { 29 result = result + 25; 30 } 31 else 32 { 33 result = result + 50; 34 } 35 36 result = value * 4; 37 result = calculateAdjustment(result); 38 39 // Add another branch to create more basic blocks 40 if (result < 20) 41 { 42 result = result + 10; 43 } 44 45 result = value * 10; 46 result = calculateAdjustment(result); 47 48 if (result < 250) 49 { 50 result = result + 100; 51 } 52 53 return result; 54} 55 56[numthreads(4, 1, 1)] 57void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 58{ 59 int i = dispatchThreadID.x; 60 61 // Call the forceinline function 62 int result1 = inlineMultipleBasicBlocks(16); 63 64 int result2 = inlineMultipleBasicBlocks(22); 65 66 int result3 = calculateAdjustment(2); 67 68 outputBuffer[i] = result1 + result2 + result3; 69} 70 71// CHECK-COUNT-3: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugFunction %{{[0-9]+}} %{{[0-9]+}} %{{[0-9]+}} %uint_{{[0-9]+}} %uint_{{[0-9]+}} %{{[0-9]+}} %{{[0-9]+}} %uint_{{[0-9]+}} %uint_{{[0-9]+}} 72// CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugFunction %{{[0-9]+}} %{{[0-9]+}} %{{[0-9]+}} %uint_{{[0-9]+}} %uint_{{[0-9]+}} %{{[0-9]+}} %{{[0-9]+}} %uint_{{[0-9]+}} %uint_{{[0-9]+}} 73 74// TODO: Actual count is 6. But the pattern matcher complains to match. 75// CHECK-COUNT-5: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugInlinedAt %uint_{{[0-9]+}} %{{[0-9]+}} %{{[0-9]+}} 76// CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugInlinedAt %uint_{{[0-9]+}} %{{[0-9]+}} %{{[0-9]+}} 77 78// CHECK-COUNT-27: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugScope %{{[0-9]+}} %{{[0-9]+}} 79// CHECK-NOT: %{{[0-9]+}} = OpExtInst %void %{{[0-9]+}} DebugScope %{{[0-9]+}} %{{[0-9]+}}