Merge pull request #3031 from rg3igalia/sub-group-size-arb-flat-fix
[platform/upstream/glslang.git] / Test / glsl.450.subgroup.frag
1 #version 450\r
2 \r
3 vec4 undeclared_errors(vec4 f4)\r
4 {\r
5   vec4 result;\r
6   gl_SubgroupSize;               // ERROR, extension not enabled (basic)\r
7   gl_SubgroupInvocationID;       // ERROR, extension not enabled (basic)\r
8   subgroupBarrier();             // ERROR, extension not enabled (basic)\r
9   subgroupMemoryBarrier();       // ERROR, extension not enabled (basic)         \r
10   subgroupMemoryBarrierBuffer(); // ERROR, extension not enabled (basic)\r
11   subgroupMemoryBarrierImage();  // ERROR, extension not enabled (basic)\r
12   subgroupElect();               // ERROR, extension not enabled (basic)\r
13   gl_NumSubgroups;               // ERROR, only defined in compute\r
14   gl_SubgroupID;                 // ERROR, only defined in compute\r
15   subgroupMemoryBarrierShared(); // ERROR, only defined in compute\r
16 \r
17   subgroupAll(true);        // ERROR extension not enabled (vote)\r
18   subgroupAny(false);       // ERROR extension not enabled (vote)\r
19   subgroupAllEqual(f4);     // ERROR extension not enabled (vote)\r
20 \r
21   gl_SubgroupEqMask;                        // ERROR extension not enabled (ballot)\r
22   gl_SubgroupGeMask;                        // ERROR extension not enabled (ballot)\r
23   gl_SubgroupGtMask;                        // ERROR extension not enabled (ballot)\r
24   gl_SubgroupLeMask;                        // ERROR extension not enabled (ballot)\r
25   gl_SubgroupLtMask;                        // ERROR extension not enabled (ballot)\r
26   subgroupBroadcast(f4, 0);                 // ERROR extension not enabled (ballot)\r
27   subgroupBroadcastFirst(f4);               // ERROR extension not enabled (ballot)\r
28   uvec4 ballot = subgroupBallot(false);     // ERROR extension not enabled (ballot)\r
29   subgroupInverseBallot(uvec4(0x1));        // ERROR extension not enabled (ballot)\r
30   subgroupBallotBitExtract(ballot, 0);      // ERROR extension not enabled (ballot)\r
31   subgroupBallotBitCount(ballot);           // ERROR extension not enabled (ballot)\r
32   subgroupBallotInclusiveBitCount(ballot);  // ERROR extension not enabled (ballot)\r
33   subgroupBallotExclusiveBitCount(ballot);  // ERROR extension not enabled (ballot)\r
34   subgroupBallotFindLSB(ballot);            // ERROR extension not enabled (ballot)\r
35   subgroupBallotFindMSB(ballot);            // ERROR extension not enabled (ballot)\r
36 \r
37   subgroupShuffle(f4, 0);           // ERROR extension not enabled (shuffle)\r
38   subgroupShuffleXor(f4, 0x1);      // ERROR extension not enabled (shuffle)\r
39   subgroupShuffleUp(f4, 1);         // ERROR extension not enabled (shuffle_relative)\r
40   subgroupShuffleDown(f4, 1);       // ERROR extension not enabled (shuffle_relative)\r
41 \r
42   result = subgroupAdd(f4);         // ERROR, extension not enabled (arith)\r
43   subgroupMul(f4);                  // ERROR, extension not enabled (arith)\r
44   subgroupMin(f4);                  // ERROR, extension not enabled (arith)\r
45   subgroupMax(f4);                  // ERROR, extension not enabled (arith)\r
46   subgroupAnd(ballot);              // ERROR, extension not enabled (arith)\r
47   subgroupOr(ballot);               // ERROR, extension not enabled (arith)\r
48   subgroupXor(ballot);              // ERROR, extension not enabled (arith)\r
49   subgroupInclusiveAdd(f4);         // ERROR, extension not enabled (arith)\r
50   subgroupInclusiveMul(f4);         // ERROR, extension not enabled (arith)\r
51   subgroupInclusiveMin(f4);         // ERROR, extension not enabled (arith)\r
52   subgroupInclusiveMax(f4);         // ERROR, extension not enabled (arith)\r
53   subgroupInclusiveAnd(ballot);     // ERROR, extension not enabled (arith)\r
54   subgroupInclusiveOr(ballot);      // ERROR, extension not enabled (arith)\r
55   subgroupInclusiveXor(ballot);     // ERROR, extension not enabled (arith)\r
56   subgroupExclusiveAdd(f4);         // ERROR, extension not enabled (arith)\r
57   subgroupExclusiveMul(f4);         // ERROR, extension not enabled (arith)\r
58   subgroupExclusiveMin(f4);         // ERROR, extension not enabled (arith)\r
59   subgroupExclusiveMax(f4);         // ERROR, extension not enabled (arith)\r
60   subgroupExclusiveAnd(ballot);     // ERROR, extension not enabled (arith)\r
61   subgroupExclusiveOr(ballot);      // ERROR, extension not enabled (arith)\r
62   subgroupExclusiveXor(ballot);     // ERROR, extension not enabled (arith)\r
63 \r
64   subgroupClusteredAdd(f4, 2);      // ERROR, extension not enabled (clustered)\r
65   subgroupClusteredMul(f4, 2);      // ERROR, extension not enabled (clustered)\r
66   subgroupClusteredMin(f4, 2);      // ERROR, extension not enabled (clustered)\r
67   subgroupClusteredMax(f4, 2);      // ERROR, extension not enabled (clustered)\r
68   subgroupClusteredAnd(ballot, 2);  // ERROR, extension not enabled (clustered)\r
69   subgroupClusteredOr(ballot, 2);   // ERROR, extension not enabled (clustered)\r
70   subgroupClusteredXor(ballot, 2);  // ERROR, extension not enabled (clustered)\r
71 \r
72   subgroupQuadBroadcast(f4, 0);     // ERROR, extension not enabled (quad)\r
73   subgroupQuadSwapHorizontal(f4);   // ERROR, extension not enabled (quad)\r
74   subgroupQuadSwapVertical(f4);     // ERROR, extension not enabled (quad)\r
75   subgroupQuadSwapDiagonal(f4);     // ERROR, extension not enabled (quad)\r
76 \r
77   uvec4 parti = subgroupPartitionNV(f4);                // ERROR, extension not enabled (partitioned)\r
78   subgroupPartitionedAddNV(f4, parti);                  // ERROR, extension not enabled (partitioned)\r
79   subgroupPartitionedMulNV(f4, parti);                  // ERROR, extension not enabled (partitioned)\r
80   subgroupPartitionedMinNV(f4, parti);                  // ERROR, extension not enabled (partitioned)\r
81   subgroupPartitionedMaxNV(f4, parti);                  // ERROR, extension not enabled (partitioned)\r
82   subgroupPartitionedAndNV(ballot, parti);              // ERROR, extension not enabled (partitioned)\r
83   subgroupPartitionedOrNV(ballot, parti);               // ERROR, extension not enabled (partitioned)\r
84   subgroupPartitionedXorNV(ballot, parti);              // ERROR, extension not enabled (partitioned)\r
85   subgroupPartitionedInclusiveAddNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
86   subgroupPartitionedInclusiveMulNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
87   subgroupPartitionedInclusiveMinNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
88   subgroupPartitionedInclusiveMaxNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
89   subgroupPartitionedInclusiveAndNV(ballot, parti);     // ERROR, extension not enabled (partitioned)\r
90   subgroupPartitionedInclusiveOrNV(ballot, parti);      // ERROR, extension not enabled (partitioned)\r
91   subgroupPartitionedInclusiveXorNV(ballot, parti);     // ERROR, extension not enabled (partitioned)\r
92   subgroupPartitionedExclusiveAddNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
93   subgroupPartitionedExclusiveMulNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
94   subgroupPartitionedExclusiveMinNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
95   subgroupPartitionedExclusiveMaxNV(f4, parti);         // ERROR, extension not enabled (partitioned)\r
96   subgroupPartitionedExclusiveAndNV(ballot, parti);     // ERROR, extension not enabled (partitioned)\r
97   subgroupPartitionedExclusiveOrNV(ballot, parti);      // ERROR, extension not enabled (partitioned)\r
98   subgroupPartitionedExclusiveXorNV(ballot, parti);     // ERROR, extension not enabled (partitioned)\r
99 \r
100   return result;\r
101 }\r
102 \r
103 #extension GL_KHR_shader_subgroup_basic: enable\r
104 layout(location = 0) out uvec4 data;\r
105 void main (void)\r
106 {\r
107   data = uvec4(gl_SubgroupSize, gl_SubgroupInvocationID, 0, 0);\r
108   subgroupBarrier();\r
109   subgroupMemoryBarrier();\r
110   subgroupMemoryBarrierBuffer();\r
111   subgroupMemoryBarrierImage();\r
112   subgroupElect();\r
113 }\r
114 \r
115 #extension GL_KHR_shader_subgroup_ballot: enable\r
116 void ballot_works(vec4 f4) {\r
117   int i;\r
118   gl_SubgroupEqMask;\r
119   gl_SubgroupGeMask;\r
120   gl_SubgroupGtMask;\r
121   gl_SubgroupLeMask;\r
122   gl_SubgroupLtMask;\r
123   subgroupBroadcast(f4, 0);\r
124   subgroupBroadcast(f4, i);\r
125   subgroupBroadcastFirst(f4);\r
126   uvec4 ballot = subgroupBallot(false);\r
127   subgroupInverseBallot(uvec4(0x1));\r
128   subgroupBallotBitExtract(ballot, 0);\r
129   subgroupBallotBitCount(ballot);\r
130   subgroupBallotInclusiveBitCount(ballot);\r
131   subgroupBallotExclusiveBitCount(ballot);\r
132   subgroupBallotFindLSB(ballot);\r
133   subgroupBallotFindMSB(ballot);\r
134 }\r
135 \r
136 #extension GL_KHR_shader_subgroup_vote: enable\r
137 void vote_works(vec4 f4)\r
138 {\r
139   subgroupAll(true);\r
140   subgroupAny(false);\r
141   subgroupAllEqual(f4);\r
142 }\r
143 \r
144 #extension GL_KHR_shader_subgroup_shuffle: enable\r
145 #extension GL_KHR_shader_subgroup_shuffle_relative: enable\r
146 void shuffle_works(vec4 f4)\r
147 {\r
148   subgroupShuffle(f4, 0);\r
149   subgroupShuffleXor(f4, 0x1);\r
150   subgroupShuffleUp(f4, 1);\r
151   subgroupShuffleDown(f4, 1);\r
152 }\r
153 \r
154 #extension GL_KHR_shader_subgroup_arithmetic: enable\r
155 void arith_works(vec4 f4)\r
156 {\r
157   uvec4 ballot;\r
158   subgroupAdd(f4);\r
159   subgroupMul(f4);\r
160   subgroupMin(f4);\r
161   subgroupMax(f4);\r
162   subgroupAnd(ballot);\r
163   subgroupOr(ballot);\r
164   subgroupXor(ballot);\r
165   subgroupInclusiveAdd(f4);\r
166   subgroupInclusiveMul(f4);\r
167   subgroupInclusiveMin(f4);\r
168   subgroupInclusiveMax(f4);\r
169   subgroupInclusiveAnd(ballot);\r
170   subgroupInclusiveOr(ballot);\r
171   subgroupInclusiveXor(ballot);\r
172   subgroupExclusiveAdd(f4);\r
173   subgroupExclusiveMul(f4);\r
174   subgroupExclusiveMin(f4);\r
175   subgroupExclusiveMax(f4);\r
176   subgroupExclusiveAnd(ballot);\r
177   subgroupExclusiveOr(ballot);\r
178   subgroupExclusiveXor(ballot);\r
179 }\r
180 \r
181 #extension GL_KHR_shader_subgroup_clustered: enable\r
182 void clustered_works(vec4 f4)\r
183 {\r
184   uvec4 ballot = uvec4(0x55,0,0,0);\r
185   subgroupClusteredAdd(f4, 2);\r
186   subgroupClusteredMul(f4, 2);\r
187   subgroupClusteredMin(f4, 2);\r
188   subgroupClusteredMax(f4, 2);\r
189   subgroupClusteredAnd(ballot, 2);\r
190   subgroupClusteredOr(ballot, 2);\r
191   subgroupClusteredXor(ballot, 2);\r
192 }\r
193 \r
194 #extension GL_KHR_shader_subgroup_quad: enable\r
195 void quad_works(vec4 f4)\r
196 {\r
197   int i;\r
198   subgroupQuadBroadcast(f4, 0);\r
199   subgroupQuadBroadcast(f4, i);\r
200   subgroupQuadSwapHorizontal(f4);\r
201   subgroupQuadSwapVertical(f4);\r
202   subgroupQuadSwapDiagonal(f4);\r
203 }\r
204 \r
205 #extension GL_NV_shader_subgroup_partitioned: enable\r
206 void partitioned_works(vec4 f4)\r
207 {\r
208   uvec4 parti = subgroupPartitionNV(f4);\r
209   uvec4 ballot = uvec4(0x55,0,0,0);\r
210   subgroupPartitionedAddNV(f4, parti);\r
211   subgroupPartitionedMulNV(f4, parti);\r
212   subgroupPartitionedMinNV(f4, parti);\r
213   subgroupPartitionedMaxNV(f4, parti);\r
214   subgroupPartitionedAndNV(ballot, parti);\r
215   subgroupPartitionedOrNV(ballot, parti);\r
216   subgroupPartitionedXorNV(ballot, parti);\r
217   subgroupPartitionedInclusiveAddNV(f4, parti);\r
218   subgroupPartitionedInclusiveMulNV(f4, parti);\r
219   subgroupPartitionedInclusiveMinNV(f4, parti);\r
220   subgroupPartitionedInclusiveMaxNV(f4, parti);\r
221   subgroupPartitionedInclusiveAndNV(ballot, parti);\r
222   subgroupPartitionedInclusiveOrNV(ballot, parti);\r
223   subgroupPartitionedInclusiveXorNV(ballot, parti);\r
224   subgroupPartitionedExclusiveAddNV(f4, parti);\r
225   subgroupPartitionedExclusiveMulNV(f4, parti);\r
226   subgroupPartitionedExclusiveMinNV(f4, parti);\r
227   subgroupPartitionedExclusiveMaxNV(f4, parti);\r
228   subgroupPartitionedExclusiveAndNV(ballot, parti);\r
229   subgroupPartitionedExclusiveOrNV(ballot, parti);\r
230   subgroupPartitionedExclusiveXorNV(ballot, parti);\r
231 }\r
232 \r
233 // tests for NV_shader_sm_builtins\r
234 void sm_builtins_err()\r
235 {\r
236     gl_WarpsPerSMNV;    // ERROR, no extension\r
237     gl_SMCountNV;       // ERROR, no extension\r
238     gl_WarpIDNV;        // ERROR, no extension\r
239     gl_SMIDNV;          // ERROR, no extension\r
240 }\r
241 \r
242 #ifdef GL_NV_shader_sm_builtins\r
243 #extension GL_NV_shader_sm_builtins : enable\r
244 #endif\r
245 \r
246 void sm_builtins()\r
247 {\r
248     gl_WarpsPerSMNV;\r
249     gl_SMCountNV;\r
250     gl_WarpIDNV;\r
251     gl_SMIDNV;\r
252 }\r