yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
adaea0e99
master
1// scope.slang 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 3//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 4//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj 5 6// Confirm that scoping on enums and types works 7 8//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer 9RWStructuredBuffer<int> outputBuffer; 10 11enum Color 12{ 13 Red, 14 Green = 2, 15 Blue, 16} 17 18struct Thing 19{ 20 int a; 21 struct Another 22 { 23 int b; 24 } 25}; 26 27int test(int val) 28{ 29 Color c = Color.Red; 30 31 Thing::Another another; 32 another.b = 20; 33 34 if(val > 1) 35 { 36 c = Color.Green; 37 } 38 39 if(c == Color::Red) 40 { 41 if((val & 1) != 0) 42 { 43 c = Color::Blue; 44 } 45 } 46 47 switch(c) 48 { 49 case Color::Red: 50 val = 1; 51 break; 52 53 case Color::Green: 54 val = 2; 55 break; 56 57 case Color::Blue: 58 val = 3; 59 break; 60 61 default: 62 val = -1; 63 break; 64 } 65 66 return (val << 4) + int(c) + another.b - 20; 67} 68 69[numthreads(4, 1, 1)] 70void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 71{ 72 uint tid = dispatchThreadID.x; 73 74 int val = int(tid); 75 val = test(val); 76 77 outputBuffer[tid] = val; 78}