yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

skallweitNVenable more metal tests (#4326)712ce653d

master
1.1 KiB67 linesraw
1// enum.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 basic `enum` declarations are supported.
7
8enum Color
9{
10    Red,
11    Green = (1 << 1),
12    Blue,
13}
14
15
16int test(int val)
17{
18    Color c = Color.Red;
19
20    if(val > 1)
21    {
22        c = Color.Green;
23    }
24
25    if(c == Color.Red)
26    {
27        if((val & 1) != 0)
28        {
29            c = Color.Blue;
30        }
31    }
32
33    switch(c)
34    {
35    case Color.Red:
36        val = 1;
37        break;
38
39    case Color.Green:
40        val = 2;
41        break;
42
43    case Color.Blue:
44        val = 3;
45        break;
46
47    default:
48        val = -1;
49        break;
50    }
51
52    return (val << 4) + int(c);
53}
54
55//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
56RWStructuredBuffer<int> outputBuffer;
57
58[numthreads(4, 1, 1)]
59void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
60{
61    int tid = dispatchThreadID.x;
62
63    int val = int(tid);
64    val = test(val);
65
66    outputBuffer[tid] = val;
67}