summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/constants/static-const-in-struct.slang
blob: 5d4ce6802c0640a3b803de11861295ade3cc9bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// static-const-in-struct.slang

//TEST(compute):COMPARE_COMPUTE: -shaderobj

// Test that `static const` variable declarations inside of
// a `struct` type correctly translate to constants in
// the output.

struct Test
{
    static const int kArraySize = 4;

    // First case: test that a `static const` can
    // be used as a constant inside the scope of
    // methods on the type.
    //
    int method(int val)
    {
        int a[kArraySize] = {};

        for(int i = 0; i < kArraySize; ++i)
            a[i] = i;

        return val * 16 + a[val];
    }
}

// Second case: test that a global function can
// reference and use a constant scoped within
// a structure type.
//
int globalFunc(int val)
{
    int a[Test.kArraySize] = {};

    for(int i = 0; i < Test::kArraySize; ++i)
        a[i] = i;

    return val * 16 + a[val];
}

int test(int val)
{
    Test t;
    return t.method(val) * 256 + globalFunc(val);
}


//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
    int tid = dispatchThreadID.x;
    int inVal = tid;
    int outVal = test(inVal);
    outputBuffer[tid] = outVal;
}