yum-mirror/slang

Making it easier to work with shaders

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

Jay KwakFix intermittent debug failures with Debug build (#7369)7dad68f86

master
7.1 KiB212 linesraw
1//TEST:SIMPLE(filecheck=CHECK_GLSL):  -allow-glsl -stage compute -entry computeMain -target glsl -DTARGET_GLSL
2//TEST:SIMPLE(filecheck=CHECK_SPV):  -allow-glsl -stage compute -entry computeMain -target spirv -emit-spirv-directly -DTARGET_SPIRV
3//TEST:SIMPLE(filecheck=CHECK_HLSL): -allow-glsl -stage compute -entry computeMain -target hlsl -DTARGET_HLSL
4//TEST:SIMPLE(filecheck=CHECK_CUDA): -allow-glsl -stage compute -entry computeMain -target cuda -DTARGET_CUDA
5
6// not testing cpp due to missing impl
7//DISABLE_TEST:SIMPLE(filecheck=CHECK_CPP):  -allow-glsl -stage compute -entry computeMain -target cpp -DTARGET_CPP
8
9//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl
10//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly
11//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-wgpu -compute -entry computeMain -allow-glsl -xslang -DWGPU -render-feature half
12
13// Not testing because CI runners may not support Metal's intrinsics.
14//DISABLE_TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF):-metal -compute -entry computeMain -allow-glsl -xslang -DMETAL
15
16#version 430
17
18#if 1                        \
19    && !defined(TARGET_HLSL) \
20    && !defined(TARGET_CUDA)
21// hlsl does not treat boolean types with subgroup.* as a logical operator
22// cuda is missing an implementation
23#define TEST_when_logical_operators_are_implemented
24#endif
25
26//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer
27buffer MyBlockName2
28{
29    uint data[];
30} outputBuffer;
31
32#define local_size_x_v 4
33layout(local_size_x = local_size_x_v) in;
34
35__generic<T : __BuiltinLogicalType>
36bool test1Logical() {
37    return true
38#if defined(TEST_when_logical_operators_are_implemented)
39        & subgroupAnd(T(1)) == T(1)
40        & subgroupOr(T(1)) == T(1)
41        & subgroupXor(T(1)) == T(0) 
42#endif // #if defined(TEST_when_logical_operators_are_implemented)
43        ;
44}
45
46__generic<T : __BuiltinLogicalType, let N : int>
47bool testVLogical() {
48    typealias gvec = vector<T, N>;
49
50    return true
51#if defined(TEST_when_logical_operators_are_implemented)
52        & subgroupAnd(gvec(T(1))) == gvec(T(1))
53        & subgroupOr(gvec(T(1))) == gvec(T(1))
54        & subgroupXor(gvec(T(1))) == gvec(T(0))
55#endif // #if defined(TEST_when_logical_operators_are_implemented)
56        ;
57}
58
59bool testLogical() {
60    return true
61        & test1Logical<int>()
62        & testVLogical<int, 2>()
63        & testVLogical<int, 3>()
64        & testVLogical<int, 4>()
65        & test1Logical<uint>()
66        & testVLogical<uint, 2>()
67        & testVLogical<uint, 3>()
68        & testVLogical<uint, 4>()
69
70        // Disabled on WGPU and Metal as these built-in types are not supported as of time of writing.
71#if !defined(WGPU) && !defined(METAL)
72        & test1Logical<int8_t>()
73        & testVLogical<int8_t, 2>()
74        & testVLogical<int8_t, 3>()
75        & testVLogical<int8_t, 4>()
76        & test1Logical<int64_t>()
77        & testVLogical<int64_t, 2>()
78        & testVLogical<int64_t, 3>()
79        & testVLogical<int64_t, 4>()
80        & test1Logical<uint8_t>()
81        & testVLogical<uint8_t, 2>()
82        & testVLogical<uint8_t, 3>()
83        & testVLogical<uint8_t, 4>()
84        & test1Logical<uint64_t>()
85        & testVLogical<uint64_t, 2>()
86        & testVLogical<uint64_t, 3>()
87        & testVLogical<uint64_t, 4>()
88        & test1Logical<bool>()
89        & testVLogical<bool, 2>()
90        & testVLogical<bool, 3>()
91        & testVLogical<bool, 4>()
92#endif
93
94        // Disabled on WGPU as these built-in types are not supported as of time of writing.
95#if !defined (WGPU)
96        & test1Logical<int16_t>()
97        & testVLogical<int16_t, 2>()
98        & testVLogical<int16_t, 3>()
99        & testVLogical<int16_t, 4>()
100        & test1Logical<uint16_t>()
101        & testVLogical<uint16_t, 2>()
102        & testVLogical<uint16_t, 3>()
103        & testVLogical<uint16_t, 4>()
104#endif
105        ;
106}
107
108__generic<T : __BuiltinArithmeticType>
109bool test1Arithmetic() {
110    return true
111        & subgroupAdd(T(1)) == T(local_size_x_v) // 32
112        & subgroupMul(T(1)) == T(1)
113        & subgroupMin(T(1)) == T(1)
114        & subgroupMax(T(1)) == T(1)
115        ;
116}
117__generic<T : __BuiltinArithmeticType, let N : int>
118bool testVArithmetic() {
119    typealias gvec = vector<T, N>;
120
121    return true
122        & subgroupAdd(gvec(T(1))) == gvec(T(local_size_x_v)) // 32
123        & subgroupMul(gvec(T(1))) == gvec(T(1))
124        & subgroupMin(gvec(T(1))) == gvec(T(1))
125        & subgroupMax(gvec(T(1))) == gvec(T(1))
126        ;
127}
128
129bool testArithmetic() {
130    return true
131        & test1Arithmetic<float>()
132        & testVArithmetic<float, 2>()
133        & testVArithmetic<float, 3>()
134        & testVArithmetic<float, 4>()
135        & test1Arithmetic<half>()
136        & testVArithmetic<half, 2>()
137        & testVArithmetic<half, 3>()
138        & testVArithmetic<half, 4>()
139        & test1Arithmetic<int>()
140        & testVArithmetic<int, 2>()
141        & testVArithmetic<int, 3>()
142        & testVArithmetic<int, 4>()
143        & test1Arithmetic<uint>()
144        & testVArithmetic<uint, 2>()
145        & testVArithmetic<uint, 3>()
146        & testVArithmetic<uint, 4>()
147
148        // Disabled on WGPU and Metal as these built-in types are not supported as of time of writing.
149#if !defined(WGPU) && !defined(METAL)
150        & test1Arithmetic<double>() // WARNING: intel GPU's lack FP64 support
151        & testVArithmetic<double, 2>()
152        & testVArithmetic<double, 3>()
153        & testVArithmetic<double, 4>()
154        & test1Arithmetic<int8_t>() 
155        & testVArithmetic<int8_t, 2>()
156        & testVArithmetic<int8_t, 3>()
157        & testVArithmetic<int8_t, 4>()
158        & test1Arithmetic<int64_t>() 
159        & testVArithmetic<int64_t, 2>()
160        & testVArithmetic<int64_t, 3>()
161        & testVArithmetic<int64_t, 4>()
162        & test1Arithmetic<uint8_t>() 
163        & testVArithmetic<uint8_t, 2>()
164        & testVArithmetic<uint8_t, 3>()
165        & testVArithmetic<uint8_t, 4>()
166        & test1Arithmetic<uint64_t>()
167        & testVArithmetic<uint64_t, 2>()
168        & testVArithmetic<uint64_t, 3>()
169        & testVArithmetic<uint64_t, 4>()
170#endif
171        // Disabled on WGPU as these built-in types are not supported as of time of writing.
172#if !defined (WGPU)
173        & test1Arithmetic<int16_t>() 
174        & testVArithmetic<int16_t, 2>()
175        & testVArithmetic<int16_t, 3>()
176        & testVArithmetic<int16_t, 4>()
177        & test1Arithmetic<uint16_t>() 
178        & testVArithmetic<uint16_t, 2>()
179        & testVArithmetic<uint16_t, 3>()
180        & testVArithmetic<uint16_t, 4>()
181#endif
182        ;
183}
184
185[shader("compute")]
186void computeMain()
187{
188
189    bool res0 = true
190            & testLogical()
191            ;
192    
193    bool res1 = true
194            & testArithmetic()
195            ;
196
197    if (gl_LocalInvocationID.x == 3) {
198        // seperate so if there is an erroneous error the "major"
199        // tests are issolated into 2 branches without polluting the
200        // file with a bunch of individual test values
201        outputBuffer.data[0] = res0;
202        outputBuffer.data[1] = res1;
203    }
204
205    // CHECK_GLSL: void main(
206    // CHECK_SPV: OpEntryPoint
207    // CHECK_HLSL: void computeMain(
208    // CHECK_CUDA: void computeMain(
209    // CHECK_CPP: void _computeMain(
210    // BUF: 1
211    // BUF-NEXT: 1
212}