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.2 KiB59 linesraw
1// static-const-in-struct.slang
2
3//TEST(compute):COMPARE_COMPUTE: -shaderobj
4
5// Test that `static const` variable declarations inside of
6// a `struct` type correctly translate to constants in
7// the output.
8
9struct Test
10{
11    static const int kArraySize = 4;
12
13    // First case: test that a `static const` can
14    // be used as a constant inside the scope of
15    // methods on the type.
16    //
17    int method(int val)
18    {
19        int a[kArraySize] = {};
20
21        for(int i = 0; i < kArraySize; ++i)
22            a[i] = i;
23
24        return val * 16 + a[val];
25    }
26}
27
28// Second case: test that a global function can
29// reference and use a constant scoped within
30// a structure type.
31//
32int globalFunc(int val)
33{
34    int a[Test.kArraySize] = {};
35
36    for(int i = 0; i < Test::kArraySize; ++i)
37        a[i] = i;
38
39    return val * 16 + a[val];
40}
41
42int test(int val)
43{
44    Test t;
45    return t.method(val) * 256 + globalFunc(val);
46}
47
48
49//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
50RWStructuredBuffer<int> outputBuffer;
51
52[numthreads(4, 1, 1)]
53void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
54{
55    int tid = dispatchThreadID.x;
56    int inVal = tid;
57    int outVal = test(inVal);
58    outputBuffer[tid] = outVal;
59}