yum-mirror/slang

Making it easier to work with shaders

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

kaizhangNVImplement default initializer list for C-Style type member (#7079)3072cfea9

master
1.4 KiB62 linesraw
1//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj -vk
2//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER):-shaderobj
3
4struct NonCStyle
5{
6  int x;
7  __init(int x)
8  {
9    this.x = x;
10  }
11}
12
13struct CLike
14{
15  NonCStyle nonCStyleMember;
16  int x;
17  int y;
18  // compiler synthesizes:
19  // __init(NonCStyle nonCStyleMember, int x = {}, int y = {});
20}
21
22//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer
23RWStructuredBuffer<int> outputBuffer;
24void test()
25{
26  // case 1: initialized with synthesized ctor call, but CLike::x and CLike::y are default initialized
27  // and `c1` is now `{1, 0, 0}`.
28  CLike c1 = {NonCStyle(1)};
29
30  // case 2: initialized with synthesized ctor call, CLike::y are default initialized
31  CLike c2 = {NonCStyle(1), 2};
32
33  // case 3: initialized with synthesized ctor call
34  CLike c3 = {NonCStyle(1), 2, 3};
35
36  outputBuffer[0] = c1.nonCStyleMember.x;
37  // BUFFER: 1
38  outputBuffer[1] = c1.x;
39  // BUFFER-NEXT: 0
40  outputBuffer[2] = c1.y;
41  // BUFFER-NEXT: 0
42
43  outputBuffer[3] = c2.nonCStyleMember.x;
44  // BUFFER-NEXT: 1
45  outputBuffer[4] = c2.x;
46  // BUFFER-NEXT: 2
47  outputBuffer[5] = c2.y;
48  // BUFFER-NEXT: 0
49
50  outputBuffer[6] = c3.nonCStyleMember.x;
51  // BUFFER-NEXT: 1
52  outputBuffer[7] = c3.x;
53  // BUFFER-NEXT: 2
54  outputBuffer[8] = c3.y;
55  // BUFFER-NEXT: 3
56}
57
58[shader("compute")]
59void computeMain()
60{
61    test();
62}