yum-mirror/slang

Making it easier to work with shaders

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

kaizhangNVFix a bug in default ctor synthesizing (#6527)e1952dc8c

master
3.5 KiB191 linesraw
1//TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry testMain -profile cs_6_0
2
3// Test that invoking the default constructor of a type then use the result as an existential value
4// works correctly.
5
6RWStructuredBuffer<uint> output;
7RWStructuredBuffer<uint> expected;
8
9interface ITest
10{
11    uint getValue();
12};
13
14
15//TEST_INPUT:type_conformance Test0:ITest = 0
16struct Test0 : ITest
17{
18    uint getValue() { return 0; }
19};
20
21//TEST_INPUT:type_conformance Test1:ITest = 1
22struct Test1 : ITest
23{
24    uint getValue() { return 1; }
25};
26
27//TEST_INPUT:type_conformance TestAny:ITest = 2
28struct TestAny : ITest
29{
30    uint value = 5;
31    __init(uint v)
32    {
33        value = v;
34    }
35
36    __init()
37    {
38        value = 0;
39    }
40
41    uint getValue() { return value; }
42}
43
44ITest makeTest0()
45{
46    return Test0();
47}
48
49ITest makeTest1()
50{
51    return Test1();
52}
53
54// CHECK: TestAny{{.*}} makeTestAny{{.*}}()
55// CHECK: return TestAny_{{.*}}init{{.*}}()
56ITest makeTestAny()
57{
58    return TestAny();
59}
60
61ITest makeTestAny(uint v)
62{
63    return TestAny(v);
64}
65
66
67[numthreads(16, 1, 1)]
68void testMain(uint3 threadID: SV_DispatchThreadID)
69{
70    if (threadID.x != 0)
71        return;
72
73    int outputIdx = 0;
74
75    /// Test0
76    {
77        Test0 test;
78        output[outputIdx] = test.getValue();
79        expected[outputIdx++] = 0;
80    }
81
82    {
83        ITest test = Test0();
84        output[outputIdx] = test.getValue();
85        expected[outputIdx++] = 0;
86    }
87
88    {
89        output[outputIdx] = Test0().getValue();
90        expected[outputIdx++] = 0;
91    }
92
93    {
94        ITest test = makeTest0();
95        output[outputIdx] = test.getValue();
96        expected[outputIdx++] = 0;
97    }
98
99    {
100        output[outputIdx] = makeTest0().getValue();
101        expected[outputIdx++] = 0;
102    }
103
104    output[outputIdx] = 1000;
105    expected[outputIdx++] = 1000;
106
107    /// Test1
108    {
109        Test1 test;
110        output[outputIdx] = test.getValue();
111        expected[outputIdx++] = 1;
112    }
113
114    {
115        ITest test = Test1();
116        output[outputIdx] = test.getValue();
117        expected[outputIdx++] = 1;
118    }
119
120    {
121        output[outputIdx] = Test1().getValue();
122        expected[outputIdx++] = 1;
123    }
124
125    {
126        ITest test = makeTest1();
127        output[outputIdx] = test.getValue();
128        expected[outputIdx++] = 1;
129    }
130
131    {
132        output[outputIdx] = makeTest1().getValue();
133        expected[outputIdx++] = 1;
134    }
135
136    output[outputIdx] = 2000;
137    expected[outputIdx++] = 2000;
138
139    /// TestAny
140    {
141        TestAny test;
142        output[outputIdx] = test.getValue();
143        expected[outputIdx++] = 5;
144    }
145
146    {
147        ITest test = TestAny();
148        output[outputIdx] = test.getValue();
149        expected[outputIdx++] = 5;
150    }
151
152    {
153        ITest test = TestAny(2);
154        output[outputIdx] = test.getValue();
155        expected[outputIdx++] = 2;
156    }
157
158    {
159        output[outputIdx] = TestAny().getValue();
160        expected[outputIdx++] = 5;
161    }
162
163    {
164        output[outputIdx] = TestAny(2).getValue();
165        expected[outputIdx++] = 2;
166    }
167
168    {
169        ITest test = makeTestAny();
170        output[outputIdx] = test.getValue();
171        expected[outputIdx++] = 5;
172    }
173
174    {
175        ITest test = makeTestAny(2);
176        output[outputIdx] = test.getValue();
177        expected[outputIdx++] = 2;
178    }
179
180    {
181        output[outputIdx] = makeTestAny().getValue();
182        expected[outputIdx++] = 5;
183    }
184
185    {
186        output[outputIdx] = makeTestAny(2).getValue();
187        expected[outputIdx++] = 2;
188    }
189
190    expected[outputIdx++] = uint(-1);
191}