yum-mirror/slang

Making it easier to work with shaders

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

kaizhangNVFeature/initialize list side branch (#6058)9ec6b9168

master
2.7 KiB105 linesraw
1
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj -vk
3//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj
4
5public struct Visibility
6{
7  internal int x = 1;
8  public int y = 5;
9
10  int getX() { return x; }
11}
12
13
14//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer
15RWStructuredBuffer<int> outputBuffer;
16void test(inout uint index)
17{
18  Visibility t1 = {}; // OK, initialized to {1,5} via ctor call.
19  // BUFFER: 1
20  outputBuffer[index++] = t1.getX();
21  // BUFFER-NEXT: 5
22  outputBuffer[index++] = t1.y;
23
24  Visibility t2 = {1}; // OK, initialized to {1,1} via ctor call.
25  // BUFFER-NEXT: 1
26  outputBuffer[index++] = t2.getX();
27  // BUFFER-NEXT: 1
28  outputBuffer[index++] = t2.y;
29}
30
31internal struct Visibility2
32{
33  // Visibility3 type is considered as C-style struct.
34  // Because all members have the same visibility as the type.
35  // Therefore we will attempt the legacy fallback logic for
36  // initializer-list syntax.
37  // Note that c-style structs can still have init exprs on members.
38  internal int x;
39  internal int y = 2;
40  // compiler synthesizes:
41  // internal __init(int x, int y = 2);
42}
43
44internal void test2(inout uint index)
45{
46  Visibility2 t = {3, 4}; // OK, initialized to {3,4} via ctor call.
47  // BUFFER-NEXT: 3
48  outputBuffer[index++] = t.x;
49  // BUFFER-NEXT: 4
50  outputBuffer[index++] = t.y;
51
52  Visibility2 t1 = {1}; // OK, initialized to {1,2} via ctor call.
53  // BUFFER-NEXT: 1
54  outputBuffer[index++] = t1.x;
55  // BUFFER-NEXT: 2
56  outputBuffer[index++] = t1.y;
57
58  Visibility2 t2 = {}; // OK, initialized to {0, 2} via legacy logic.
59  // BUFFER-NEXT: 0
60  outputBuffer[index++] = t2.x;
61  // BUFFER-NEXT: 2
62  outputBuffer[index++] = t2.y;
63}
64
65internal struct Visibility3
66{
67  // Visibility4 type is considered as C-style struct.
68  // And we still synthesize a ctor for member initialization.
69  // Because Visibility4 has no public members, the synthesized
70  // ctor will take 0 arguments.
71  internal int x = 1;
72  internal int y = 2;
73  // compiler synthesizes:
74  // internal __init(int x = 1, int y = 2);
75}
76
77internal void test3(inout uint index)
78{
79  Visibility3 t = {0, 0}; // OK, initialized to {0,0} via ctor call.
80  // BUFFER-NEXT: 0
81  outputBuffer[index++] = t.x;
82  // BUFFER-NEXT: 0
83  outputBuffer[index++] = t.y;
84
85  Visibility3 t1 = {3}; // OK, initialized to {3,2} via ctor call.
86  // BUFFER-NEXT: 3
87  outputBuffer[index++] = t1.x;
88  // BUFFER-NEXT: 2
89  outputBuffer[index++] = t1.y;
90
91  Visibility3 t2 = {}; // OK, initialized to {1,2} via ctor call.
92  // BUFFER-NEXT: 1
93  outputBuffer[index++] = t2.x;
94  // BUFFER-NEXT: 2
95  outputBuffer[index++] = t2.y;
96}
97
98[shader("compute")]
99void computeMain()
100{
101    uint index = 0;
102    test(index);
103    test2(index);
104    test3(index);
105}