yum-mirror/slang

Making it easier to work with shaders

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

James Helferty (NVIDIA)render-test: Change D3D12 default to sm_6_5 (#8320)f02b08490

master
7.7 KiB267 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute -shaderobj
2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile cs_6_6 -dx12 -shaderobj -render-feature hardware-device
3//TEST(compute):COMPARE_COMPUTE_EX:-metal -compute -shaderobj 
4//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj
5
6// 16 bit variants are not supported by WGSL.
7//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -shaderobj -xslang -DWGSL
8// Debug info for inlining errors can be given out, so disable them for this test.
9//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -g0
10
11//TEST(compute):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -xslang -DUSE_SLANG_SYNTAX
12//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -profile cs_6_6 -dx12 -shaderobj -render-feature hardware-device -xslang -DUSE_SLANG_SYNTAX
13//TEST(compute):COMPARE_COMPUTE_EX:-metal -compute -shaderobj -xslang -DUSE_SLANG_SYNTAX
14//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj -xslang -DUSE_SLANG_SYNTAX
15
16// 16 bit variants are not supported by WGSL.
17//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -shaderobj -xslang -DWGSL -xslang -DUSE_SLANG_SYNTAX
18// Debug info for inlining errors can be given out, so disable them for this test.
19//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -g0 -xslang -DUSE_SLANG_SYNTAX
20
21
22//TEST_INPUT:ubuffer(data=[0xD37A83FF], stride=4):name unpackTestBuffer
23StructuredBuffer<uint32_t> unpackTestBuffer;
24
25//TEST_INPUT:ubuffer(data=[0xB3F 0x6A 0x123 0xD4], stride=4): name packTestBuffer
26StructuredBuffer<uint32_t4> packTestBuffer;
27
28// These should clamp to (5, 255, 255, 254) or (0x5, 0xFF, 0xFF, 0xFE).
29//TEST_INPUT:ubuffer(data=[5 256 12345 254], stride=4): name packClampUTestBuffer
30StructuredBuffer<int32_t4> packClampUTestBuffer;
31
32// These should clamp to (-1, 127, -128, 125) or (0xFF, 0x7F, 0x80, 0x81)
33// Inputs are [-1 250 -32768 -127].
34//TEST_INPUT:ubuffer(data=[0xFFFFFFFF 0xFA 0xFFFF8000 0xFFFFFF81], stride=4): name packClampSTestBuffer
35StructuredBuffer<int32_t4> packClampSTestBuffer;
36
37//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], stride=4):out,name outputBuffer
38RWStructuredBuffer<uint> outputBuffer;
39
40uint32_t4 __unpack_u8u32(uint value)
41{
42#if defined(USE_SLANG_SYNTAX)
43    return unpackUint4x8ToUint32(value);
44#else
45    return unpack_u8u32(uint8_t4_packed(value));
46#endif
47}
48
49uint16_t4 __unpack_u8u16(uint value)
50{
51#if defined(USE_SLANG_SYNTAX)
52    return unpackUint4x8ToUint16(value);
53#else
54    return unpack_u8u16(uint8_t4_packed(value));
55#endif
56}
57
58int32_t4 __unpack_s8s32(uint value)
59{
60#if defined(USE_SLANG_SYNTAX)
61    return unpackInt4x8ToInt32(value);
62#else
63    return unpack_s8s32(int8_t4_packed(value));
64#endif
65}
66
67int16_t4 __unpack_s8s16(uint value)
68{
69#if defined(USE_SLANG_SYNTAX)
70    return unpackInt4x8ToInt16(value);
71#else
72    return unpack_s8s16(int8_t4_packed(value));
73#endif
74}
75
76uint __pack_u8(uint32_t4 value)
77{
78#if defined(USE_SLANG_SYNTAX)
79    return packUint4x8(value);
80#else
81    return uint(pack_u8(value));
82#endif
83}
84
85uint __pack_u8(uint16_t4 value)
86{
87#if defined(USE_SLANG_SYNTAX)
88    return packUint4x8(value);
89#else
90    return uint(pack_u8(value));
91#endif
92}
93
94uint __pack_s8(int32_t4 value)
95{
96#if defined(USE_SLANG_SYNTAX)
97    return packInt4x8(value);
98#else
99    return uint(pack_s8(value));
100#endif
101}
102
103uint __pack_s8(int16_t4 value)
104{
105#if defined(USE_SLANG_SYNTAX)
106    return packInt4x8(value);
107#else
108    return uint(pack_s8(value));
109#endif
110}
111
112uint __pack_clamp_u8(int32_t4 value)
113{
114#if defined(USE_SLANG_SYNTAX)
115    return packUint4x8Clamp(value);
116#else
117    return uint(pack_clamp_u8(value));
118#endif
119}
120
121uint __pack_clamp_u8(int16_t4 value)
122{
123#if defined(USE_SLANG_SYNTAX)
124    return packUint4x8Clamp(value);
125#else
126    return uint(pack_clamp_u8(value));
127#endif
128}
129
130uint __pack_clamp_s8(int32_t4 value)
131{
132#if defined(USE_SLANG_SYNTAX)
133    return packInt4x8Clamp(value);
134#else
135    return uint(pack_clamp_s8(value));
136#endif
137}
138
139uint __pack_clamp_s8(int16_t4 value)
140{
141#if defined(USE_SLANG_SYNTAX)
142    return packInt4x8Clamp(value);
143#else
144    return uint(pack_clamp_s8(value));
145#endif
146}
147
148[numthreads(1, 1, 1)]
149void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
150{
151    const uint unpackTestValue = unpackTestBuffer[0];
152
153    uint index = 0;
154
155    /*
156     * Unpack without sign extension.
157     */
158    uint32_t4 unpackedU32 = __unpack_u8u32(unpackTestValue);
159    // 0xFF
160    outputBuffer[index++] = uint(unpackedU32.x);
161    // 0x83
162    outputBuffer[index++] = uint(unpackedU32.y);
163    // 0x7A
164    outputBuffer[index++] = uint(unpackedU32.z);
165    // 0xD3
166    outputBuffer[index++] = uint(unpackedU32.w);
167
168#if !defined(WGSL)
169    uint16_t4 unpackedU16 = __unpack_u8u16(unpackTestValue);
170    // 0xFF
171    outputBuffer[index++] = uint(unpackedU16.x);
172    // 0x83
173    outputBuffer[index++] = uint(unpackedU16.y);
174    // 0x7A
175    outputBuffer[index++] = uint(unpackedU16.z);
176    // 0xD3
177    outputBuffer[index++] = uint(unpackedU16.w);
178#else 
179    outputBuffer[index++] = 0xFFU;
180    outputBuffer[index++] = 0x83U;
181    outputBuffer[index++] = 0x7AU;
182    outputBuffer[index++] = 0xD3U;
183#endif
184
185    /*
186     * Unpack with sign extension.
187     */
188    int32_t4 unpackedS32 = __unpack_s8s32(unpackTestValue);
189    // 0xFFFFFFFF
190    outputBuffer[index++] = uint(unpackedS32.x);
191    // 0xFFFFFF83
192    outputBuffer[index++] = uint(unpackedS32.y);
193    // 0x7A
194    outputBuffer[index++] = uint(unpackedS32.z);
195    // 0xFFFFFFD3
196    outputBuffer[index++] = uint(unpackedS32.w);
197
198#if !defined(WGSL)
199    int16_t4 unpackedS16 = __unpack_s8s16(unpackTestValue);
200    // 0xFFFFFFFF
201    outputBuffer[index++] = uint(unpackedS16.x);
202    // 0xFFFFFF83
203    outputBuffer[index++] = uint(unpackedS16.y);
204    // 0x7A
205    outputBuffer[index++] = uint(unpackedS16.z);
206    // 0xFFFFFFD3
207    outputBuffer[index++] = uint(unpackedS16.w);
208#else
209    outputBuffer[index++] = 0xFFFFFFFFU;
210    outputBuffer[index++] = 0xFFFFFF83U;
211    outputBuffer[index++] = 0x7AU;
212    outputBuffer[index++] = 0xFFFFFFD3U;
213#endif
214
215
216    /*
217     * Pack without clamping, dropping unused bits.
218     */
219    uint32_t4 packU32TestValues = packTestBuffer[0];
220    int32_t4 packS32TestValues = packU32TestValues;
221
222    // 0xD4236A3F
223    outputBuffer[index++] = __pack_u8(packU32TestValues);
224    outputBuffer[index++] = __pack_s8(packS32TestValues);
225
226#if !defined(WGSL)
227    uint16_t4 packU16TestValues = int16_t4(int16_t(packU32TestValues.x), int16_t(packU32TestValues.y), 
228                                           int16_t(packU32TestValues.z), int16_t(packU32TestValues.w));
229    int16_t4 packS16TestValues = packU16TestValues;
230    outputBuffer[index++] = __pack_u8(packU16TestValues);
231    outputBuffer[index++] = __pack_s8(packS16TestValues);
232#else
233    outputBuffer[index++] = 0xD4236A3F;
234    outputBuffer[index++] = 0xD4236A3F;
235#endif
236
237    /*
238     * Pack with unsigned clamping.
239     */
240    int32_t4 packClampU32TestValues = packClampUTestBuffer[0];
241    // 0xFEFFFF05
242    outputBuffer[index++] = __pack_clamp_u8(packClampU32TestValues);
243
244#if !defined(WGSL)
245    int16_t4 packClampU16TestValues = int16_t4(int16_t(packClampU32TestValues.x), int16_t(packClampU32TestValues.y),
246                                               int16_t(packClampU32TestValues.z), int16_t(packClampU32TestValues.w));
247    outputBuffer[index++] = __pack_clamp_u8(packClampU16TestValues);
248#else
249    outputBuffer[index++] = 0xFEFFFF05;
250#endif
251
252    /*
253     * Pack with signed clamping
254     */
255    int32_t4 packClampS32TestValues = packClampSTestBuffer[0];
256    // 0x81807FFF
257    outputBuffer[index++] = __pack_clamp_s8(packClampS32TestValues);
258
259#if !defined(WGSL)
260    int16_t4 packClampS16TestValues = int16_t4(int16_t(packClampS32TestValues.x), int16_t(packClampS32TestValues.y),
261                                               int16_t(packClampS32TestValues.z), int16_t(packClampS32TestValues.w));
262    outputBuffer[index++] = __pack_clamp_s8(packClampS16TestValues);
263#else
264    outputBuffer[index++] = 0x81807FFF;
265#endif
266}
267