summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/inheritance/derived-struct-init-list.slang
blob: 213e5ee8e606aa74f960dc52c04face5ceeaf22b (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
// derived-struct-init-list.slang

//TEST(compute):COMPARE_COMPUTE:
//TEST(compute):COMPARE_COMPUTE: -vk -shaderobj

// Test that use of an initializer list (especially
// an empty initializer list) is still possible
// when using `struct` inheritance.

#pragma warning(disable:30816)

struct Base
{
    int a = 1;
}

struct Derived : Base
{
    int b = 2;

    void write(inout int val) { val = val*0x100 + a*0x10 + b; }
}

int test(int val)
{
    Derived x = {};
    Derived y = { val, val+1 };

    int result = 1;
    x.write(result);
    y.write(result);
    return result;
}

//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;
}