yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)Enable metal tests (#8446)8086adc90

master
12.1 KiB342 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -dx12 -profile cs_6_6 -shaderobj -output-using-type
2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -cuda -profile cs_6_6 -shaderobj -output-using-type
3
4// This is to support 64-bit `Interlocked*` functions defined for HLSL SM6.6
5// https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Int64_and_Float_Atomics.html
6
7//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):name=f32Buffer
8RWStructuredBuffer<float> f32Buffer;
9//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=8):name=u64Buffer
10RWStructuredBuffer<uint64_t> u64Buffer;
11//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0], stride=8):name=i64Buffer
12RWStructuredBuffer<int64_t> i64Buffer;
13
14//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]):name=fBuf
15RWByteAddressBuffer fBuf;
16//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]):name=uBuf
17RWByteAddressBuffer uBuf;
18//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]):name=iBuf
19RWByteAddressBuffer iBuf;
20
21groupshared float f32Shared[4];
22groupshared uint64_t u64Shared[4];
23groupshared int64_t i64Shared[4];
24groupshared uint64_t indexAlloc;
25
26//TEST_INPUT: ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
27RWStructuredBuffer<int> outputBuffer;
28
29[numthreads(4, 1, 1)]
30void computeMain(uint groupIndex : SV_GroupIndex, int3 dispatchThreadID: SV_DispatchThreadID)
31{
32    f32Shared = { 0.f, 0.f, 0.f, 0.f };
33    u64Shared = { 0, 0, 0, 0 };
34    i64Shared = { 0, 0, 0, 0 };
35    indexAlloc = 0;
36    GroupMemoryBarrierWithGroupSync();
37
38    int idx = dispatchThreadID.x;
39    bool result = true;
40
41    uint64_t u64Value[9];
42    int64_t  i64Value[9];
43    float    f32Value[9];
44
45    // Add
46    InterlockedAdd(u64Shared[idx], uint64_t(1));
47    InterlockedAdd(i64Shared[idx],  int64_t(1));
48    InterlockedAdd(u64Buffer[idx], uint64_t(1));
49    InterlockedAdd(i64Buffer[idx],  int64_t(1));
50    uBuf.InterlockedAdd64(idx * 8, uint64_t(1));
51    iBuf.InterlockedAdd64(idx * 8,  int64_t(1));
52
53    result = result
54        && (u64Shared[idx] == 1)
55        && (i64Shared[idx] == 1)
56        && (u64Buffer[idx] == 1)
57        && (i64Buffer[idx] == 1)
58        && (uBuf.Load<uint64_t>(idx * 8) == 1)
59        && (iBuf.Load< int64_t>(idx * 8) == 1)
60        ;
61
62    // Add - original_value
63    InterlockedAdd(u64Shared[idx], uint64_t(1), u64Value[0]);
64    InterlockedAdd(i64Shared[idx],  int64_t(1), i64Value[1]);
65    InterlockedAdd(u64Buffer[idx], uint64_t(1), u64Value[2]);
66    InterlockedAdd(i64Buffer[idx],  int64_t(1), i64Value[3]);
67    uBuf.InterlockedAdd64(idx * 8, uint64_t(1), u64Value[4]);
68    iBuf.InterlockedAdd64(idx * 8,  int64_t(1), i64Value[5]);
69
70    result = result
71        && (u64Value[0] == 1)
72        && (i64Value[1] == 1)
73        && (u64Value[2] == 1)
74        && (i64Value[3] == 1)
75        && (u64Value[4] == 1)
76        && (i64Value[5] == 1)
77        && (u64Shared[idx] == 2)
78        && (i64Shared[idx] == 2)
79        && (u64Buffer[idx] == 2)
80        && (i64Buffer[idx] == 2)
81        && (uBuf.Load<uint64_t>(idx * 8) == 2)
82        && (iBuf.Load< int64_t>(idx * 8) == 2)
83        ;
84
85    // Bitwise-And
86    InterlockedAnd(u64Shared[idx], uint64_t(3));
87    InterlockedAnd(u64Buffer[idx], uint64_t(3));
88    uBuf.InterlockedAnd64(idx * 8, uint64_t(3));
89
90    result = result
91        && (u64Shared[idx] == 2)
92        && (u64Buffer[idx] == 2)
93        && (uBuf.Load<uint64_t>(idx * 8) == 2)
94        ;
95
96    // And - original_value
97    InterlockedAnd(u64Shared[idx], uint64_t(1), u64Value[0]);
98    InterlockedAnd(u64Buffer[idx], uint64_t(1), u64Value[1]);
99    uBuf.InterlockedAnd64(idx * 8, uint64_t(1), u64Value[2]);
100
101    result = result
102        && (u64Value[0] == 2)
103        && (u64Value[1] == 2)
104        && (u64Value[2] == 2)
105        && (u64Shared[idx] == 0)
106        && (u64Buffer[idx] == 0)
107        && (uBuf.Load<uint64_t>(idx * 8) == 0)
108        ;
109
110    // Bitwise-Or
111    InterlockedOr(u64Shared[idx], uint64_t(1));
112    InterlockedOr(u64Buffer[idx], uint64_t(1));
113    uBuf.InterlockedOr64(idx * 8, uint64_t(1));
114
115    result = result
116        && (u64Shared[idx] == 1)
117        && (u64Buffer[idx] == 1)
118        && (uBuf.Load<uint64_t>(idx * 8) == 1)
119        ;
120
121    // Or - original_value
122    InterlockedOr(u64Shared[idx], uint64_t(2), u64Value[0]);
123    InterlockedOr(u64Buffer[idx], uint64_t(2), u64Value[1]);
124    uBuf.InterlockedOr64(idx * 8, uint64_t(2), u64Value[2]);
125
126    result = result
127        && (u64Value[0] == 1)
128        && (u64Value[1] == 1)
129        && (u64Value[2] == 1)
130        && (u64Shared[idx] == 3)
131        && (u64Buffer[idx] == 3)
132        && (uBuf.Load<uint64_t>(idx * 8) == 3)
133        ;
134
135    // Bitwise-Xor
136    InterlockedXor(u64Shared[idx], uint64_t(5));
137    InterlockedXor(u64Buffer[idx], uint64_t(5));
138    uBuf.InterlockedXor64(idx * 8, uint64_t(5));
139
140    result = result
141        && (u64Shared[idx] == 6)
142        && (u64Buffer[idx] == 6)
143        && (uBuf.Load<uint64_t>(idx * 8) == 6)
144        ;
145
146    // Xor - original_value
147    InterlockedXor(u64Shared[idx], uint64_t(1), u64Value[0]);
148    InterlockedXor(u64Buffer[idx], uint64_t(1), u64Value[1]);
149    uBuf.InterlockedXor64(idx * 8, uint64_t(1), u64Value[2]);
150
151    result = result
152        && (u64Value[0] == 6)
153        && (u64Value[1] == 6)
154        && (u64Value[2] == 6)
155        && (u64Shared[idx] == 7)
156        && (u64Buffer[idx] == 7)
157        && (uBuf.Load<uint64_t>(idx * 8) == 7)
158        ;
159
160    // Min
161    InterlockedMin(u64Shared[idx], uint64_t(1));
162    InterlockedMin(i64Shared[idx],  int64_t(1));
163    InterlockedMin(u64Buffer[idx], uint64_t(1));
164    InterlockedMin(i64Buffer[idx],  int64_t(1));
165    uBuf.InterlockedMin64(idx * 8, uint64_t(1));
166    iBuf.InterlockedMin64(idx * 8,  int64_t(1));
167
168    result = result
169        && (u64Shared[idx] == 1)
170        && (i64Shared[idx] == 1)
171        && (u64Buffer[idx] == 1)
172        && (i64Buffer[idx] == 1)
173        && (uBuf.Load<uint64_t>(idx * 8) == 1)
174        && (iBuf.Load< int64_t>(idx * 8) == 1)
175        ;
176
177    // Min - original_value
178    InterlockedMin(u64Shared[idx], uint64_t(2), u64Value[0]);
179    InterlockedMin(i64Shared[idx],  int64_t(2), i64Value[1]);
180    InterlockedMin(u64Buffer[idx], uint64_t(2), u64Value[2]);
181    InterlockedMin(i64Buffer[idx],  int64_t(2), i64Value[3]);
182    uBuf.InterlockedMin64(idx * 8, uint64_t(2), u64Value[4]);
183    iBuf.InterlockedMin64(idx * 8,  int64_t(2), i64Value[5]);
184
185    result = result
186        && (u64Value[0] == 1)
187        && (i64Value[1] == 1)
188        && (u64Value[2] == 1)
189        && (i64Value[3] == 1)
190        && (u64Value[4] == 1)
191        && (i64Value[5] == 1)
192        && (u64Shared[idx] == 1)
193        && (i64Shared[idx] == 1)
194        && (u64Buffer[idx] == 1)
195        && (i64Buffer[idx] == 1)
196        && (uBuf.Load<uint64_t>(idx * 8) == 1)
197        && (iBuf.Load< int64_t>(idx * 8) == 1)
198        ;
199
200    // Max
201    InterlockedMax(u64Shared[idx], uint64_t(2));
202    InterlockedMax(i64Shared[idx],  int64_t(2));
203    InterlockedMax(u64Buffer[idx], uint64_t(2));
204    InterlockedMax(i64Buffer[idx],  int64_t(2));
205    uBuf.InterlockedMax64(idx * 8, uint64_t(2));
206    iBuf.InterlockedMax64(idx * 8,  int64_t(2));
207
208    result = result
209        && (u64Shared[idx] == 2)
210        && (i64Shared[idx] == 2)
211        && (u64Buffer[idx] == 2)
212        && (i64Buffer[idx] == 2)
213        && (uBuf.Load<uint64_t>(idx * 8) == 2)
214        && (iBuf.Load< int64_t>(idx * 8) == 2)
215        ;
216
217    // Max - original_value
218    InterlockedMax(u64Shared[idx], uint64_t(0), u64Value[0]);
219    InterlockedMax(i64Shared[idx],  int64_t(0), i64Value[1]);
220    InterlockedMax(u64Buffer[idx], uint64_t(0), u64Value[2]);
221    InterlockedMax(i64Buffer[idx],  int64_t(0), i64Value[3]);
222    uBuf.InterlockedMax64(idx * 8, uint64_t(0), u64Value[4]);
223    iBuf.InterlockedMax64(idx * 8,  int64_t(0), i64Value[5]);
224
225    result = result
226        && (u64Value[0] == 2)
227        && (i64Value[1] == 2)
228        && (u64Value[2] == 2)
229        && (i64Value[3] == 2)
230        && (u64Value[4] == 2)
231        && (i64Value[5] == 2)
232        && (u64Shared[idx] == 2)
233        && (i64Shared[idx] == 2)
234        && (u64Buffer[idx] == 2)
235        && (i64Buffer[idx] == 2)
236        && (uBuf.Load<uint64_t>(idx * 8) == 2)
237        && (iBuf.Load< int64_t>(idx * 8) == 2)
238        ;
239
240    // Exchange
241    InterlockedExchange(f32Shared[idx],    float(1), f32Value[0]);
242    InterlockedExchange(u64Shared[idx], uint64_t(1), u64Value[1]);
243    InterlockedExchange(i64Shared[idx],  int64_t(1), i64Value[2]);
244    InterlockedExchange(f32Buffer[idx],    float(1), f32Value[3]);
245    InterlockedExchange(u64Buffer[idx], uint64_t(1), u64Value[4]);
246    InterlockedExchange(i64Buffer[idx],  int64_t(1), i64Value[5]);
247    fBuf.InterlockedExchangeFloat(idx * 8, float(1), f32Value[6]);
248    uBuf.InterlockedExchange64(idx * 8, uint64_t(1), u64Value[7]);
249    iBuf.InterlockedExchange64(idx * 8,  int64_t(1), i64Value[8]);
250
251    result = result
252        && (f32Value[0] == 0)
253        && (u64Value[1] == 2)
254        && (i64Value[2] == 2)
255        && (f32Value[3] == 0)
256        && (u64Value[4] == 2)
257        && (i64Value[5] == 2)
258        && (f32Value[6] == 0)
259        && (u64Value[7] == 2)
260        && (i64Value[8] == 2)
261        && (f32Buffer[idx] == 1.f)
262        && (u64Shared[idx] == 1)
263        && (i64Shared[idx] == 1)
264        && (f32Buffer[idx] == 1.f)
265        && (u64Buffer[idx] == 1)
266        && (i64Buffer[idx] == 1)
267        && (fBuf.Load<   float>(idx * 8) == 1.f)
268        && (uBuf.Load<uint64_t>(idx * 8) == 1)
269        && (iBuf.Load< int64_t>(idx * 8) == 1)
270        ;
271
272    // CompareStore
273    InterlockedCompareStore(u64Shared[idx], uint64_t(1), uint64_t(0));
274    InterlockedCompareStore(i64Shared[idx],  int64_t(1),  int64_t(0));
275    InterlockedCompareStore(u64Buffer[idx], uint64_t(1), uint64_t(0));
276    InterlockedCompareStore(i64Buffer[idx],  int64_t(1),  int64_t(0));
277    uBuf.InterlockedCompareStore64(idx * 8, uint64_t(1), uint64_t(0));
278    iBuf.InterlockedCompareStore64(idx * 8,  int64_t(1),  int64_t(0));
279
280    result = result
281        && (u64Shared[idx] == 0)
282        && (i64Shared[idx] == 0)
283        && (u64Buffer[idx] == 0)
284        && (i64Buffer[idx] == 0)
285        && (uBuf.Load<uint64_t>(idx * 8) == 0)
286        && (iBuf.Load< int64_t>(idx * 8) == 0)
287        ;
288
289    // CompareStoreFloatBitwise
290    InterlockedCompareStoreFloatBitwise(f32Shared[idx], float(1), float(0));
291    InterlockedCompareStoreFloatBitwise(f32Buffer[idx], float(1), float(0));
292    fBuf.InterlockedCompareStoreFloatBitwise(idx * 8,   float(1), float(0));
293
294    result = result
295        && (f32Shared[idx] == float(0))
296        && (f32Buffer[idx] == float(0))
297        && (fBuf.Load<float>(idx * 8) == float(0))
298        ;
299
300    // CompareExchange
301    InterlockedCompareExchange(u64Shared[idx], uint64_t(0), uint64_t(1), u64Value[0]);
302    InterlockedCompareExchange(i64Shared[idx],  int64_t(0),  int64_t(1), i64Value[1]);
303    InterlockedCompareExchange(u64Buffer[idx], uint64_t(0), uint64_t(1), u64Value[2]);
304    InterlockedCompareExchange(i64Buffer[idx],  int64_t(0),  int64_t(1), i64Value[3]);
305    uBuf.InterlockedCompareExchange64(idx * 8, uint64_t(0), uint64_t(1), u64Value[4]);
306    iBuf.InterlockedCompareExchange64(idx * 8,  int64_t(0),  int64_t(1), i64Value[5]);
307
308    result = result
309        && (u64Value[0] == 0)
310        && (i64Value[1] == 0)
311        && (u64Value[2] == 0)
312        && (i64Value[3] == 0)
313        && (u64Value[4] == 0)
314        && (i64Value[5] == 0)
315        && (u64Shared[idx] == 1)
316        && (i64Shared[idx] == 1)
317        && (u64Buffer[idx] == 1)
318        && (i64Buffer[idx] == 1)
319        && (uBuf.Load<uint64_t>(idx * 8) == 1)
320        && (iBuf.Load< int64_t>(idx * 8) == 1)
321        ;
322
323    // CompareExchangeFloatBitwise
324    InterlockedCompareExchangeFloatBitwise(f32Shared[idx], float(0), float(1), f32Value[0]);
325    InterlockedCompareExchangeFloatBitwise(f32Buffer[idx], float(0), float(1), f32Value[1]);
326    fBuf.InterlockedCompareExchangeFloatBitwise(idx * 8,   float(0), float(1), f32Value[2]);
327
328    result = result
329        && (f32Value[0] == float(0))
330        && (f32Value[1] == float(0))
331        && (f32Value[2] == float(0))
332        && (f32Shared[idx] == float(1))
333        && (f32Buffer[idx] == float(1))
334        && (fBuf.Load<float>(idx * 8) == float(1))
335        ;
336
337    // BUF: 1
338    // BUF-NEXT: 1
339    // BUF-NEXT: 1
340    // BUF-NEXT: 1
341    outputBuffer[idx] = int(result);
342}