summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/struct-field-initializers/struct-field-initializer.slang
blob: 9b52a7ac614a50df3b09958498eb574caadc8368 (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
60
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain 
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -emit-spirv-directly
//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-cpu -compute -entry computeMain
//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-dx12 -compute -entry computeMain

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

static int myTwo = 2;
static int myThree = 1+2;

struct DefaultStructNoInit
{
    int data0 = 0;
    int data1 = myTwo;
    int data2 = 2;
};
struct DefaultStructWithInit
{
    int data0 = 3;
    int data1 = myThree;
    int data2;
    __init()
    {
        data2 = 3;
    }
};
struct DefaultStructWithInit2
{
    int data0 = 4;
    int data1 = 1;
    int data2 = 1;
    __init()
    {
        data1 = 4;
        data2 = 4;
    }
};
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    DefaultStructNoInit noInit = DefaultStructNoInit();
    noInit.data0 = 2;
    DefaultStructWithInit withInit = DefaultStructWithInit();
    DefaultStructWithInit2 withInit2 = DefaultStructWithInit2();
    // BUF: 1
    outputBuffer[0] = true
        && noInit.data0 == 2
        && noInit.data1 == 2
        && noInit.data2 == 2

        && withInit.data0 == 3
        && withInit.data1 == 3
        && withInit.data2 == 3

        && withInit2.data0 == 4
        && withInit2.data1 == 4
        && withInit2.data2 == 4
        ;
}