yum-mirror/slang

Making it easier to work with shaders

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

kaizhangNVImplement short-circuit logic operator (#3635)2297623aa

master
5.6 KiB171 linesraw
1//TEST:SIMPLE(filecheck=CHECK_GLSL):  -allow-glsl -stage compute -entry computeMain -target glsl
2//TEST:SIMPLE(filecheck=CHECK_SPV):  -allow-glsl -stage compute -entry computeMain -target spirv -emit-spirv-directly
3
4// not testing hlsl due to missing impl
5//DISABLE_TEST:SIMPLE(filecheck=CHECK_HLSL): -allow-glsl -stage compute -entry computeMain -target hlsl -DTARGET_HLSL
6// not testing cuda due to missing impl
7//DISABLE_TEST:SIMPLE(filecheck=CHECK_CUDA): -allow-glsl -stage compute -entry computeMain -target cuda -DTARGET_CUDA 
8// not testing cpp due to missing impl
9//DISABLE_TEST:SIMPLE(filecheck=CHECK_CPP):  -allow-glsl -stage compute -entry computeMain -target cpp -DTARGET_CPP
10
11//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl
12//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -emit-spirv-directly
13#version 430
14
15//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer
16buffer MyBlockName2 
17{
18    uint data[];
19} outputBuffer;
20
21layout(local_size_x = 32) in;
22
23__generic<T : __BuiltinLogicalType>
24bool test1Logical() {
25    return true
26        & subgroupClusteredAnd(T(1), 1) == T(1)
27        & subgroupClusteredOr(T(1), 1) == T(1)
28        & subgroupClusteredXor(T(1), 1) == T(1)
29        ;
30}
31
32__generic<T : __BuiltinLogicalType, let N : int>
33bool testVLogical() {
34    typealias gvec = vector<T, N>;
35
36    return true
37        & subgroupClusteredAnd(gvec(T(1)), 1) == gvec(T(1))
38        & subgroupClusteredOr(gvec(T(1)), 1) == gvec(T(1))
39        & subgroupClusteredXor(gvec(T(1)), 1) == gvec(T(1))   
40        ;     
41}
42
43bool testLogical() {
44    return true
45        & test1Logical<int>()
46        & testVLogical<int, 2>()
47        & testVLogical<int, 3>()
48        & testVLogical<int, 4>()
49        & test1Logical<int8_t>()
50        & testVLogical<int8_t, 2>()
51        & testVLogical<int8_t, 3>()
52        & testVLogical<int8_t, 4>()
53        & test1Logical<int16_t>()
54        & testVLogical<int16_t, 2>()
55        & testVLogical<int16_t, 3>()
56        & testVLogical<int16_t, 4>()
57        & test1Logical<int64_t>()
58        & testVLogical<int64_t, 2>()
59        & testVLogical<int64_t, 3>()
60        & testVLogical<int64_t, 4>()
61        & test1Logical<uint>()
62        & testVLogical<uint, 2>()
63        & testVLogical<uint, 3>()
64        & testVLogical<uint, 4>()
65        & test1Logical<uint8_t>()
66        & testVLogical<uint8_t, 2>()
67        & testVLogical<uint8_t, 3>()
68        & testVLogical<uint8_t, 4>()
69        & test1Logical<uint16_t>()
70        & testVLogical<uint16_t, 2>()
71        & testVLogical<uint16_t, 3>()
72        & testVLogical<uint16_t, 4>()
73        & test1Logical<uint64_t>()
74        & testVLogical<uint64_t, 2>()
75        & testVLogical<uint64_t, 3>()
76        & testVLogical<uint64_t, 4>()
77        & test1Logical<bool>()
78        & testVLogical<bool, 2>()
79        & testVLogical<bool, 3>()
80        & testVLogical<bool, 4>()
81        ;
82}
83
84__generic<T : __BuiltinArithmeticType>
85bool test1Arithmetic() {
86    return true
87        & subgroupClusteredAdd(T(1), 1) == T(1)
88        & subgroupClusteredMul(T(1), 1) == T(1)
89        & subgroupClusteredMin(T(1), 1) == T(1)
90        & subgroupClusteredMax(T(1), 1) == T(1)
91        ;
92}
93
94__generic<T : __BuiltinArithmeticType, let N : int>
95bool testVArithmetic() {
96    typealias gvec = vector<T, N>;
97
98    return true
99        & subgroupClusteredAdd(gvec(T(1)), 1) == gvec(T(1))
100        & subgroupClusteredMul(gvec(T(1)), 1) == gvec(T(1))
101        & subgroupClusteredMin(gvec(T(1)), 1) == gvec(T(1))
102        & subgroupClusteredMax(gvec(T(1)), 1) == gvec(T(1))
103        ;
104}
105
106bool testArithmetic() {
107    return true
108        & test1Arithmetic<float>()
109        & testVArithmetic<float, 2>()
110        & testVArithmetic<float, 3>()
111        & testVArithmetic<float, 4>()
112        & test1Arithmetic<double>() // WARNING: intel GPU's lack FP64 support
113        & testVArithmetic<double, 2>() 
114        & testVArithmetic<double, 3>()
115        & testVArithmetic<double, 4>()
116        & test1Arithmetic<half>() 
117        & testVArithmetic<half, 2>()
118        & testVArithmetic<half, 3>()
119        & testVArithmetic<half, 4>()
120        & test1Arithmetic<int>()
121        & testVArithmetic<int, 2>()
122        & testVArithmetic<int, 3>()
123        & testVArithmetic<int, 4>()
124        & test1Arithmetic<int8_t>() 
125        & testVArithmetic<int8_t, 2>()
126        & testVArithmetic<int8_t, 3>()
127        & testVArithmetic<int8_t, 4>()
128        & test1Arithmetic<int16_t>() 
129        & testVArithmetic<int16_t, 2>()
130        & testVArithmetic<int16_t, 3>()
131        & testVArithmetic<int16_t, 4>()
132        & test1Arithmetic<int64_t>() 
133        & testVArithmetic<int64_t, 2>()
134        & testVArithmetic<int64_t, 3>()
135        & testVArithmetic<int64_t, 4>()
136        & test1Arithmetic<uint>()
137        & testVArithmetic<uint, 2>()
138        & testVArithmetic<uint, 3>()
139        & testVArithmetic<uint, 4>()
140        & test1Arithmetic<uint8_t>() 
141        & testVArithmetic<uint8_t, 2>()
142        & testVArithmetic<uint8_t, 3>()
143        & testVArithmetic<uint8_t, 4>()
144        & test1Arithmetic<uint16_t>() 
145        & testVArithmetic<uint16_t, 2>()
146        & testVArithmetic<uint16_t, 3>()
147        & testVArithmetic<uint16_t, 4>()
148        & test1Arithmetic<uint64_t>() 
149        & testVArithmetic<uint64_t, 2>()
150        & testVArithmetic<uint64_t, 3>()
151        & testVArithmetic<uint64_t, 4>()
152        ;
153}
154
155void computeMain()
156{
157    outputBuffer.data[0] = true
158        & testLogical()
159        ;
160    outputBuffer.data[1] = true
161        & testArithmetic()
162        ;
163
164    // CHECK_GLSL: void main(
165    // CHECK_SPV: OpEntryPoint
166    // CHECK_HLSL: void computeMain(
167    // CHECK_CUDA: void computeMain(
168    // CHECK_CPP: void _computeMain(
169    // BUF: 1
170    // BUF-NEXT: 1
171}