Debian Codegraph @

test/val/val_ext_inst_test.cpp

raw
1 // Copyright (c) 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Tests validation rules of GLSL.450.std and OpenCL.std extended instructions.
16 // Doesn't test OpenCL.std vector size 2, 3, 4, 8 or 16 rules (not supported
17 // by standard SPIR-V).
18
19 #include <sstream>
20 #include <string>
21 #include <vector>
22
23 #include "gmock/gmock.h"
24 #include "test/unit_spirv.h"
25 #include "test/val/val_fixtures.h"
26
27 namespace spvtools {
28 namespace val {
29 namespace {
30
31 using ::testing::Eq;
32 using ::testing::HasSubstr;
33 using ::testing::Not;
34
35 using ValidateExtInst = spvtest::ValidateBase<bool>;
36 using ValidateGlslStd450SqrtLike = spvtest::ValidateBase<std::string>;
37 using ValidateGlslStd450FMinLike = spvtest::ValidateBase<std::string>;
38 using ValidateGlslStd450FClampLike = spvtest::ValidateBase<std::string>;
39 using ValidateGlslStd450SAbsLike = spvtest::ValidateBase<std::string>;
40 using ValidateGlslStd450UMinLike = spvtest::ValidateBase<std::string>;
41 using ValidateGlslStd450UClampLike = spvtest::ValidateBase<std::string>;
42 using ValidateGlslStd450SinLike = spvtest::ValidateBase<std::string>;
43 using ValidateGlslStd450PowLike = spvtest::ValidateBase<std::string>;
44 using ValidateGlslStd450Pack = spvtest::ValidateBase<std::string>;
45 using ValidateGlslStd450Unpack = spvtest::ValidateBase<std::string>;
46 using ValidateOpenCLStdSqrtLike = spvtest::ValidateBase<std::string>;
47 using ValidateOpenCLStdFMinLike = spvtest::ValidateBase<std::string>;
48 using ValidateOpenCLStdFClampLike = spvtest::ValidateBase<std::string>;
49 using ValidateOpenCLStdSAbsLike = spvtest::ValidateBase<std::string>;
50 using ValidateOpenCLStdUMinLike = spvtest::ValidateBase<std::string>;
51 using ValidateOpenCLStdUClampLike = spvtest::ValidateBase<std::string>;
52 using ValidateOpenCLStdUMul24Like = spvtest::ValidateBase<std::string>;
53 using ValidateOpenCLStdUMad24Like = spvtest::ValidateBase<std::string>;
54 using ValidateOpenCLStdLengthLike = spvtest::ValidateBase<std::string>;
55 using ValidateOpenCLStdDistanceLike = spvtest::ValidateBase<std::string>;
56 using ValidateOpenCLStdNormalizeLike = spvtest::ValidateBase<std::string>;
57 using ValidateOpenCLStdVStoreHalfLike = spvtest::ValidateBase<std::string>;
58 using ValidateOpenCLStdVLoadHalfLike = spvtest::ValidateBase<std::string>;
59 using ValidateOpenCLStdFractLike = spvtest::ValidateBase<std::string>;
60 using ValidateOpenCLStdFrexpLike = spvtest::ValidateBase<std::string>;
61 using ValidateOpenCLStdLdexpLike = spvtest::ValidateBase<std::string>;
62 using ValidateOpenCLStdUpsampleLike = spvtest::ValidateBase<std::string>;
63 using ValidateClspvReflection = spvtest::ValidateBase<bool>;
64
65 // Returns number of components in Pack/Unpack extended instructions.
66 // |ext_inst_name| is expected to be of the format "PackHalf2x16".
67 // Number of components is assumed to be single-digit.
68 uint32_t GetPackedNumComponents(const std::string& ext_inst_name) {
69 const size_t x_index = ext_inst_name.find_last_of('x');
70 const std::string num_components_str =
71 ext_inst_name.substr(x_index - 1, x_index);
72 return uint32_t(std::stoul(num_components_str));
73 }
74
75 // Returns packed bit width in Pack/Unpack extended instructions.
76 // |ext_inst_name| is expected to be of the format "PackHalf2x16".
77 uint32_t GetPackedBitWidth(const std::string& ext_inst_name) {
78 const size_t x_index = ext_inst_name.find_last_of('x');
79 const std::string packed_bit_width_str = ext_inst_name.substr(x_index + 1);
80 return uint32_t(std::stoul(packed_bit_width_str));
81 }
82
83 std::string GenerateShaderCode(
84 const std::string& body,
85 const std::string& capabilities_and_extensions = "",
86 const std::string& execution_model = "Fragment") {
87 std::ostringstream ss;
88 ss << R"(
89 OpCapability Shader
90 OpCapability Float16
91 OpCapability Float64
92 OpCapability Int16
93 OpCapability Int64
94 )";
95
96 ss << capabilities_and_extensions;
97 ss << "%extinst = OpExtInstImport \"GLSL.std.450\"\n";
98 ss << "OpMemoryModel Logical GLSL450\n";
99 ss << "OpEntryPoint " << execution_model << " %main \"main\""
100 << " %f32_output"
101 << " %f32vec2_output"
102 << " %u32_output"
103 << " %u32vec2_output"
104 << " %u64_output"
105 << " %f32_input"
106 << " %f32vec2_input"
107 << " %u32_input"
108 << " %u32vec2_input"
109 << " %u64_input"
110 << "\n";
111 if (execution_model == "Fragment") {
112 ss << "OpExecutionMode %main OriginUpperLeft\n";
113 }
114
115 ss << R"(
116 %void = OpTypeVoid
117 %func = OpTypeFunction %void
118 %bool = OpTypeBool
119 %f16 = OpTypeFloat 16
120 %f32 = OpTypeFloat 32
121 %f64 = OpTypeFloat 64
122 %u32 = OpTypeInt 32 0
123 %s32 = OpTypeInt 32 1
124 %u64 = OpTypeInt 64 0
125 %s64 = OpTypeInt 64 1
126 %u16 = OpTypeInt 16 0
127 %s16 = OpTypeInt 16 1
128 %f32vec2 = OpTypeVector %f32 2
129 %f32vec3 = OpTypeVector %f32 3
130 %f32vec4 = OpTypeVector %f32 4
131 %f64vec2 = OpTypeVector %f64 2
132 %f64vec3 = OpTypeVector %f64 3
133 %f64vec4 = OpTypeVector %f64 4
134 %u32vec2 = OpTypeVector %u32 2
135 %u32vec3 = OpTypeVector %u32 3
136 %s32vec2 = OpTypeVector %s32 2
137 %u32vec4 = OpTypeVector %u32 4
138 %s32vec4 = OpTypeVector %s32 4
139 %u64vec2 = OpTypeVector %u64 2
140 %s64vec2 = OpTypeVector %s64 2
141 %f64mat22 = OpTypeMatrix %f64vec2 2
142 %f32mat22 = OpTypeMatrix %f32vec2 2
143 %f32mat23 = OpTypeMatrix %f32vec2 3
144 %f32mat32 = OpTypeMatrix %f32vec3 2
145 %f32mat33 = OpTypeMatrix %f32vec3 3
146
147 %f32_0 = OpConstant %f32 0
148 %f32_1 = OpConstant %f32 1
149 %f32_2 = OpConstant %f32 2
150 %f32_3 = OpConstant %f32 3
151 %f32_4 = OpConstant %f32 4
152 %f32_h = OpConstant %f32 0.5
153 %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
154 %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
155 %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
156 %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
157 %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
158 %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
159
160 %f64_0 = OpConstant %f64 0
161 %f64_1 = OpConstant %f64 1
162 %f64_2 = OpConstant %f64 2
163 %f64_3 = OpConstant %f64 3
164 %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
165 %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
166 %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
167
168 %f16_0 = OpConstant %f16 0
169 %f16_1 = OpConstant %f16 1
170 %f16_h = OpConstant %f16 0.5
171
172 %u32_0 = OpConstant %u32 0
173 %u32_1 = OpConstant %u32 1
174 %u32_2 = OpConstant %u32 2
175 %u32_3 = OpConstant %u32 3
176
177 %s32_0 = OpConstant %s32 0
178 %s32_1 = OpConstant %s32 1
179 %s32_2 = OpConstant %s32 2
180 %s32_3 = OpConstant %s32 3
181
182 %u64_0 = OpConstant %u64 0
183 %u64_1 = OpConstant %u64 1
184 %u64_2 = OpConstant %u64 2
185 %u64_3 = OpConstant %u64 3
186
187 %s64_0 = OpConstant %s64 0
188 %s64_1 = OpConstant %s64 1
189 %s64_2 = OpConstant %s64 2
190 %s64_3 = OpConstant %s64 3
191
192 %s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
193 %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
194
195 %s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
196 %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
197
198 %s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
199 %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
200
201 %s64vec2_01 = OpConstantComposite %s64vec2 %s64_0 %s64_1
202 %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
203
204 %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
205 %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
206
207 %f32_ptr_output = OpTypePointer Output %f32
208 %f32vec2_ptr_output = OpTypePointer Output %f32vec2
209
210 %u32_ptr_output = OpTypePointer Output %u32
211 %u32vec2_ptr_output = OpTypePointer Output %u32vec2
212
213 %u64_ptr_output = OpTypePointer Output %u64
214
215 %f32_output = OpVariable %f32_ptr_output Output
216 %f32vec2_output = OpVariable %f32vec2_ptr_output Output
217
218 %u32_output = OpVariable %u32_ptr_output Output
219 %u32vec2_output = OpVariable %u32vec2_ptr_output Output
220
221 %u64_output = OpVariable %u64_ptr_output Output
222
223 %f32_ptr_input = OpTypePointer Input %f32
224 %f32vec2_ptr_input = OpTypePointer Input %f32vec2
225
226 %u32_ptr_input = OpTypePointer Input %u32
227 %u32vec2_ptr_input = OpTypePointer Input %u32vec2
228
229 %u64_ptr_input = OpTypePointer Input %u64
230
231 %f32_input = OpVariable %f32_ptr_input Input
232 %f32vec2_input = OpVariable %f32vec2_ptr_input Input
233
234 %u32_input = OpVariable %u32_ptr_input Input
235 %u32vec2_input = OpVariable %u32vec2_ptr_input Input
236
237 %u64_input = OpVariable %u64_ptr_input Input
238
239 %struct_f16_u16 = OpTypeStruct %f16 %u16
240 %struct_f32_f32 = OpTypeStruct %f32 %f32
241 %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
242 %struct_f32_u32 = OpTypeStruct %f32 %u32
243 %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
244 %struct_u32_f32 = OpTypeStruct %u32 %f32
245 %struct_u32_u32 = OpTypeStruct %u32 %u32
246 %struct_f32_f64 = OpTypeStruct %f32 %f64
247 %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
248 %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
249
250 %main = OpFunction %void None %func
251 %main_entry = OpLabel
252 )";
253
254 ss << body;
255
256 ss << R"(
257 OpReturn
258 OpFunctionEnd)";
259
260 return ss.str();
261 }
262
263 std::string GenerateKernelCode(
264 const std::string& body,
265 const std::string& capabilities_and_extensions = "",
266 const std::string& memory_model = "Physical32") {
267 std::ostringstream ss;
268 ss << R"(
269 OpCapability Addresses
270 OpCapability Kernel
271 OpCapability Linkage
272 OpCapability GenericPointer
273 OpCapability Int8
274 OpCapability Int16
275 OpCapability Int64
276 OpCapability Float16
277 OpCapability Float64
278 OpCapability Vector16
279 OpCapability Matrix
280 )";
281
282 ss << capabilities_and_extensions;
283 ss << "%extinst = OpExtInstImport \"OpenCL.std\"\n";
284 ss << "OpMemoryModel " << memory_model << " OpenCL\n";
285
286 ss << R"(
287 %void = OpTypeVoid
288 %func = OpTypeFunction %void
289 %bool = OpTypeBool
290 %f16 = OpTypeFloat 16
291 %f32 = OpTypeFloat 32
292 %f64 = OpTypeFloat 64
293 %u32 = OpTypeInt 32 0
294 %u64 = OpTypeInt 64 0
295 %u16 = OpTypeInt 16 0
296 %u8 = OpTypeInt 8 0
297 %f32vec2 = OpTypeVector %f32 2
298 %f32vec3 = OpTypeVector %f32 3
299 %f32vec4 = OpTypeVector %f32 4
300 %f32vec8 = OpTypeVector %f32 8
301 %f16vec8 = OpTypeVector %f16 8
302 %f32vec16 = OpTypeVector %f32 16
303 %f64vec2 = OpTypeVector %f64 2
304 %f64vec3 = OpTypeVector %f64 3
305 %f64vec4 = OpTypeVector %f64 4
306 %u32vec2 = OpTypeVector %u32 2
307 %u32vec3 = OpTypeVector %u32 3
308 %u32vec4 = OpTypeVector %u32 4
309 %u32vec8 = OpTypeVector %u32 8
310 %u64vec2 = OpTypeVector %u64 2
311 %f64mat22 = OpTypeMatrix %f64vec2 2
312 %f32mat22 = OpTypeMatrix %f32vec2 2
313 %f32mat23 = OpTypeMatrix %f32vec2 3
314 %f32mat32 = OpTypeMatrix %f32vec3 2
315 %f32mat33 = OpTypeMatrix %f32vec3 3
316
317 %f32_0 = OpConstant %f32 0
318 %f32_1 = OpConstant %f32 1
319 %f32_2 = OpConstant %f32 2
320 %f32_3 = OpConstant %f32 3
321 %f32_4 = OpConstant %f32 4
322 %f32_h = OpConstant %f32 0.5
323 %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
324 %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
325 %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
326 %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
327 %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
328 %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
329 %f32vec8_01010101 = OpConstantComposite %f32vec8 %f32_0 %f32_1 %f32_0 %f32_1 %f32_0 %f32_1 %f32_0 %f32_1
330
331 %f64_0 = OpConstant %f64 0
332 %f64_1 = OpConstant %f64 1
333 %f64_2 = OpConstant %f64 2
334 %f64_3 = OpConstant %f64 3
335 %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
336 %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
337 %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
338
339 %f16_0 = OpConstant %f16 0
340 %f16_1 = OpConstant %f16 1
341
342 %u8_0 = OpConstant %u8 0
343 %u8_1 = OpConstant %u8 1
344 %u8_2 = OpConstant %u8 2
345 %u8_3 = OpConstant %u8 3
346
347 %u16_0 = OpConstant %u16 0
348 %u16_1 = OpConstant %u16 1
349 %u16_2 = OpConstant %u16 2
350 %u16_3 = OpConstant %u16 3
351
352 %u32_0 = OpConstant %u32 0
353 %u32_1 = OpConstant %u32 1
354 %u32_2 = OpConstant %u32 2
355 %u32_3 = OpConstant %u32 3
356 %u32_256 = OpConstant %u32 256
357
358 %u64_0 = OpConstant %u64 0
359 %u64_1 = OpConstant %u64 1
360 %u64_2 = OpConstant %u64 2
361 %u64_3 = OpConstant %u64 3
362 %u64_256 = OpConstant %u64 256
363
364 %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
365 %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
366 %u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
367 %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
368
369 %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
370
371 %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
372 %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
373
374 %struct_f32_f32 = OpTypeStruct %f32 %f32
375 %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
376 %struct_f32_u32 = OpTypeStruct %f32 %u32
377 %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
378 %struct_u32_f32 = OpTypeStruct %u32 %f32
379 %struct_u32_u32 = OpTypeStruct %u32 %u32
380 %struct_f32_f64 = OpTypeStruct %f32 %f64
381 %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
382 %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
383
384 %f16vec8_ptr_workgroup = OpTypePointer Workgroup %f16vec8
385 %f16vec8_workgroup = OpVariable %f16vec8_ptr_workgroup Workgroup
386 %f16_ptr_workgroup = OpTypePointer Workgroup %f16
387
388 %u32vec8_ptr_workgroup = OpTypePointer Workgroup %u32vec8
389 %u32vec8_workgroup = OpVariable %u32vec8_ptr_workgroup Workgroup
390 %u32_ptr_workgroup = OpTypePointer Workgroup %u32
391
392 %f32vec8_ptr_workgroup = OpTypePointer Workgroup %f32vec8
393 %f32vec8_workgroup = OpVariable %f32vec8_ptr_workgroup Workgroup
394 %f32_ptr_workgroup = OpTypePointer Workgroup %f32
395
396 %u32arr = OpTypeArray %u32 %u32_256
397 %u32arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %u32arr
398 %u32arr_cross_workgroup = OpVariable %u32arr_ptr_cross_workgroup CrossWorkgroup
399 %u32_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %u32
400
401 %f32arr = OpTypeArray %f32 %u32_256
402 %f32arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32arr
403 %f32arr_cross_workgroup = OpVariable %f32arr_ptr_cross_workgroup CrossWorkgroup
404 %f32_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32
405
406 %f32vec2arr = OpTypeArray %f32vec2 %u32_256
407 %f32vec2arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32vec2arr
408 %f32vec2arr_cross_workgroup = OpVariable %f32vec2arr_ptr_cross_workgroup CrossWorkgroup
409 %f32vec2_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32vec2
410
411 %struct_arr = OpTypeArray %struct_f32_f32 %u32_256
412 %struct_arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %struct_arr
413 %struct_arr_cross_workgroup = OpVariable %struct_arr_ptr_cross_workgroup CrossWorkgroup
414 %struct_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %struct_f32_f32
415
416 %f16vec8_ptr_uniform_constant = OpTypePointer UniformConstant %f16vec8
417 %f16vec8_uniform_constant = OpVariable %f16vec8_ptr_uniform_constant UniformConstant
418 %f16_ptr_uniform_constant = OpTypePointer UniformConstant %f16
419
420 %u32vec8_ptr_uniform_constant = OpTypePointer UniformConstant %u32vec8
421 %u32vec8_uniform_constant = OpVariable %u32vec8_ptr_uniform_constant UniformConstant
422 %u32_ptr_uniform_constant = OpTypePointer UniformConstant %u32
423
424 %f32vec8_ptr_uniform_constant = OpTypePointer UniformConstant %f32vec8
425 %f32vec8_uniform_constant = OpVariable %f32vec8_ptr_uniform_constant UniformConstant
426 %f32_ptr_uniform_constant = OpTypePointer UniformConstant %f32
427
428 %f16vec8_ptr_input = OpTypePointer Input %f16vec8
429 %f16vec8_input = OpVariable %f16vec8_ptr_input Input
430 %f16_ptr_input = OpTypePointer Input %f16
431
432 %u32vec8_ptr_input = OpTypePointer Input %u32vec8
433 %u32vec8_input = OpVariable %u32vec8_ptr_input Input
434 %u32_ptr_input = OpTypePointer Input %u32
435
436 %f32_ptr_generic = OpTypePointer Generic %f32
437 %u32_ptr_generic = OpTypePointer Generic %u32
438
439 %f32_ptr_function = OpTypePointer Function %f32
440 %f32vec2_ptr_function = OpTypePointer Function %f32vec2
441 %u32_ptr_function = OpTypePointer Function %u32
442 %u64_ptr_function = OpTypePointer Function %u64
443 %u32vec2_ptr_function = OpTypePointer Function %u32vec2
444
445 %u8arr = OpTypeArray %u8 %u32_256
446 %u8arr_ptr_uniform_constant = OpTypePointer UniformConstant %u8arr
447 %u8arr_uniform_constant = OpVariable %u8arr_ptr_uniform_constant UniformConstant
448 %u8_ptr_uniform_constant = OpTypePointer UniformConstant %u8
449 %u8_ptr_generic = OpTypePointer Generic %u8
450 %u8_ptr_input = OpTypePointer Input %u8
451
452 %main = OpFunction %void None %func
453 %main_entry = OpLabel
454 )";
455
456 ss << body;
457
458 ss << R"(
459 OpReturn
460 OpFunctionEnd)";
461
462 return ss.str();
463 }
464
465 TEST_P(ValidateGlslStd450SqrtLike, Success) {
466 const std::string ext_inst_name = GetParam();
467 std::ostringstream ss;
468 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
469 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
470 << " %f32vec2_01\n";
471 ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name << " %f64_0\n";
472 CompileSuccessfully(GenerateShaderCode(ss.str()));
473 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
474 }
475
476 TEST_P(ValidateGlslStd450SqrtLike, IntResultType) {
477 const std::string ext_inst_name = GetParam();
478 const std::string body =
479 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
480
481 CompileSuccessfully(GenerateShaderCode(body));
482 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
483 EXPECT_THAT(getDiagnosticString(),
484 HasSubstr("GLSL.std.450 " + ext_inst_name +
485 ": expected Result Type to be a float scalar "
486 "or vector type"));
487 }
488
489 TEST_P(ValidateGlslStd450SqrtLike, IntOperand) {
490 const std::string ext_inst_name = GetParam();
491 const std::string body =
492 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
493
494 CompileSuccessfully(GenerateShaderCode(body));
495 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
496 EXPECT_THAT(getDiagnosticString(),
497 HasSubstr("GLSL.std.450 " + ext_inst_name +
498 ": expected types of all operands to be equal to "
499 "Result Type"));
500 }
501
502 INSTANTIATE_TEST_SUITE_P(AllSqrtLike, ValidateGlslStd450SqrtLike,
503 ::testing::ValuesIn(std::vector<std::string>{
504 "Round",
505 "RoundEven",
506 "FAbs",
507 "Trunc",
508 "FSign",
509 "Floor",
510 "Ceil",
511 "Fract",
512 "Sqrt",
513 "InverseSqrt",
514 "Normalize",
515 }));
516
517 TEST_P(ValidateGlslStd450FMinLike, Success) {
518 const std::string ext_inst_name = GetParam();
519 std::ostringstream ss;
520 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
521 << " %f32_0 %f32_1\n";
522 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
523 << " %f32vec2_01 %f32vec2_12\n";
524 ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
525 << " %f64_0 %f64_0\n";
526 CompileSuccessfully(GenerateShaderCode(ss.str()));
527 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
528 }
529
530 TEST_P(ValidateGlslStd450FMinLike, IntResultType) {
531 const std::string ext_inst_name = GetParam();
532 const std::string body =
533 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %f32_1\n";
534
535 CompileSuccessfully(GenerateShaderCode(body));
536 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
537 EXPECT_THAT(getDiagnosticString(),
538 HasSubstr("GLSL.std.450 " + ext_inst_name +
539 ": expected Result Type to be a float scalar "
540 "or vector type"));
541 }
542
543 TEST_P(ValidateGlslStd450FMinLike, IntOperand1) {
544 const std::string ext_inst_name = GetParam();
545 const std::string body =
546 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
547
548 CompileSuccessfully(GenerateShaderCode(body));
549 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
550 EXPECT_THAT(getDiagnosticString(),
551 HasSubstr("GLSL.std.450 " + ext_inst_name +
552 ": expected types of all operands to be equal to "
553 "Result Type"));
554 }
555
556 TEST_P(ValidateGlslStd450FMinLike, IntOperand2) {
557 const std::string ext_inst_name = GetParam();
558 const std::string body =
559 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
560
561 CompileSuccessfully(GenerateShaderCode(body));
562 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
563 EXPECT_THAT(getDiagnosticString(),
564 HasSubstr("GLSL.std.450 " + ext_inst_name +
565 ": expected types of all operands to be equal to "
566 "Result Type"));
567 }
568
569 INSTANTIATE_TEST_SUITE_P(AllFMinLike, ValidateGlslStd450FMinLike,
570 ::testing::ValuesIn(std::vector<std::string>{
571 "FMin",
572 "FMax",
573 "Step",
574 "Reflect",
575 "NMin",
576 "NMax",
577 }));
578
579 TEST_P(ValidateGlslStd450FClampLike, Success) {
580 const std::string ext_inst_name = GetParam();
581 std::ostringstream ss;
582 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
583 << " %f32_0 %f32_1 %f32_2\n";
584 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
585 << " %f32vec2_01 %f32vec2_01 %f32vec2_12\n";
586 ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
587 << " %f64_0 %f64_0 %f64_1\n";
588 CompileSuccessfully(GenerateShaderCode(ss.str()));
589 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
590 }
591
592 TEST_P(ValidateGlslStd450FClampLike, IntResultType) {
593 const std::string ext_inst_name = GetParam();
594 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
595 " %f32_0 %f32_1 %f32_2\n";
596
597 CompileSuccessfully(GenerateShaderCode(body));
598 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
599 EXPECT_THAT(getDiagnosticString(),
600 HasSubstr("GLSL.std.450 " + ext_inst_name +
601 ": expected Result Type to be a float scalar "
602 "or vector type"));
603 }
604
605 TEST_P(ValidateGlslStd450FClampLike, IntOperand1) {
606 const std::string ext_inst_name = GetParam();
607 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
608 " %u32_0 %f32_0 %f32_1\n";
609
610 CompileSuccessfully(GenerateShaderCode(body));
611 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
612 EXPECT_THAT(getDiagnosticString(),
613 HasSubstr("GLSL.std.450 " + ext_inst_name +
614 ": expected types of all operands to be equal to "
615 "Result Type"));
616 }
617
618 TEST_P(ValidateGlslStd450FClampLike, IntOperand2) {
619 const std::string ext_inst_name = GetParam();
620 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
621 " %f32_0 %u32_0 %f32_1\n";
622
623 CompileSuccessfully(GenerateShaderCode(body));
624 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
625 EXPECT_THAT(getDiagnosticString(),
626 HasSubstr("GLSL.std.450 " + ext_inst_name +
627 ": expected types of all operands to be equal to "
628 "Result Type"));
629 }
630
631 TEST_P(ValidateGlslStd450FClampLike, IntOperand3) {
632 const std::string ext_inst_name = GetParam();
633 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
634 " %f32_1 %f32_0 %u32_2\n";
635
636 CompileSuccessfully(GenerateShaderCode(body));
637 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
638 EXPECT_THAT(getDiagnosticString(),
639 HasSubstr("GLSL.std.450 " + ext_inst_name +
640 ": expected types of all operands to be equal to "
641 "Result Type"));
642 }
643
644 INSTANTIATE_TEST_SUITE_P(AllFClampLike, ValidateGlslStd450FClampLike,
645 ::testing::ValuesIn(std::vector<std::string>{
646 "FClamp",
647 "FMix",
648 "SmoothStep",
649 "Fma",
650 "FaceForward",
651 "NClamp",
652 }));
653
654 TEST_P(ValidateGlslStd450SAbsLike, Success) {
655 const std::string ext_inst_name = GetParam();
656 std::ostringstream ss;
657 ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name << " %u32_1\n";
658 ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name << " %s32_1\n";
659 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
660 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name << " %s32_1\n";
661 ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
662 << " %s32vec2_01\n";
663 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
664 << " %u32vec2_01\n";
665 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
666 << " %s32vec2_01\n";
667 ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
668 << " %u32vec2_01\n";
669 CompileSuccessfully(GenerateShaderCode(ss.str()));
670 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
671 }
672
673 TEST_P(ValidateGlslStd450SAbsLike, FloatResultType) {
674 const std::string ext_inst_name = GetParam();
675 const std::string body =
676 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
677
678 CompileSuccessfully(GenerateShaderCode(body));
679 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
680 EXPECT_THAT(getDiagnosticString(),
681 HasSubstr("GLSL.std.450 " + ext_inst_name +
682 ": expected Result Type to be an int scalar "
683 "or vector type"));
684 }
685
686 TEST_P(ValidateGlslStd450SAbsLike, FloatOperand) {
687 const std::string ext_inst_name = GetParam();
688 const std::string body =
689 "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %f32_0\n";
690
691 CompileSuccessfully(GenerateShaderCode(body));
692 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
693 EXPECT_THAT(getDiagnosticString(),
694 HasSubstr("GLSL.std.450 " + ext_inst_name +
695 ": expected all operands to be int scalars or "
696 "vectors"));
697 }
698
699 TEST_P(ValidateGlslStd450SAbsLike, WrongDimOperand) {
700 const std::string ext_inst_name = GetParam();
701 const std::string body =
702 "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %s32vec2_01\n";
703
704 CompileSuccessfully(GenerateShaderCode(body));
705 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
706 EXPECT_THAT(getDiagnosticString(),
707 HasSubstr("GLSL.std.450 " + ext_inst_name +
708 ": expected all operands to have the same dimension as "
709 "Result Type"));
710 }
711
712 TEST_P(ValidateGlslStd450SAbsLike, WrongBitWidthOperand) {
713 const std::string ext_inst_name = GetParam();
714 const std::string body =
715 "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s32_0\n";
716
717 CompileSuccessfully(GenerateShaderCode(body));
718 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
719 EXPECT_THAT(getDiagnosticString(),
720 HasSubstr("GLSL.std.450 " + ext_inst_name +
721 ": expected all operands to have the same bit width as "
722 "Result Type"));
723 }
724
725 TEST_P(ValidateGlslStd450SAbsLike, TypelessOperand) {
726 const std::string ext_inst_name = GetParam();
727 const std::string body =
728 "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %main_entry\n";
729
730 CompileSuccessfully(GenerateShaderCode(body));
731 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
732 EXPECT_THAT(
733 getDiagnosticString(),
734 HasSubstr("GLSL.std.450 " + ext_inst_name +
735 ": expected all operands to be int scalars or vectors"));
736 }
737
738 INSTANTIATE_TEST_SUITE_P(AllSAbsLike, ValidateGlslStd450SAbsLike,
739 ::testing::ValuesIn(std::vector<std::string>{
740 "SAbs",
741 "SSign",
742 "FindILsb",
743 "FindUMsb",
744 "FindSMsb",
745 }));
746
747 TEST_F(ValidateExtInst, FindUMsbNot32Bit) {
748 const std::string body = R"(
749 %val1 = OpExtInst %s64 %extinst FindUMsb %u64_1
750 )";
751
752 CompileSuccessfully(GenerateShaderCode(body));
753 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
754 EXPECT_THAT(getDiagnosticString(),
755 HasSubstr("GLSL.std.450 FindUMsb: this instruction is currently "
756 "limited to 32-bit width components"));
757 }
758
759 TEST_F(ValidateExtInst, FindSMsbNot32Bit) {
760 const std::string body = R"(
761 %val1 = OpExtInst %s64 %extinst FindSMsb %u64_1
762 )";
763
764 CompileSuccessfully(GenerateShaderCode(body));
765 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
766 EXPECT_THAT(getDiagnosticString(),
767 HasSubstr("GLSL.std.450 FindSMsb: this instruction is currently "
768 "limited to 32-bit width components"));
769 }
770
771 TEST_P(ValidateGlslStd450UMinLike, Success) {
772 const std::string ext_inst_name = GetParam();
773 std::ostringstream ss;
774 ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name
775 << " %u32_1 %s32_2\n";
776 ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name
777 << " %s32_1 %u32_2\n";
778 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
779 << " %u32_1 %s32_2\n";
780 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
781 << " %s32_1 %u32_2\n";
782 ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
783 << " %s32vec2_01 %u32vec2_01\n";
784 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
785 << " %u32vec2_01 %s32vec2_01\n";
786 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
787 << " %s32vec2_01 %u32vec2_01\n";
788 ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
789 << " %u32vec2_01 %s32vec2_01\n";
790 ss << "%val9 = OpExtInst %s64 %extinst " << ext_inst_name
791 << " %u64_1 %s64_0\n";
792 CompileSuccessfully(GenerateShaderCode(ss.str()));
793 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
794 }
795
796 TEST_P(ValidateGlslStd450UMinLike, FloatResultType) {
797 const std::string ext_inst_name = GetParam();
798 const std::string body =
799 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
800
801 CompileSuccessfully(GenerateShaderCode(body));
802 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
803 EXPECT_THAT(getDiagnosticString(),
804 HasSubstr("GLSL.std.450 " + ext_inst_name +
805 ": expected Result Type to be an int scalar "
806 "or vector type"));
807 }
808
809 TEST_P(ValidateGlslStd450UMinLike, FloatOperand1) {
810 const std::string ext_inst_name = GetParam();
811 const std::string body =
812 "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
813
814 CompileSuccessfully(GenerateShaderCode(body));
815 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
816 EXPECT_THAT(getDiagnosticString(),
817 HasSubstr("GLSL.std.450 " + ext_inst_name +
818 ": expected all operands to be int scalars or "
819 "vectors"));
820 }
821
822 TEST_P(ValidateGlslStd450UMinLike, FloatOperand2) {
823 const std::string ext_inst_name = GetParam();
824 const std::string body =
825 "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
826
827 CompileSuccessfully(GenerateShaderCode(body));
828 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
829 EXPECT_THAT(getDiagnosticString(),
830 HasSubstr("GLSL.std.450 " + ext_inst_name +
831 ": expected all operands to be int scalars or "
832 "vectors"));
833 }
834
835 TEST_P(ValidateGlslStd450UMinLike, WrongDimOperand1) {
836 const std::string ext_inst_name = GetParam();
837 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
838 " %s32vec2_01 %s32_0\n";
839
840 CompileSuccessfully(GenerateShaderCode(body));
841 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
842 EXPECT_THAT(getDiagnosticString(),
843 HasSubstr("GLSL.std.450 " + ext_inst_name +
844 ": expected all operands to have the same dimension as "
845 "Result Type"));
846 }
847
848 TEST_P(ValidateGlslStd450UMinLike, WrongDimOperand2) {
849 const std::string ext_inst_name = GetParam();
850 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
851 " %s32_0 %s32vec2_01\n";
852
853 CompileSuccessfully(GenerateShaderCode(body));
854 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
855 EXPECT_THAT(getDiagnosticString(),
856 HasSubstr("GLSL.std.450 " + ext_inst_name +
857 ": expected all operands to have the same dimension as "
858 "Result Type"));
859 }
860
861 TEST_P(ValidateGlslStd450UMinLike, WrongBitWidthOperand1) {
862 const std::string ext_inst_name = GetParam();
863 const std::string body =
864 "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s32_0 %s64_0\n";
865
866 CompileSuccessfully(GenerateShaderCode(body));
867 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
868 EXPECT_THAT(getDiagnosticString(),
869 HasSubstr("GLSL.std.450 " + ext_inst_name +
870 ": expected all operands to have the same bit width as "
871 "Result Type"));
872 }
873
874 TEST_P(ValidateGlslStd450UMinLike, WrongBitWidthOperand2) {
875 const std::string ext_inst_name = GetParam();
876 const std::string body =
877 "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s64_0 %s32_0\n";
878
879 CompileSuccessfully(GenerateShaderCode(body));
880 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
881 EXPECT_THAT(getDiagnosticString(),
882 HasSubstr("GLSL.std.450 " + ext_inst_name +
883 ": expected all operands to have the same bit width as "
884 "Result Type"));
885 }
886
887 TEST_P(ValidateGlslStd450UMinLike, TypelessOperand) {
888 const std::string ext_inst_name = GetParam();
889 const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
890 " %s64_0 %main_entry\n";
891
892 CompileSuccessfully(GenerateShaderCode(body));
893 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
894 EXPECT_THAT(
895 getDiagnosticString(),
896 HasSubstr("GLSL.std.450 " + ext_inst_name +
897 ": expected all operands to be int scalars or vectors"));
898 }
899
900 INSTANTIATE_TEST_SUITE_P(AllUMinLike, ValidateGlslStd450UMinLike,
901 ::testing::ValuesIn(std::vector<std::string>{
902 "UMin",
903 "SMin",
904 "UMax",
905 "SMax",
906 }));
907
908 TEST_P(ValidateGlslStd450UClampLike, Success) {
909 const std::string ext_inst_name = GetParam();
910 std::ostringstream ss;
911 ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name
912 << " %s32_0 %u32_1 %s32_2\n";
913 ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name
914 << " %u32_0 %s32_1 %u32_2\n";
915 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
916 << " %s32_0 %u32_1 %s32_2\n";
917 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
918 << " %u32_0 %s32_1 %u32_2\n";
919 ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
920 << " %s32vec2_01 %u32vec2_01 %u32vec2_12\n";
921 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
922 << " %u32vec2_01 %s32vec2_01 %s32vec2_12\n";
923 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
924 << " %s32vec2_01 %u32vec2_01 %u32vec2_12\n";
925 ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
926 << " %u32vec2_01 %s32vec2_01 %s32vec2_12\n";
927 ss << "%val9 = OpExtInst %s64 %extinst " << ext_inst_name
928 << " %u64_1 %s64_0 %s64_1\n";
929 CompileSuccessfully(GenerateShaderCode(ss.str()));
930 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
931 }
932
933 TEST_P(ValidateGlslStd450UClampLike, FloatResultType) {
934 const std::string ext_inst_name = GetParam();
935 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
936 " %u32_0 %u32_0 %u32_1\n";
937
938 CompileSuccessfully(GenerateShaderCode(body));
939 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
940 EXPECT_THAT(getDiagnosticString(),
941 HasSubstr("GLSL.std.450 " + ext_inst_name +
942 ": expected Result Type to be an int scalar "
943 "or vector type"));
944 }
945
946 TEST_P(ValidateGlslStd450UClampLike, FloatOperand1) {
947 const std::string ext_inst_name = GetParam();
948 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
949 " %f32_0 %u32_0 %u32_1\n";
950
951 CompileSuccessfully(GenerateShaderCode(body));
952 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
953 EXPECT_THAT(getDiagnosticString(),
954 HasSubstr("GLSL.std.450 " + ext_inst_name +
955 ": expected all operands to be int scalars or "
956 "vectors"));
957 }
958
959 TEST_P(ValidateGlslStd450UClampLike, FloatOperand2) {
960 const std::string ext_inst_name = GetParam();
961 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
962 " %u32_0 %f32_0 %u32_1\n";
963
964 CompileSuccessfully(GenerateShaderCode(body));
965 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
966 EXPECT_THAT(getDiagnosticString(),
967 HasSubstr("GLSL.std.450 " + ext_inst_name +
968 ": expected all operands to be int scalars or "
969 "vectors"));
970 }
971
972 TEST_P(ValidateGlslStd450UClampLike, FloatOperand3) {
973 const std::string ext_inst_name = GetParam();
974 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
975 " %u32_0 %u32_0 %f32_1\n";
976
977 CompileSuccessfully(GenerateShaderCode(body));
978 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
979 EXPECT_THAT(getDiagnosticString(),
980 HasSubstr("GLSL.std.450 " + ext_inst_name +
981 ": expected all operands to be int scalars or "
982 "vectors"));
983 }
984
985 TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand1) {
986 const std::string ext_inst_name = GetParam();
987 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
988 " %s32vec2_01 %s32_0 %u32_1\n";
989
990 CompileSuccessfully(GenerateShaderCode(body));
991 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
992 EXPECT_THAT(getDiagnosticString(),
993 HasSubstr("GLSL.std.450 " + ext_inst_name +
994 ": expected all operands to have the same dimension as "
995 "Result Type"));
996 }
997
998 TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand2) {
999 const std::string ext_inst_name = GetParam();
1000 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
1001 " %s32_0 %s32vec2_01 %u32_1\n";
1002
1003 CompileSuccessfully(GenerateShaderCode(body));
1004 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1005 EXPECT_THAT(getDiagnosticString(),
1006 HasSubstr("GLSL.std.450 " + ext_inst_name +
1007 ": expected all operands to have the same dimension as "
1008 "Result Type"));
1009 }
1010
1011 TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand3) {
1012 const std::string ext_inst_name = GetParam();
1013 const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
1014 " %s32_0 %u32_1 %s32vec2_01\n";
1015
1016 CompileSuccessfully(GenerateShaderCode(body));
1017 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1018 EXPECT_THAT(getDiagnosticString(),
1019 HasSubstr("GLSL.std.450 " + ext_inst_name +
1020 ": expected all operands to have the same dimension as "
1021 "Result Type"));
1022 }
1023
1024 TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand1) {
1025 const std::string ext_inst_name = GetParam();
1026 const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
1027 " %s32_0 %s64_0 %s64_1\n";
1028
1029 CompileSuccessfully(GenerateShaderCode(body));
1030 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1031 EXPECT_THAT(getDiagnosticString(),
1032 HasSubstr("GLSL.std.450 " + ext_inst_name +
1033 ": expected all operands to have the same bit width as "
1034 "Result Type"));
1035 }
1036
1037 TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand2) {
1038 const std::string ext_inst_name = GetParam();
1039 const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
1040 " %s64_0 %s32_0 %s64_1\n";
1041
1042 CompileSuccessfully(GenerateShaderCode(body));
1043 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1044 EXPECT_THAT(getDiagnosticString(),
1045 HasSubstr("GLSL.std.450 " + ext_inst_name +
1046 ": expected all operands to have the same bit width as "
1047 "Result Type"));
1048 }
1049
1050 TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand3) {
1051 const std::string ext_inst_name = GetParam();
1052 const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
1053 " %s64_0 %s64_0 %s32_1\n";
1054
1055 CompileSuccessfully(GenerateShaderCode(body));
1056 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1057 EXPECT_THAT(getDiagnosticString(),
1058 HasSubstr("GLSL.std.450 " + ext_inst_name +
1059 ": expected all operands to have the same bit width as "
1060 "Result Type"));
1061 }
1062
1063 TEST_P(ValidateGlslStd450UClampLike, TypelessOperand) {
1064 const std::string ext_inst_name = GetParam();
1065 const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
1066 " %main_entry %s64_0 %s64_0\n";
1067
1068 CompileSuccessfully(GenerateShaderCode(body));
1069 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1070 EXPECT_THAT(
1071 getDiagnosticString(),
1072 HasSubstr("GLSL.std.450 " + ext_inst_name +
1073 ": expected all operands to be int scalars or vectors"));
1074 }
1075
1076 INSTANTIATE_TEST_SUITE_P(AllUClampLike, ValidateGlslStd450UClampLike,
1077 ::testing::ValuesIn(std::vector<std::string>{
1078 "UClamp",
1079 "SClamp",
1080 }));
1081
1082 TEST_P(ValidateGlslStd450SinLike, Success) {
1083 const std::string ext_inst_name = GetParam();
1084 std::ostringstream ss;
1085 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
1086 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
1087 << " %f32vec2_01\n";
1088 CompileSuccessfully(GenerateShaderCode(ss.str()));
1089 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1090 }
1091
1092 TEST_P(ValidateGlslStd450SinLike, IntResultType) {
1093 const std::string ext_inst_name = GetParam();
1094 const std::string body =
1095 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
1096
1097 CompileSuccessfully(GenerateShaderCode(body));
1098 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1099 EXPECT_THAT(getDiagnosticString(),
1100 HasSubstr("GLSL.std.450 " + ext_inst_name +
1101 ": expected Result Type to be a 16 or 32-bit scalar "
1102 "or vector float type"));
1103 }
1104
1105 TEST_P(ValidateGlslStd450SinLike, F64ResultType) {
1106 const std::string ext_inst_name = GetParam();
1107 const std::string body =
1108 "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32_0\n";
1109
1110 CompileSuccessfully(GenerateShaderCode(body));
1111 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1112 EXPECT_THAT(getDiagnosticString(),
1113 HasSubstr("GLSL.std.450 " + ext_inst_name +
1114 ": expected Result Type to be a 16 or 32-bit scalar "
1115 "or vector float type"));
1116 }
1117
1118 TEST_P(ValidateGlslStd450SinLike, IntOperand) {
1119 const std::string ext_inst_name = GetParam();
1120 const std::string body =
1121 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
1122
1123 CompileSuccessfully(GenerateShaderCode(body));
1124 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1125 EXPECT_THAT(getDiagnosticString(),
1126 HasSubstr("GLSL.std.450 " + ext_inst_name +
1127 ": expected types of all operands to be equal to "
1128 "Result Type"));
1129 }
1130
1131 INSTANTIATE_TEST_SUITE_P(AllSinLike, ValidateGlslStd450SinLike,
1132 ::testing::ValuesIn(std::vector<std::string>{
1133 "Radians",
1134 "Degrees",
1135 "Sin",
1136 "Cos",
1137 "Tan",
1138 "Asin",
1139 "Acos",
1140 "Atan",
1141 "Sinh",
1142 "Cosh",
1143 "Tanh",
1144 "Asinh",
1145 "Acosh",
1146 "Atanh",
1147 "Exp",
1148 "Exp2",
1149 "Log",
1150 "Log2",
1151 }));
1152
1153 TEST_P(ValidateGlslStd450PowLike, Success) {
1154 const std::string ext_inst_name = GetParam();
1155 std::ostringstream ss;
1156 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
1157 << " %f32_1 %f32_1\n";
1158 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
1159 << " %f32vec2_01 %f32vec2_12\n";
1160 CompileSuccessfully(GenerateShaderCode(ss.str()));
1161 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1162 }
1163
1164 TEST_P(ValidateGlslStd450PowLike, IntResultType) {
1165 const std::string ext_inst_name = GetParam();
1166 const std::string body =
1167 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_1 %f32_0\n";
1168
1169 CompileSuccessfully(GenerateShaderCode(body));
1170 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1171 EXPECT_THAT(getDiagnosticString(),
1172 HasSubstr("GLSL.std.450 " + ext_inst_name +
1173 ": expected Result Type to be a 16 or 32-bit scalar "
1174 "or vector float type"));
1175 }
1176
1177 TEST_P(ValidateGlslStd450PowLike, F64ResultType) {
1178 const std::string ext_inst_name = GetParam();
1179 const std::string body =
1180 "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32_1 %f32_0\n";
1181
1182 CompileSuccessfully(GenerateShaderCode(body));
1183 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1184 EXPECT_THAT(getDiagnosticString(),
1185 HasSubstr("GLSL.std.450 " + ext_inst_name +
1186 ": expected Result Type to be a 16 or 32-bit scalar "
1187 "or vector float type"));
1188 }
1189
1190 TEST_P(ValidateGlslStd450PowLike, IntOperand1) {
1191 const std::string ext_inst_name = GetParam();
1192 const std::string body =
1193 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
1194
1195 CompileSuccessfully(GenerateShaderCode(body));
1196 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1197 EXPECT_THAT(getDiagnosticString(),
1198 HasSubstr("GLSL.std.450 " + ext_inst_name +
1199 ": expected types of all operands to be equal to "
1200 "Result Type"));
1201 }
1202
1203 TEST_P(ValidateGlslStd450PowLike, IntOperand2) {
1204 const std::string ext_inst_name = GetParam();
1205 const std::string body =
1206 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
1207
1208 CompileSuccessfully(GenerateShaderCode(body));
1209 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1210 EXPECT_THAT(getDiagnosticString(),
1211 HasSubstr("GLSL.std.450 " + ext_inst_name +
1212 ": expected types of all operands to be equal to "
1213 "Result Type"));
1214 }
1215
1216 INSTANTIATE_TEST_SUITE_P(AllPowLike, ValidateGlslStd450PowLike,
1217 ::testing::ValuesIn(std::vector<std::string>{
1218 "Atan2",
1219 "Pow",
1220 }));
1221
1222 TEST_F(ValidateExtInst, GlslStd450DeterminantSuccess) {
1223 const std::string body = R"(
1224 %val1 = OpExtInst %f32 %extinst Determinant %f32mat22_1212
1225 )";
1226
1227 CompileSuccessfully(GenerateShaderCode(body));
1228 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1229 }
1230
1231 TEST_F(ValidateExtInst, GlslStd450DeterminantIncompatibleResultType) {
1232 const std::string body = R"(
1233 %val1 = OpExtInst %f64 %extinst Determinant %f32mat22_1212
1234 )";
1235
1236 CompileSuccessfully(GenerateShaderCode(body));
1237 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1238 EXPECT_THAT(getDiagnosticString(),
1239 HasSubstr("GLSL.std.450 Determinant: "
1240 "expected operand X component type to be equal to "
1241 "Result Type"));
1242 }
1243
1244 TEST_F(ValidateExtInst, GlslStd450DeterminantNotMatrix) {
1245 const std::string body = R"(
1246 %val1 = OpExtInst %f32 %extinst Determinant %f32_1
1247 )";
1248
1249 CompileSuccessfully(GenerateShaderCode(body));
1250 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1251 EXPECT_THAT(getDiagnosticString(),
1252 HasSubstr("GLSL.std.450 Determinant: "
1253 "expected operand X to be a square matrix"));
1254 }
1255
1256 TEST_F(ValidateExtInst, GlslStd450DeterminantMatrixNotSquare) {
1257 const std::string body = R"(
1258 %val1 = OpExtInst %f32 %extinst Determinant %f32mat23_121212
1259 )";
1260
1261 CompileSuccessfully(GenerateShaderCode(body));
1262 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1263 EXPECT_THAT(getDiagnosticString(),
1264 HasSubstr("GLSL.std.450 Determinant: "
1265 "expected operand X to be a square matrix"));
1266 }
1267
1268 TEST_F(ValidateExtInst, GlslStd450MatrixInverseSuccess) {
1269 const std::string body = R"(
1270 %val1 = OpExtInst %f32mat22 %extinst MatrixInverse %f32mat22_1212
1271 )";
1272
1273 CompileSuccessfully(GenerateShaderCode(body));
1274 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1275 }
1276
1277 TEST_F(ValidateExtInst, GlslStd450MatrixInverseIncompatibleResultType) {
1278 const std::string body = R"(
1279 %val1 = OpExtInst %f32mat33 %extinst MatrixInverse %f32mat22_1212
1280 )";
1281
1282 CompileSuccessfully(GenerateShaderCode(body));
1283 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1284 EXPECT_THAT(getDiagnosticString(),
1285 HasSubstr("GLSL.std.450 MatrixInverse: "
1286 "expected operand X type to be equal to "
1287 "Result Type"));
1288 }
1289
1290 TEST_F(ValidateExtInst, GlslStd450MatrixInverseNotMatrix) {
1291 const std::string body = R"(
1292 %val1 = OpExtInst %f32 %extinst MatrixInverse %f32mat22_1212
1293 )";
1294
1295 CompileSuccessfully(GenerateShaderCode(body));
1296 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1297 EXPECT_THAT(getDiagnosticString(),
1298 HasSubstr("GLSL.std.450 MatrixInverse: "
1299 "expected Result Type to be a square matrix"));
1300 }
1301
1302 TEST_F(ValidateExtInst, GlslStd450MatrixInverseMatrixNotSquare) {
1303 const std::string body = R"(
1304 %val1 = OpExtInst %f32mat23 %extinst MatrixInverse %f32mat23_121212
1305 )";
1306
1307 CompileSuccessfully(GenerateShaderCode(body));
1308 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1309 EXPECT_THAT(getDiagnosticString(),
1310 HasSubstr("GLSL.std.450 MatrixInverse: "
1311 "expected Result Type to be a square matrix"));
1312 }
1313
1314 TEST_F(ValidateExtInst, GlslStd450ModfSuccess) {
1315 const std::string body = R"(
1316 %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32_output
1317 %val2 = OpExtInst %f32vec2 %extinst Modf %f32vec2_01 %f32vec2_output
1318 )";
1319
1320 CompileSuccessfully(GenerateShaderCode(body));
1321 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1322 }
1323
1324 TEST_F(ValidateExtInst, GlslStd450ModfIntResultType) {
1325 const std::string body = R"(
1326 %val1 = OpExtInst %u32 %extinst Modf %f32_h %f32_output
1327 )";
1328
1329 CompileSuccessfully(GenerateShaderCode(body));
1330 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1331 EXPECT_THAT(getDiagnosticString(),
1332 HasSubstr("GLSL.std.450 Modf: "
1333 "expected Result Type to be a scalar or vector "
1334 "float type"));
1335 }
1336
1337 TEST_F(ValidateExtInst, GlslStd450ModfXNotOfResultType) {
1338 const std::string body = R"(
1339 %val1 = OpExtInst %f32 %extinst Modf %f64_0 %f32_output
1340 )";
1341
1342 CompileSuccessfully(GenerateShaderCode(body));
1343 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1344 EXPECT_THAT(getDiagnosticString(),
1345 HasSubstr("GLSL.std.450 Modf: "
1346 "expected operand X type to be equal to Result Type"));
1347 }
1348
1349 TEST_F(ValidateExtInst, GlslStd450ModfINotPointer) {
1350 const std::string body = R"(
1351 %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32_1
1352 )";
1353
1354 CompileSuccessfully(GenerateShaderCode(body));
1355 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1356 EXPECT_THAT(getDiagnosticString(),
1357 HasSubstr("GLSL.std.450 Modf: "
1358 "expected operand I to be a pointer"));
1359 }
1360
1361 TEST_F(ValidateExtInst, GlslStd450ModfIDataNotOfResultType) {
1362 const std::string body = R"(
1363 %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32vec2_output
1364 )";
1365
1366 CompileSuccessfully(GenerateShaderCode(body));
1367 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1368 EXPECT_THAT(getDiagnosticString(),
1369 HasSubstr("GLSL.std.450 Modf: "
1370 "expected operand I data type to be equal to "
1371 "Result Type"));
1372 }
1373
1374 TEST_F(ValidateExtInst, GlslStd450ModfStructSuccess) {
1375 const std::string body = R"(
1376 %val1 = OpExtInst %struct_f32_f32 %extinst ModfStruct %f32_h
1377 %val2 = OpExtInst %struct_f32vec2_f32vec2 %extinst ModfStruct %f32vec2_01
1378 )";
1379
1380 CompileSuccessfully(GenerateShaderCode(body));
1381 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1382 }
1383
1384 TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeNotStruct) {
1385 const std::string body = R"(
1386 %val1 = OpExtInst %f32 %extinst ModfStruct %f32_h
1387 )";
1388
1389 CompileSuccessfully(GenerateShaderCode(body));
1390 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1391 EXPECT_THAT(getDiagnosticString(),
1392 HasSubstr("GLSL.std.450 ModfStruct: "
1393 "expected Result Type to be a struct with two "
1394 "identical scalar or vector float type members"));
1395 }
1396
1397 TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructWrongSize) {
1398 const std::string body = R"(
1399 %val1 = OpExtInst %struct_f32_f32_f32 %extinst ModfStruct %f32_h
1400 )";
1401
1402 CompileSuccessfully(GenerateShaderCode(body));
1403 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1404 EXPECT_THAT(getDiagnosticString(),
1405 HasSubstr("GLSL.std.450 ModfStruct: "
1406 "expected Result Type to be a struct with two "
1407 "identical scalar or vector float type members"));
1408 }
1409
1410 TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructWrongFirstMember) {
1411 const std::string body = R"(
1412 %val1 = OpExtInst %struct_u32_f32 %extinst ModfStruct %f32_h
1413 )";
1414
1415 CompileSuccessfully(GenerateShaderCode(body));
1416 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1417 EXPECT_THAT(getDiagnosticString(),
1418 HasSubstr("GLSL.std.450 ModfStruct: "
1419 "expected Result Type to be a struct with two "
1420 "identical scalar or vector float type members"));
1421 }
1422
1423 TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructMembersNotEqual) {
1424 const std::string body = R"(
1425 %val1 = OpExtInst %struct_f32_f64 %extinst ModfStruct %f32_h
1426 )";
1427
1428 CompileSuccessfully(GenerateShaderCode(body));
1429 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1430 EXPECT_THAT(getDiagnosticString(),
1431 HasSubstr("GLSL.std.450 ModfStruct: "
1432 "expected Result Type to be a struct with two "
1433 "identical scalar or vector float type members"));
1434 }
1435
1436 TEST_F(ValidateExtInst, GlslStd450ModfStructXWrongType) {
1437 const std::string body = R"(
1438 %val1 = OpExtInst %struct_f32_f32 %extinst ModfStruct %f64_0
1439 )";
1440
1441 CompileSuccessfully(GenerateShaderCode(body));
1442 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1443 EXPECT_THAT(getDiagnosticString(),
1444 HasSubstr("GLSL.std.450 ModfStruct: "
1445 "expected operand X type to be equal to members of "
1446 "Result Type struct"));
1447 }
1448
1449 TEST_F(ValidateExtInst, GlslStd450FrexpSuccess) {
1450 const std::string body = R"(
1451 %val1 = OpExtInst %f32 %extinst Frexp %f32_h %u32_output
1452 %val2 = OpExtInst %f32vec2 %extinst Frexp %f32vec2_01 %u32vec2_output
1453 )";
1454
1455 CompileSuccessfully(GenerateShaderCode(body));
1456 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1457 }
1458
1459 TEST_F(ValidateExtInst, GlslStd450FrexpIntResultType) {
1460 const std::string body = R"(
1461 %val1 = OpExtInst %u32 %extinst Frexp %f32_h %u32_output
1462 )";
1463
1464 CompileSuccessfully(GenerateShaderCode(body));
1465 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1466 EXPECT_THAT(getDiagnosticString(),
1467 HasSubstr("GLSL.std.450 Frexp: "
1468 "expected Result Type to be a scalar or vector "
1469 "float type"));
1470 }
1471
1472 TEST_F(ValidateExtInst, GlslStd450FrexpWrongXType) {
1473 const std::string body = R"(
1474 %val1 = OpExtInst %f32 %extinst Frexp %u32_1 %u32_output
1475 )";
1476
1477 CompileSuccessfully(GenerateShaderCode(body));
1478 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1479 EXPECT_THAT(getDiagnosticString(),
1480 HasSubstr("GLSL.std.450 Frexp: "
1481 "expected operand X type to be equal to Result Type"));
1482 }
1483
1484 TEST_F(ValidateExtInst, GlslStd450FrexpExpNotPointer) {
1485 const std::string body = R"(
1486 %val1 = OpExtInst %f32 %extinst Frexp %f32_1 %u32_1
1487 )";
1488
1489 CompileSuccessfully(GenerateShaderCode(body));
1490 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1491 EXPECT_THAT(getDiagnosticString(),
1492 HasSubstr("GLSL.std.450 Frexp: "
1493 "expected operand Exp to be a pointer"));
1494 }
1495
1496 TEST_F(ValidateExtInst, GlslStd450FrexpExpNotInt32Pointer) {
1497 const std::string body = R"(
1498 %val1 = OpExtInst %f32 %extinst Frexp %f32_1 %f32_output
1499 )";
1500
1501 CompileSuccessfully(GenerateShaderCode(body));
1502 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1503 EXPECT_THAT(getDiagnosticString(),
1504 HasSubstr("GLSL.std.450 Frexp: "
1505 "expected operand Exp data type to be a 32-bit int "
1506 "scalar or vector type"));
1507 }
1508
1509 TEST_F(ValidateExtInst, GlslStd450FrexpExpWrongComponentNumber) {
1510 const std::string body = R"(
1511 %val1 = OpExtInst %f32vec2 %extinst Frexp %f32vec2_01 %u32_output
1512 )";
1513
1514 CompileSuccessfully(GenerateShaderCode(body));
1515 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1516 EXPECT_THAT(getDiagnosticString(),
1517 HasSubstr("GLSL.std.450 Frexp: "
1518 "expected operand Exp data type to have the same "
1519 "component number as Result Type"));
1520 }
1521
1522 TEST_F(ValidateExtInst, GlslStd450LdexpSuccess) {
1523 const std::string body = R"(
1524 %val1 = OpExtInst %f32 %extinst Ldexp %f32_h %u32_2
1525 %val2 = OpExtInst %f32vec2 %extinst Ldexp %f32vec2_01 %u32vec2_12
1526 %val3 = OpExtInst %f32 %extinst Ldexp %f32_h %u64_1
1527 )";
1528
1529 CompileSuccessfully(GenerateShaderCode(body));
1530 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1531 }
1532
1533 TEST_F(ValidateExtInst, GlslStd450LdexpIntResultType) {
1534 const std::string body = R"(
1535 %val1 = OpExtInst %u32 %extinst Ldexp %f32_h %u32_2
1536 )";
1537
1538 CompileSuccessfully(GenerateShaderCode(body));
1539 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1540 EXPECT_THAT(getDiagnosticString(),
1541 HasSubstr("GLSL.std.450 Ldexp: "
1542 "expected Result Type to be a scalar or vector "
1543 "float type"));
1544 }
1545
1546 TEST_F(ValidateExtInst, GlslStd450LdexpWrongXType) {
1547 const std::string body = R"(
1548 %val1 = OpExtInst %f32 %extinst Ldexp %u32_1 %u32_2
1549 )";
1550
1551 CompileSuccessfully(GenerateShaderCode(body));
1552 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1553 EXPECT_THAT(getDiagnosticString(),
1554 HasSubstr("GLSL.std.450 Ldexp: "
1555 "expected operand X type to be equal to Result Type"));
1556 }
1557
1558 TEST_F(ValidateExtInst, GlslStd450LdexpFloatExp) {
1559 const std::string body = R"(
1560 %val1 = OpExtInst %f32 %extinst Ldexp %f32_1 %f32_2
1561 )";
1562
1563 CompileSuccessfully(GenerateShaderCode(body));
1564 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1565 EXPECT_THAT(getDiagnosticString(),
1566 HasSubstr("GLSL.std.450 Ldexp: "
1567 "expected operand Exp to be a 32-bit int scalar "
1568 "or vector type"));
1569 }
1570
1571 TEST_F(ValidateExtInst, GlslStd450LdexpExpWrongSize) {
1572 const std::string body = R"(
1573 %val1 = OpExtInst %f32vec2 %extinst Ldexp %f32vec2_12 %u32_2
1574 )";
1575
1576 CompileSuccessfully(GenerateShaderCode(body));
1577 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1578 EXPECT_THAT(getDiagnosticString(),
1579 HasSubstr("GLSL.std.450 Ldexp: "
1580 "expected operand Exp to have the same component "
1581 "number as Result Type"));
1582 }
1583
1584 TEST_F(ValidateExtInst, GlslStd450LdexpExpNoType) {
1585 const std::string body = R"(
1586 %val1 = OpExtInst %f32 %extinst Ldexp %f32_1 %main_entry
1587 )";
1588
1589 CompileSuccessfully(GenerateShaderCode(body));
1590 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1591 EXPECT_THAT(getDiagnosticString(),
1592 HasSubstr("GLSL.std.450 Ldexp: "
1593 "expected operand Exp to be a 32-bit int scalar "
1594 "or vector type"));
1595 }
1596
1597 TEST_F(ValidateExtInst, GlslStd450FrexpStructSuccess) {
1598 const std::string body = R"(
1599 %val1 = OpExtInst %struct_f32_u32 %extinst FrexpStruct %f32_h
1600 %val2 = OpExtInst %struct_f32vec2_u32vec2 %extinst FrexpStruct %f32vec2_01
1601 )";
1602
1603 CompileSuccessfully(GenerateShaderCode(body));
1604 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1605 }
1606
1607 TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeNotStruct) {
1608 const std::string body = R"(
1609 %val1 = OpExtInst %f32 %extinst FrexpStruct %f32_h
1610 )";
1611
1612 CompileSuccessfully(GenerateShaderCode(body));
1613 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1614 EXPECT_THAT(getDiagnosticString(),
1615 HasSubstr("GLSL.std.450 FrexpStruct: "
1616 "expected Result Type to be a struct with two members, "
1617 "first member a float scalar or vector, second member "
1618 "a 32-bit int scalar or vector with the same number of "
1619 "components as the first member"));
1620 }
1621
1622 TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongSize) {
1623 const std::string body = R"(
1624 %val1 = OpExtInst %struct_f32_u32_f32 %extinst FrexpStruct %f32_h
1625 )";
1626
1627 CompileSuccessfully(GenerateShaderCode(body));
1628 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1629 EXPECT_THAT(getDiagnosticString(),
1630 HasSubstr("GLSL.std.450 FrexpStruct: "
1631 "expected Result Type to be a struct with two members, "
1632 "first member a float scalar or vector, second member "
1633 "a 32-bit int scalar or vector with the same number of "
1634 "components as the first member"));
1635 }
1636
1637 TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongMember1) {
1638 const std::string body = R"(
1639 %val1 = OpExtInst %struct_u32_u32 %extinst FrexpStruct %f32_h
1640 )";
1641
1642 CompileSuccessfully(GenerateShaderCode(body));
1643 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1644 EXPECT_THAT(getDiagnosticString(),
1645 HasSubstr("GLSL.std.450 FrexpStruct: "
1646 "expected Result Type to be a struct with two members, "
1647 "first member a float scalar or vector, second member "
1648 "a 32-bit int scalar or vector with the same number of "
1649 "components as the first member"));
1650 }
1651
1652 TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongMember2) {
1653 const std::string body = R"(
1654 %val1 = OpExtInst %struct_f32_f32 %extinst FrexpStruct %f32_h
1655 )";
1656
1657 CompileSuccessfully(GenerateShaderCode(body));
1658 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1659 EXPECT_THAT(getDiagnosticString(),
1660 HasSubstr("GLSL.std.450 FrexpStruct: "
1661 "expected Result Type to be a struct with two members, "
1662 "first member a float scalar or vector, second member "
1663 "a 32-bit int scalar or vector with the same number of "
1664 "components as the first member"));
1665 }
1666
1667 TEST_F(ValidateExtInst, GlslStd450FrexpStructXWrongType) {
1668 const std::string body = R"(
1669 %val1 = OpExtInst %struct_f32_u32 %extinst FrexpStruct %f64_0
1670 )";
1671
1672 CompileSuccessfully(GenerateShaderCode(body));
1673 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1674 EXPECT_THAT(getDiagnosticString(),
1675 HasSubstr("GLSL.std.450 FrexpStruct: "
1676 "expected operand X type to be equal to the first "
1677 "member of Result Type struct"));
1678 }
1679
1680 TEST_F(ValidateExtInst,
1681 GlslStd450FrexpStructResultTypeStructRightInt16Member2) {
1682 const std::string body = R"(
1683 %val1 = OpExtInst %struct_f16_u16 %extinst FrexpStruct %f16_h
1684 )";
1685
1686 const std::string extension = R"(
1687 OpExtension "SPV_AMD_gpu_shader_int16"
1688 )";
1689
1690 CompileSuccessfully(GenerateShaderCode(body, extension));
1691 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1692 }
1693
1694 TEST_F(ValidateExtInst,
1695 GlslStd450FrexpStructResultTypeStructWrongInt16Member2) {
1696 const std::string body = R"(
1697 %val1 = OpExtInst %struct_f16_u16 %extinst FrexpStruct %f16_h
1698 )";
1699
1700 CompileSuccessfully(GenerateShaderCode(body));
1701 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1702 EXPECT_THAT(getDiagnosticString(),
1703 HasSubstr("GLSL.std.450 FrexpStruct: "
1704 "expected Result Type to be a struct with two members, "
1705 "first member a float scalar or vector, second member "
1706 "a 32-bit int scalar or vector with the same number of "
1707 "components as the first member"));
1708 }
1709
1710 TEST_P(ValidateGlslStd450Pack, Success) {
1711 const std::string ext_inst_name = GetParam();
1712 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1713 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1714 const uint32_t total_bit_width = num_components * packed_bit_width;
1715 const std::string vec_str =
1716 num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
1717
1718 std::ostringstream body;
1719 body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
1720 << ext_inst_name << vec_str;
1721 body << "%val2 = OpExtInst %s" << total_bit_width << " %extinst "
1722 << ext_inst_name << vec_str;
1723 CompileSuccessfully(GenerateShaderCode(body.str()));
1724 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1725 }
1726
1727 TEST_P(ValidateGlslStd450Pack, Float32ResultType) {
1728 const std::string ext_inst_name = GetParam();
1729 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1730 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1731 const uint32_t total_bit_width = num_components * packed_bit_width;
1732 const std::string vec_str =
1733 num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
1734
1735 std::ostringstream body;
1736 body << "%val1 = OpExtInst %f" << total_bit_width << " %extinst "
1737 << ext_inst_name << vec_str;
1738
1739 std::ostringstream expected;
1740 expected << "GLSL.std.450 " << ext_inst_name
1741 << ": expected Result Type to be " << total_bit_width
1742 << "-bit int scalar type";
1743
1744 CompileSuccessfully(GenerateShaderCode(body.str()));
1745 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1746 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
1747 }
1748
1749 TEST_P(ValidateGlslStd450Pack, Int16ResultType) {
1750 const std::string ext_inst_name = GetParam();
1751 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1752 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1753 const uint32_t total_bit_width = num_components * packed_bit_width;
1754 const std::string vec_str =
1755 num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
1756
1757 std::ostringstream body;
1758 body << "%val1 = OpExtInst %u16 %extinst " << ext_inst_name << vec_str;
1759
1760 std::ostringstream expected;
1761 expected << "GLSL.std.450 " << ext_inst_name
1762 << ": expected Result Type to be " << total_bit_width
1763 << "-bit int scalar type";
1764
1765 CompileSuccessfully(GenerateShaderCode(body.str()));
1766 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1767 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
1768 }
1769
1770 TEST_P(ValidateGlslStd450Pack, VNotVector) {
1771 const std::string ext_inst_name = GetParam();
1772 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1773 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1774 const uint32_t total_bit_width = num_components * packed_bit_width;
1775
1776 std::ostringstream body;
1777 body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
1778 << ext_inst_name << " %f32_1\n";
1779
1780 std::ostringstream expected;
1781 expected << "GLSL.std.450 " << ext_inst_name
1782 << ": expected operand V to be a 32-bit float vector of size "
1783 << num_components;
1784
1785 CompileSuccessfully(GenerateShaderCode(body.str()));
1786 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1787 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
1788 }
1789
1790 TEST_P(ValidateGlslStd450Pack, VNotFloatVector) {
1791 const std::string ext_inst_name = GetParam();
1792 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1793 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1794 const uint32_t total_bit_width = num_components * packed_bit_width;
1795 const std::string vec_str =
1796 num_components == 2 ? " %u32vec2_01\n" : " %u32vec4_0123\n";
1797
1798 std::ostringstream body;
1799 body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
1800 << ext_inst_name << vec_str;
1801
1802 std::ostringstream expected;
1803 expected << "GLSL.std.450 " << ext_inst_name
1804 << ": expected operand V to be a 32-bit float vector of size "
1805 << num_components;
1806
1807 CompileSuccessfully(GenerateShaderCode(body.str()));
1808 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1809 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
1810 }
1811
1812 TEST_P(ValidateGlslStd450Pack, VNotFloat32Vector) {
1813 const std::string ext_inst_name = GetParam();
1814 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1815 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1816 const uint32_t total_bit_width = num_components * packed_bit_width;
1817 const std::string vec_str =
1818 num_components == 2 ? " %f64vec2_01\n" : " %f64vec4_0123\n";
1819
1820 std::ostringstream body;
1821 body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
1822 << ext_inst_name << vec_str;
1823
1824 std::ostringstream expected;
1825 expected << "GLSL.std.450 " << ext_inst_name
1826 << ": expected operand V to be a 32-bit float vector of size "
1827 << num_components;
1828
1829 CompileSuccessfully(GenerateShaderCode(body.str()));
1830 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1831 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
1832 }
1833
1834 TEST_P(ValidateGlslStd450Pack, VWrongSizeVector) {
1835 const std::string ext_inst_name = GetParam();
1836 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1837 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1838 const uint32_t total_bit_width = num_components * packed_bit_width;
1839 const std::string vec_str =
1840 num_components == 4 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
1841
1842 std::ostringstream body;
1843 body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
1844 << ext_inst_name << vec_str;
1845
1846 std::ostringstream expected;
1847 expected << "GLSL.std.450 " << ext_inst_name
1848 << ": expected operand V to be a 32-bit float vector of size "
1849 << num_components;
1850
1851 CompileSuccessfully(GenerateShaderCode(body.str()));
1852 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1853 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
1854 }
1855
1856 INSTANTIATE_TEST_SUITE_P(AllPack, ValidateGlslStd450Pack,
1857 ::testing::ValuesIn(std::vector<std::string>{
1858 "PackSnorm4x8",
1859 "PackUnorm4x8",
1860 "PackSnorm2x16",
1861 "PackUnorm2x16",
1862 "PackHalf2x16",
1863 }));
1864
1865 TEST_F(ValidateExtInst, PackDouble2x32Success) {
1866 const std::string body = R"(
1867 %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u32vec2_01
1868 )";
1869
1870 CompileSuccessfully(GenerateShaderCode(body));
1871 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1872 }
1873
1874 TEST_F(ValidateExtInst, PackDouble2x32Float32ResultType) {
1875 const std::string body = R"(
1876 %val1 = OpExtInst %f32 %extinst PackDouble2x32 %u32vec2_01
1877 )";
1878
1879 CompileSuccessfully(GenerateShaderCode(body));
1880 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1881 EXPECT_THAT(getDiagnosticString(),
1882 HasSubstr("GLSL.std.450 PackDouble2x32: expected Result Type to "
1883 "be 64-bit float scalar type"));
1884 }
1885
1886 TEST_F(ValidateExtInst, PackDouble2x32Int64ResultType) {
1887 const std::string body = R"(
1888 %val1 = OpExtInst %u64 %extinst PackDouble2x32 %u32vec2_01
1889 )";
1890
1891 CompileSuccessfully(GenerateShaderCode(body));
1892 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1893 EXPECT_THAT(getDiagnosticString(),
1894 HasSubstr("GLSL.std.450 PackDouble2x32: expected Result Type to "
1895 "be 64-bit float scalar type"));
1896 }
1897
1898 TEST_F(ValidateExtInst, PackDouble2x32VNotVector) {
1899 const std::string body = R"(
1900 %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u64_1
1901 )";
1902
1903 CompileSuccessfully(GenerateShaderCode(body));
1904 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1905 EXPECT_THAT(getDiagnosticString(),
1906 HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
1907 "a 32-bit int vector of size 2"));
1908 }
1909
1910 TEST_F(ValidateExtInst, PackDouble2x32VNotIntVector) {
1911 const std::string body = R"(
1912 %val1 = OpExtInst %f64 %extinst PackDouble2x32 %f32vec2_01
1913 )";
1914
1915 CompileSuccessfully(GenerateShaderCode(body));
1916 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1917 EXPECT_THAT(getDiagnosticString(),
1918 HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
1919 "a 32-bit int vector of size 2"));
1920 }
1921
1922 TEST_F(ValidateExtInst, PackDouble2x32VNotInt32Vector) {
1923 const std::string body = R"(
1924 %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u64vec2_01
1925 )";
1926
1927 CompileSuccessfully(GenerateShaderCode(body));
1928 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1929 EXPECT_THAT(getDiagnosticString(),
1930 HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
1931 "a 32-bit int vector of size 2"));
1932 }
1933
1934 TEST_F(ValidateExtInst, PackDouble2x32VWrongSize) {
1935 const std::string body = R"(
1936 %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u32vec4_0123
1937 )";
1938
1939 CompileSuccessfully(GenerateShaderCode(body));
1940 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1941 EXPECT_THAT(getDiagnosticString(),
1942 HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
1943 "a 32-bit int vector of size 2"));
1944 }
1945
1946 TEST_P(ValidateGlslStd450Unpack, Success) {
1947 const std::string ext_inst_name = GetParam();
1948 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1949 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1950 const uint32_t total_bit_width = num_components * packed_bit_width;
1951 const std::string result_type_str =
1952 num_components == 2 ? "%f32vec2" : " %f32vec4";
1953
1954 std::ostringstream body;
1955 body << "%val1 = OpExtInst " << result_type_str << " %extinst "
1956 << ext_inst_name << " %u" << total_bit_width << "_1\n";
1957 body << "%val2 = OpExtInst " << result_type_str << " %extinst "
1958 << ext_inst_name << " %s" << total_bit_width << "_1\n";
1959 CompileSuccessfully(GenerateShaderCode(body.str()));
1960 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
1961 }
1962
1963 TEST_P(ValidateGlslStd450Unpack, ResultTypeNotVector) {
1964 const std::string ext_inst_name = GetParam();
1965 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1966 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1967 const uint32_t total_bit_width = num_components * packed_bit_width;
1968 const std::string result_type_str = "%f32";
1969
1970 std::ostringstream body;
1971 body << "%val1 = OpExtInst " << result_type_str << " %extinst "
1972 << ext_inst_name << " %u" << total_bit_width << "_1\n";
1973
1974 std::ostringstream expected;
1975 expected << "GLSL.std.450 " << ext_inst_name
1976 << ": expected Result Type to be a 32-bit float vector of size "
1977 << num_components;
1978
1979 CompileSuccessfully(GenerateShaderCode(body.str()));
1980 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1981 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
1982 }
1983
1984 TEST_P(ValidateGlslStd450Unpack, ResultTypeNotFloatVector) {
1985 const std::string ext_inst_name = GetParam();
1986 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
1987 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
1988 const uint32_t total_bit_width = num_components * packed_bit_width;
1989 const std::string result_type_str =
1990 num_components == 2 ? "%u32vec2" : " %u32vec4";
1991
1992 std::ostringstream body;
1993 body << "%val1 = OpExtInst " << result_type_str << " %extinst "
1994 << ext_inst_name << " %u" << total_bit_width << "_1\n";
1995
1996 std::ostringstream expected;
1997 expected << "GLSL.std.450 " << ext_inst_name
1998 << ": expected Result Type to be a 32-bit float vector of size "
1999 << num_components;
2000
2001 CompileSuccessfully(GenerateShaderCode(body.str()));
2002 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2003 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
2004 }
2005
2006 TEST_P(ValidateGlslStd450Unpack, ResultTypeNotFloat32Vector) {
2007 const std::string ext_inst_name = GetParam();
2008 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
2009 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
2010 const uint32_t total_bit_width = num_components * packed_bit_width;
2011 const std::string result_type_str =
2012 num_components == 2 ? "%f64vec2" : " %f64vec4";
2013
2014 std::ostringstream body;
2015 body << "%val1 = OpExtInst " << result_type_str << " %extinst "
2016 << ext_inst_name << " %u" << total_bit_width << "_1\n";
2017
2018 std::ostringstream expected;
2019 expected << "GLSL.std.450 " << ext_inst_name
2020 << ": expected Result Type to be a 32-bit float vector of size "
2021 << num_components;
2022
2023 CompileSuccessfully(GenerateShaderCode(body.str()));
2024 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2025 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
2026 }
2027
2028 TEST_P(ValidateGlslStd450Unpack, ResultTypeWrongSize) {
2029 const std::string ext_inst_name = GetParam();
2030 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
2031 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
2032 const uint32_t total_bit_width = num_components * packed_bit_width;
2033 const std::string result_type_str =
2034 num_components == 4 ? "%f32vec2" : " %f32vec4";
2035
2036 std::ostringstream body;
2037 body << "%val1 = OpExtInst " << result_type_str << " %extinst "
2038 << ext_inst_name << " %u" << total_bit_width << "_1\n";
2039
2040 std::ostringstream expected;
2041 expected << "GLSL.std.450 " << ext_inst_name
2042 << ": expected Result Type to be a 32-bit float vector of size "
2043 << num_components;
2044
2045 CompileSuccessfully(GenerateShaderCode(body.str()));
2046 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2047 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
2048 }
2049
2050 TEST_P(ValidateGlslStd450Unpack, ResultPNotInt) {
2051 const std::string ext_inst_name = GetParam();
2052 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
2053 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
2054 const uint32_t total_bit_width = num_components * packed_bit_width;
2055 const std::string result_type_str =
2056 num_components == 2 ? "%f32vec2" : " %f32vec4";
2057
2058 std::ostringstream body;
2059 body << "%val1 = OpExtInst " << result_type_str << " %extinst "
2060 << ext_inst_name << " %f" << total_bit_width << "_1\n";
2061
2062 std::ostringstream expected;
2063 expected << "GLSL.std.450 " << ext_inst_name
2064 << ": expected operand P to be a " << total_bit_width
2065 << "-bit int scalar";
2066
2067 CompileSuccessfully(GenerateShaderCode(body.str()));
2068 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2069 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
2070 }
2071
2072 TEST_P(ValidateGlslStd450Unpack, ResultPWrongBitWidth) {
2073 const std::string ext_inst_name = GetParam();
2074 const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
2075 const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
2076 const uint32_t total_bit_width = num_components * packed_bit_width;
2077 const uint32_t wrong_bit_width = total_bit_width == 32 ? 64 : 32;
2078 const std::string result_type_str =
2079 num_components == 2 ? "%f32vec2" : " %f32vec4";
2080
2081 std::ostringstream body;
2082 body << "%val1 = OpExtInst " << result_type_str << " %extinst "
2083 << ext_inst_name << " %u" << wrong_bit_width << "_1\n";
2084
2085 std::ostringstream expected;
2086 expected << "GLSL.std.450 " << ext_inst_name
2087 << ": expected operand P to be a " << total_bit_width
2088 << "-bit int scalar";
2089
2090 CompileSuccessfully(GenerateShaderCode(body.str()));
2091 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2092 EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
2093 }
2094
2095 INSTANTIATE_TEST_SUITE_P(AllUnpack, ValidateGlslStd450Unpack,
2096 ::testing::ValuesIn(std::vector<std::string>{
2097 "UnpackSnorm4x8",
2098 "UnpackUnorm4x8",
2099 "UnpackSnorm2x16",
2100 "UnpackUnorm2x16",
2101 "UnpackHalf2x16",
2102 }));
2103
2104 TEST_F(ValidateExtInst, UnpackDouble2x32Success) {
2105 const std::string body = R"(
2106 %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %f64_1
2107 )";
2108
2109 CompileSuccessfully(GenerateShaderCode(body));
2110 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2111 }
2112
2113 TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotVector) {
2114 const std::string body = R"(
2115 %val1 = OpExtInst %u64 %extinst UnpackDouble2x32 %f64_1
2116 )";
2117
2118 CompileSuccessfully(GenerateShaderCode(body));
2119 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2120 EXPECT_THAT(getDiagnosticString(),
2121 HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
2122 "to be a 32-bit int vector of size 2"));
2123 }
2124
2125 TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotIntVector) {
2126 const std::string body = R"(
2127 %val1 = OpExtInst %f32vec2 %extinst UnpackDouble2x32 %f64_1
2128 )";
2129
2130 CompileSuccessfully(GenerateShaderCode(body));
2131 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2132 EXPECT_THAT(getDiagnosticString(),
2133 HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
2134 "to be a 32-bit int vector of size 2"));
2135 }
2136
2137 TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotInt32Vector) {
2138 const std::string body = R"(
2139 %val1 = OpExtInst %u64vec2 %extinst UnpackDouble2x32 %f64_1
2140 )";
2141
2142 CompileSuccessfully(GenerateShaderCode(body));
2143 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2144 EXPECT_THAT(getDiagnosticString(),
2145 HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
2146 "to be a 32-bit int vector of size 2"));
2147 }
2148
2149 TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeWrongSize) {
2150 const std::string body = R"(
2151 %val1 = OpExtInst %u32vec4 %extinst UnpackDouble2x32 %f64_1
2152 )";
2153
2154 CompileSuccessfully(GenerateShaderCode(body));
2155 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2156 EXPECT_THAT(getDiagnosticString(),
2157 HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
2158 "to be a 32-bit int vector of size 2"));
2159 }
2160
2161 TEST_F(ValidateExtInst, UnpackDouble2x32VNotFloat) {
2162 const std::string body = R"(
2163 %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %u64_1
2164 )";
2165
2166 CompileSuccessfully(GenerateShaderCode(body));
2167 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2168 EXPECT_THAT(getDiagnosticString(),
2169 HasSubstr("GLSL.std.450 UnpackDouble2x32: expected operand V to "
2170 "be a 64-bit float scalar"));
2171 }
2172
2173 TEST_F(ValidateExtInst, UnpackDouble2x32VNotFloat64) {
2174 const std::string body = R"(
2175 %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %f32_1
2176 )";
2177
2178 CompileSuccessfully(GenerateShaderCode(body));
2179 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2180 EXPECT_THAT(getDiagnosticString(),
2181 HasSubstr("GLSL.std.450 UnpackDouble2x32: expected operand V to "
2182 "be a 64-bit float scalar"));
2183 }
2184
2185 TEST_F(ValidateExtInst, GlslStd450LengthSuccess) {
2186 const std::string body = R"(
2187 %val1 = OpExtInst %f32 %extinst Length %f32_1
2188 %val2 = OpExtInst %f32 %extinst Length %f32vec2_01
2189 %val3 = OpExtInst %f32 %extinst Length %f32vec4_0123
2190 )";
2191
2192 CompileSuccessfully(GenerateShaderCode(body));
2193 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2194 }
2195
2196 TEST_F(ValidateExtInst, GlslStd450LengthIntResultType) {
2197 const std::string body = R"(
2198 %val1 = OpExtInst %u32 %extinst Length %f32vec2_01
2199 )";
2200
2201 CompileSuccessfully(GenerateShaderCode(body));
2202 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2203 EXPECT_THAT(getDiagnosticString(),
2204 HasSubstr("GLSL.std.450 Length: "
2205 "expected Result Type to be a float scalar type"));
2206 }
2207
2208 TEST_F(ValidateExtInst, GlslStd450LengthIntX) {
2209 const std::string body = R"(
2210 %val1 = OpExtInst %f32 %extinst Length %u32vec2_01
2211 )";
2212
2213 CompileSuccessfully(GenerateShaderCode(body));
2214 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2215 EXPECT_THAT(getDiagnosticString(),
2216 HasSubstr("GLSL.std.450 Length: "
2217 "expected operand X to be of float scalar or "
2218 "vector type"));
2219 }
2220
2221 TEST_F(ValidateExtInst, GlslStd450LengthDifferentType) {
2222 const std::string body = R"(
2223 %val1 = OpExtInst %f64 %extinst Length %f32vec2_01
2224 )";
2225
2226 CompileSuccessfully(GenerateShaderCode(body));
2227 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2228 EXPECT_THAT(getDiagnosticString(),
2229 HasSubstr("GLSL.std.450 Length: "
2230 "expected operand X component type to be equal to "
2231 "Result Type"));
2232 }
2233
2234 TEST_F(ValidateExtInst, GlslStd450DistanceSuccess) {
2235 const std::string body = R"(
2236 %val1 = OpExtInst %f32 %extinst Distance %f32_0 %f32_1
2237 %val2 = OpExtInst %f32 %extinst Distance %f32vec2_01 %f32vec2_12
2238 %val3 = OpExtInst %f32 %extinst Distance %f32vec4_0123 %f32vec4_1234
2239 )";
2240
2241 CompileSuccessfully(GenerateShaderCode(body));
2242 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2243 }
2244
2245 TEST_F(ValidateExtInst, GlslStd450DistanceIntResultType) {
2246 const std::string body = R"(
2247 %val1 = OpExtInst %u32 %extinst Distance %f32vec2_01 %f32vec2_12
2248 )";
2249
2250 CompileSuccessfully(GenerateShaderCode(body));
2251 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2252 EXPECT_THAT(getDiagnosticString(),
2253 HasSubstr("GLSL.std.450 Distance: "
2254 "expected Result Type to be a float scalar type"));
2255 }
2256
2257 TEST_F(ValidateExtInst, GlslStd450DistanceIntP0) {
2258 const std::string body = R"(
2259 %val1 = OpExtInst %f32 %extinst Distance %u32_0 %f32_1
2260 )";
2261
2262 CompileSuccessfully(GenerateShaderCode(body));
2263 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2264 EXPECT_THAT(getDiagnosticString(),
2265 HasSubstr("GLSL.std.450 Distance: "
2266 "expected operand P0 to be of float scalar or "
2267 "vector type"));
2268 }
2269
2270 TEST_F(ValidateExtInst, GlslStd450DistanceF64VectorP0) {
2271 const std::string body = R"(
2272 %val1 = OpExtInst %f32 %extinst Distance %f64vec2_01 %f32vec2_12
2273 )";
2274
2275 CompileSuccessfully(GenerateShaderCode(body));
2276 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2277 EXPECT_THAT(getDiagnosticString(),
2278 HasSubstr("GLSL.std.450 Distance: "
2279 "expected operand P0 component type to be equal to "
2280 "Result Type"));
2281 }
2282
2283 TEST_F(ValidateExtInst, GlslStd450DistanceIntP1) {
2284 const std::string body = R"(
2285 %val1 = OpExtInst %f32 %extinst Distance %f32_0 %u32_1
2286 )";
2287
2288 CompileSuccessfully(GenerateShaderCode(body));
2289 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2290 EXPECT_THAT(getDiagnosticString(),
2291 HasSubstr("GLSL.std.450 Distance: "
2292 "expected operand P1 to be of float scalar or "
2293 "vector type"));
2294 }
2295
2296 TEST_F(ValidateExtInst, GlslStd450DistanceF64VectorP1) {
2297 const std::string body = R"(
2298 %val1 = OpExtInst %f32 %extinst Distance %f32vec2_12 %f64vec2_01
2299 )";
2300
2301 CompileSuccessfully(GenerateShaderCode(body));
2302 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2303 EXPECT_THAT(getDiagnosticString(),
2304 HasSubstr("GLSL.std.450 Distance: "
2305 "expected operand P1 component type to be equal to "
2306 "Result Type"));
2307 }
2308
2309 TEST_F(ValidateExtInst, GlslStd450DistanceDifferentSize) {
2310 const std::string body = R"(
2311 %val1 = OpExtInst %f32 %extinst Distance %f32vec2_01 %f32vec4_0123
2312 )";
2313
2314 CompileSuccessfully(GenerateShaderCode(body));
2315 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2316 EXPECT_THAT(getDiagnosticString(),
2317 HasSubstr("GLSL.std.450 Distance: "
2318 "expected operands P0 and P1 to have the same number "
2319 "of components"));
2320 }
2321
2322 TEST_F(ValidateExtInst, GlslStd450CrossSuccess) {
2323 const std::string body = R"(
2324 %val1 = OpExtInst %f32vec3 %extinst Cross %f32vec3_012 %f32vec3_123
2325 )";
2326
2327 CompileSuccessfully(GenerateShaderCode(body));
2328 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2329 }
2330
2331 TEST_F(ValidateExtInst, GlslStd450CrossIntVectorResultType) {
2332 const std::string body = R"(
2333 %val1 = OpExtInst %u32vec3 %extinst Cross %f32vec3_012 %f32vec3_123
2334 )";
2335
2336 CompileSuccessfully(GenerateShaderCode(body));
2337 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2338 EXPECT_THAT(getDiagnosticString(),
2339 HasSubstr("GLSL.std.450 Cross: "
2340 "expected Result Type to be a float vector type"));
2341 }
2342
2343 TEST_F(ValidateExtInst, GlslStd450CrossResultTypeWrongSize) {
2344 const std::string body = R"(
2345 %val1 = OpExtInst %f32vec2 %extinst Cross %f32vec3_012 %f32vec3_123
2346 )";
2347
2348 CompileSuccessfully(GenerateShaderCode(body));
2349 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2350 EXPECT_THAT(getDiagnosticString(),
2351 HasSubstr("GLSL.std.450 Cross: "
2352 "expected Result Type to have 3 components"));
2353 }
2354
2355 TEST_F(ValidateExtInst, GlslStd450CrossXWrongType) {
2356 const std::string body = R"(
2357 %val1 = OpExtInst %f32vec3 %extinst Cross %f64vec3_012 %f32vec3_123
2358 )";
2359
2360 CompileSuccessfully(GenerateShaderCode(body));
2361 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2362 EXPECT_THAT(getDiagnosticString(),
2363 HasSubstr("GLSL.std.450 Cross: "
2364 "expected operand X type to be equal to Result Type"));
2365 }
2366
2367 TEST_F(ValidateExtInst, GlslStd450CrossYWrongType) {
2368 const std::string body = R"(
2369 %val1 = OpExtInst %f32vec3 %extinst Cross %f32vec3_123 %f64vec3_012
2370 )";
2371
2372 CompileSuccessfully(GenerateShaderCode(body));
2373 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2374 EXPECT_THAT(getDiagnosticString(),
2375 HasSubstr("GLSL.std.450 Cross: "
2376 "expected operand Y type to be equal to Result Type"));
2377 }
2378
2379 TEST_F(ValidateExtInst, GlslStd450RefractSuccess) {
2380 const std::string body = R"(
2381 %val1 = OpExtInst %f32 %extinst Refract %f32_1 %f32_1 %f32_1
2382 %val2 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f16_1
2383 )";
2384
2385 CompileSuccessfully(GenerateShaderCode(body));
2386 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2387 }
2388
2389 TEST_F(ValidateExtInst, GlslStd450RefractIntVectorResultType) {
2390 const std::string body = R"(
2391 %val1 = OpExtInst %u32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f32_1
2392 )";
2393
2394 CompileSuccessfully(GenerateShaderCode(body));
2395 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2396 EXPECT_THAT(getDiagnosticString(),
2397 HasSubstr("GLSL.std.450 Refract: "
2398 "expected Result Type to be a float scalar or "
2399 "vector type"));
2400 }
2401
2402 TEST_F(ValidateExtInst, GlslStd450RefractIntVectorI) {
2403 const std::string body = R"(
2404 %val1 = OpExtInst %f32vec2 %extinst Refract %u32vec2_01 %f32vec2_01 %f32_1
2405 )";
2406
2407 CompileSuccessfully(GenerateShaderCode(body));
2408 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2409 EXPECT_THAT(getDiagnosticString(),
2410 HasSubstr("GLSL.std.450 Refract: "
2411 "expected operand I to be of type equal to "
2412 "Result Type"));
2413 }
2414
2415 TEST_F(ValidateExtInst, GlslStd450RefractIntVectorN) {
2416 const std::string body = R"(
2417 %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %u32vec2_01 %f32_1
2418 )";
2419
2420 CompileSuccessfully(GenerateShaderCode(body));
2421 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2422 EXPECT_THAT(getDiagnosticString(),
2423 HasSubstr("GLSL.std.450 Refract: "
2424 "expected operand N to be of type equal to "
2425 "Result Type"));
2426 }
2427
2428 TEST_F(ValidateExtInst, GlslStd450RefractIntEta) {
2429 const std::string body = R"(
2430 %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %u32_1
2431 )";
2432
2433 CompileSuccessfully(GenerateShaderCode(body));
2434 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2435 EXPECT_THAT(getDiagnosticString(),
2436 HasSubstr("GLSL.std.450 Refract: "
2437 "expected operand Eta to be a float scalar"));
2438 }
2439
2440 TEST_F(ValidateExtInst, GlslStd450RefractFloat64Eta) {
2441 // SPIR-V issue 337: Eta can be 64-bit float scalar.
2442 const std::string body = R"(
2443 %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f64_1
2444 )";
2445
2446 CompileSuccessfully(GenerateShaderCode(body));
2447 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2448 EXPECT_THAT(getDiagnosticString(), Eq(""));
2449 }
2450
2451 TEST_F(ValidateExtInst, GlslStd450RefractVectorEta) {
2452 const std::string body = R"(
2453 %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f32vec2_01
2454 )";
2455
2456 CompileSuccessfully(GenerateShaderCode(body));
2457 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2458 EXPECT_THAT(getDiagnosticString(),
2459 HasSubstr("GLSL.std.450 Refract: "
2460 "expected operand Eta to be a float scalar"));
2461 }
2462
2463 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidSuccess) {
2464 const std::string body = R"(
2465 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
2466 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtCentroid %f32vec2_input
2467 )";
2468
2469 CompileSuccessfully(
2470 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2471 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2472 }
2473
2474 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidInternalSuccess) {
2475 const std::string body = R"(
2476 %ld1 = OpLoad %f32 %f32_input
2477 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %ld1
2478 %ld2 = OpLoad %f32vec2 %f32vec2_input
2479 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtCentroid %ld2
2480 )";
2481
2482 CompileSuccessfully(
2483 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2484 getValidatorOptions()->before_hlsl_legalization = true;
2485 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2486 }
2487
2488 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidInternalInvalidDataF32) {
2489 const std::string body = R"(
2490 %ld1 = OpLoad %f32 %f32_input
2491 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %ld1
2492 )";
2493
2494 CompileSuccessfully(
2495 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2496 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2497 EXPECT_THAT(getDiagnosticString(),
2498 HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
2499 "expected Interpolant to be a pointer"));
2500 }
2501
2502 TEST_F(ValidateExtInst,
2503 GlslStd450InterpolateAtCentroidInternalInvalidDataF32Vec2) {
2504 const std::string body = R"(
2505 %ld2 = OpLoad %f32vec2 %f32vec2_input
2506 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtCentroid %ld2
2507 )";
2508
2509 CompileSuccessfully(
2510 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2511 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2512 EXPECT_THAT(getDiagnosticString(),
2513 HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
2514 "expected Interpolant to be a pointer"));
2515 }
2516
2517 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidNoCapability) {
2518 const std::string body = R"(
2519 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
2520 )";
2521
2522 CompileSuccessfully(GenerateShaderCode(body));
2523 ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
2524 EXPECT_THAT(getDiagnosticString(),
2525 HasSubstr("GLSL.std.450 InterpolateAtCentroid requires "
2526 "capability InterpolationFunction"));
2527 }
2528
2529 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidIntResultType) {
2530 const std::string body = R"(
2531 %val1 = OpExtInst %u32 %extinst InterpolateAtCentroid %f32_input
2532 )";
2533
2534 CompileSuccessfully(
2535 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2536 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2537 EXPECT_THAT(getDiagnosticString(),
2538 HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
2539 "expected Result Type to be a 32-bit float scalar "
2540 "or vector type"));
2541 }
2542
2543 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidF64ResultType) {
2544 const std::string body = R"(
2545 %val1 = OpExtInst %f64 %extinst InterpolateAtCentroid %f32_input
2546 )";
2547
2548 CompileSuccessfully(
2549 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2550 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2551 EXPECT_THAT(getDiagnosticString(),
2552 HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
2553 "expected Result Type to be a 32-bit float scalar "
2554 "or vector type"));
2555 }
2556
2557 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidNotPointer) {
2558 const std::string body = R"(
2559 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_1
2560 )";
2561
2562 CompileSuccessfully(
2563 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2564 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2565 EXPECT_THAT(getDiagnosticString(),
2566 HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
2567 "expected Interpolant to be a pointer"));
2568 }
2569
2570 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongDataType) {
2571 const std::string body = R"(
2572 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32vec2_input
2573 )";
2574
2575 CompileSuccessfully(
2576 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2577 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2578 EXPECT_THAT(getDiagnosticString(),
2579 HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
2580 "expected Interpolant data type to be equal to "
2581 "Result Type"));
2582 }
2583
2584 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongStorageClass) {
2585 const std::string body = R"(
2586 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_output
2587 )";
2588
2589 CompileSuccessfully(
2590 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2591 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2592 EXPECT_THAT(getDiagnosticString(),
2593 HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
2594 "expected Interpolant storage class to be Input"));
2595 }
2596
2597 TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongExecutionModel) {
2598 const std::string body = R"(
2599 %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
2600 )";
2601
2602 CompileSuccessfully(GenerateShaderCode(
2603 body, "OpCapability InterpolationFunction\n", "Vertex"));
2604 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
2605 EXPECT_THAT(getDiagnosticString(),
2606 HasSubstr("GLSL.std.450 InterpolateAtCentroid requires "
2607 "Fragment execution model"));
2608 }
2609
2610 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleSuccess) {
2611 const std::string body = R"(
2612 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
2613 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtSample %f32vec2_input %u32_1
2614 )";
2615
2616 CompileSuccessfully(
2617 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2618 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2619 }
2620
2621 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleInternalSuccess) {
2622 const std::string body = R"(
2623 %ld1 = OpLoad %f32 %f32_input
2624 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %ld1 %u32_1
2625 %ld2 = OpLoad %f32vec2 %f32vec2_input
2626 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtSample %ld2 %u32_1
2627 )";
2628
2629 CompileSuccessfully(
2630 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2631 getValidatorOptions()->before_hlsl_legalization = true;
2632 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2633 }
2634
2635 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleInternalInvalidDataF32) {
2636 const std::string body = R"(
2637 %ld1 = OpLoad %f32 %f32_input
2638 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %ld1 %u32_1
2639 )";
2640
2641 CompileSuccessfully(
2642 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2643 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2644 EXPECT_THAT(getDiagnosticString(),
2645 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2646 "expected Interpolant to be a pointer"));
2647 }
2648
2649 TEST_F(ValidateExtInst,
2650 GlslStd450InterpolateAtSampleInternalInvalidDataF32Vec2) {
2651 const std::string body = R"(
2652 %ld2 = OpLoad %f32vec2 %f32vec2_input
2653 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtSample %ld2 %u32_1
2654 )";
2655
2656 CompileSuccessfully(
2657 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2658 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2659 EXPECT_THAT(getDiagnosticString(),
2660 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2661 "expected Interpolant to be a pointer"));
2662 }
2663
2664 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleNoCapability) {
2665 const std::string body = R"(
2666 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
2667 )";
2668
2669 CompileSuccessfully(GenerateShaderCode(body));
2670 ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
2671 EXPECT_THAT(getDiagnosticString(),
2672 HasSubstr("GLSL.std.450 InterpolateAtSample requires "
2673 "capability InterpolationFunction"));
2674 }
2675
2676 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleIntResultType) {
2677 const std::string body = R"(
2678 %val1 = OpExtInst %u32 %extinst InterpolateAtSample %f32_input %u32_1
2679 )";
2680
2681 CompileSuccessfully(
2682 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2683 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2684 EXPECT_THAT(getDiagnosticString(),
2685 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2686 "expected Result Type to be a 32-bit float scalar "
2687 "or vector type"));
2688 }
2689
2690 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleF64ResultType) {
2691 const std::string body = R"(
2692 %val1 = OpExtInst %f64 %extinst InterpolateAtSample %f32_input %u32_1
2693 )";
2694
2695 CompileSuccessfully(
2696 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2697 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2698 EXPECT_THAT(getDiagnosticString(),
2699 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2700 "expected Result Type to be a 32-bit float scalar "
2701 "or vector type"));
2702 }
2703
2704 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleNotPointer) {
2705 const std::string body = R"(
2706 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_1 %u32_1
2707 )";
2708
2709 CompileSuccessfully(
2710 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2711 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2712 EXPECT_THAT(getDiagnosticString(),
2713 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2714 "expected Interpolant to be a pointer"));
2715 }
2716
2717 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongDataType) {
2718 const std::string body = R"(
2719 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32vec2_input %u32_1
2720 )";
2721
2722 CompileSuccessfully(
2723 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2724 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2725 EXPECT_THAT(getDiagnosticString(),
2726 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2727 "expected Interpolant data type to be equal to "
2728 "Result Type"));
2729 }
2730
2731 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongStorageClass) {
2732 const std::string body = R"(
2733 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_output %u32_1
2734 )";
2735
2736 CompileSuccessfully(
2737 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2738 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2739 EXPECT_THAT(getDiagnosticString(),
2740 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2741 "expected Interpolant storage class to be Input"));
2742 }
2743
2744 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleFloatSample) {
2745 const std::string body = R"(
2746 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %f32_1
2747 )";
2748
2749 CompileSuccessfully(
2750 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2751 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2752 EXPECT_THAT(getDiagnosticString(),
2753 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2754 "expected Sample to be 32-bit integer"));
2755 }
2756
2757 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleU64Sample) {
2758 const std::string body = R"(
2759 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u64_1
2760 )";
2761
2762 CompileSuccessfully(
2763 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2764 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2765 EXPECT_THAT(getDiagnosticString(),
2766 HasSubstr("GLSL.std.450 InterpolateAtSample: "
2767 "expected Sample to be 32-bit integer"));
2768 }
2769
2770 TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongExecutionModel) {
2771 const std::string body = R"(
2772 %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
2773 )";
2774
2775 CompileSuccessfully(GenerateShaderCode(
2776 body, "OpCapability InterpolationFunction\n", "Vertex"));
2777 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
2778 EXPECT_THAT(getDiagnosticString(),
2779 HasSubstr("GLSL.std.450 InterpolateAtSample requires "
2780 "Fragment execution model"));
2781 }
2782
2783 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetSuccess) {
2784 const std::string body = R"(
2785 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
2786 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtOffset %f32vec2_input %f32vec2_01
2787 )";
2788
2789 CompileSuccessfully(
2790 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2791 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2792 }
2793
2794 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetInternalSuccess) {
2795 const std::string body = R"(
2796 %ld1 = OpLoad %f32 %f32_input
2797 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %ld1 %f32vec2_01
2798 %ld2 = OpLoad %f32vec2 %f32vec2_input
2799 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtOffset %ld2 %f32vec2_01
2800 )";
2801
2802 CompileSuccessfully(
2803 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2804 getValidatorOptions()->before_hlsl_legalization = true;
2805 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2806 }
2807
2808 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetInternalInvalidDataF32) {
2809 const std::string body = R"(
2810 %ld1 = OpLoad %f32 %f32_input
2811 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %ld1 %f32vec2_01
2812 )";
2813
2814 CompileSuccessfully(
2815 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2816 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2817 EXPECT_THAT(getDiagnosticString(),
2818 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2819 "expected Interpolant to be a pointer"));
2820 }
2821
2822 TEST_F(ValidateExtInst,
2823 GlslStd450InterpolateAtOffsetInternalInvalidDataF32Vec2) {
2824 const std::string body = R"(
2825 %ld2 = OpLoad %f32vec2 %f32vec2_input
2826 %val2 = OpExtInst %f32vec2 %extinst InterpolateAtOffset %ld2 %f32vec2_01
2827 )";
2828
2829 CompileSuccessfully(
2830 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2831 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2832 EXPECT_THAT(getDiagnosticString(),
2833 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2834 "expected Interpolant to be a pointer"));
2835 }
2836
2837 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetNoCapability) {
2838 const std::string body = R"(
2839 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
2840 )";
2841
2842 CompileSuccessfully(GenerateShaderCode(body));
2843 ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
2844 EXPECT_THAT(getDiagnosticString(),
2845 HasSubstr("GLSL.std.450 InterpolateAtOffset requires "
2846 "capability InterpolationFunction"));
2847 }
2848
2849 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetIntResultType) {
2850 const std::string body = R"(
2851 %val1 = OpExtInst %u32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
2852 )";
2853
2854 CompileSuccessfully(
2855 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2856 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2857 EXPECT_THAT(getDiagnosticString(),
2858 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2859 "expected Result Type to be a 32-bit float scalar "
2860 "or vector type"));
2861 }
2862
2863 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetF64ResultType) {
2864 const std::string body = R"(
2865 %val1 = OpExtInst %f64 %extinst InterpolateAtOffset %f32_input %f32vec2_01
2866 )";
2867
2868 CompileSuccessfully(
2869 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2870 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2871 EXPECT_THAT(getDiagnosticString(),
2872 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2873 "expected Result Type to be a 32-bit float scalar "
2874 "or vector type"));
2875 }
2876
2877 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetNotPointer) {
2878 const std::string body = R"(
2879 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_1 %f32vec2_01
2880 )";
2881
2882 CompileSuccessfully(
2883 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2884 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2885 EXPECT_THAT(getDiagnosticString(),
2886 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2887 "expected Interpolant to be a pointer"));
2888 }
2889
2890 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongDataType) {
2891 const std::string body = R"(
2892 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32vec2_input %f32vec2_01
2893 )";
2894
2895 CompileSuccessfully(
2896 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2897 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2898 EXPECT_THAT(getDiagnosticString(),
2899 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2900 "expected Interpolant data type to be equal to "
2901 "Result Type"));
2902 }
2903
2904 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongStorageClass) {
2905 const std::string body = R"(
2906 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_output %f32vec2_01
2907 )";
2908
2909 CompileSuccessfully(
2910 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2911 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2912 EXPECT_THAT(getDiagnosticString(),
2913 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2914 "expected Interpolant storage class to be Input"));
2915 }
2916
2917 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotVector) {
2918 const std::string body = R"(
2919 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32_0
2920 )";
2921
2922 CompileSuccessfully(
2923 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2924 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2925 EXPECT_THAT(getDiagnosticString(),
2926 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2927 "expected Offset to be a vector of 2 32-bit floats"));
2928 }
2929
2930 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotVector2) {
2931 const std::string body = R"(
2932 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec3_012
2933 )";
2934
2935 CompileSuccessfully(
2936 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2937 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2938 EXPECT_THAT(getDiagnosticString(),
2939 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2940 "expected Offset to be a vector of 2 32-bit floats"));
2941 }
2942
2943 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotFloatVector) {
2944 const std::string body = R"(
2945 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %u32vec2_01
2946 )";
2947
2948 CompileSuccessfully(
2949 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2950 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2951 EXPECT_THAT(getDiagnosticString(),
2952 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2953 "expected Offset to be a vector of 2 32-bit floats"));
2954 }
2955
2956 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotFloat32Vector) {
2957 const std::string body = R"(
2958 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f64vec2_01
2959 )";
2960
2961 CompileSuccessfully(
2962 GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
2963 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2964 EXPECT_THAT(getDiagnosticString(),
2965 HasSubstr("GLSL.std.450 InterpolateAtOffset: "
2966 "expected Offset to be a vector of 2 32-bit floats"));
2967 }
2968
2969 TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongExecutionModel) {
2970 const std::string body = R"(
2971 %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
2972 )";
2973
2974 CompileSuccessfully(GenerateShaderCode(
2975 body, "OpCapability InterpolationFunction\n", "Vertex"));
2976 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
2977 EXPECT_THAT(getDiagnosticString(),
2978 HasSubstr("GLSL.std.450 InterpolateAtOffset requires "
2979 "Fragment execution model"));
2980 }
2981
2982 TEST_P(ValidateOpenCLStdSqrtLike, Success) {
2983 const std::string ext_inst_name = GetParam();
2984 std::ostringstream ss;
2985 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
2986 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
2987 << " %f32vec2_01\n";
2988 ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
2989 << " %f32vec4_0123\n";
2990 ss << "%val4 = OpExtInst %f64 %extinst " << ext_inst_name << " %f64_0\n";
2991 CompileSuccessfully(GenerateKernelCode(ss.str()));
2992 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2993 }
2994
2995 TEST_P(ValidateOpenCLStdSqrtLike, IntResultType) {
2996 const std::string ext_inst_name = GetParam();
2997 const std::string body =
2998 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
2999
3000 CompileSuccessfully(GenerateKernelCode(body));
3001 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3002 EXPECT_THAT(getDiagnosticString(),
3003 HasSubstr("OpenCL.std " + ext_inst_name +
3004 ": expected Result Type to be a float scalar "
3005 "or vector type"));
3006 }
3007
3008 TEST_P(ValidateOpenCLStdSqrtLike, IntOperand) {
3009 const std::string ext_inst_name = GetParam();
3010 const std::string body =
3011 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
3012
3013 CompileSuccessfully(GenerateKernelCode(body));
3014 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3015 EXPECT_THAT(getDiagnosticString(),
3016 HasSubstr("OpenCL.std " + ext_inst_name +
3017 ": expected types of all operands to be equal to "
3018 "Result Type"));
3019 }
3020
3021 INSTANTIATE_TEST_SUITE_P(
3022 AllSqrtLike, ValidateOpenCLStdSqrtLike,
3023 ::testing::ValuesIn(std::vector<std::string>{
3024 "acos", "acosh", "acospi", "asin",
3025 "asinh", "asinpi", "atan", "atanh",
3026 "atanpi", "cbrt", "ceil", "cos",
3027 "cosh", "cospi", "erfc", "erf",
3028 "exp", "exp2", "exp10", "expm1",
3029 "fabs", "floor", "log", "log2",
3030 "log10", "log1p", "logb", "rint",
3031 "round", "rsqrt", "sin", "sinh",
3032 "sinpi", "sqrt", "tan", "tanh",
3033 "tanpi", "tgamma", "trunc", "half_cos",
3034 "half_exp", "half_exp2", "half_exp10", "half_log",
3035 "half_log2", "half_log10", "half_recip", "half_rsqrt",
3036 "half_sin", "half_sqrt", "half_tan", "lgamma",
3037 "native_cos", "native_exp", "native_exp2", "native_exp10",
3038 "native_log", "native_log2", "native_log10", "native_recip",
3039 "native_rsqrt", "native_sin", "native_sqrt", "native_tan",
3040 "degrees", "radians", "sign",
3041 }));
3042
3043 TEST_P(ValidateOpenCLStdFMinLike, Success) {
3044 const std::string ext_inst_name = GetParam();
3045 std::ostringstream ss;
3046 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
3047 << " %f32_0 %f32_1\n";
3048 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
3049 << " %f32vec2_01 %f32vec2_12\n";
3050 ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
3051 << " %f64_0 %f64_0\n";
3052 CompileSuccessfully(GenerateKernelCode(ss.str()));
3053 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3054 }
3055
3056 TEST_P(ValidateOpenCLStdFMinLike, IntResultType) {
3057 const std::string ext_inst_name = GetParam();
3058 const std::string body =
3059 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %f32_1\n";
3060
3061 CompileSuccessfully(GenerateKernelCode(body));
3062 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3063 EXPECT_THAT(getDiagnosticString(),
3064 HasSubstr("OpenCL.std " + ext_inst_name +
3065 ": expected Result Type to be a float scalar "
3066 "or vector type"));
3067 }
3068
3069 TEST_P(ValidateOpenCLStdFMinLike, IntOperand1) {
3070 const std::string ext_inst_name = GetParam();
3071 const std::string body =
3072 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
3073
3074 CompileSuccessfully(GenerateKernelCode(body));
3075 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3076 EXPECT_THAT(getDiagnosticString(),
3077 HasSubstr("OpenCL.std " + ext_inst_name +
3078 ": expected types of all operands to be equal to "
3079 "Result Type"));
3080 }
3081
3082 TEST_P(ValidateOpenCLStdFMinLike, IntOperand2) {
3083 const std::string ext_inst_name = GetParam();
3084 const std::string body =
3085 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
3086
3087 CompileSuccessfully(GenerateKernelCode(body));
3088 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3089 EXPECT_THAT(getDiagnosticString(),
3090 HasSubstr("OpenCL.std " + ext_inst_name +
3091 ": expected types of all operands to be equal to "
3092 "Result Type"));
3093 }
3094
3095 INSTANTIATE_TEST_SUITE_P(AllFMinLike, ValidateOpenCLStdFMinLike,
3096 ::testing::ValuesIn(std::vector<std::string>{
3097 "atan2", "atan2pi", "copysign",
3098 "fdim", "fmax", "fmin",
3099 "fmod", "maxmag", "minmag",
3100 "hypot", "nextafter", "pow",
3101 "powr", "remainder", "half_divide",
3102 "half_powr", "native_divide", "native_powr",
3103 "step", "fmax_common", "fmin_common",
3104 }));
3105
3106 TEST_P(ValidateOpenCLStdFClampLike, Success) {
3107 const std::string ext_inst_name = GetParam();
3108 std::ostringstream ss;
3109 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
3110 << " %f32_0 %f32_1 %f32_2\n";
3111 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
3112 << " %f32vec2_01 %f32vec2_01 %f32vec2_12\n";
3113 ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
3114 << " %f64_0 %f64_0 %f64_1\n";
3115 CompileSuccessfully(GenerateKernelCode(ss.str()));
3116 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3117 }
3118
3119 TEST_P(ValidateOpenCLStdFClampLike, IntResultType) {
3120 const std::string ext_inst_name = GetParam();
3121 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3122 " %f32_0 %f32_1 %f32_2\n";
3123
3124 CompileSuccessfully(GenerateKernelCode(body));
3125 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3126 EXPECT_THAT(getDiagnosticString(),
3127 HasSubstr("OpenCL.std " + ext_inst_name +
3128 ": expected Result Type to be a float scalar "
3129 "or vector type"));
3130 }
3131
3132 TEST_P(ValidateOpenCLStdFClampLike, IntOperand1) {
3133 const std::string ext_inst_name = GetParam();
3134 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3135 " %u32_0 %f32_0 %f32_1\n";
3136
3137 CompileSuccessfully(GenerateKernelCode(body));
3138 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3139 EXPECT_THAT(getDiagnosticString(),
3140 HasSubstr("OpenCL.std " + ext_inst_name +
3141 ": expected types of all operands to be equal to "
3142 "Result Type"));
3143 }
3144
3145 TEST_P(ValidateOpenCLStdFClampLike, IntOperand2) {
3146 const std::string ext_inst_name = GetParam();
3147 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3148 " %f32_0 %u32_0 %f32_1\n";
3149
3150 CompileSuccessfully(GenerateKernelCode(body));
3151 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3152 EXPECT_THAT(getDiagnosticString(),
3153 HasSubstr("OpenCL.std " + ext_inst_name +
3154 ": expected types of all operands to be equal to "
3155 "Result Type"));
3156 }
3157
3158 TEST_P(ValidateOpenCLStdFClampLike, IntOperand3) {
3159 const std::string ext_inst_name = GetParam();
3160 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3161 " %f32_1 %f32_0 %u32_2\n";
3162
3163 CompileSuccessfully(GenerateKernelCode(body));
3164 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3165 EXPECT_THAT(getDiagnosticString(),
3166 HasSubstr("OpenCL.std " + ext_inst_name +
3167 ": expected types of all operands to be equal to "
3168 "Result Type"));
3169 }
3170
3171 INSTANTIATE_TEST_SUITE_P(AllFClampLike, ValidateOpenCLStdFClampLike,
3172 ::testing::ValuesIn(std::vector<std::string>{
3173 "fma",
3174 "mad",
3175 "fclamp",
3176 "mix",
3177 "smoothstep",
3178 }));
3179
3180 TEST_P(ValidateOpenCLStdSAbsLike, Success) {
3181 const std::string ext_inst_name = GetParam();
3182 std::ostringstream ss;
3183 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
3184 ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
3185 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
3186 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
3187 ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3188 << " %u32vec2_01\n";
3189 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3190 << " %u32vec2_01\n";
3191 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3192 << " %u32vec2_01\n";
3193 ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3194 << " %u32vec2_01\n";
3195 CompileSuccessfully(GenerateKernelCode(ss.str()));
3196 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3197 }
3198
3199 TEST_P(ValidateOpenCLStdSAbsLike, FloatResultType) {
3200 const std::string ext_inst_name = GetParam();
3201 const std::string body =
3202 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
3203
3204 CompileSuccessfully(GenerateKernelCode(body));
3205 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3206 EXPECT_THAT(getDiagnosticString(),
3207 HasSubstr("OpenCL.std " + ext_inst_name +
3208 ": expected Result Type to be an int scalar "
3209 "or vector type"));
3210 }
3211
3212 TEST_P(ValidateOpenCLStdSAbsLike, FloatOperand) {
3213 const std::string ext_inst_name = GetParam();
3214 const std::string body =
3215 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
3216
3217 CompileSuccessfully(GenerateKernelCode(body));
3218 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3219 EXPECT_THAT(
3220 getDiagnosticString(),
3221 HasSubstr("OpenCL.std " + ext_inst_name +
3222 ": expected types of all operands to be equal to Result Type"));
3223 }
3224
3225 TEST_P(ValidateOpenCLStdSAbsLike, U64Operand) {
3226 const std::string ext_inst_name = GetParam();
3227 const std::string body =
3228 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0\n";
3229
3230 CompileSuccessfully(GenerateKernelCode(body));
3231 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3232 EXPECT_THAT(
3233 getDiagnosticString(),
3234 HasSubstr("OpenCL.std " + ext_inst_name +
3235 ": expected types of all operands to be equal to Result Type"));
3236 }
3237
3238 INSTANTIATE_TEST_SUITE_P(AllSAbsLike, ValidateOpenCLStdSAbsLike,
3239 ::testing::ValuesIn(std::vector<std::string>{
3240 "s_abs",
3241 "clz",
3242 "ctz",
3243 "popcount",
3244 "u_abs",
3245 }));
3246
3247 TEST_P(ValidateOpenCLStdUMinLike, Success) {
3248 const std::string ext_inst_name = GetParam();
3249 std::ostringstream ss;
3250 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
3251 << " %u32_1 %u32_2\n";
3252 ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
3253 << " %u32_1 %u32_2\n";
3254 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
3255 << " %u32_1 %u32_2\n";
3256 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
3257 << " %u32_1 %u32_2\n";
3258 ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3259 << " %u32vec2_01 %u32vec2_01\n";
3260 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3261 << " %u32vec2_01 %u32vec2_01\n";
3262 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3263 << " %u32vec2_01 %u32vec2_01\n";
3264 ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3265 << " %u32vec2_01 %u32vec2_01\n";
3266 ss << "%val9 = OpExtInst %u64 %extinst " << ext_inst_name
3267 << " %u64_1 %u64_0\n";
3268 CompileSuccessfully(GenerateKernelCode(ss.str()));
3269 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3270 }
3271
3272 TEST_P(ValidateOpenCLStdUMinLike, FloatResultType) {
3273 const std::string ext_inst_name = GetParam();
3274 const std::string body =
3275 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
3276
3277 CompileSuccessfully(GenerateKernelCode(body));
3278 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3279 EXPECT_THAT(getDiagnosticString(),
3280 HasSubstr("OpenCL.std " + ext_inst_name +
3281 ": expected Result Type to be an int scalar "
3282 "or vector type"));
3283 }
3284
3285 TEST_P(ValidateOpenCLStdUMinLike, FloatOperand1) {
3286 const std::string ext_inst_name = GetParam();
3287 const std::string body =
3288 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
3289
3290 CompileSuccessfully(GenerateKernelCode(body));
3291 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3292 EXPECT_THAT(
3293 getDiagnosticString(),
3294 HasSubstr("OpenCL.std " + ext_inst_name +
3295 ": expected types of all operands to be equal to Result Type"));
3296 }
3297
3298 TEST_P(ValidateOpenCLStdUMinLike, FloatOperand2) {
3299 const std::string ext_inst_name = GetParam();
3300 const std::string body =
3301 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
3302
3303 CompileSuccessfully(GenerateKernelCode(body));
3304 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3305 EXPECT_THAT(
3306 getDiagnosticString(),
3307 HasSubstr("OpenCL.std " + ext_inst_name +
3308 ": expected types of all operands to be equal to Result Type"));
3309 }
3310
3311 TEST_P(ValidateOpenCLStdUMinLike, U64Operand1) {
3312 const std::string ext_inst_name = GetParam();
3313 const std::string body =
3314 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0 %u32_0\n";
3315
3316 CompileSuccessfully(GenerateKernelCode(body));
3317 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3318 EXPECT_THAT(
3319 getDiagnosticString(),
3320 HasSubstr("OpenCL.std " + ext_inst_name +
3321 ": expected types of all operands to be equal to Result Type"));
3322 }
3323
3324 TEST_P(ValidateOpenCLStdUMinLike, U64Operand2) {
3325 const std::string ext_inst_name = GetParam();
3326 const std::string body =
3327 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %u64_0\n";
3328
3329 CompileSuccessfully(GenerateKernelCode(body));
3330 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3331 EXPECT_THAT(
3332 getDiagnosticString(),
3333 HasSubstr("OpenCL.std " + ext_inst_name +
3334 ": expected types of all operands to be equal to Result Type"));
3335 }
3336
3337 INSTANTIATE_TEST_SUITE_P(AllUMinLike, ValidateOpenCLStdUMinLike,
3338 ::testing::ValuesIn(std::vector<std::string>{
3339 "s_max",
3340 "u_max",
3341 "s_min",
3342 "u_min",
3343 "s_abs_diff",
3344 "s_add_sat",
3345 "u_add_sat",
3346 "s_mul_hi",
3347 "rotate",
3348 "s_sub_sat",
3349 "u_sub_sat",
3350 "s_hadd",
3351 "u_hadd",
3352 "s_rhadd",
3353 "u_rhadd",
3354 "u_abs_diff",
3355 "u_mul_hi",
3356 }));
3357
3358 TEST_P(ValidateOpenCLStdUClampLike, Success) {
3359 const std::string ext_inst_name = GetParam();
3360 std::ostringstream ss;
3361 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
3362 << " %u32_0 %u32_1 %u32_2\n";
3363 ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
3364 << " %u32_0 %u32_1 %u32_2\n";
3365 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
3366 << " %u32_0 %u32_1 %u32_2\n";
3367 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
3368 << " %u32_0 %u32_1 %u32_2\n";
3369 ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3370 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3371 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3372 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3373 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3374 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3375 ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3376 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3377 ss << "%val9 = OpExtInst %u64 %extinst " << ext_inst_name
3378 << " %u64_1 %u64_0 %u64_1\n";
3379 CompileSuccessfully(GenerateKernelCode(ss.str()));
3380 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3381 }
3382
3383 TEST_P(ValidateOpenCLStdUClampLike, FloatResultType) {
3384 const std::string ext_inst_name = GetParam();
3385 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3386 " %u32_0 %u32_0 %u32_1\n";
3387
3388 CompileSuccessfully(GenerateKernelCode(body));
3389 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3390 EXPECT_THAT(getDiagnosticString(),
3391 HasSubstr("OpenCL.std " + ext_inst_name +
3392 ": expected Result Type to be an int scalar "
3393 "or vector type"));
3394 }
3395
3396 TEST_P(ValidateOpenCLStdUClampLike, FloatOperand1) {
3397 const std::string ext_inst_name = GetParam();
3398 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3399 " %f32_0 %u32_0 %u32_1\n";
3400
3401 CompileSuccessfully(GenerateKernelCode(body));
3402 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3403 EXPECT_THAT(
3404 getDiagnosticString(),
3405 HasSubstr("OpenCL.std " + ext_inst_name +
3406 ": expected types of all operands to be equal to Result Type"));
3407 }
3408
3409 TEST_P(ValidateOpenCLStdUClampLike, FloatOperand2) {
3410 const std::string ext_inst_name = GetParam();
3411 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3412 " %u32_0 %f32_0 %u32_1\n";
3413
3414 CompileSuccessfully(GenerateKernelCode(body));
3415 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3416 EXPECT_THAT(
3417 getDiagnosticString(),
3418 HasSubstr("OpenCL.std " + ext_inst_name +
3419 ": expected types of all operands to be equal to Result Type"));
3420 }
3421
3422 TEST_P(ValidateOpenCLStdUClampLike, FloatOperand3) {
3423 const std::string ext_inst_name = GetParam();
3424 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3425 " %u32_0 %u32_0 %f32_1\n";
3426
3427 CompileSuccessfully(GenerateKernelCode(body));
3428 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3429 EXPECT_THAT(
3430 getDiagnosticString(),
3431 HasSubstr("OpenCL.std " + ext_inst_name +
3432 ": expected types of all operands to be equal to Result Type"));
3433 }
3434
3435 TEST_P(ValidateOpenCLStdUClampLike, U64Operand1) {
3436 const std::string ext_inst_name = GetParam();
3437 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3438 " %f32_0 %u32_0 %u64_1\n";
3439
3440 CompileSuccessfully(GenerateKernelCode(body));
3441 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3442 EXPECT_THAT(
3443 getDiagnosticString(),
3444 HasSubstr("OpenCL.std " + ext_inst_name +
3445 ": expected types of all operands to be equal to Result Type"));
3446 }
3447
3448 TEST_P(ValidateOpenCLStdUClampLike, U64Operand2) {
3449 const std::string ext_inst_name = GetParam();
3450 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3451 " %u32_0 %f32_0 %u64_1\n";
3452
3453 CompileSuccessfully(GenerateKernelCode(body));
3454 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3455 EXPECT_THAT(
3456 getDiagnosticString(),
3457 HasSubstr("OpenCL.std " + ext_inst_name +
3458 ": expected types of all operands to be equal to Result Type"));
3459 }
3460
3461 TEST_P(ValidateOpenCLStdUClampLike, U64Operand3) {
3462 const std::string ext_inst_name = GetParam();
3463 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3464 " %u32_0 %u32_0 %u64_1\n";
3465
3466 CompileSuccessfully(GenerateKernelCode(body));
3467 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3468 EXPECT_THAT(
3469 getDiagnosticString(),
3470 HasSubstr("OpenCL.std " + ext_inst_name +
3471 ": expected types of all operands to be equal to Result Type"));
3472 }
3473
3474 INSTANTIATE_TEST_SUITE_P(AllUClampLike, ValidateOpenCLStdUClampLike,
3475 ::testing::ValuesIn(std::vector<std::string>{
3476 "s_clamp",
3477 "u_clamp",
3478 "s_mad_hi",
3479 "u_mad_sat",
3480 "s_mad_sat",
3481 "u_mad_hi",
3482 }));
3483
3484 // -------------------------------------------------------------
3485 TEST_P(ValidateOpenCLStdUMul24Like, Success) {
3486 const std::string ext_inst_name = GetParam();
3487 std::ostringstream ss;
3488 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
3489 << " %u32_1 %u32_2\n";
3490 ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
3491 << " %u32_1 %u32_2\n";
3492 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
3493 << " %u32_1 %u32_2\n";
3494 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
3495 << " %u32_1 %u32_2\n";
3496 ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3497 << " %u32vec2_01 %u32vec2_01\n";
3498 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3499 << " %u32vec2_01 %u32vec2_01\n";
3500 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3501 << " %u32vec2_01 %u32vec2_01\n";
3502 ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3503 << " %u32vec2_01 %u32vec2_01\n";
3504 CompileSuccessfully(GenerateKernelCode(ss.str()));
3505 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3506 }
3507
3508 TEST_P(ValidateOpenCLStdUMul24Like, FloatResultType) {
3509 const std::string ext_inst_name = GetParam();
3510 const std::string body =
3511 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
3512
3513 CompileSuccessfully(GenerateKernelCode(body));
3514 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3515 EXPECT_THAT(
3516 getDiagnosticString(),
3517 HasSubstr(
3518 "OpenCL.std " + ext_inst_name +
3519 ": expected Result Type to be a 32-bit int scalar or vector type"));
3520 }
3521
3522 TEST_P(ValidateOpenCLStdUMul24Like, U64ResultType) {
3523 const std::string ext_inst_name = GetParam();
3524 const std::string body =
3525 "%val1 = OpExtInst %u64 %extinst " + ext_inst_name + " %u64_0 %u64_0\n";
3526
3527 CompileSuccessfully(GenerateKernelCode(body));
3528 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3529 EXPECT_THAT(
3530 getDiagnosticString(),
3531 HasSubstr(
3532 "OpenCL.std " + ext_inst_name +
3533 ": expected Result Type to be a 32-bit int scalar or vector type"));
3534 }
3535
3536 TEST_P(ValidateOpenCLStdUMul24Like, FloatOperand1) {
3537 const std::string ext_inst_name = GetParam();
3538 const std::string body =
3539 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
3540
3541 CompileSuccessfully(GenerateKernelCode(body));
3542 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3543 EXPECT_THAT(
3544 getDiagnosticString(),
3545 HasSubstr("OpenCL.std " + ext_inst_name +
3546 ": expected types of all operands to be equal to Result Type"));
3547 }
3548
3549 TEST_P(ValidateOpenCLStdUMul24Like, FloatOperand2) {
3550 const std::string ext_inst_name = GetParam();
3551 const std::string body =
3552 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
3553
3554 CompileSuccessfully(GenerateKernelCode(body));
3555 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3556 EXPECT_THAT(
3557 getDiagnosticString(),
3558 HasSubstr("OpenCL.std " + ext_inst_name +
3559 ": expected types of all operands to be equal to Result Type"));
3560 }
3561
3562 TEST_P(ValidateOpenCLStdUMul24Like, U64Operand1) {
3563 const std::string ext_inst_name = GetParam();
3564 const std::string body =
3565 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0 %u32_0\n";
3566
3567 CompileSuccessfully(GenerateKernelCode(body));
3568 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3569 EXPECT_THAT(
3570 getDiagnosticString(),
3571 HasSubstr("OpenCL.std " + ext_inst_name +
3572 ": expected types of all operands to be equal to Result Type"));
3573 }
3574
3575 TEST_P(ValidateOpenCLStdUMul24Like, U64Operand2) {
3576 const std::string ext_inst_name = GetParam();
3577 const std::string body =
3578 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %u64_0\n";
3579
3580 CompileSuccessfully(GenerateKernelCode(body));
3581 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3582 EXPECT_THAT(
3583 getDiagnosticString(),
3584 HasSubstr("OpenCL.std " + ext_inst_name +
3585 ": expected types of all operands to be equal to Result Type"));
3586 }
3587
3588 INSTANTIATE_TEST_SUITE_P(AllUMul24Like, ValidateOpenCLStdUMul24Like,
3589 ::testing::ValuesIn(std::vector<std::string>{
3590 "s_mul24",
3591 "u_mul24",
3592 }));
3593
3594 TEST_P(ValidateOpenCLStdUMad24Like, Success) {
3595 const std::string ext_inst_name = GetParam();
3596 std::ostringstream ss;
3597 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
3598 << " %u32_0 %u32_1 %u32_2\n";
3599 ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
3600 << " %u32_0 %u32_1 %u32_2\n";
3601 ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
3602 << " %u32_0 %u32_1 %u32_2\n";
3603 ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
3604 << " %u32_0 %u32_1 %u32_2\n";
3605 ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3606 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3607 ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3608 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3609 ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3610 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3611 ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
3612 << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
3613 CompileSuccessfully(GenerateKernelCode(ss.str()));
3614 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3615 }
3616
3617 TEST_P(ValidateOpenCLStdUMad24Like, FloatResultType) {
3618 const std::string ext_inst_name = GetParam();
3619 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3620 " %u32_0 %u32_0 %u32_1\n";
3621
3622 CompileSuccessfully(GenerateKernelCode(body));
3623 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3624 EXPECT_THAT(
3625 getDiagnosticString(),
3626 HasSubstr(
3627 "OpenCL.std " + ext_inst_name +
3628 ": expected Result Type to be a 32-bit int scalar or vector type"));
3629 }
3630
3631 TEST_P(ValidateOpenCLStdUMad24Like, U64ResultType) {
3632 const std::string ext_inst_name = GetParam();
3633 const std::string body = "%val1 = OpExtInst %u64 %extinst " + ext_inst_name +
3634 " %u64_0 %u64_0 %u64_1\n";
3635
3636 CompileSuccessfully(GenerateKernelCode(body));
3637 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3638 EXPECT_THAT(
3639 getDiagnosticString(),
3640 HasSubstr(
3641 "OpenCL.std " + ext_inst_name +
3642 ": expected Result Type to be a 32-bit int scalar or vector type"));
3643 }
3644
3645 TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand1) {
3646 const std::string ext_inst_name = GetParam();
3647 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3648 " %f32_0 %u32_0 %u32_1\n";
3649
3650 CompileSuccessfully(GenerateKernelCode(body));
3651 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3652 EXPECT_THAT(
3653 getDiagnosticString(),
3654 HasSubstr("OpenCL.std " + ext_inst_name +
3655 ": expected types of all operands to be equal to Result Type"));
3656 }
3657
3658 TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand2) {
3659 const std::string ext_inst_name = GetParam();
3660 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3661 " %u32_0 %f32_0 %u32_1\n";
3662
3663 CompileSuccessfully(GenerateKernelCode(body));
3664 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3665 EXPECT_THAT(
3666 getDiagnosticString(),
3667 HasSubstr("OpenCL.std " + ext_inst_name +
3668 ": expected types of all operands to be equal to Result Type"));
3669 }
3670
3671 TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand3) {
3672 const std::string ext_inst_name = GetParam();
3673 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3674 " %u32_0 %u32_0 %f32_1\n";
3675
3676 CompileSuccessfully(GenerateKernelCode(body));
3677 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3678 EXPECT_THAT(
3679 getDiagnosticString(),
3680 HasSubstr("OpenCL.std " + ext_inst_name +
3681 ": expected types of all operands to be equal to Result Type"));
3682 }
3683
3684 TEST_P(ValidateOpenCLStdUMad24Like, U64Operand1) {
3685 const std::string ext_inst_name = GetParam();
3686 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3687 " %f32_0 %u32_0 %u64_1\n";
3688
3689 CompileSuccessfully(GenerateKernelCode(body));
3690 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3691 EXPECT_THAT(
3692 getDiagnosticString(),
3693 HasSubstr("OpenCL.std " + ext_inst_name +
3694 ": expected types of all operands to be equal to Result Type"));
3695 }
3696
3697 TEST_P(ValidateOpenCLStdUMad24Like, U64Operand2) {
3698 const std::string ext_inst_name = GetParam();
3699 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3700 " %u32_0 %f32_0 %u64_1\n";
3701
3702 CompileSuccessfully(GenerateKernelCode(body));
3703 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3704 EXPECT_THAT(
3705 getDiagnosticString(),
3706 HasSubstr("OpenCL.std " + ext_inst_name +
3707 ": expected types of all operands to be equal to Result Type"));
3708 }
3709
3710 TEST_P(ValidateOpenCLStdUMad24Like, U64Operand3) {
3711 const std::string ext_inst_name = GetParam();
3712 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3713 " %u32_0 %u32_0 %u64_1\n";
3714
3715 CompileSuccessfully(GenerateKernelCode(body));
3716 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3717 EXPECT_THAT(
3718 getDiagnosticString(),
3719 HasSubstr("OpenCL.std " + ext_inst_name +
3720 ": expected types of all operands to be equal to Result Type"));
3721 }
3722
3723 INSTANTIATE_TEST_SUITE_P(AllUMad24Like, ValidateOpenCLStdUMad24Like,
3724 ::testing::ValuesIn(std::vector<std::string>{
3725 "s_mad24",
3726 "u_mad24",
3727 }));
3728
3729 TEST_F(ValidateExtInst, OpenCLStdCrossSuccess) {
3730 const std::string body = R"(
3731 %val1 = OpExtInst %f32vec3 %extinst cross %f32vec3_012 %f32vec3_123
3732 %val2 = OpExtInst %f32vec4 %extinst cross %f32vec4_0123 %f32vec4_0123
3733 )";
3734
3735 CompileSuccessfully(GenerateKernelCode(body));
3736 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3737 }
3738
3739 TEST_F(ValidateExtInst, OpenCLStdCrossIntVectorResultType) {
3740 const std::string body = R"(
3741 %val1 = OpExtInst %u32vec3 %extinst cross %f32vec3_012 %f32vec3_123
3742 )";
3743
3744 CompileSuccessfully(GenerateKernelCode(body));
3745 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3746 EXPECT_THAT(getDiagnosticString(),
3747 HasSubstr("OpenCL.std cross: "
3748 "expected Result Type to be a float vector type"));
3749 }
3750
3751 TEST_F(ValidateExtInst, OpenCLStdCrossResultTypeWrongSize) {
3752 const std::string body = R"(
3753 %val1 = OpExtInst %f32vec2 %extinst cross %f32vec3_012 %f32vec3_123
3754 )";
3755
3756 CompileSuccessfully(GenerateKernelCode(body));
3757 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3758 EXPECT_THAT(getDiagnosticString(),
3759 HasSubstr("OpenCL.std cross: "
3760 "expected Result Type to have 3 or 4 components"));
3761 }
3762
3763 TEST_F(ValidateExtInst, OpenCLStdCrossXWrongType) {
3764 const std::string body = R"(
3765 %val1 = OpExtInst %f32vec3 %extinst cross %f64vec3_012 %f32vec3_123
3766 )";
3767
3768 CompileSuccessfully(GenerateKernelCode(body));
3769 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3770 EXPECT_THAT(getDiagnosticString(),
3771 HasSubstr("OpenCL.std cross: "
3772 "expected operand X type to be equal to Result Type"));
3773 }
3774
3775 TEST_F(ValidateExtInst, OpenCLStdCrossYWrongType) {
3776 const std::string body = R"(
3777 %val1 = OpExtInst %f32vec3 %extinst cross %f32vec3_123 %f64vec3_012
3778 )";
3779
3780 CompileSuccessfully(GenerateKernelCode(body));
3781 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3782 EXPECT_THAT(getDiagnosticString(),
3783 HasSubstr("OpenCL.std cross: "
3784 "expected operand Y type to be equal to Result Type"));
3785 }
3786
3787 TEST_P(ValidateOpenCLStdLengthLike, Success) {
3788 const std::string ext_inst_name = GetParam();
3789 std::ostringstream ss;
3790 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32vec2_01\n";
3791 ss << "%val2 = OpExtInst %f32 %extinst " << ext_inst_name
3792 << " %f32vec4_0123\n";
3793
3794 CompileSuccessfully(GenerateKernelCode(ss.str()));
3795 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3796 }
3797
3798 TEST_P(ValidateOpenCLStdLengthLike, IntResultType) {
3799 const std::string ext_inst_name = GetParam();
3800 const std::string body =
3801 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32vec2_01\n";
3802
3803 CompileSuccessfully(GenerateKernelCode(body));
3804 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3805 EXPECT_THAT(getDiagnosticString(),
3806 HasSubstr("OpenCL.std " + ext_inst_name +
3807 ": "
3808 "expected Result Type to be a float scalar type"));
3809 }
3810
3811 TEST_P(ValidateOpenCLStdLengthLike, IntX) {
3812 const std::string ext_inst_name = GetParam();
3813 const std::string body =
3814 "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32vec2_01\n";
3815
3816 CompileSuccessfully(GenerateKernelCode(body));
3817 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3818 EXPECT_THAT(getDiagnosticString(),
3819 HasSubstr("OpenCL.std " + ext_inst_name +
3820 ": "
3821 "expected operand P to be a float scalar or vector"));
3822 }
3823
3824 TEST_P(ValidateOpenCLStdLengthLike, VectorTooBig) {
3825 const std::string ext_inst_name = GetParam();
3826 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3827 " %f32vec8_01010101\n";
3828
3829 CompileSuccessfully(GenerateKernelCode(body));
3830 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3831 EXPECT_THAT(
3832 getDiagnosticString(),
3833 HasSubstr("OpenCL.std " + ext_inst_name +
3834 ": "
3835 "expected operand P to have no more than 4 components"));
3836 }
3837
3838 TEST_P(ValidateOpenCLStdLengthLike, DifferentType) {
3839 const std::string ext_inst_name = GetParam();
3840 const std::string body =
3841 "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32vec2_01\n";
3842
3843 CompileSuccessfully(GenerateKernelCode(body));
3844 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3845 EXPECT_THAT(getDiagnosticString(),
3846 HasSubstr("OpenCL.std " + ext_inst_name +
3847 ": "
3848 "expected operand P component type to be equal to "
3849 "Result Type"));
3850 }
3851
3852 INSTANTIATE_TEST_SUITE_P(AllLengthLike, ValidateOpenCLStdLengthLike,
3853 ::testing::ValuesIn(std::vector<std::string>{
3854 "length",
3855 "fast_length",
3856 }));
3857
3858 TEST_P(ValidateOpenCLStdDistanceLike, Success) {
3859 const std::string ext_inst_name = GetParam();
3860 std::ostringstream ss;
3861 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
3862 << " %f32vec2_01 %f32vec2_01\n";
3863 ss << "%val2 = OpExtInst %f32 %extinst " << ext_inst_name
3864 << " %f32vec4_0123 %f32vec4_1234\n";
3865 ss << "%val3 = OpExtInst %f32 %extinst " << ext_inst_name
3866 << " %f32_0 %f32_1\n";
3867
3868 CompileSuccessfully(GenerateKernelCode(ss.str()));
3869 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3870 }
3871
3872 TEST_P(ValidateOpenCLStdDistanceLike, IntResultType) {
3873 const std::string ext_inst_name = GetParam();
3874 const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
3875 " %f32vec2_01 %f32vec2_12\n";
3876
3877 CompileSuccessfully(GenerateKernelCode(body));
3878 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3879 EXPECT_THAT(getDiagnosticString(),
3880 HasSubstr("OpenCL.std " + ext_inst_name +
3881 ": "
3882 "expected Result Type to be a float scalar type"));
3883 }
3884
3885 TEST_P(ValidateOpenCLStdDistanceLike, IntP0) {
3886 const std::string ext_inst_name = GetParam();
3887 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3888 " %u32vec2_01 %f32vec2_12\n";
3889
3890 CompileSuccessfully(GenerateKernelCode(body));
3891 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3892 EXPECT_THAT(
3893 getDiagnosticString(),
3894 HasSubstr("OpenCL.std " + ext_inst_name +
3895 ": "
3896 "expected operand P0 to be of float scalar or vector type"));
3897 }
3898
3899 TEST_P(ValidateOpenCLStdDistanceLike, VectorTooBig) {
3900 const std::string ext_inst_name = GetParam();
3901 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3902 " %f32vec8_01010101 %f32vec8_01010101\n";
3903
3904 CompileSuccessfully(GenerateKernelCode(body));
3905 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3906 EXPECT_THAT(
3907 getDiagnosticString(),
3908 HasSubstr("OpenCL.std " + ext_inst_name +
3909 ": "
3910 "expected operand P0 to have no more than 4 components"));
3911 }
3912
3913 TEST_P(ValidateOpenCLStdDistanceLike, F64P0) {
3914 const std::string ext_inst_name = GetParam();
3915 const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
3916 " %f64vec2_01 %f32vec2_12\n";
3917
3918 CompileSuccessfully(GenerateKernelCode(body));
3919 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3920 EXPECT_THAT(
3921 getDiagnosticString(),
3922 HasSubstr(
3923 "OpenCL.std " + ext_inst_name +
3924 ": "
3925 "expected operand P0 component type to be equal to Result Type"));
3926 }
3927
3928 TEST_P(ValidateOpenCLStdDistanceLike, DifferentOperands) {
3929 const std::string ext_inst_name = GetParam();
3930 const std::string body = "%val1 = OpExtInst %f64 %extinst " + ext_inst_name +
3931 " %f64vec2_01 %f32vec2_12\n";
3932
3933 CompileSuccessfully(GenerateKernelCode(body));
3934 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3935 EXPECT_THAT(getDiagnosticString(),
3936 HasSubstr("OpenCL.std " + ext_inst_name +
3937 ": "
3938 "expected operands P0 and P1 to be of the same type"));
3939 }
3940
3941 INSTANTIATE_TEST_SUITE_P(AllDistanceLike, ValidateOpenCLStdDistanceLike,
3942 ::testing::ValuesIn(std::vector<std::string>{
3943 "distance",
3944 "fast_distance",
3945 }));
3946
3947 TEST_P(ValidateOpenCLStdNormalizeLike, Success) {
3948 const std::string ext_inst_name = GetParam();
3949 std::ostringstream ss;
3950 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
3951 << " %f32vec2_01\n";
3952 ss << "%val2 = OpExtInst %f32vec4 %extinst " << ext_inst_name
3953 << " %f32vec4_0123\n";
3954 ss << "%val3 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_2\n";
3955
3956 CompileSuccessfully(GenerateKernelCode(ss.str()));
3957 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
3958 }
3959
3960 TEST_P(ValidateOpenCLStdNormalizeLike, IntResultType) {
3961 const std::string ext_inst_name = GetParam();
3962 const std::string body =
3963 "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_2\n";
3964
3965 CompileSuccessfully(GenerateKernelCode(body));
3966 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3967 EXPECT_THAT(
3968 getDiagnosticString(),
3969 HasSubstr("OpenCL.std " + ext_inst_name +
3970 ": "
3971 "expected Result Type to be a float scalar or vector type"));
3972 }
3973
3974 TEST_P(ValidateOpenCLStdNormalizeLike, VectorTooBig) {
3975 const std::string ext_inst_name = GetParam();
3976 const std::string body = "%val1 = OpExtInst %f32vec8 %extinst " +
3977 ext_inst_name + " %f32vec8_01010101\n";
3978
3979 CompileSuccessfully(GenerateKernelCode(body));
3980 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3981 EXPECT_THAT(
3982 getDiagnosticString(),
3983 HasSubstr("OpenCL.std " + ext_inst_name +
3984 ": "
3985 "expected Result Type to have no more than 4 components"));
3986 }
3987
3988 TEST_P(ValidateOpenCLStdNormalizeLike, DifferentType) {
3989 const std::string ext_inst_name = GetParam();
3990 const std::string body =
3991 "%val1 = OpExtInst %f64vec2 %extinst " + ext_inst_name + " %f32vec2_01\n";
3992
3993 CompileSuccessfully(GenerateKernelCode(body));
3994 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
3995 EXPECT_THAT(getDiagnosticString(),
3996 HasSubstr("OpenCL.std " + ext_inst_name +
3997 ": "
3998 "expected operand P type to be equal to Result Type"));
3999 }
4000
4001 INSTANTIATE_TEST_SUITE_P(AllNormalizeLike, ValidateOpenCLStdNormalizeLike,
4002 ::testing::ValuesIn(std::vector<std::string>{
4003 "normalize",
4004 "fast_normalize",
4005 }));
4006
4007 TEST_F(ValidateExtInst, OpenCLStdBitselectSuccess) {
4008 const std::string body = R"(
4009 %val1 = OpExtInst %f32 %extinst bitselect %f32_2 %f32_1 %f32_1
4010 %val2 = OpExtInst %f32vec4 %extinst bitselect %f32vec4_0123 %f32vec4_1234 %f32vec4_0123
4011 %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %u32_1 %u32_1
4012 %val4 = OpExtInst %u32vec4 %extinst bitselect %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
4013 %val5 = OpExtInst %u64 %extinst bitselect %u64_2 %u64_1 %u64_1
4014 )";
4015
4016 CompileSuccessfully(GenerateKernelCode(body));
4017 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4018 }
4019
4020 TEST_F(ValidateExtInst, OpenCLStdBitselectWrongResultType) {
4021 const std::string body = R"(
4022 %val3 = OpExtInst %struct_f32_f32 %extinst bitselect %u32_2 %u32_1 %u32_1
4023 )";
4024
4025 CompileSuccessfully(GenerateKernelCode(body));
4026 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4027 EXPECT_THAT(
4028 getDiagnosticString(),
4029 HasSubstr(
4030 "OpenCL.std bitselect: "
4031 "expected Result Type to be an int or float scalar or vector type"));
4032 }
4033
4034 TEST_F(ValidateExtInst, OpenCLStdBitselectAWrongType) {
4035 const std::string body = R"(
4036 %val3 = OpExtInst %u32 %extinst bitselect %f32_2 %u32_1 %u32_1
4037 )";
4038
4039 CompileSuccessfully(GenerateKernelCode(body));
4040 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4041 EXPECT_THAT(
4042 getDiagnosticString(),
4043 HasSubstr("OpenCL.std bitselect: "
4044 "expected types of all operands to be equal to Result Type"));
4045 }
4046
4047 TEST_F(ValidateExtInst, OpenCLStdBitselectBWrongType) {
4048 const std::string body = R"(
4049 %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %f32_1 %u32_1
4050 )";
4051
4052 CompileSuccessfully(GenerateKernelCode(body));
4053 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4054 EXPECT_THAT(
4055 getDiagnosticString(),
4056 HasSubstr("OpenCL.std bitselect: "
4057 "expected types of all operands to be equal to Result Type"));
4058 }
4059
4060 TEST_F(ValidateExtInst, OpenCLStdBitselectCWrongType) {
4061 const std::string body = R"(
4062 %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %u32_1 %f32_1
4063 )";
4064
4065 CompileSuccessfully(GenerateKernelCode(body));
4066 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4067 EXPECT_THAT(
4068 getDiagnosticString(),
4069 HasSubstr("OpenCL.std bitselect: "
4070 "expected types of all operands to be equal to Result Type"));
4071 }
4072
4073 TEST_F(ValidateExtInst, OpenCLStdSelectSuccess) {
4074 const std::string body = R"(
4075 %val1 = OpExtInst %f32 %extinst select %f32_2 %f32_1 %u32_1
4076 %val2 = OpExtInst %f32vec4 %extinst select %f32vec4_0123 %f32vec4_1234 %u32vec4_0123
4077 %val3 = OpExtInst %u32 %extinst select %u32_2 %u32_1 %u32_1
4078 %val4 = OpExtInst %u32vec4 %extinst select %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
4079 %val5 = OpExtInst %u64 %extinst select %u64_2 %u64_1 %u64_1
4080 )";
4081
4082 CompileSuccessfully(GenerateKernelCode(body));
4083 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4084 }
4085
4086 TEST_F(ValidateExtInst, OpenCLStdSelectWrongResultType) {
4087 const std::string body = R"(
4088 %val3 = OpExtInst %struct_f32_f32 %extinst select %u32_2 %u32_1 %u32_1
4089 )";
4090
4091 CompileSuccessfully(GenerateKernelCode(body));
4092 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4093 EXPECT_THAT(
4094 getDiagnosticString(),
4095 HasSubstr(
4096 "OpenCL.std select: "
4097 "expected Result Type to be an int or float scalar or vector type"));
4098 }
4099
4100 TEST_F(ValidateExtInst, OpenCLStdSelectAWrongType) {
4101 const std::string body = R"(
4102 %val3 = OpExtInst %u32 %extinst select %f32_2 %u32_1 %u32_1
4103 )";
4104
4105 CompileSuccessfully(GenerateKernelCode(body));
4106 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4107 EXPECT_THAT(getDiagnosticString(),
4108 HasSubstr("OpenCL.std select: "
4109 "expected operand A type to be equal to Result Type"));
4110 }
4111
4112 TEST_F(ValidateExtInst, OpenCLStdSelectBWrongType) {
4113 const std::string body = R"(
4114 %val3 = OpExtInst %u32 %extinst select %u32_2 %f32_1 %u32_1
4115 )";
4116
4117 CompileSuccessfully(GenerateKernelCode(body));
4118 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4119 EXPECT_THAT(getDiagnosticString(),
4120 HasSubstr("OpenCL.std select: "
4121 "expected operand B type to be equal to Result Type"));
4122 }
4123
4124 TEST_F(ValidateExtInst, OpenCLStdSelectCWrongType) {
4125 const std::string body = R"(
4126 %val3 = OpExtInst %f32 %extinst select %f32_2 %f32_1 %f32_1
4127 )";
4128
4129 CompileSuccessfully(GenerateKernelCode(body));
4130 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4131 EXPECT_THAT(getDiagnosticString(),
4132 HasSubstr("OpenCL.std select: "
4133 "expected operand C to be an int scalar or vector"));
4134 }
4135
4136 TEST_F(ValidateExtInst, OpenCLStdSelectCWrongComponentNumber) {
4137 const std::string body = R"(
4138 %val3 = OpExtInst %f32vec2 %extinst select %f32vec2_12 %f32vec2_01 %u32_1
4139 )";
4140
4141 CompileSuccessfully(GenerateKernelCode(body));
4142 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4143 EXPECT_THAT(getDiagnosticString(),
4144 HasSubstr("OpenCL.std select: "
4145 "expected operand C to have the same number of "
4146 "components as Result Type"));
4147 }
4148
4149 TEST_F(ValidateExtInst, OpenCLStdSelectCWrongBitWidth) {
4150 const std::string body = R"(
4151 %val3 = OpExtInst %f32vec2 %extinst select %f32vec2_12 %f32vec2_01 %u64vec2_01
4152 )";
4153
4154 CompileSuccessfully(GenerateKernelCode(body));
4155 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4156 EXPECT_THAT(
4157 getDiagnosticString(),
4158 HasSubstr(
4159 "OpenCL.std select: "
4160 "expected operand C to have the same bit width as Result Type"));
4161 }
4162
4163 TEST_P(ValidateOpenCLStdVStoreHalfLike, SuccessPhysical32) {
4164 const std::string ext_inst_name = GetParam();
4165 const std::string rounding_mode =
4166 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4167
4168 std::ostringstream ss;
4169 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4170 if (std::string::npos == ext_inst_name.find("halfn")) {
4171 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4172 << " %f32_1 %u32_1 %ptr" << rounding_mode << "\n";
4173 ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
4174 << " %f64_0 %u32_2 %ptr" << rounding_mode << "\n";
4175 } else {
4176 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4177 << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4178 ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
4179 << " %f32vec4_0123 %u32_0 %ptr" << rounding_mode << "\n";
4180 ss << "%val3 = OpExtInst %void %extinst " << ext_inst_name
4181 << " %f64vec2_01 %u32_2 %ptr" << rounding_mode << "\n";
4182 }
4183
4184 CompileSuccessfully(GenerateKernelCode(ss.str()));
4185 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4186 }
4187
4188 TEST_P(ValidateOpenCLStdVStoreHalfLike, SuccessPhysical64) {
4189 const std::string ext_inst_name = GetParam();
4190 const std::string rounding_mode =
4191 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4192
4193 std::ostringstream ss;
4194 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4195 if (std::string::npos == ext_inst_name.find("halfn")) {
4196 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4197 << " %f32_1 %u64_1 %ptr" << rounding_mode << "\n";
4198 ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
4199 << " %f64_0 %u64_2 %ptr" << rounding_mode << "\n";
4200 } else {
4201 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4202 << " %f32vec2_01 %u64_1 %ptr" << rounding_mode << "\n";
4203 ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
4204 << " %f32vec4_0123 %u64_0 %ptr" << rounding_mode << "\n";
4205 ss << "%val3 = OpExtInst %void %extinst " << ext_inst_name
4206 << " %f64vec2_01 %u64_2 %ptr" << rounding_mode << "\n";
4207 }
4208
4209 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4210 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4211 }
4212
4213 TEST_P(ValidateOpenCLStdVStoreHalfLike, NonVoidResultType) {
4214 const std::string ext_inst_name = GetParam();
4215 const std::string rounding_mode =
4216 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4217
4218 std::ostringstream ss;
4219 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4220 if (std::string::npos == ext_inst_name.find("halfn")) {
4221 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
4222 << " %f32_1 %u32_1 %ptr" << rounding_mode << "\n";
4223 } else {
4224 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
4225 << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4226 }
4227
4228 CompileSuccessfully(GenerateKernelCode(ss.str()));
4229 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4230 EXPECT_THAT(getDiagnosticString(),
4231 HasSubstr("OpenCL.std " + ext_inst_name +
4232 ": expected Result Type to be void"));
4233 }
4234
4235 TEST_P(ValidateOpenCLStdVStoreHalfLike, WrongDataType) {
4236 const std::string ext_inst_name = GetParam();
4237 const std::string rounding_mode =
4238 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4239
4240 std::ostringstream ss;
4241 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4242 if (std::string::npos == ext_inst_name.find("halfn")) {
4243 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4244 << " %f64vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4245 CompileSuccessfully(GenerateKernelCode(ss.str()));
4246 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4247 EXPECT_THAT(getDiagnosticString(),
4248 HasSubstr("OpenCL.std " + ext_inst_name +
4249 ": expected Data to be a 32 or 64-bit float scalar"));
4250 } else {
4251 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4252 << " %f64_0 %u32_1 %ptr" << rounding_mode << "\n";
4253 CompileSuccessfully(GenerateKernelCode(ss.str()));
4254 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4255 EXPECT_THAT(getDiagnosticString(),
4256 HasSubstr("OpenCL.std " + ext_inst_name +
4257 ": expected Data to be a 32 or 64-bit float vector"));
4258 }
4259 }
4260
4261 TEST_P(ValidateOpenCLStdVStoreHalfLike, AddressingModelLogical) {
4262 const std::string ext_inst_name = GetParam();
4263 const std::string rounding_mode =
4264 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4265
4266 std::ostringstream ss;
4267 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4268 if (std::string::npos == ext_inst_name.find("halfn")) {
4269 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4270 << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
4271 } else {
4272 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4273 << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4274 }
4275
4276 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
4277 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4278 EXPECT_THAT(getDiagnosticString(),
4279 HasSubstr("OpenCL.std " + ext_inst_name +
4280 " can only be used with physical addressing models"));
4281 }
4282
4283 TEST_P(ValidateOpenCLStdVStoreHalfLike, OffsetNotSizeT) {
4284 const std::string ext_inst_name = GetParam();
4285 const std::string rounding_mode =
4286 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4287
4288 std::ostringstream ss;
4289 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4290 if (std::string::npos == ext_inst_name.find("halfn")) {
4291 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4292 << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
4293 } else {
4294 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4295 << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4296 }
4297
4298 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4299 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4300 EXPECT_THAT(
4301 getDiagnosticString(),
4302 HasSubstr("OpenCL.std " + ext_inst_name +
4303 ": "
4304 "expected operand Offset to be of type size_t (64-bit integer "
4305 "for the addressing model used in the module)"));
4306 }
4307
4308 TEST_P(ValidateOpenCLStdVStoreHalfLike, PNotPointer) {
4309 const std::string ext_inst_name = GetParam();
4310 const std::string rounding_mode =
4311 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4312
4313 std::ostringstream ss;
4314 if (std::string::npos == ext_inst_name.find("halfn")) {
4315 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4316 << " %f32_0 %u32_1 %f16_ptr_workgroup" << rounding_mode << "\n";
4317 } else {
4318 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4319 << " %f32vec2_01 %u32_1 %f16_ptr_workgroup" << rounding_mode << "\n";
4320 }
4321
4322 CompileSuccessfully(GenerateKernelCode(ss.str()));
4323 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4324 EXPECT_THAT(getDiagnosticString(),
4325 HasSubstr("Operand '89[%_ptr_Workgroup_half]' cannot be a type"));
4326 }
4327
4328 TEST_P(ValidateOpenCLStdVStoreHalfLike, ConstPointer) {
4329 const std::string ext_inst_name = GetParam();
4330 const std::string rounding_mode =
4331 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4332
4333 std::ostringstream ss;
4334 ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
4335 "%f16vec8_uniform_constant %u32_1\n";
4336 if (std::string::npos == ext_inst_name.find("halfn")) {
4337 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4338 << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
4339 } else {
4340 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4341 << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4342 }
4343
4344 CompileSuccessfully(GenerateKernelCode(ss.str()));
4345 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4346 EXPECT_THAT(getDiagnosticString(),
4347 HasSubstr("OpenCL.std " + ext_inst_name +
4348 ": expected operand P storage class to be Generic, "
4349 "CrossWorkgroup, Workgroup or Function"));
4350 }
4351
4352 TEST_P(ValidateOpenCLStdVStoreHalfLike, PDataTypeInt) {
4353 const std::string ext_inst_name = GetParam();
4354 const std::string rounding_mode =
4355 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4356
4357 std::ostringstream ss;
4358 ss << "%ptr = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
4359 if (std::string::npos == ext_inst_name.find("halfn")) {
4360 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4361 << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
4362 } else {
4363 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4364 << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4365 }
4366
4367 CompileSuccessfully(GenerateKernelCode(ss.str()));
4368 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4369 EXPECT_THAT(
4370 getDiagnosticString(),
4371 HasSubstr("OpenCL.std " + ext_inst_name +
4372 ": expected operand P data type to be 16-bit float scalar"));
4373 }
4374
4375 TEST_P(ValidateOpenCLStdVStoreHalfLike, PDataTypeFloat32) {
4376 const std::string ext_inst_name = GetParam();
4377 const std::string rounding_mode =
4378 ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
4379
4380 std::ostringstream ss;
4381 ss << "%ptr = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4382 if (std::string::npos == ext_inst_name.find("halfn")) {
4383 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4384 << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
4385 } else {
4386 ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
4387 << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
4388 }
4389
4390 CompileSuccessfully(GenerateKernelCode(ss.str()));
4391 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4392 EXPECT_THAT(
4393 getDiagnosticString(),
4394 HasSubstr("OpenCL.std " + ext_inst_name +
4395 ": expected operand P data type to be 16-bit float scalar"));
4396 }
4397
4398 INSTANTIATE_TEST_SUITE_P(AllVStoreHalfLike, ValidateOpenCLStdVStoreHalfLike,
4399 ::testing::ValuesIn(std::vector<std::string>{
4400 "vstore_half",
4401 "vstore_half_r",
4402 "vstore_halfn",
4403 "vstore_halfn_r",
4404 "vstorea_halfn",
4405 "vstorea_halfn_r",
4406 }));
4407
4408 TEST_P(ValidateOpenCLStdVLoadHalfLike, SuccessPhysical32) {
4409 const std::string ext_inst_name = GetParam();
4410
4411 std::ostringstream ss;
4412 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4413 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4414 << " %u32_1 %ptr 2\n";
4415 ss << "%val2 = OpExtInst %f32vec3 %extinst " << ext_inst_name
4416 << " %u32_1 %ptr 3\n";
4417 ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
4418 << " %u32_1 %ptr 4\n";
4419
4420 CompileSuccessfully(GenerateKernelCode(ss.str()));
4421 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4422 }
4423
4424 TEST_P(ValidateOpenCLStdVLoadHalfLike, SuccessPhysical64) {
4425 const std::string ext_inst_name = GetParam();
4426
4427 std::ostringstream ss;
4428 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4429 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4430 << " %u64_1 %ptr 2\n";
4431 ss << "%val2 = OpExtInst %f32vec3 %extinst " << ext_inst_name
4432 << " %u64_1 %ptr 3\n";
4433 ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
4434 << " %u64_1 %ptr 4\n";
4435
4436 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4437 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4438 }
4439
4440 TEST_P(ValidateOpenCLStdVLoadHalfLike, ResultTypeNotFloatVector) {
4441 const std::string ext_inst_name = GetParam();
4442
4443 std::ostringstream ss;
4444 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4445 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
4446 << " %u32_1 %ptr 1\n";
4447
4448 CompileSuccessfully(GenerateKernelCode(ss.str()));
4449 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4450 EXPECT_THAT(getDiagnosticString(),
4451 HasSubstr("OpenCL.std " + ext_inst_name +
4452 ": expected Result Type to be a float vector type"));
4453 }
4454
4455 TEST_P(ValidateOpenCLStdVLoadHalfLike, AddressingModelLogical) {
4456 const std::string ext_inst_name = GetParam();
4457
4458 std::ostringstream ss;
4459 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4460 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4461 << " %u32_1 %ptr 2\n";
4462
4463 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
4464 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4465 EXPECT_THAT(getDiagnosticString(),
4466 HasSubstr("OpenCL.std " + ext_inst_name +
4467 " can only be used with physical addressing models"));
4468 }
4469
4470 TEST_P(ValidateOpenCLStdVLoadHalfLike, OffsetNotSizeT) {
4471 const std::string ext_inst_name = GetParam();
4472
4473 std::ostringstream ss;
4474 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4475 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4476 << " %u64_1 %ptr 2\n";
4477
4478 CompileSuccessfully(GenerateKernelCode(ss.str()));
4479 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4480 EXPECT_THAT(
4481 getDiagnosticString(),
4482 HasSubstr("OpenCL.std " + ext_inst_name +
4483 ": expected operand Offset to be of type size_t (32-bit "
4484 "integer for the addressing model used in the module)"));
4485 }
4486
4487 TEST_P(ValidateOpenCLStdVLoadHalfLike, PNotPointer) {
4488 const std::string ext_inst_name = GetParam();
4489
4490 std::ostringstream ss;
4491 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4492 << " %u32_1 %f16_ptr_workgroup 2\n";
4493
4494 CompileSuccessfully(GenerateKernelCode(ss.str()));
4495 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4496 EXPECT_THAT(getDiagnosticString(),
4497 HasSubstr("Operand '89[%_ptr_Workgroup_half]' cannot be a type"));
4498 }
4499
4500 TEST_P(ValidateOpenCLStdVLoadHalfLike, OffsetWrongStorageType) {
4501 const std::string ext_inst_name = GetParam();
4502
4503 std::ostringstream ss;
4504 ss << "%ptr = OpAccessChain %f16_ptr_input %f16vec8_input %u32_1\n";
4505 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4506 << " %u32_1 %ptr 2\n";
4507
4508 CompileSuccessfully(GenerateKernelCode(ss.str()));
4509 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4510 EXPECT_THAT(
4511 getDiagnosticString(),
4512 HasSubstr("OpenCL.std " + ext_inst_name +
4513 ": expected operand P storage class to be UniformConstant, "
4514 "Generic, CrossWorkgroup, Workgroup or Function"));
4515 }
4516
4517 TEST_P(ValidateOpenCLStdVLoadHalfLike, PDataTypeInt) {
4518 const std::string ext_inst_name = GetParam();
4519
4520 std::ostringstream ss;
4521 ss << "%ptr = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
4522 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4523 << " %u32_1 %ptr 2\n";
4524
4525 CompileSuccessfully(GenerateKernelCode(ss.str()));
4526 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4527 EXPECT_THAT(
4528 getDiagnosticString(),
4529 HasSubstr("OpenCL.std " + ext_inst_name +
4530 ": expected operand P data type to be 16-bit float scalar"));
4531 }
4532
4533 TEST_P(ValidateOpenCLStdVLoadHalfLike, PDataTypeFloat32) {
4534 const std::string ext_inst_name = GetParam();
4535
4536 std::ostringstream ss;
4537 ss << "%ptr = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4538 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4539 << " %u32_1 %ptr 2\n";
4540
4541 CompileSuccessfully(GenerateKernelCode(ss.str()));
4542 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4543 EXPECT_THAT(
4544 getDiagnosticString(),
4545 HasSubstr("OpenCL.std " + ext_inst_name +
4546 ": expected operand P data type to be 16-bit float scalar"));
4547 }
4548
4549 TEST_P(ValidateOpenCLStdVLoadHalfLike, WrongN) {
4550 const std::string ext_inst_name = GetParam();
4551
4552 std::ostringstream ss;
4553 ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
4554 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
4555 << " %u32_1 %ptr 3\n";
4556
4557 CompileSuccessfully(GenerateKernelCode(ss.str()));
4558 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4559 EXPECT_THAT(getDiagnosticString(),
4560 HasSubstr("OpenCL.std " + ext_inst_name +
4561 ": expected literal N to be equal to the number of "
4562 "components of Result Type"));
4563 }
4564
4565 INSTANTIATE_TEST_SUITE_P(AllVLoadHalfLike, ValidateOpenCLStdVLoadHalfLike,
4566 ::testing::ValuesIn(std::vector<std::string>{
4567 "vload_halfn",
4568 "vloada_halfn",
4569 }));
4570
4571 TEST_F(ValidateExtInst, VLoadNSuccessFloatPhysical32) {
4572 std::ostringstream ss;
4573 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4574 "%f32vec8_uniform_constant %u32_1\n";
4575 ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 2\n";
4576 ss << "%val2 = OpExtInst %f32vec3 %extinst vloadn %u32_1 %ptr 3\n";
4577 ss << "%val3 = OpExtInst %f32vec4 %extinst vloadn %u32_1 %ptr 4\n";
4578
4579 CompileSuccessfully(GenerateKernelCode(ss.str()));
4580 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4581 }
4582
4583 TEST_F(ValidateExtInst, VLoadNSuccessIntPhysical32) {
4584 std::ostringstream ss;
4585 ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
4586 "%u32vec8_uniform_constant %u32_1\n";
4587 ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
4588 ss << "%val2 = OpExtInst %u32vec3 %extinst vloadn %u32_1 %ptr 3\n";
4589 ss << "%val3 = OpExtInst %u32vec4 %extinst vloadn %u32_1 %ptr 4\n";
4590
4591 CompileSuccessfully(GenerateKernelCode(ss.str()));
4592 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4593 }
4594
4595 TEST_F(ValidateExtInst, VLoadNSuccessFloatPhysical64) {
4596 std::ostringstream ss;
4597 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4598 "%f32vec8_uniform_constant %u32_1\n";
4599 ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u64_1 %ptr 2\n";
4600 ss << "%val2 = OpExtInst %f32vec3 %extinst vloadn %u64_1 %ptr 3\n";
4601 ss << "%val3 = OpExtInst %f32vec4 %extinst vloadn %u64_1 %ptr 4\n";
4602
4603 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4604 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4605 }
4606
4607 TEST_F(ValidateExtInst, VLoadNSuccessIntPhysical64) {
4608 std::ostringstream ss;
4609 ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
4610 "%u32vec8_uniform_constant %u32_1\n";
4611 ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u64_1 %ptr 2\n";
4612 ss << "%val2 = OpExtInst %u32vec3 %extinst vloadn %u64_1 %ptr 3\n";
4613 ss << "%val3 = OpExtInst %u32vec4 %extinst vloadn %u64_1 %ptr 4\n";
4614
4615 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4616 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4617 }
4618
4619 TEST_F(ValidateExtInst, VLoadNWrongResultType) {
4620 std::ostringstream ss;
4621 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4622 "%f32vec8_uniform_constant %u32_1\n";
4623 ss << "%val1 = OpExtInst %f32 %extinst vloadn %u32_1 %ptr 2\n";
4624
4625 CompileSuccessfully(GenerateKernelCode(ss.str()));
4626 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4627 EXPECT_THAT(
4628 getDiagnosticString(),
4629 HasSubstr("OpenCL.std vloadn: "
4630 "expected Result Type to be an int or float vector type"));
4631 }
4632
4633 TEST_F(ValidateExtInst, VLoadNAddressingModelLogical) {
4634 std::ostringstream ss;
4635 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4636 "%f32vec8_uniform_constant %u32_1\n";
4637 ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 2\n";
4638
4639 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
4640 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4641 EXPECT_THAT(getDiagnosticString(),
4642 HasSubstr("OpenCL.std vloadn can only be used with physical "
4643 "addressing models"));
4644 }
4645
4646 TEST_F(ValidateExtInst, VLoadNOffsetNotSizeT) {
4647 std::ostringstream ss;
4648 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4649 "%f32vec8_uniform_constant %u32_1\n";
4650 ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u64_1 %ptr 2\n";
4651
4652 CompileSuccessfully(GenerateKernelCode(ss.str()));
4653 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4654 EXPECT_THAT(
4655 getDiagnosticString(),
4656 HasSubstr(
4657 "OpenCL.std vloadn: expected operand Offset to be of type size_t "
4658 "(32-bit integer for the addressing model used in the module)"));
4659 }
4660
4661 TEST_F(ValidateExtInst, VLoadNPNotPointer) {
4662 std::ostringstream ss;
4663 ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 "
4664 "%f32_ptr_uniform_constant 2\n";
4665
4666 CompileSuccessfully(GenerateKernelCode(ss.str()));
4667 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4668 EXPECT_THAT(
4669 getDiagnosticString(),
4670 HasSubstr("Operand '120[%_ptr_UniformConstant_float]' cannot be a "
4671 "type"));
4672 }
4673
4674 TEST_F(ValidateExtInst, VLoadNWrongStorageClass) {
4675 std::ostringstream ss;
4676 ss << "%ptr = OpAccessChain %u32_ptr_input %u32vec8_input %u32_1\n";
4677 ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
4678
4679 CompileSuccessfully(GenerateKernelCode(ss.str()));
4680 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4681 EXPECT_THAT(getDiagnosticString(),
4682 HasSubstr("OpenCL.std vloadn: expected operand P storage class "
4683 "to be UniformConstant, Generic, CrossWorkgroup, "
4684 "Workgroup or Function"));
4685 }
4686
4687 TEST_F(ValidateExtInst, VLoadNWrongComponentType) {
4688 std::ostringstream ss;
4689 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4690 "%f32vec8_uniform_constant %u32_1\n";
4691 ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
4692
4693 CompileSuccessfully(GenerateKernelCode(ss.str()));
4694 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4695 EXPECT_THAT(getDiagnosticString(),
4696 HasSubstr("OpenCL.std vloadn: expected operand P data type to be "
4697 "equal to component type of Result Type"));
4698 }
4699
4700 TEST_F(ValidateExtInst, VLoadNWrongN) {
4701 std::ostringstream ss;
4702 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4703 "%f32vec8_uniform_constant %u32_1\n";
4704 ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 3\n";
4705
4706 CompileSuccessfully(GenerateKernelCode(ss.str()));
4707 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4708 EXPECT_THAT(getDiagnosticString(),
4709 HasSubstr("OpenCL.std vloadn: expected literal N to be equal to "
4710 "the number of components of Result Type"));
4711 }
4712
4713 TEST_F(ValidateExtInst, VLoadHalfSuccessPhysical32) {
4714 std::ostringstream ss;
4715 ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
4716 "%f16vec8_uniform_constant %u32_1\n";
4717 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
4718 ss << "%val2 = OpExtInst %f64 %extinst vload_half %u32_1 %ptr\n";
4719
4720 CompileSuccessfully(GenerateKernelCode(ss.str()));
4721 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4722 }
4723
4724 TEST_F(ValidateExtInst, VLoadHalfSuccessPhysical64) {
4725 std::ostringstream ss;
4726 ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
4727 "%f16vec8_uniform_constant %u32_1\n";
4728 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u64_1 %ptr\n";
4729 ss << "%val2 = OpExtInst %f64 %extinst vload_half %u64_1 %ptr\n";
4730
4731 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4732 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4733 }
4734
4735 TEST_F(ValidateExtInst, VLoadHalfWrongResultType) {
4736 std::ostringstream ss;
4737 ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
4738 "%f16vec8_uniform_constant %u32_1\n";
4739 ss << "%val1 = OpExtInst %u32 %extinst vload_half %u32_1 %ptr\n";
4740
4741 CompileSuccessfully(GenerateKernelCode(ss.str()));
4742 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4743 EXPECT_THAT(getDiagnosticString(),
4744 HasSubstr("OpenCL.std vload_half: "
4745 "expected Result Type to be a float scalar type"));
4746 }
4747
4748 TEST_F(ValidateExtInst, VLoadHalfAddressingModelLogical) {
4749 std::ostringstream ss;
4750 ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
4751 "%f16vec8_uniform_constant %u32_1\n";
4752 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
4753
4754 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
4755 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4756 EXPECT_THAT(getDiagnosticString(),
4757 HasSubstr("OpenCL.std vload_half can only be used with physical "
4758 "addressing models"));
4759 }
4760
4761 TEST_F(ValidateExtInst, VLoadHalfOffsetNotSizeT) {
4762 std::ostringstream ss;
4763 ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
4764 "%f16vec8_uniform_constant %u32_1\n";
4765 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u64_1 %ptr\n";
4766
4767 CompileSuccessfully(GenerateKernelCode(ss.str()));
4768 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4769 EXPECT_THAT(
4770 getDiagnosticString(),
4771 HasSubstr(
4772 "OpenCL.std vload_half: expected operand Offset to be of type size_t "
4773 "(32-bit integer for the addressing model used in the module)"));
4774 }
4775
4776 TEST_F(ValidateExtInst, VLoadHalfPNotPointer) {
4777 std::ostringstream ss;
4778 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 "
4779 "%f16_ptr_uniform_constant\n";
4780
4781 CompileSuccessfully(GenerateKernelCode(ss.str()));
4782 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4783 EXPECT_THAT(getDiagnosticString(),
4784 HasSubstr("Operand '114[%_ptr_UniformConstant_half]' cannot be a "
4785 "type"));
4786 }
4787
4788 TEST_F(ValidateExtInst, VLoadHalfWrongStorageClass) {
4789 std::ostringstream ss;
4790 ss << "%ptr = OpAccessChain %f16_ptr_input %f16vec8_input %u32_1\n";
4791 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
4792
4793 CompileSuccessfully(GenerateKernelCode(ss.str()));
4794 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4795 EXPECT_THAT(
4796 getDiagnosticString(),
4797 HasSubstr(
4798 "OpenCL.std vload_half: expected operand P storage class to be "
4799 "UniformConstant, Generic, CrossWorkgroup, Workgroup or Function"));
4800 }
4801
4802 TEST_F(ValidateExtInst, VLoadHalfPDataTypeInt) {
4803 std::ostringstream ss;
4804 ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
4805 "%u32vec8_uniform_constant %u32_1\n";
4806 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
4807
4808 CompileSuccessfully(GenerateKernelCode(ss.str()));
4809 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4810 EXPECT_THAT(getDiagnosticString(),
4811 HasSubstr("OpenCL.std vload_half: expected operand P data type "
4812 "to be 16-bit float scalar"));
4813 }
4814
4815 TEST_F(ValidateExtInst, VLoadHalfPDataTypeFloat32) {
4816 std::ostringstream ss;
4817 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
4818 "%f32vec8_uniform_constant %u32_1\n";
4819 ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
4820
4821 CompileSuccessfully(GenerateKernelCode(ss.str()));
4822 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4823 EXPECT_THAT(getDiagnosticString(),
4824 HasSubstr("OpenCL.std vload_half: expected operand P data type "
4825 "to be 16-bit float scalar"));
4826 }
4827
4828 TEST_F(ValidateExtInst, VStoreNSuccessFloatPhysical32) {
4829 std::ostringstream ss;
4830 ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4831 ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
4832 ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
4833 ss << "%val2 = OpExtInst %void %extinst vstoren %f32vec4_0123 %u32_1 "
4834 "%ptr_g\n";
4835
4836 CompileSuccessfully(GenerateKernelCode(ss.str()));
4837 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4838 }
4839
4840 TEST_F(ValidateExtInst, VStoreNSuccessFloatPhysical64) {
4841 std::ostringstream ss;
4842 ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4843 ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
4844 ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u64_1 %ptr_g\n";
4845 ss << "%val2 = OpExtInst %void %extinst vstoren %f32vec4_0123 %u64_1 "
4846 "%ptr_g\n";
4847
4848 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4849 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4850 }
4851
4852 TEST_F(ValidateExtInst, VStoreNSuccessIntPhysical32) {
4853 std::ostringstream ss;
4854 ss << "%ptr_w = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
4855 ss << "%ptr_g = OpPtrCastToGeneric %u32_ptr_generic %ptr_w\n";
4856 ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u32_1 %ptr_g\n";
4857 ss << "%val2 = OpExtInst %void %extinst vstoren %u32vec4_0123 %u32_1 "
4858 "%ptr_g\n";
4859
4860 CompileSuccessfully(GenerateKernelCode(ss.str()));
4861 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4862 }
4863
4864 TEST_F(ValidateExtInst, VStoreNSuccessIntPhysical64) {
4865 std::ostringstream ss;
4866 ss << "%ptr_w = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
4867 ss << "%ptr_g = OpPtrCastToGeneric %u32_ptr_generic %ptr_w\n";
4868 ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u64_1 %ptr_g\n";
4869 ss << "%val2 = OpExtInst %void %extinst vstoren %u32vec4_0123 %u64_1 "
4870 "%ptr_g\n";
4871
4872 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4873 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4874 }
4875
4876 TEST_F(ValidateExtInst, VStoreNResultTypeNotVoid) {
4877 std::ostringstream ss;
4878 ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4879 ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
4880 ss << "%val1 = OpExtInst %f32 %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
4881
4882 CompileSuccessfully(GenerateKernelCode(ss.str()));
4883 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4884 EXPECT_THAT(getDiagnosticString(),
4885 HasSubstr("OpenCL.std vstoren: expected Result Type to be void"));
4886 }
4887
4888 TEST_F(ValidateExtInst, VStoreNDataWrongType) {
4889 std::ostringstream ss;
4890 ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4891 ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
4892 ss << "%val1 = OpExtInst %void %extinst vstoren %f32_1 %u32_1 %ptr_g\n";
4893
4894 CompileSuccessfully(GenerateKernelCode(ss.str()));
4895 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4896 EXPECT_THAT(
4897 getDiagnosticString(),
4898 HasSubstr(
4899 "OpenCL.std vstoren: expected Data to be an int or float vector"));
4900 }
4901
4902 TEST_F(ValidateExtInst, VStoreNAddressingModelLogical) {
4903 std::ostringstream ss;
4904 ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4905 ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
4906 ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
4907
4908 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
4909 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4910 EXPECT_THAT(getDiagnosticString(),
4911 HasSubstr("OpenCL.std vstoren can only be used with physical "
4912 "addressing models"));
4913 }
4914
4915 TEST_F(ValidateExtInst, VStoreNOffsetNotSizeT) {
4916 std::ostringstream ss;
4917 ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4918 ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
4919 ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
4920
4921 CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
4922 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4923 EXPECT_THAT(
4924 getDiagnosticString(),
4925 HasSubstr(
4926 "OpenCL.std vstoren: expected operand Offset to be of type size_t "
4927 "(64-bit integer for the addressing model used in the module)"));
4928 }
4929
4930 TEST_F(ValidateExtInst, VStoreNPNotPointer) {
4931 std::ostringstream ss;
4932 ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 "
4933 "%f32_ptr_generic\n";
4934
4935 CompileSuccessfully(GenerateKernelCode(ss.str()));
4936 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
4937 EXPECT_THAT(getDiagnosticString(),
4938 HasSubstr("Operand '127[%_ptr_Generic_float]' cannot be a type"));
4939 }
4940
4941 TEST_F(ValidateExtInst, VStoreNWrongStorageClass) {
4942 std::ostringstream ss;
4943 ss << "%ptr_w = OpAccessChain %f32_ptr_uniform_constant "
4944 "%f32vec8_uniform_constant %u32_1\n";
4945 ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_w\n";
4946
4947 CompileSuccessfully(GenerateKernelCode(ss.str()));
4948 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4949 EXPECT_THAT(
4950 getDiagnosticString(),
4951 HasSubstr("OpenCL.std vstoren: expected operand P storage class "
4952 "to be Generic, CrossWorkgroup, Workgroup or Function"));
4953 }
4954
4955 TEST_F(ValidateExtInst, VStorePWrongDataType) {
4956 std::ostringstream ss;
4957 ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
4958 ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
4959 ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u32_1 %ptr_g\n";
4960
4961 CompileSuccessfully(GenerateKernelCode(ss.str()));
4962 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4963 EXPECT_THAT(getDiagnosticString(),
4964 HasSubstr("OpenCL.std vstoren: expected operand P data type to "
4965 "be equal to the type of operand Data components"));
4966 }
4967
4968 TEST_F(ValidateExtInst, OpenCLStdShuffleSuccess) {
4969 const std::string body = R"(
4970 %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec4_0123 %u32vec2_01
4971 %val2 = OpExtInst %f32vec4 %extinst shuffle %f32vec4_0123 %u32vec4_0123
4972 %val3 = OpExtInst %u32vec2 %extinst shuffle %u32vec4_0123 %u32vec2_01
4973 %val4 = OpExtInst %u32vec4 %extinst shuffle %u32vec4_0123 %u32vec4_0123
4974 )";
4975
4976 CompileSuccessfully(GenerateKernelCode(body));
4977 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
4978 }
4979
4980 TEST_F(ValidateExtInst, OpenCLStdShuffleWrongResultType) {
4981 const std::string body = R"(
4982 %val1 = OpExtInst %f32 %extinst shuffle %f32vec4_0123 %u32vec2_01
4983 )";
4984
4985 CompileSuccessfully(GenerateKernelCode(body));
4986 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4987 EXPECT_THAT(
4988 getDiagnosticString(),
4989 HasSubstr("OpenCL.std shuffle: "
4990 "expected Result Type to be an int or float vector type"));
4991 }
4992
4993 TEST_F(ValidateExtInst, OpenCLStdShuffleResultTypeInvalidNumComponents) {
4994 const std::string body = R"(
4995 %val1 = OpExtInst %f32vec3 %extinst shuffle %f32vec4_0123 %u32vec3_012
4996 )";
4997
4998 CompileSuccessfully(GenerateKernelCode(body));
4999 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5000 EXPECT_THAT(
5001 getDiagnosticString(),
5002 HasSubstr("OpenCL.std shuffle: "
5003 "expected Result Type to have 2, 4, 8 or 16 components"));
5004 }
5005
5006 TEST_F(ValidateExtInst, OpenCLStdShuffleXWrongType) {
5007 const std::string body = R"(
5008 %val1 = OpExtInst %f32vec2 %extinst shuffle %f32_0 %u32vec2_01
5009 )";
5010
5011 CompileSuccessfully(GenerateKernelCode(body));
5012 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5013 EXPECT_THAT(getDiagnosticString(),
5014 HasSubstr("OpenCL.std shuffle: "
5015 "expected operand X to be an int or float vector"));
5016 }
5017
5018 TEST_F(ValidateExtInst, OpenCLStdShuffleXInvalidNumComponents) {
5019 const std::string body = R"(
5020 %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec3_012 %u32vec2_01
5021 )";
5022
5023 CompileSuccessfully(GenerateKernelCode(body));
5024 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5025 EXPECT_THAT(getDiagnosticString(),
5026 HasSubstr("OpenCL.std shuffle: "
5027 "expected operand X to have 2, 4, 8 or 16 components"));
5028 }
5029
5030 TEST_F(ValidateExtInst, OpenCLStdShuffleXInvalidComponentType) {
5031 const std::string body = R"(
5032 %val1 = OpExtInst %f32vec2 %extinst shuffle %f64vec4_0123 %u32vec2_01
5033 )";
5034
5035 CompileSuccessfully(GenerateKernelCode(body));
5036 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5037 EXPECT_THAT(
5038 getDiagnosticString(),
5039 HasSubstr(
5040 "OpenCL.std shuffle: "
5041 "expected operand X and Result Type to have equal component types"));
5042 }
5043
5044 TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskNotIntVector) {
5045 const std::string body = R"(
5046 %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec4_0123 %f32vec2_01
5047 )";
5048
5049 CompileSuccessfully(GenerateKernelCode(body));
5050 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5051 EXPECT_THAT(getDiagnosticString(),
5052 HasSubstr("OpenCL.std shuffle: "
5053 "expected operand Shuffle Mask to be an int vector"));
5054 }
5055
5056 TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskInvalidNumComponents) {
5057 const std::string body = R"(
5058 %val1 = OpExtInst %f32vec4 %extinst shuffle %f32vec4_0123 %u32vec2_01
5059 )";
5060
5061 CompileSuccessfully(GenerateKernelCode(body));
5062 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5063 EXPECT_THAT(getDiagnosticString(),
5064 HasSubstr("OpenCL.std shuffle: "
5065 "expected operand Shuffle Mask to have the same number "
5066 "of components as Result Type"));
5067 }
5068
5069 TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskInvalidBitWidth) {
5070 const std::string body = R"(
5071 %val1 = OpExtInst %f64vec2 %extinst shuffle %f64vec4_0123 %u32vec2_01
5072 )";
5073
5074 CompileSuccessfully(GenerateKernelCode(body));
5075 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5076 EXPECT_THAT(getDiagnosticString(),
5077 HasSubstr("OpenCL.std shuffle: "
5078 "expected operand Shuffle Mask components to have the "
5079 "same bit width as Result Type components"));
5080 }
5081
5082 TEST_F(ValidateExtInst, OpenCLStdShuffle2Success) {
5083 const std::string body = R"(
5084 %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
5085 %val2 = OpExtInst %f32vec4 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec4_0123
5086 %val3 = OpExtInst %u32vec2 %extinst shuffle2 %u32vec4_0123 %u32vec4_0123 %u32vec2_01
5087 %val4 = OpExtInst %u32vec4 %extinst shuffle2 %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
5088 )";
5089
5090 CompileSuccessfully(GenerateKernelCode(body));
5091 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5092 }
5093
5094 TEST_F(ValidateExtInst, OpenCLStdShuffle2WrongResultType) {
5095 const std::string body = R"(
5096 %val1 = OpExtInst %f32 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
5097 )";
5098
5099 CompileSuccessfully(GenerateKernelCode(body));
5100 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5101 EXPECT_THAT(
5102 getDiagnosticString(),
5103 HasSubstr("OpenCL.std shuffle2: "
5104 "expected Result Type to be an int or float vector type"));
5105 }
5106
5107 TEST_F(ValidateExtInst, OpenCLStdShuffle2ResultTypeInvalidNumComponents) {
5108 const std::string body = R"(
5109 %val1 = OpExtInst %f32vec3 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec3_012
5110 )";
5111
5112 CompileSuccessfully(GenerateKernelCode(body));
5113 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5114 EXPECT_THAT(
5115 getDiagnosticString(),
5116 HasSubstr("OpenCL.std shuffle2: "
5117 "expected Result Type to have 2, 4, 8 or 16 components"));
5118 }
5119
5120 TEST_F(ValidateExtInst, OpenCLStdShuffle2XWrongType) {
5121 const std::string body = R"(
5122 %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32_0 %f32_0 %u32vec2_01
5123 )";
5124
5125 CompileSuccessfully(GenerateKernelCode(body));
5126 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5127 EXPECT_THAT(getDiagnosticString(),
5128 HasSubstr("OpenCL.std shuffle2: "
5129 "expected operand X to be an int or float vector"));
5130 }
5131
5132 TEST_F(ValidateExtInst, OpenCLStdShuffle2YTypeDifferentFromX) {
5133 const std::string body = R"(
5134 %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec2_01 %f32vec4_0123 %u32vec2_01
5135 )";
5136
5137 CompileSuccessfully(GenerateKernelCode(body));
5138 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5139 EXPECT_THAT(getDiagnosticString(),
5140 HasSubstr("OpenCL.std shuffle2: "
5141 "expected operands X and Y to be of the same type"));
5142 }
5143
5144 TEST_F(ValidateExtInst, OpenCLStdShuffle2XInvalidNumComponents) {
5145 const std::string body = R"(
5146 %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec3_012 %f32vec3_012 %u32vec2_01
5147 )";
5148
5149 CompileSuccessfully(GenerateKernelCode(body));
5150 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5151 EXPECT_THAT(getDiagnosticString(),
5152 HasSubstr("OpenCL.std shuffle2: "
5153 "expected operand X to have 2, 4, 8 or 16 components"));
5154 }
5155
5156 TEST_F(ValidateExtInst, OpenCLStdShuffle2XInvalidComponentType) {
5157 const std::string body = R"(
5158 %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f64vec4_0123 %f64vec4_0123 %u32vec2_01
5159 )";
5160
5161 CompileSuccessfully(GenerateKernelCode(body));
5162 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5163 EXPECT_THAT(
5164 getDiagnosticString(),
5165 HasSubstr(
5166 "OpenCL.std shuffle2: "
5167 "expected operand X and Result Type to have equal component types"));
5168 }
5169
5170 TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskNotIntVector) {
5171 const std::string body = R"(
5172 %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %f32vec2_01
5173 )";
5174
5175 CompileSuccessfully(GenerateKernelCode(body));
5176 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5177 EXPECT_THAT(getDiagnosticString(),
5178 HasSubstr("OpenCL.std shuffle2: "
5179 "expected operand Shuffle Mask to be an int vector"));
5180 }
5181
5182 TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskInvalidNumComponents) {
5183 const std::string body = R"(
5184 %val1 = OpExtInst %f32vec4 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
5185 )";
5186
5187 CompileSuccessfully(GenerateKernelCode(body));
5188 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5189 EXPECT_THAT(getDiagnosticString(),
5190 HasSubstr("OpenCL.std shuffle2: "
5191 "expected operand Shuffle Mask to have the same number "
5192 "of components as Result Type"));
5193 }
5194
5195 TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskInvalidBitWidth) {
5196 const std::string body = R"(
5197 %val1 = OpExtInst %f64vec2 %extinst shuffle2 %f64vec4_0123 %f64vec4_0123 %u32vec2_01
5198 )";
5199
5200 CompileSuccessfully(GenerateKernelCode(body));
5201 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5202 EXPECT_THAT(getDiagnosticString(),
5203 HasSubstr("OpenCL.std shuffle2: "
5204 "expected operand Shuffle Mask components to have the "
5205 "same bit width as Result Type components"));
5206 }
5207
5208 TEST_F(ValidateExtInst, OpenCLStdPrintfSuccess) {
5209 const std::string body = R"(
5210 %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
5211 %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
5212 )";
5213
5214 CompileSuccessfully(GenerateKernelCode(body));
5215 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5216 }
5217
5218 TEST_F(ValidateExtInst, OpenCLStdPrintfBoolResultType) {
5219 const std::string body = R"(
5220 %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
5221 %val1 = OpExtInst %bool %extinst printf %format %u32_0 %u32_1
5222 )";
5223
5224 CompileSuccessfully(GenerateKernelCode(body));
5225 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5226 EXPECT_THAT(
5227 getDiagnosticString(),
5228 HasSubstr(
5229 "OpenCL.std printf: expected Result Type to be a 32-bit int type"));
5230 }
5231
5232 TEST_F(ValidateExtInst, OpenCLStdPrintfU64ResultType) {
5233 const std::string body = R"(
5234 %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
5235 %val1 = OpExtInst %u64 %extinst printf %format %u32_0 %u32_1
5236 )";
5237
5238 CompileSuccessfully(GenerateKernelCode(body));
5239 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5240 EXPECT_THAT(
5241 getDiagnosticString(),
5242 HasSubstr(
5243 "OpenCL.std printf: expected Result Type to be a 32-bit int type"));
5244 }
5245
5246 TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotPointer) {
5247 const std::string body = R"(
5248 %val1 = OpExtInst %u32 %extinst printf %u8_ptr_uniform_constant %u32_0 %u32_1
5249 )";
5250
5251 CompileSuccessfully(GenerateKernelCode(body));
5252 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5253 EXPECT_THAT(
5254 getDiagnosticString(),
5255 HasSubstr("Operand '137[%_ptr_UniformConstant_uchar]' cannot be a "
5256 "type"));
5257 }
5258
5259 TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotUniformConstStorageClass) {
5260 const std::string body = R"(
5261 %format_const = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
5262 %format = OpBitcast %u8_ptr_generic %format_const
5263 %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
5264 )";
5265
5266 CompileSuccessfully(GenerateKernelCode(body));
5267 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5268 EXPECT_THAT(getDiagnosticString(),
5269 HasSubstr("OpenCL.std printf: expected Format storage class to "
5270 "be UniformConstant"));
5271 }
5272
5273 TEST_F(ValidateExtInst,
5274 OpenCLStdPrintfFormatWithExtensionNotAllowedStorageClass) {
5275 const std::string body = R"(
5276 %format_const = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
5277 %format = OpBitcast %u8_ptr_input %format_const
5278 %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
5279 )";
5280
5281 const std::string extension = R"(
5282 OpExtension "SPV_EXT_relaxed_printf_string_address_space"
5283 )";
5284
5285 CompileSuccessfully(GenerateKernelCode(body, extension));
5286 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5287 EXPECT_THAT(getDiagnosticString(),
5288 HasSubstr("OpenCL.std printf: expected Format storage class to "
5289 "be UniformConstant, Crossworkgroup, Workgroup, "
5290 "Function, or Generic"));
5291 }
5292
5293 TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotU8Pointer) {
5294 const std::string body = R"(
5295 %format = OpAccessChain %u32_ptr_uniform_constant %u32vec8_uniform_constant %u32_0
5296 %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
5297 )";
5298
5299 CompileSuccessfully(GenerateKernelCode(body));
5300 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5301 EXPECT_THAT(
5302 getDiagnosticString(),
5303 HasSubstr(
5304 "OpenCL.std printf: expected Format data type to be 8-bit int"));
5305 }
5306
5307 TEST_F(ValidateExtInst, OpenCLStdPrefetchU32Success) {
5308 const std::string body = R"(
5309 %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
5310 %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
5311 )";
5312
5313 CompileSuccessfully(GenerateKernelCode(body));
5314 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5315 }
5316
5317 TEST_F(ValidateExtInst, OpenCLStdPrefetchU32Physical64Success) {
5318 const std::string body = R"(
5319 %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
5320 %val1 = OpExtInst %void %extinst prefetch %ptr %u64_256
5321 )";
5322
5323 CompileSuccessfully(GenerateKernelCode(body, "", "Physical64"));
5324 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5325 }
5326
5327 TEST_F(ValidateExtInst, OpenCLStdPrefetchF32Success) {
5328 const std::string body = R"(
5329 %ptr = OpAccessChain %f32_ptr_cross_workgroup %f32arr_cross_workgroup %u32_0
5330 %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
5331 )";
5332
5333 CompileSuccessfully(GenerateKernelCode(body));
5334 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5335 }
5336
5337 TEST_F(ValidateExtInst, OpenCLStdPrefetchF32Vec2Success) {
5338 const std::string body = R"(
5339 %ptr = OpAccessChain %f32vec2_ptr_cross_workgroup %f32vec2arr_cross_workgroup %u32_0
5340 %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
5341 )";
5342
5343 CompileSuccessfully(GenerateKernelCode(body));
5344 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5345 }
5346
5347 TEST_F(ValidateExtInst, OpenCLStdPrefetchResultTypeNotVoid) {
5348 const std::string body = R"(
5349 %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
5350 %val1 = OpExtInst %u32 %extinst prefetch %ptr %u32_256
5351 )";
5352
5353 CompileSuccessfully(GenerateKernelCode(body));
5354 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5355 EXPECT_THAT(
5356 getDiagnosticString(),
5357 HasSubstr("OpenCL.std prefetch: expected Result Type to be void"));
5358 }
5359
5360 TEST_F(ValidateExtInst, OpenCLStdPrefetchPtrNotPointer) {
5361 const std::string body = R"(
5362 %val1 = OpExtInst %void %extinst prefetch %u32_ptr_cross_workgroup %u32_256
5363 )";
5364
5365 CompileSuccessfully(GenerateKernelCode(body));
5366 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
5367 EXPECT_THAT(getDiagnosticString(),
5368 HasSubstr("Operand '99[%_ptr_CrossWorkgroup_uint]' cannot be a "
5369 "type"));
5370 }
5371
5372 TEST_F(ValidateExtInst, OpenCLStdPrefetchPtrNotCrossWorkgroup) {
5373 const std::string body = R"(
5374 %ptr = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
5375 %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
5376 )";
5377
5378 CompileSuccessfully(GenerateKernelCode(body));
5379 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5380 EXPECT_THAT(getDiagnosticString(),
5381 HasSubstr("OpenCL.std prefetch: expected operand Ptr storage "
5382 "class to be CrossWorkgroup"));
5383 }
5384
5385 TEST_F(ValidateExtInst, OpenCLStdPrefetchInvalidDataType) {
5386 const std::string body = R"(
5387 %ptr = OpAccessChain %struct_ptr_cross_workgroup %struct_arr_cross_workgroup %u32_0
5388 %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
5389 )";
5390
5391 CompileSuccessfully(GenerateKernelCode(body));
5392 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5393 EXPECT_THAT(getDiagnosticString(),
5394 HasSubstr("OpenCL.std prefetch: expected Ptr data type to be int "
5395 "or float scalar or vector"));
5396 }
5397
5398 TEST_F(ValidateExtInst, OpenCLStdPrefetchAddressingModelLogical) {
5399 const std::string body = R"(
5400 %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
5401 %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
5402 )";
5403
5404 CompileSuccessfully(GenerateKernelCode(body, "", "Logical"));
5405 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5406 EXPECT_THAT(getDiagnosticString(),
5407 HasSubstr("OpenCL.std prefetch can only be used with physical "
5408 "addressing models"));
5409 }
5410
5411 TEST_F(ValidateExtInst, OpenCLStdPrefetchNumElementsNotSizeT) {
5412 const std::string body = R"(
5413 %ptr = OpAccessChain %f32_ptr_cross_workgroup %f32arr_cross_workgroup %u32_0
5414 %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
5415 )";
5416
5417 CompileSuccessfully(GenerateKernelCode(body, "", "Physical64"));
5418 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5419 EXPECT_THAT(getDiagnosticString(),
5420 HasSubstr("OpenCL.std prefetch: expected operand Num Elements to "
5421 "be of type size_t (64-bit integer for the addressing "
5422 "model used in the module)"));
5423 }
5424
5425 TEST_P(ValidateOpenCLStdFractLike, Success) {
5426 const std::string ext_inst_name = GetParam();
5427 std::ostringstream ss;
5428 ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
5429 ss << "%var_f32vec2 = OpVariable %f32vec2_ptr_function Function\n";
5430 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5431 << " %f32_0 %var_f32\n";
5432 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
5433 << " %f32vec2_01 %var_f32vec2\n";
5434
5435 CompileSuccessfully(GenerateKernelCode(ss.str()));
5436 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5437 }
5438
5439 TEST_P(ValidateOpenCLStdFractLike, IntResultType) {
5440 const std::string ext_inst_name = GetParam();
5441 std::ostringstream ss;
5442 ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
5443 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
5444 << " %f32_0 %var_f32\n";
5445
5446 CompileSuccessfully(GenerateKernelCode(ss.str()));
5447 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5448 EXPECT_THAT(
5449 getDiagnosticString(),
5450 HasSubstr("OpenCL.std " + ext_inst_name +
5451 ": expected Result Type to be a float scalar or vector type"));
5452 }
5453
5454 TEST_P(ValidateOpenCLStdFractLike, XWrongType) {
5455 const std::string ext_inst_name = GetParam();
5456 std::ostringstream ss;
5457 ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
5458 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5459 << " %f64_0 %var_f32\n";
5460
5461 CompileSuccessfully(GenerateKernelCode(ss.str()));
5462 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5463 EXPECT_THAT(
5464 getDiagnosticString(),
5465 HasSubstr("OpenCL.std " + ext_inst_name +
5466 ": expected type of operand X to be equal to Result Type"));
5467 }
5468
5469 TEST_P(ValidateOpenCLStdFractLike, NotPointer) {
5470 const std::string ext_inst_name = GetParam();
5471 std::ostringstream ss;
5472 ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
5473 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5474 << " %f32_0 %f32_1\n";
5475
5476 CompileSuccessfully(GenerateKernelCode(ss.str()));
5477 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5478 EXPECT_THAT(getDiagnosticString(),
5479 HasSubstr("OpenCL.std " + ext_inst_name +
5480 ": expected the last operand to be a pointer"));
5481 }
5482
5483 TEST_P(ValidateOpenCLStdFractLike, PointerInvalidStorageClass) {
5484 const std::string ext_inst_name = GetParam();
5485 std::ostringstream ss;
5486 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
5487 "%f32vec8_uniform_constant %u32_1\n";
5488 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0 %ptr\n";
5489
5490 CompileSuccessfully(GenerateKernelCode(ss.str()));
5491 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5492 EXPECT_THAT(getDiagnosticString(),
5493 HasSubstr("OpenCL.std " + ext_inst_name +
5494 ": expected storage class of the pointer to be "
5495 "Generic, CrossWorkgroup, Workgroup or Function"));
5496 }
5497
5498 TEST_P(ValidateOpenCLStdFractLike, PointerWrongDataType) {
5499 const std::string ext_inst_name = GetParam();
5500 std::ostringstream ss;
5501 ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
5502 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5503 << " %f32_0 %var_u32\n";
5504
5505 CompileSuccessfully(GenerateKernelCode(ss.str()));
5506 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5507 EXPECT_THAT(
5508 getDiagnosticString(),
5509 HasSubstr(
5510 "OpenCL.std " + ext_inst_name +
5511 ": expected data type of the pointer to be equal to Result Type"));
5512 }
5513
5514 INSTANTIATE_TEST_SUITE_P(AllFractLike, ValidateOpenCLStdFractLike,
5515 ::testing::ValuesIn(std::vector<std::string>{
5516 "fract",
5517 "modf",
5518 "sincos",
5519 }));
5520
5521 TEST_F(ValidateExtInst, OpenCLStdRemquoSuccess) {
5522 const std::string body = R"(
5523 %var_u32 = OpVariable %u32_ptr_function Function
5524 %var_u32vec2 = OpVariable %u32vec2_ptr_function Function
5525 %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u32
5526 %val2 = OpExtInst %f32vec2 %extinst remquo %f32vec2_01 %f32vec2_12 %var_u32vec2
5527 )";
5528
5529 CompileSuccessfully(GenerateKernelCode(body));
5530 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5531 }
5532
5533 TEST_F(ValidateExtInst, OpenCLStdRemquoIntResultType) {
5534 const std::string body = R"(
5535 %var_u32 = OpVariable %u32_ptr_function Function
5536 %val1 = OpExtInst %u32 %extinst remquo %f32_3 %f32_2 %var_u32
5537 )";
5538
5539 CompileSuccessfully(GenerateKernelCode(body));
5540 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5541 EXPECT_THAT(
5542 getDiagnosticString(),
5543 HasSubstr("OpenCL.std remquo: "
5544 "expected Result Type to be a float scalar or vector type"));
5545 }
5546
5547 TEST_F(ValidateExtInst, OpenCLStdRemquoXWrongType) {
5548 const std::string body = R"(
5549 %var_u32 = OpVariable %f32_ptr_function Function
5550 %val1 = OpExtInst %f32 %extinst remquo %u32_3 %f32_2 %var_u32
5551 )";
5552
5553 CompileSuccessfully(GenerateKernelCode(body));
5554 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5555 EXPECT_THAT(
5556 getDiagnosticString(),
5557 HasSubstr("OpenCL.std remquo: "
5558 "expected type of operand X to be equal to Result Type"));
5559 }
5560
5561 TEST_F(ValidateExtInst, OpenCLStdRemquoYWrongType) {
5562 const std::string body = R"(
5563 %var_u32 = OpVariable %f32_ptr_function Function
5564 %val1 = OpExtInst %f32 %extinst remquo %f32_3 %u32_2 %var_u32
5565 )";
5566
5567 CompileSuccessfully(GenerateKernelCode(body));
5568 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5569 EXPECT_THAT(
5570 getDiagnosticString(),
5571 HasSubstr("OpenCL.std remquo: "
5572 "expected type of operand Y to be equal to Result Type"));
5573 }
5574
5575 TEST_F(ValidateExtInst, OpenCLStdRemquoNotPointer) {
5576 const std::string body = R"(
5577 %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %f32_1
5578 )";
5579
5580 CompileSuccessfully(GenerateKernelCode(body));
5581 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5582 EXPECT_THAT(getDiagnosticString(),
5583 HasSubstr("OpenCL.std remquo: "
5584 "expected the last operand to be a pointer"));
5585 }
5586
5587 TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongStorageClass) {
5588 const std::string body = R"(
5589 %ptr = OpAccessChain %f32_ptr_uniform_constant %f32vec8_uniform_constant %u32_1
5590 %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %ptr
5591 )";
5592
5593 CompileSuccessfully(GenerateKernelCode(body));
5594 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5595 EXPECT_THAT(getDiagnosticString(),
5596 HasSubstr("OpenCL.std remquo: "
5597 "expected storage class of the pointer to be Generic, "
5598 "CrossWorkgroup, Workgroup or Function"));
5599 }
5600
5601 TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongDataType) {
5602 const std::string body = R"(
5603 %var_f32 = OpVariable %f32_ptr_function Function
5604 %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_f32
5605 )";
5606
5607 CompileSuccessfully(GenerateKernelCode(body));
5608 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5609 EXPECT_THAT(getDiagnosticString(),
5610 HasSubstr("OpenCL.std remquo: "
5611 "expected data type of the pointer to be a 32-bit int "
5612 "scalar or vector type"));
5613 }
5614
5615 TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongDataTypeWidth) {
5616 const std::string body = R"(
5617 %var_u64 = OpVariable %u64_ptr_function Function
5618 %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u64
5619 )";
5620 CompileSuccessfully(GenerateKernelCode(body));
5621 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5622 EXPECT_THAT(getDiagnosticString(),
5623 HasSubstr("OpenCL.std remquo: "
5624 "expected data type of the pointer to be a 32-bit int "
5625 "scalar or vector type"));
5626 }
5627
5628 TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongNumberOfComponents) {
5629 const std::string body = R"(
5630 %var_u32vec2 = OpVariable %u32vec2_ptr_function Function
5631 %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u32vec2
5632 )";
5633
5634 CompileSuccessfully(GenerateKernelCode(body));
5635 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5636 EXPECT_THAT(
5637 getDiagnosticString(),
5638 HasSubstr("OpenCL.std remquo: "
5639 "expected data type of the pointer to have the same number "
5640 "of components as Result Type"));
5641 }
5642
5643 TEST_P(ValidateOpenCLStdFrexpLike, Success) {
5644 const std::string ext_inst_name = GetParam();
5645 std::ostringstream ss;
5646 ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
5647 ss << "%var_u32vec2 = OpVariable %u32vec2_ptr_function Function\n";
5648 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5649 << " %f32_0 %var_u32\n";
5650 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
5651 << " %f32vec2_01 %var_u32vec2\n";
5652
5653 CompileSuccessfully(GenerateKernelCode(ss.str()));
5654 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5655 }
5656
5657 TEST_P(ValidateOpenCLStdFrexpLike, IntResultType) {
5658 const std::string ext_inst_name = GetParam();
5659 std::ostringstream ss;
5660 ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
5661 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
5662 << " %f32_0 %var_u32\n";
5663
5664 CompileSuccessfully(GenerateKernelCode(ss.str()));
5665 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5666 EXPECT_THAT(
5667 getDiagnosticString(),
5668 HasSubstr("OpenCL.std " + ext_inst_name +
5669 ": expected Result Type to be a float scalar or vector type"));
5670 }
5671
5672 TEST_P(ValidateOpenCLStdFrexpLike, XWrongType) {
5673 const std::string ext_inst_name = GetParam();
5674 std::ostringstream ss;
5675 ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
5676 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5677 << " %f64_0 %var_u32\n";
5678
5679 CompileSuccessfully(GenerateKernelCode(ss.str()));
5680 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5681 EXPECT_THAT(
5682 getDiagnosticString(),
5683 HasSubstr("OpenCL.std " + ext_inst_name +
5684 ": expected type of operand X to be equal to Result Type"));
5685 }
5686
5687 TEST_P(ValidateOpenCLStdFrexpLike, NotPointer) {
5688 const std::string ext_inst_name = GetParam();
5689 std::ostringstream ss;
5690 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5691 << " %f32_0 %u32_1\n";
5692
5693 CompileSuccessfully(GenerateKernelCode(ss.str()));
5694 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5695 EXPECT_THAT(getDiagnosticString(),
5696 HasSubstr("OpenCL.std " + ext_inst_name +
5697 ": expected the last operand to be a pointer"));
5698 }
5699
5700 TEST_P(ValidateOpenCLStdFrexpLike, PointerInvalidStorageClass) {
5701 const std::string ext_inst_name = GetParam();
5702 std::ostringstream ss;
5703 ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
5704 "%f32vec8_uniform_constant %u32_1\n";
5705 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0 %ptr\n";
5706
5707 CompileSuccessfully(GenerateKernelCode(ss.str()));
5708 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5709 EXPECT_THAT(getDiagnosticString(),
5710 HasSubstr("OpenCL.std " + ext_inst_name +
5711 ": expected storage class of the pointer to be "
5712 "Generic, CrossWorkgroup, Workgroup or Function"));
5713 }
5714
5715 TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeFloat) {
5716 const std::string ext_inst_name = GetParam();
5717 std::ostringstream ss;
5718 ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
5719 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5720 << " %f32_0 %var_f32\n";
5721
5722 CompileSuccessfully(GenerateKernelCode(ss.str()));
5723 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5724 EXPECT_THAT(getDiagnosticString(),
5725 HasSubstr("OpenCL.std " + ext_inst_name +
5726 ": expected data type of the pointer to be a 32-bit "
5727 "int scalar or vector type"));
5728 }
5729
5730 TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeU64) {
5731 const std::string ext_inst_name = GetParam();
5732 std::ostringstream ss;
5733 ss << "%var_u64 = OpVariable %u64_ptr_function Function\n";
5734 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5735 << " %f32_0 %var_u64\n";
5736
5737 CompileSuccessfully(GenerateKernelCode(ss.str()));
5738 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5739 EXPECT_THAT(getDiagnosticString(),
5740 HasSubstr("OpenCL.std " + ext_inst_name +
5741 ": expected data type of the pointer to be a 32-bit "
5742 "int scalar or vector type"));
5743 }
5744
5745 TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeDiffSize) {
5746 const std::string ext_inst_name = GetParam();
5747 std::ostringstream ss;
5748 ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
5749 ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
5750 << " %f32vec2_01 %var_u32\n";
5751
5752 CompileSuccessfully(GenerateKernelCode(ss.str()));
5753 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5754 EXPECT_THAT(getDiagnosticString(),
5755 HasSubstr("OpenCL.std " + ext_inst_name +
5756 ": expected data type of the pointer to have the same "
5757 "number of components as Result Type"));
5758 }
5759
5760 INSTANTIATE_TEST_SUITE_P(AllFrexpLike, ValidateOpenCLStdFrexpLike,
5761 ::testing::ValuesIn(std::vector<std::string>{
5762 "frexp",
5763 "lgamma_r",
5764 }));
5765
5766 TEST_F(ValidateExtInst, OpenCLStdIlogbSuccess) {
5767 const std::string body = R"(
5768 %val1 = OpExtInst %u32 %extinst ilogb %f32_3
5769 %val2 = OpExtInst %u32vec2 %extinst ilogb %f32vec2_12
5770 )";
5771
5772 CompileSuccessfully(GenerateKernelCode(body));
5773 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5774 }
5775
5776 TEST_F(ValidateExtInst, OpenCLStdIlogbFloatResultType) {
5777 const std::string body = R"(
5778 %val1 = OpExtInst %f32 %extinst ilogb %f32_3
5779 )";
5780
5781 CompileSuccessfully(GenerateKernelCode(body));
5782 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5783 EXPECT_THAT(
5784 getDiagnosticString(),
5785 HasSubstr(
5786 "OpenCL.std ilogb: "
5787 "expected Result Type to be a 32-bit int scalar or vector type"));
5788 }
5789
5790 TEST_F(ValidateExtInst, OpenCLStdIlogbIntX) {
5791 const std::string body = R"(
5792 %val1 = OpExtInst %u32 %extinst ilogb %u32_3
5793 )";
5794
5795 CompileSuccessfully(GenerateKernelCode(body));
5796 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5797 EXPECT_THAT(getDiagnosticString(),
5798 HasSubstr("OpenCL.std ilogb: "
5799 "expected operand X to be a float scalar or vector"));
5800 }
5801
5802 TEST_F(ValidateExtInst, OpenCLStdIlogbDiffSize) {
5803 const std::string body = R"(
5804 %val2 = OpExtInst %u32vec2 %extinst ilogb %f32_1
5805 )";
5806
5807 CompileSuccessfully(GenerateKernelCode(body));
5808 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5809 EXPECT_THAT(getDiagnosticString(),
5810 HasSubstr("OpenCL.std ilogb: "
5811 "expected operand X to have the same number of "
5812 "components as Result Type"));
5813 }
5814
5815 TEST_F(ValidateExtInst, OpenCLStdNanSuccess) {
5816 const std::string body = R"(
5817 %val1 = OpExtInst %f32 %extinst nan %u32_3
5818 %val2 = OpExtInst %f32vec2 %extinst nan %u32vec2_12
5819 )";
5820
5821 CompileSuccessfully(GenerateKernelCode(body));
5822 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5823 }
5824
5825 TEST_F(ValidateExtInst, OpenCLStdNanIntResultType) {
5826 const std::string body = R"(
5827 %val1 = OpExtInst %u32 %extinst nan %u32_3
5828 )";
5829
5830 CompileSuccessfully(GenerateKernelCode(body));
5831 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5832 EXPECT_THAT(
5833 getDiagnosticString(),
5834 HasSubstr("OpenCL.std nan: "
5835 "expected Result Type to be a float scalar or vector type"));
5836 }
5837
5838 TEST_F(ValidateExtInst, OpenCLStdNanFloatNancode) {
5839 const std::string body = R"(
5840 %val1 = OpExtInst %f32 %extinst nan %f32_3
5841 )";
5842
5843 CompileSuccessfully(GenerateKernelCode(body));
5844 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5845 EXPECT_THAT(getDiagnosticString(),
5846 HasSubstr("OpenCL.std nan: "
5847 "expected Nancode to be an int scalar or vector type"));
5848 }
5849
5850 TEST_F(ValidateExtInst, OpenCLStdNanFloatDiffSize) {
5851 const std::string body = R"(
5852 %val1 = OpExtInst %f32 %extinst nan %u32vec2_12
5853 )";
5854
5855 CompileSuccessfully(GenerateKernelCode(body));
5856 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5857 EXPECT_THAT(getDiagnosticString(),
5858 HasSubstr("OpenCL.std nan: "
5859 "expected Nancode to have the same number of "
5860 "components as Result Type"));
5861 }
5862
5863 TEST_F(ValidateExtInst, OpenCLStdNanFloatDiffBitWidth) {
5864 const std::string body = R"(
5865 %val1 = OpExtInst %f64 %extinst nan %u32_2
5866 )";
5867
5868 CompileSuccessfully(GenerateKernelCode(body));
5869 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5870 EXPECT_THAT(
5871 getDiagnosticString(),
5872 HasSubstr("OpenCL.std nan: "
5873 "expected Nancode to have the same bit width as Result Type"));
5874 }
5875
5876 TEST_P(ValidateOpenCLStdLdexpLike, Success) {
5877 const std::string ext_inst_name = GetParam();
5878 std::ostringstream ss;
5879 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5880 << " %f32_0 %u32_1\n";
5881 ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
5882 << " %f32vec2_12 %u32vec2_12\n";
5883
5884 CompileSuccessfully(GenerateKernelCode(ss.str()));
5885 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5886 }
5887
5888 TEST_P(ValidateOpenCLStdLdexpLike, IntResultType) {
5889 const std::string ext_inst_name = GetParam();
5890 std::ostringstream ss;
5891 ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
5892 << " %f32_0 %u32_1\n";
5893
5894 CompileSuccessfully(GenerateKernelCode(ss.str()));
5895 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5896 EXPECT_THAT(
5897 getDiagnosticString(),
5898 HasSubstr("OpenCL.std " + ext_inst_name +
5899 ": expected Result Type to be a float scalar or vector type"));
5900 }
5901
5902 TEST_P(ValidateOpenCLStdLdexpLike, XWrongType) {
5903 const std::string ext_inst_name = GetParam();
5904 std::ostringstream ss;
5905 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5906 << " %u32_0 %u32_1\n";
5907
5908 CompileSuccessfully(GenerateKernelCode(ss.str()));
5909 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5910 EXPECT_THAT(
5911 getDiagnosticString(),
5912 HasSubstr("OpenCL.std " + ext_inst_name +
5913 ": expected type of operand X to be equal to Result Type"));
5914 }
5915
5916 TEST_P(ValidateOpenCLStdLdexpLike, ExponentNotInt) {
5917 const std::string ext_inst_name = GetParam();
5918 std::ostringstream ss;
5919 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5920 << " %f32_0 %f32_1\n";
5921
5922 CompileSuccessfully(GenerateKernelCode(ss.str()));
5923 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5924 EXPECT_THAT(
5925 getDiagnosticString(),
5926 HasSubstr("OpenCL.std " + ext_inst_name +
5927 ": expected the exponent to be a 32-bit int scalar or vector"));
5928 }
5929
5930 TEST_P(ValidateOpenCLStdLdexpLike, ExponentNotInt32) {
5931 const std::string ext_inst_name = GetParam();
5932 std::ostringstream ss;
5933 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5934 << " %f32_0 %u64_1\n";
5935
5936 CompileSuccessfully(GenerateKernelCode(ss.str()));
5937 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5938 EXPECT_THAT(
5939 getDiagnosticString(),
5940 HasSubstr("OpenCL.std " + ext_inst_name +
5941 ": expected the exponent to be a 32-bit int scalar or vector"));
5942 }
5943
5944 TEST_P(ValidateOpenCLStdLdexpLike, ExponentWrongSize) {
5945 const std::string ext_inst_name = GetParam();
5946 std::ostringstream ss;
5947 ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
5948 << " %f32_0 %u32vec2_01\n";
5949
5950 CompileSuccessfully(GenerateKernelCode(ss.str()));
5951 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5952 EXPECT_THAT(getDiagnosticString(),
5953 HasSubstr("OpenCL.std " + ext_inst_name +
5954 ": expected the exponent to have the same number of "
5955 "components as Result Type"));
5956 }
5957
5958 INSTANTIATE_TEST_SUITE_P(AllLdexpLike, ValidateOpenCLStdLdexpLike,
5959 ::testing::ValuesIn(std::vector<std::string>{
5960 "ldexp",
5961 "pown",
5962 "rootn",
5963 }));
5964
5965 TEST_P(ValidateOpenCLStdUpsampleLike, Success) {
5966 const std::string ext_inst_name = GetParam();
5967 std::ostringstream ss;
5968 ss << "%val1 = OpExtInst %u16 %extinst " << ext_inst_name << " %u8_1 %u8_2\n";
5969 ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
5970 << " %u16_1 %u16_2\n";
5971 ss << "%val3 = OpExtInst %u64 %extinst " << ext_inst_name
5972 << " %u32_1 %u32_2\n";
5973 ss << "%val4 = OpExtInst %u64vec2 %extinst " << ext_inst_name
5974 << " %u32vec2_01 %u32vec2_01\n";
5975
5976 CompileSuccessfully(GenerateKernelCode(ss.str()));
5977 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
5978 }
5979
5980 TEST_P(ValidateOpenCLStdUpsampleLike, FloatResultType) {
5981 const std::string ext_inst_name = GetParam();
5982 std::ostringstream ss;
5983 ss << "%val1 = OpExtInst %f64 %extinst " << ext_inst_name
5984 << " %u32_1 %u32_2\n";
5985
5986 CompileSuccessfully(GenerateKernelCode(ss.str()));
5987 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
5988 EXPECT_THAT(
5989 getDiagnosticString(),
5990 HasSubstr("OpenCL.std " + ext_inst_name +
5991 ": expected Result Type to be an int scalar or vector type"));
5992 }
5993
5994 TEST_P(ValidateOpenCLStdUpsampleLike, InvalidResultTypeBitWidth) {
5995 const std::string ext_inst_name = GetParam();
5996 std::ostringstream ss;
5997 ss << "%val1 = OpExtInst %u8 %extinst " << ext_inst_name << " %u8_1 %u8_2\n";
5998
5999 CompileSuccessfully(GenerateKernelCode(ss.str()));
6000 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6001 EXPECT_THAT(
6002 getDiagnosticString(),
6003 HasSubstr(
6004 "OpenCL.std " + ext_inst_name +
6005 ": expected bit width of Result Type components to be 16, 32 or 64"));
6006 }
6007
6008 TEST_P(ValidateOpenCLStdUpsampleLike, LoHiDiffType) {
6009 const std::string ext_inst_name = GetParam();
6010 std::ostringstream ss;
6011 ss << "%val1 = OpExtInst %u64 %extinst " << ext_inst_name
6012 << " %u32_1 %u16_2\n";
6013
6014 CompileSuccessfully(GenerateKernelCode(ss.str()));
6015 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6016 EXPECT_THAT(getDiagnosticString(),
6017 HasSubstr("OpenCL.std " + ext_inst_name +
6018 ": expected Hi and Lo operands to have the same type"));
6019 }
6020
6021 TEST_P(ValidateOpenCLStdUpsampleLike, DiffNumberOfComponents) {
6022 const std::string ext_inst_name = GetParam();
6023 std::ostringstream ss;
6024 ss << "%val1 = OpExtInst %u64vec2 %extinst " << ext_inst_name
6025 << " %u32_1 %u32_2\n";
6026
6027 CompileSuccessfully(GenerateKernelCode(ss.str()));
6028 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6029 EXPECT_THAT(getDiagnosticString(),
6030 HasSubstr("OpenCL.std " + ext_inst_name +
6031 ": expected Hi and Lo operands to have the same number "
6032 "of components as Result Type"));
6033 }
6034
6035 TEST_P(ValidateOpenCLStdUpsampleLike, HiLoWrongBitWidth) {
6036 const std::string ext_inst_name = GetParam();
6037 std::ostringstream ss;
6038 ss << "%val1 = OpExtInst %u64 %extinst " << ext_inst_name
6039 << " %u16_1 %u16_2\n";
6040
6041 CompileSuccessfully(GenerateKernelCode(ss.str()));
6042 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6043 EXPECT_THAT(
6044 getDiagnosticString(),
6045 HasSubstr("OpenCL.std " + ext_inst_name +
6046 ": expected bit width of components of Hi and Lo operands to "
6047 "be half of the bit width of components of Result Type"));
6048 }
6049
6050 INSTANTIATE_TEST_SUITE_P(AllUpsampleLike, ValidateOpenCLStdUpsampleLike,
6051 ::testing::ValuesIn(std::vector<std::string>{
6052 "u_upsample",
6053 "s_upsample",
6054 }));
6055
6056 TEST_F(ValidateClspvReflection, RequiresNonSemanticExtension) {
6057 const std::string text = R"(
6058 OpCapability Shader
6059 OpCapability Linkage
6060 %1 = OpExtInstImport "NonSemantic.ClspvReflection.1"
6061 OpMemoryModel Logical GLSL450
6062 )";
6063
6064 CompileSuccessfully(text);
6065 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6066 EXPECT_THAT(getDiagnosticString(),
6067 HasSubstr("NonSemantic extended instruction sets cannot be "
6068 "declared without SPV_KHR_non_semantic_info"));
6069 }
6070
6071 TEST_F(ValidateClspvReflection, DoesNotRequiresNonSemanticExtensionPost1p6) {
6072 const std::string text = R"(
6073 OpCapability Shader
6074 OpCapability Linkage
6075 %1 = OpExtInstImport "NonSemantic.ClspvReflection.1"
6076 OpMemoryModel Logical GLSL450
6077 )";
6078
6079 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_6);
6080 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
6081 }
6082
6083 TEST_F(ValidateClspvReflection, MissingVersion) {
6084 const std::string text = R"(
6085 OpCapability Shader
6086 OpCapability Linkage
6087 OpExtension "SPV_KHR_non_semantic_info"
6088 %1 = OpExtInstImport "NonSemantic.ClspvReflection."
6089 OpMemoryModel Logical GLSL450
6090 %2 = OpTypeVoid
6091 %3 = OpTypeInt 32 0
6092 %4 = OpConstant %3 1
6093 %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
6094 )";
6095
6096 CompileSuccessfully(text);
6097 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6098 EXPECT_THAT(getDiagnosticString(),
6099 HasSubstr("Missing NonSemantic.ClspvReflection import version"));
6100 }
6101
6102 TEST_F(ValidateClspvReflection, BadVersion0) {
6103 const std::string text = R"(
6104 OpCapability Shader
6105 OpCapability Linkage
6106 OpExtension "SPV_KHR_non_semantic_info"
6107 %1 = OpExtInstImport "NonSemantic.ClspvReflection.0"
6108 OpMemoryModel Logical GLSL450
6109 %2 = OpTypeVoid
6110 %3 = OpTypeInt 32 0
6111 %4 = OpConstant %3 1
6112 %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
6113 )";
6114
6115 CompileSuccessfully(text);
6116 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6117 EXPECT_THAT(getDiagnosticString(),
6118 HasSubstr("Unknown NonSemantic.ClspvReflection import version"));
6119 }
6120
6121 TEST_F(ValidateClspvReflection, BadVersionNotANumber) {
6122 const std::string text = R"(
6123 OpCapability Shader
6124 OpCapability Linkage
6125 OpExtension "SPV_KHR_non_semantic_info"
6126 %1 = OpExtInstImport "NonSemantic.ClspvReflection.1a"
6127 OpMemoryModel Logical GLSL450
6128 %2 = OpTypeVoid
6129 %3 = OpTypeInt 32 0
6130 %4 = OpConstant %3 1
6131 %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
6132 )";
6133
6134 CompileSuccessfully(text);
6135 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
6136 EXPECT_THAT(getDiagnosticString(),
6137 HasSubstr("NonSemantic.ClspvReflection import does not encode "
6138 "the version correctly"));
6139 }
6140
6141 TEST_F(ValidateClspvReflection, Kernel) {
6142 const std::string text = R"(
6143 OpCapability Shader
6144 OpExtension "SPV_KHR_non_semantic_info"
6145 %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
6146 OpMemoryModel Logical GLSL450
6147 OpEntryPoint GLCompute %foo "foo"
6148 OpExecutionMode %foo LocalSize 1 1 1
6149 %foo_name = OpString "foo"
6150 %void = OpTypeVoid
6151 %void_fn = OpTypeFunction %void
6152 %foo = OpFunction %void None %void_fn
6153 %entry = OpLabel
6154 OpReturn
6155 OpFunctionEnd
6156 %decl = OpExtInst %void %ext Kernel %foo %foo_name
6157 )";
6158
6159 CompileSuccessfully(text);
6160 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6161 }
6162
6163 TEST_F(ValidateClspvReflection, KernelNotAFunction) {
6164 const std::string text = R"(
6165 OpCapability Shader
6166 OpExtension "SPV_KHR_non_semantic_info"
6167 %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
6168 OpMemoryModel Logical GLSL450
6169 OpEntryPoint GLCompute %foo "foo"
6170 OpExecutionMode %foo LocalSize 1 1 1
6171 %foo_name = OpString "foo"
6172 %void = OpTypeVoid
6173 %void_fn = OpTypeFunction %void
6174 %foo = OpFunction %void None %void_fn
6175 %entry = OpLabel
6176 OpReturn
6177 OpFunctionEnd
6178 %decl = OpExtInst %void %ext Kernel %foo_name %foo_name
6179 )";
6180
6181 CompileSuccessfully(text);
6182 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6183 EXPECT_THAT(getDiagnosticString(),
6184 HasSubstr("Kernel does not reference a function"));
6185 }
6186
6187 TEST_F(ValidateClspvReflection, KernelNotAnEntryPoint) {
6188 const std::string text = R"(
6189 OpCapability Shader
6190 OpExtension "SPV_KHR_non_semantic_info"
6191 %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
6192 OpMemoryModel Logical GLSL450
6193 OpEntryPoint GLCompute %foo "foo"
6194 OpExecutionMode %foo LocalSize 1 1 1
6195 %foo_name = OpString "foo"
6196 %void = OpTypeVoid
6197 %void_fn = OpTypeFunction %void
6198 %foo = OpFunction %void None %void_fn
6199 %entry = OpLabel
6200 OpReturn
6201 OpFunctionEnd
6202 %bar = OpFunction %void None %void_fn
6203 %bar_entry = OpLabel
6204 OpReturn
6205 OpFunctionEnd
6206 %decl = OpExtInst %void %ext Kernel %bar %foo_name
6207 )";
6208
6209 CompileSuccessfully(text);
6210 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6211 EXPECT_THAT(getDiagnosticString(),
6212 HasSubstr("Kernel does not reference an entry-point"));
6213 }
6214
6215 TEST_F(ValidateClspvReflection, KernelNotGLCompute) {
6216 const std::string text = R"(
6217 OpCapability Shader
6218 OpExtension "SPV_KHR_non_semantic_info"
6219 %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
6220 OpMemoryModel Logical GLSL450
6221 OpEntryPoint Fragment %foo "foo"
6222 OpExecutionMode %foo OriginUpperLeft
6223 %foo_name = OpString "foo"
6224 %void = OpTypeVoid
6225 %void_fn = OpTypeFunction %void
6226 %foo = OpFunction %void None %void_fn
6227 %entry = OpLabel
6228 OpReturn
6229 OpFunctionEnd
6230 %decl = OpExtInst %void %ext Kernel %foo %foo_name
6231 )";
6232
6233 CompileSuccessfully(text);
6234 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6235 EXPECT_THAT(getDiagnosticString(),
6236 HasSubstr("Kernel must refer only to GLCompute entry-points"));
6237 }
6238
6239 TEST_F(ValidateClspvReflection, KernelNameMismatch) {
6240 const std::string text = R"(
6241 OpCapability Shader
6242 OpExtension "SPV_KHR_non_semantic_info"
6243 %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
6244 OpMemoryModel Logical GLSL450
6245 OpEntryPoint GLCompute %foo "foo"
6246 OpExecutionMode %foo LocalSize 1 1 1
6247 %foo_name = OpString "bar"
6248 %void = OpTypeVoid
6249 %void_fn = OpTypeFunction %void
6250 %foo = OpFunction %void None %void_fn
6251 %entry = OpLabel
6252 OpReturn
6253 OpFunctionEnd
6254 %decl = OpExtInst %void %ext Kernel %foo %foo_name
6255 )";
6256
6257 CompileSuccessfully(text);
6258 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6259 EXPECT_THAT(getDiagnosticString(),
6260 HasSubstr("Name must match an entry-point for Kernel"));
6261 }
6262
6263 TEST_F(ValidateClspvReflection, KernelArgumentsVersionGood) {
6264 const std::string text = R"(
6265 OpCapability Shader
6266 OpExtension "SPV_KHR_non_semantic_info"
6267 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6268 OpMemoryModel Logical GLSL450
6269 OpEntryPoint GLCompute %foo "foo"
6270 OpExecutionMode %foo LocalSize 1 1 1
6271 %foo_name = OpString "foo"
6272 %void = OpTypeVoid
6273 %void_fn = OpTypeFunction %void
6274 %int = OpTypeInt 32 0
6275 %int_1 = OpConstant %int 1
6276 %foo = OpFunction %void None %void_fn
6277 %entry = OpLabel
6278 OpReturn
6279 OpFunctionEnd
6280 %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_1
6281 )";
6282
6283 CompileSuccessfully(text);
6284 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6285 }
6286
6287 TEST_F(ValidateClspvReflection, KernelArgumentsVersionBad) {
6288 const std::string text = R"(
6289 OpCapability Shader
6290 OpExtension "SPV_KHR_non_semantic_info"
6291 %ext = OpExtInstImport "NonSemantic.ClspvReflection.4"
6292 OpMemoryModel Logical GLSL450
6293 OpEntryPoint GLCompute %foo "foo"
6294 OpExecutionMode %foo LocalSize 1 1 1
6295 %foo_name = OpString "foo"
6296 %void = OpTypeVoid
6297 %void_fn = OpTypeFunction %void
6298 %int = OpTypeInt 32 0
6299 %int_1 = OpConstant %int 1
6300 %foo = OpFunction %void None %void_fn
6301 %entry = OpLabel
6302 OpReturn
6303 OpFunctionEnd
6304 %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_1
6305 )";
6306
6307 CompileSuccessfully(text);
6308 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6309 EXPECT_THAT(getDiagnosticString(),
6310 HasSubstr("Version 4 of the Kernel instruction can only have 2 "
6311 "additional operands"));
6312 }
6313
6314 TEST_F(ValidateClspvReflection, KernelNumArgumentsNotInt) {
6315 const std::string text = R"(
6316 OpCapability Shader
6317 OpExtension "SPV_KHR_non_semantic_info"
6318 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6319 OpMemoryModel Logical GLSL450
6320 OpEntryPoint GLCompute %foo "foo"
6321 OpExecutionMode %foo LocalSize 1 1 1
6322 %foo_name = OpString "foo"
6323 %void = OpTypeVoid
6324 %void_fn = OpTypeFunction %void
6325 %int = OpTypeInt 32 0
6326 %int_0 = OpConstant %int 0
6327 %float = OpTypeFloat 32
6328 %float_0 = OpConstant %float 0
6329 %foo = OpFunction %void None %void_fn
6330 %entry = OpLabel
6331 OpReturn
6332 OpFunctionEnd
6333 %decl = OpExtInst %void %ext Kernel %foo %foo_name %float_0
6334 )";
6335
6336 CompileSuccessfully(text);
6337 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6338 EXPECT_THAT(
6339 getDiagnosticString(),
6340 HasSubstr("NumArguments must be a 32-bit unsigned integer OpConstant"));
6341 }
6342
6343 TEST_F(ValidateClspvReflection, KernelNumArgumentsNotConstant) {
6344 const std::string text = R"(
6345 OpCapability Shader
6346 OpExtension "SPV_KHR_non_semantic_info"
6347 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6348 OpMemoryModel Logical GLSL450
6349 OpEntryPoint GLCompute %foo "foo"
6350 OpExecutionMode %foo LocalSize 1 1 1
6351 %foo_name = OpString "foo"
6352 %void = OpTypeVoid
6353 %void_fn = OpTypeFunction %void
6354 %int = OpTypeInt 32 0
6355 %int_0 = OpConstant %int 0
6356 %null = OpConstantNull %int
6357 %foo = OpFunction %void None %void_fn
6358 %entry = OpLabel
6359 OpReturn
6360 OpFunctionEnd
6361 %decl = OpExtInst %void %ext Kernel %foo %foo_name %null
6362 )";
6363
6364 CompileSuccessfully(text);
6365 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6366 EXPECT_THAT(
6367 getDiagnosticString(),
6368 HasSubstr("NumArguments must be a 32-bit unsigned integer OpConstant"));
6369 }
6370
6371 TEST_F(ValidateClspvReflection, KernelFlagsNotInt) {
6372 const std::string text = R"(
6373 OpCapability Shader
6374 OpExtension "SPV_KHR_non_semantic_info"
6375 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6376 OpMemoryModel Logical GLSL450
6377 OpEntryPoint GLCompute %foo "foo"
6378 OpExecutionMode %foo LocalSize 1 1 1
6379 %foo_name = OpString "foo"
6380 %void = OpTypeVoid
6381 %void_fn = OpTypeFunction %void
6382 %int = OpTypeInt 32 0
6383 %int_0 = OpConstant %int 0
6384 %float = OpTypeFloat 32
6385 %float_0 = OpConstant %float 0
6386 %foo = OpFunction %void None %void_fn
6387 %entry = OpLabel
6388 OpReturn
6389 OpFunctionEnd
6390 %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_0 %float_0
6391 )";
6392
6393 CompileSuccessfully(text);
6394 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6395 EXPECT_THAT(getDiagnosticString(),
6396 HasSubstr("Flags must be a 32-bit unsigned integer OpConstant"));
6397 }
6398
6399 TEST_F(ValidateClspvReflection, KernelFlagsNotConstant) {
6400 const std::string text = R"(
6401 OpCapability Shader
6402 OpExtension "SPV_KHR_non_semantic_info"
6403 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6404 OpMemoryModel Logical GLSL450
6405 OpEntryPoint GLCompute %foo "foo"
6406 OpExecutionMode %foo LocalSize 1 1 1
6407 %foo_name = OpString "foo"
6408 %void = OpTypeVoid
6409 %void_fn = OpTypeFunction %void
6410 %int = OpTypeInt 32 0
6411 %int_0 = OpConstant %int 0
6412 %null = OpConstantNull %int
6413 %foo = OpFunction %void None %void_fn
6414 %entry = OpLabel
6415 OpReturn
6416 OpFunctionEnd
6417 %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_0 %null
6418 )";
6419
6420 CompileSuccessfully(text);
6421 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6422 EXPECT_THAT(getDiagnosticString(),
6423 HasSubstr("Flags must be a 32-bit unsigned integer OpConstant"));
6424 }
6425
6426 TEST_F(ValidateClspvReflection, KernelAttributesNotString) {
6427 const std::string text = R"(
6428 OpCapability Shader
6429 OpExtension "SPV_KHR_non_semantic_info"
6430 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6431 OpMemoryModel Logical GLSL450
6432 OpEntryPoint GLCompute %foo "foo"
6433 OpExecutionMode %foo LocalSize 1 1 1
6434 %foo_name = OpString "foo"
6435 %void = OpTypeVoid
6436 %void_fn = OpTypeFunction %void
6437 %int = OpTypeInt 32 0
6438 %int_0 = OpConstant %int 0
6439 %float = OpTypeFloat 32
6440 %float_0 = OpConstant %float 0
6441 %foo = OpFunction %void None %void_fn
6442 %entry = OpLabel
6443 OpReturn
6444 OpFunctionEnd
6445 %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_0 %int_0 %int_0
6446 )";
6447
6448 CompileSuccessfully(text);
6449 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6450 EXPECT_THAT(getDiagnosticString(),
6451 HasSubstr("Attributes must be an OpString"));
6452 }
6453
6454 using ArgumentBasics =
6455 spvtest::ValidateBase<std::pair<std::string, std::string>>;
6456
6457 INSTANTIATE_TEST_SUITE_P(
6458 ValidateClspvReflectionArgumentKernel, ArgumentBasics,
6459 ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
6460 std::make_pair("ArgumentStorageBuffer", "%int_0 %int_0"),
6461 std::make_pair("ArgumentUniform", "%int_0 %int_0"),
6462 std::make_pair("ArgumentPodStorageBuffer",
6463 "%int_0 %int_0 %int_0 %int_4"),
6464 std::make_pair("ArgumentPodUniform", "%int_0 %int_0 %int_0 %int_4"),
6465 std::make_pair("ArgumentPodPushConstant", "%int_0 %int_4"),
6466 std::make_pair("ArgumentSampledImage", "%int_0 %int_0"),
6467 std::make_pair("ArgumentStorageImage", "%int_0 %int_0"),
6468 std::make_pair("ArgumentSampler", "%int_0 %int_0"),
6469 std::make_pair("ArgumentWorkgroup", "%int_0 %int_0"),
6470 std::make_pair("ArgumentPointerPushConstant", "%int_0 %int_4"),
6471 std::make_pair("ArgumentPointerUniform", "%int_0 %int_0 %int_0 %int_4"),
6472 std::make_pair("ArgumentStorageTexelBuffer", "%int_0 %int_0"),
6473 std::make_pair("ArgumentUniformTexelBuffer", "%int_0 %int_0")}));
6474
6475 TEST_P(ArgumentBasics, KernelNotAnExtendedInstruction) {
6476 const std::string ext_inst = std::get<0>(GetParam());
6477 const std::string extra = std::get<1>(GetParam());
6478 const std::string text = R"(
6479 OpCapability Shader
6480 OpExtension "SPV_KHR_non_semantic_info"
6481 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6482 OpMemoryModel Logical GLSL450
6483 OpEntryPoint GLCompute %foo "foo"
6484 OpExecutionMode %foo LocalSize 1 1 1
6485 %foo_name = OpString "foo"
6486 %void = OpTypeVoid
6487 %int = OpTypeInt 32 0
6488 %int_0 = OpConstant %int 0
6489 %int_4 = OpConstant %int 4
6490 %void_fn = OpTypeFunction %void
6491 %foo = OpFunction %void None %void_fn
6492 %entry = OpLabel
6493 OpReturn
6494 OpFunctionEnd
6495 %in = OpExtInst %void %ext )" +
6496 ext_inst + " %int_0 %int_0 " + extra;
6497
6498 CompileSuccessfully(text);
6499 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6500 EXPECT_THAT(getDiagnosticString(),
6501 HasSubstr("Kernel must be a Kernel extended instruction"));
6502 }
6503
6504 TEST_P(ArgumentBasics, KernelFromDifferentImport) {
6505 const std::string ext_inst = std::get<0>(GetParam());
6506 const std::string extra = std::get<1>(GetParam());
6507 const std::string text = R"(
6508 OpCapability Shader
6509 OpExtension "SPV_KHR_non_semantic_info"
6510 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6511 %ext2 = OpExtInstImport "NonSemantic.ClspvReflection.5"
6512 OpMemoryModel Logical GLSL450
6513 OpEntryPoint GLCompute %foo "foo"
6514 OpExecutionMode %foo LocalSize 1 1 1
6515 %foo_name = OpString "foo"
6516 %void = OpTypeVoid
6517 %int = OpTypeInt 32 0
6518 %int_0 = OpConstant %int 0
6519 %int_4 = OpConstant %int 4
6520 %void_fn = OpTypeFunction %void
6521 %foo = OpFunction %void None %void_fn
6522 %entry = OpLabel
6523 OpReturn
6524 OpFunctionEnd
6525 %decl = OpExtInst %void %ext2 Kernel %foo %foo_name
6526 %in = OpExtInst %void %ext )" +
6527 ext_inst + " %decl %int_0 " + extra;
6528
6529 CompileSuccessfully(text);
6530 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6531 EXPECT_THAT(
6532 getDiagnosticString(),
6533 HasSubstr("Kernel must be from the same extended instruction import"));
6534 }
6535
6536 TEST_P(ArgumentBasics, KernelWrongExtendedInstruction) {
6537 const std::string ext_inst = std::get<0>(GetParam());
6538 const std::string extra = std::get<1>(GetParam());
6539 const std::string text = R"(
6540 OpCapability Shader
6541 OpExtension "SPV_KHR_non_semantic_info"
6542 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6543 OpMemoryModel Logical GLSL450
6544 OpEntryPoint GLCompute %foo "foo"
6545 OpExecutionMode %foo LocalSize 1 1 1
6546 %foo_name = OpString "foo"
6547 %void = OpTypeVoid
6548 %int = OpTypeInt 32 0
6549 %int_0 = OpConstant %int 0
6550 %int_4 = OpConstant %int 4
6551 %void_fn = OpTypeFunction %void
6552 %foo = OpFunction %void None %void_fn
6553 %entry = OpLabel
6554 OpReturn
6555 OpFunctionEnd
6556 %decl = OpExtInst %void %ext ArgumentInfo %foo_name
6557 %in = OpExtInst %void %ext )" +
6558 ext_inst + " %decl %int_0 " + extra;
6559
6560 CompileSuccessfully(text);
6561 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6562 EXPECT_THAT(getDiagnosticString(),
6563 HasSubstr("Kernel must be a Kernel extended instruction"));
6564 }
6565
6566 TEST_P(ArgumentBasics, ArgumentInfo) {
6567 const std::string ext_inst = std::get<0>(GetParam());
6568 const std::string operands = std::get<1>(GetParam());
6569 const std::string text = R"(
6570 OpCapability Shader
6571 OpExtension "SPV_KHR_non_semantic_info"
6572 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6573 OpMemoryModel Logical GLSL450
6574 OpEntryPoint GLCompute %foo "foo"
6575 OpExecutionMode %foo LocalSize 1 1 1
6576 %foo_name = OpString "foo"
6577 %in_name = OpString "in"
6578 %void = OpTypeVoid
6579 %int = OpTypeInt 32 0
6580 %int_0 = OpConstant %int 0
6581 %int_4 = OpConstant %int 4
6582 %void_fn = OpTypeFunction %void
6583 %foo = OpFunction %void None %void_fn
6584 %entry = OpLabel
6585 OpReturn
6586 OpFunctionEnd
6587 %decl = OpExtInst %void %ext Kernel %foo %foo_name
6588 %info = OpExtInst %void %ext ArgumentInfo %in_name
6589 %in = OpExtInst %void %ext )" +
6590 ext_inst + " %decl %int_0 " + operands + " %info";
6591
6592 CompileSuccessfully(text);
6593 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
6594 }
6595
6596 TEST_P(ArgumentBasics, ArgumentInfoNotAnExtendedInstruction) {
6597 const std::string ext_inst = std::get<0>(GetParam());
6598 const std::string operands = std::get<1>(GetParam());
6599 const std::string text = R"(
6600 OpCapability Shader
6601 OpExtension "SPV_KHR_non_semantic_info"
6602 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6603 OpMemoryModel Logical GLSL450
6604 OpEntryPoint GLCompute %foo "foo"
6605 OpExecutionMode %foo LocalSize 1 1 1
6606 %foo_name = OpString "foo"
6607 %void = OpTypeVoid
6608 %int = OpTypeInt 32 0
6609 %int_0 = OpConstant %int 0
6610 %int_4 = OpConstant %int 4
6611 %void_fn = OpTypeFunction %void
6612 %foo = OpFunction %void None %void_fn
6613 %entry = OpLabel
6614 OpReturn
6615 OpFunctionEnd
6616 %decl = OpExtInst %void %ext Kernel %foo %foo_name
6617 %in = OpExtInst %void %ext )" +
6618 ext_inst + " %decl %int_0 " + operands + " %int_0";
6619
6620 CompileSuccessfully(text);
6621 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6622 EXPECT_THAT(
6623 getDiagnosticString(),
6624 HasSubstr("ArgInfo must be an ArgumentInfo extended instruction"));
6625 }
6626
6627 TEST_P(ArgumentBasics, ArgumentInfoFromDifferentImport) {
6628 const std::string ext_inst = std::get<0>(GetParam());
6629 const std::string operands = std::get<1>(GetParam());
6630 const std::string text = R"(
6631 OpCapability Shader
6632 OpExtension "SPV_KHR_non_semantic_info"
6633 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
6634 %ext2 = OpExtInstImport "NonSemantic.ClspvReflection.5"
6635 OpMemoryModel Logical GLSL450
6636 OpEntryPoint GLCompute %foo "foo"
6637 OpExecutionMode %foo LocalSize 1 1 1
6638 %foo_name = OpString "foo"
6639 %in_name = OpString "in"
6640 %void = OpTypeVoid
6641 %int = OpTypeInt 32 0
6642 %int_0 = OpConstant %int 0
6643 %int_4 = OpConstant %int 4
6644 %void_fn = OpTypeFunction %void
6645 %foo = OpFunction %void None %void_fn
6646 %entry = OpLabel
6647 OpReturn
6648 OpFunctionEnd
6649 %decl = OpExtInst %void %ext Kernel %foo %foo_name
6650 %info = OpExtInst %void %ext2 ArgumentInfo %in_name
6651 %in = OpExtInst %void %ext )" +
6652 ext_inst + " %decl %int_0 " + operands + " %info";
6653
6654 CompileSuccessfully(text);
6655 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
6656 EXPECT_THAT(
6657 getDiagnosticString(),
6658 HasSubstr("ArgInfo must be from the same extended instruction import"));
6659 }
6660
6661 using Uint32Constant =
6662 spvtest::ValidateBase<std::pair<std::string, std::string>>;
6663
6664 INSTANTIATE_TEST_SUITE_P(
6665 ValidateClspvReflectionUint32Constants, Uint32Constant,
6666 ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
6667 std::make_pair("ArgumentStorageBuffer %decl %float_0 %int_0 %int_0",
6668 "Ordinal"),
6669 std::make_pair("ArgumentStorageBuffer %decl %null %int_0 %int_0",
6670 "Ordinal"),
6671 std::make_pair("ArgumentStorageBuffer %decl %int_0 %float_0 %int_0",
6672 "DescriptorSet"),
6673 std::make_pair("ArgumentStorageBuffer %decl %int_0 %null %int_0",
6674 "DescriptorSet"),
6675 std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %float_0",
6676 "Binding"),
6677 std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %null",
6678 "Binding"),
6679 std::make_pair("ArgumentUniform %decl %float_0 %int_0 %int_0",
6680 "Ordinal"),
6681 std::make_pair("ArgumentUniform %decl %null %int_0 %int_0", "Ordinal"),
6682 std::make_pair("ArgumentUniform %decl %int_0 %float_0 %int_0",
6683 "DescriptorSet"),
6684 std::make_pair("ArgumentUniform %decl %int_0 %null %int_0",
6685 "DescriptorSet"),
6686 std::make_pair("ArgumentUniform %decl %int_0 %int_0 %float_0",
6687 "Binding"),
6688 std::make_pair("ArgumentUniform %decl %int_0 %int_0 %null", "Binding"),
6689 std::make_pair("ArgumentSampledImage %decl %float_0 %int_0 %int_0",
6690 "Ordinal"),
6691 std::make_pair("ArgumentSampledImage %decl %null %int_0 %int_0",
6692 "Ordinal"),
6693 std::make_pair("ArgumentSampledImage %decl %int_0 %float_0 %int_0",
6694 "DescriptorSet"),
6695 std::make_pair("ArgumentSampledImage %decl %int_0 %null %int_0",
6696 "DescriptorSet"),
6697 std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %float_0",
6698 "Binding"),
6699 std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %null",
6700 "Binding"),
6701 std::make_pair("ArgumentStorageImage %decl %float_0 %int_0 %int_0",
6702 "Ordinal"),
6703 std::make_pair("ArgumentStorageImage %decl %null %int_0 %int_0",
6704 "Ordinal"),
6705 std::make_pair("ArgumentStorageImage %decl %int_0 %float_0 %int_0",
6706 "DescriptorSet"),
6707 std::make_pair("ArgumentStorageImage %decl %int_0 %null %int_0",
6708 "DescriptorSet"),
6709 std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %float_0",
6710 "Binding"),
6711 std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %null",
6712 "Binding"),
6713 std::make_pair("ArgumentSampler %decl %float_0 %int_0 %int_0",
6714 "Ordinal"),
6715 std::make_pair("ArgumentSampler %decl %null %int_0 %int_0", "Ordinal"),
6716 std::make_pair("ArgumentSampler %decl %int_0 %float_0 %int_0",
6717 "DescriptorSet"),
6718 std::make_pair("ArgumentSampler %decl %int_0 %null %int_0",
6719 "DescriptorSet"),
6720 std::make_pair("ArgumentSampler %decl %int_0 %int_0 %float_0",
6721 "Binding"),
6722 std::make_pair("ArgumentSampler %decl %int_0 %int_0 %null", "Binding"),
6723 std::make_pair("ArgumentPodStorageBuffer %decl %float_0 %int_0 %int_0 "
6724 "%int_0 %int_4",
6725 "Ordinal"),
6726 std::make_pair(
6727 "ArgumentPodStorageBuffer %decl %null %int_0 %int_0 %int_0 %int_4",
6728 "Ordinal"),
6729 std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %float_0 %int_0 "
6730 "%int_0 %int_4",
6731 "DescriptorSet"),
6732 std::make_pair(
6733 "ArgumentPodStorageBuffer %decl %int_0 %null %int_0 %int_0 %int_4",
6734 "DescriptorSet"),
6735 std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %float_0 "
6736 "%int_0 %int_4",
6737 "Binding"),
6738 std::make_pair(
6739 "ArgumentPodStorageBuffer %decl %int_0 %int_0 %null %int_0 %int_4",
6740 "Binding"),
6741 std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 "
6742 "%float_0 %int_4",
6743 "Offset"),
6744 std::make_pair(
6745 "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %null %int_4",
6746 "Offset"),
6747 std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 "
6748 "%int_0 %float_0",
6749 "Size"),
6750 std::make_pair(
6751 "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %int_0 %null",
6752 "Size"),
6753 std::make_pair(
6754 "ArgumentPodUniform %decl %float_0 %int_0 %int_0 %int_0 %int_4",
6755 "Ordinal"),
6756 std::make_pair(
6757 "ArgumentPodUniform %decl %null %int_0 %int_0 %int_0 %int_4",
6758 "Ordinal"),
6759 std::make_pair(
6760 "ArgumentPodUniform %decl %int_0 %float_0 %int_0 %int_0 %int_4",
6761 "DescriptorSet"),
6762 std::make_pair(
6763 "ArgumentPodUniform %decl %int_0 %null %int_0 %int_0 %int_4",
6764 "DescriptorSet"),
6765 std::make_pair(
6766 "ArgumentPodUniform %decl %int_0 %int_0 %float_0 %int_0 %int_4",
6767 "Binding"),
6768 std::make_pair(
6769 "ArgumentPodUniform %decl %int_0 %int_0 %null %int_0 %int_4",
6770 "Binding"),
6771 std::make_pair(
6772 "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %float_0 %int_4",
6773 "Offset"),
6774 std::make_pair(
6775 "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %null %int_4",
6776 "Offset"),
6777 std::make_pair(
6778 "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %float_0",
6779 "Size"),
6780 std::make_pair(
6781 "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %null",
6782 "Size"),
6783 std::make_pair("ArgumentPodPushConstant %decl %float_0 %int_0 %int_4",
6784 "Ordinal"),
6785 std::make_pair("ArgumentPodPushConstant %decl %null %int_0 %int_4",
6786 "Ordinal"),
6787 std::make_pair("ArgumentPodPushConstant %decl %int_0 %float_0 %int_4",
6788 "Offset"),
6789 std::make_pair("ArgumentPodPushConstant %decl %int_0 %null %int_4",
6790 "Offset"),
6791 std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %float_0",
6792 "Size"),
6793 std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %null",
6794 "Size"),
6795 std::make_pair("ArgumentWorkgroup %decl %float_0 %int_0 %int_4",
6796 "Ordinal"),
6797 std::make_pair("ArgumentWorkgroup %decl %null %int_0 %int_4",
6798 "Ordinal"),
6799 std::make_pair("ArgumentWorkgroup %decl %int_0 %float_0 %int_4",
6800 "SpecId"),
6801 std::make_pair("ArgumentWorkgroup %decl %int_0 %null %int_4", "SpecId"),
6802 std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %float_0",
6803 "ElemSize"),
6804 std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %null",
6805 "ElemSize"),
6806 std::make_pair("SpecConstantWorkgroupSize %float_0 %int_0 %int_4", "X"),
6807 std::make_pair("SpecConstantWorkgroupSize %null %int_0 %int_4", "X"),
6808 std::make_pair("SpecConstantWorkgroupSize %int_0 %float_0 %int_4", "Y"),
6809 std::make_pair("SpecConstantWorkgroupSize %int_0 %null %int_4", "Y"),
6810 std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %float_0", "Z"),
6811 std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %null", "Z"),
6812 std::make_pair("SpecConstantGlobalOffset %float_0 %int_0 %int_4", "X"),
6813 std::make_pair("SpecConstantGlobalOffset %null %int_0 %int_4", "X"),
6814 std::make_pair("SpecConstantGlobalOffset %int_0 %float_0 %int_4", "Y"),
6815 std::make_pair("SpecConstantGlobalOffset %int_0 %null %int_4", "Y"),
6816 std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %float_0", "Z"),
6817 std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %null", "Z"),
6818 std::make_pair("SpecConstantWorkDim %float_0", "Dim"),
6819 std::make_pair("SpecConstantWorkDim %null", "Dim"),
6820 std::make_pair("PushConstantGlobalOffset %float_0 %int_0", "Offset"),
6821 std::make_pair("PushConstantGlobalOffset %null %int_0", "Offset"),
6822 std::make_pair("PushConstantGlobalOffset %int_0 %float_0", "Size"),
6823 std::make_pair("PushConstantGlobalOffset %int_0 %null", "Size"),
6824 std::make_pair("PushConstantEnqueuedLocalSize %float_0 %int_0",
6825 "Offset"),
6826 std::make_pair("PushConstantEnqueuedLocalSize %null %int_0", "Offset"),
6827 std::make_pair("PushConstantEnqueuedLocalSize %int_0 %float_0", "Size"),
6828 std::make_pair("PushConstantEnqueuedLocalSize %int_0 %null", "Size"),
6829 std::make_pair("PushConstantGlobalSize %float_0 %int_0", "Offset"),
6830 std::make_pair("PushConstantGlobalSize %null %int_0", "Offset"),
6831 std::make_pair("PushConstantGlobalSize %int_0 %float_0", "Size"),
6832 std::make_pair("PushConstantGlobalSize %int_0 %null", "Size"),
6833 std::make_pair("PushConstantRegionOffset %float_0 %int_0", "Offset"),
6834 std::make_pair("PushConstantRegionOffset %null %int_0", "Offset"),
6835 std::make_pair("PushConstantRegionOffset %int_0 %float_0", "Size"),
6836 std::make_pair("PushConstantRegionOffset %int_0 %null", "Size"),
6837 std::make_pair("PushConstantNumWorkgroups %float_0 %int_0", "Offset"),
6838 std::make_pair("PushConstantNumWorkgroups %null %int_0", "Offset"),
6839 std::make_pair("PushConstantNumWorkgroups %int_0 %float_0", "Size"),
6840 std::make_pair("PushConstantNumWorkgroups %int_0 %null", "Size"),
6841 std::make_pair("PushConstantRegionGroupOffset %float_0 %int_0",
6842 "Offset"),
6843 std::make_pair("PushConstantRegionGroupOffset %null %int_0", "Offset"),
6844 std::make_pair("PushConstantRegionGroupOffset %int_0 %float_0", "Size"),
6845 std::make_pair("PushConstantRegionGroupOffset %int_0 %null", "Size"),
6846 std::make_pair("ConstantDataStorageBuffer %float_0 %int_0 %data",
6847 "DescriptorSet"),
6848 std::make_pair("ConstantDataStorageBuffer %null %int_0 %data",
6849 "DescriptorSet"),
6850 std::make_pair("ConstantDataStorageBuffer %int_0 %float_0 %data",
6851 "Binding"),
6852 std::make_pair("ConstantDataStorageBuffer %int_0 %null %data",
6853 "Binding"),
6854 std::make_pair("ConstantDataUniform %float_0 %int_0 %data",
6855 "DescriptorSet"),
6856 std::make_pair("ConstantDataUniform %null %int_0 %data",
6857 "DescriptorSet"),
6858 std::make_pair("ConstantDataUniform %int_0 %float_0 %data", "Binding"),
6859 std::make_pair("ConstantDataUniform %int_0 %null %data", "Binding"),
6860 std::make_pair("LiteralSampler %float_0 %int_0 %int_4",
6861 "DescriptorSet"),
6862 std::make_pair("LiteralSampler %null %int_0 %int_4", "DescriptorSet"),
6863 std::make_pair("LiteralSampler %int_0 %float_0 %int_4", "Binding"),
6864 std::make_pair("LiteralSampler %int_0 %null %int_4", "Binding"),
6865 std::make_pair("LiteralSampler %int_0 %int_0 %float_0", "Mask"),
6866 std::make_pair("LiteralSampler %int_0 %int_0 %null", "Mask"),
6867 std::make_pair(
6868 "PropertyRequiredWorkgroupSize %decl %float_0 %int_1 %int_4", "X"),
6869 std::make_pair(
6870 "PropertyRequiredWorkgroupSize %decl %null %int_1 %int_4", "X"),
6871 std::make_pair(
6872 "PropertyRequiredWorkgroupSize %decl %int_1 %float_0 %int_4", "Y"),
6873 std::make_pair(
6874 "PropertyRequiredWorkgroupSize %decl %int_1 %null %int_4", "Y"),
6875 std::make_pair(
6876 "PropertyRequiredWorkgroupSize %decl %int_1 %int_1 %float_0", "Z"),
6877 std::make_pair(
6878 "PropertyRequiredWorkgroupSize %decl %int_1 %int_1 %null", "Z"),
6879 std::make_pair("SpecConstantSubgroupMaxSize %float_0", "Size"),
6880 std::make_pair("SpecConstantSubgroupMaxSize %null", "Size"),
6881 std::make_pair(
6882 "ArgumentPointerPushConstant %decl %float_0 %int_0 %int_0",
6883 "Ordinal"),
6884 std::make_pair("ArgumentPointerPushConstant %decl %null %int_0 %int_0",
6885 "Ordinal"),
6886 std::make_pair(
6887 "ArgumentPointerPushConstant %decl %int_0 %float_0 %int_0",
6888 "Offset"),
6889 std::make_pair("ArgumentPointerPushConstant %decl %int_0 %null %int_0",
6890 "Offset"),
6891 std::make_pair(
6892 "ArgumentPointerPushConstant %decl %int_0 %int_0 %float_0", "Size"),
6893 std::make_pair("ArgumentPointerPushConstant %decl %int_0 %int_0 %null",
6894 "Size"),
6895 std::make_pair(
6896 "ArgumentPointerUniform %decl %float_0 %int_0 %int_0 %int_0 %int_4",
6897 "Ordinal"),
6898 std::make_pair(
6899 "ArgumentPointerUniform %decl %null %int_0 %int_0 %int_0 %int_4",
6900 "Ordinal"),
6901 std::make_pair(
6902 "ArgumentPointerUniform %decl %int_0 %float_0 %int_0 %int_0 %int_4",
6903 "DescriptorSet"),
6904 std::make_pair(
6905 "ArgumentPointerUniform %decl %int_0 %null %int_0 %int_0 %int_4",
6906 "DescriptorSet"),
6907 std::make_pair(
6908 "ArgumentPointerUniform %decl %int_0 %int_0 %float_0 %int_0 %int_4",
6909 "Binding"),
6910 std::make_pair(
6911 "ArgumentPointerUniform %decl %int_0 %int_0 %null %int_0 %int_4",
6912 "Binding"),
6913 std::make_pair(
6914 "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %float_0 %int_4",
6915 "Offset"),
6916 std::make_pair(
6917 "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %null %int_4",
6918 "Offset"),
6919 std::make_pair(
6920 "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %int_0 %float_0",
6921 "Size"),
6922 std::make_pair(
6923 "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %int_0 %null",
6924 "Size"),
6925 std::make_pair(
6926 "ProgramScopeVariablesStorageBuffer %float_0 %int_0 %data",
6927 "DescriptorSet"),
6928 std::make_pair("ProgramScopeVariablesStorageBuffer %null %int_0 %data",
6929 "DescriptorSet"),
6930 std::make_pair(
6931 "ProgramScopeVariablesStorageBuffer %int_0 %float_0 %data",
6932 "Binding"),
6933 std::make_pair("ProgramScopeVariablesStorageBuffer %int_0 %null %data",
6934 "Binding"),
6935 std::make_pair(
6936 "ProgramScopeVariablePointerRelocation %float_0 %int_0 %int_4",
6937 "ObjectOffset"),
6938 std::make_pair(
6939 "ProgramScopeVariablePointerRelocation %null %int_0 %int_4",
6940 "ObjectOffset"),
6941 std::make_pair(
6942 "ProgramScopeVariablePointerRelocation %int_0 %float_0 %int_4",
6943 "PointerOffset"),
6944 std::make_pair(
6945 "ProgramScopeVariablePointerRelocation %int_0 %null %int_4",
6946 "PointerOffset"),
6947 std::make_pair(
6948 "ProgramScopeVariablePointerRelocation %int_0 %int_0 %float_0",
6949 "PointerSize"),
6950 std::make_pair(
6951 "ProgramScopeVariablePointerRelocation %int_0 %int_0 %null",
6952 "PointerSize"),
6953 std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl "
6954 "%float_0 %int_0 %int_4",
6955 "Ordinal"),
6956 std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %null "
6957 "%int_0 %int_4",
6958 "Ordinal"),
6959 std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
6960 "%float_0 %int_4",
6961 "Offset"),
6962 std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
6963 "%null %int_4",
6964 "Offset"),
6965 std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
6966 "%int_0 %float_0",
6967 "Size"),
6968 std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
6969 "%int_0 %null",
6970 "Size"),
6971 std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
6972 "%float_0 %int_0 %int_4",
6973 "Ordinal"),
6974 std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
6975 "%null %int_0 %int_4",
6976 "Ordinal"),
6977 std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
6978 "%int_0 %float_0 %int_4",
6979 "Offset"),
6980 std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
6981 "%int_0 %null %int_4",
6982 "Offset"),
6983 std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
6984 "%int_0 %int_0 %float_0",
6985 "Size"),
6986 std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
6987 "%int_0 %int_0 %null",
6988 "Size"),
6989 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %float_0 "
6990 "%int_0 %int_0 %int_0 %int_4",
6991 "Ordinal"),
6992 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %null "
6993 "%int_0 %int_0 %int_0 %int_4",
6994 "Ordinal"),
6995 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
6996 "%float_0 %int_0 %int_0 %int_4",
6997 "DescriptorSet"),
6998 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
6999 "%null %int_0 %int_0 %int_4",
7000 "DescriptorSet"),
7001 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
7002 "%int_0 %float_0 %int_0 %int_4",
7003 "Binding"),
7004 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
7005 "%int_0 %null %int_0 %int_4",
7006 "Binding"),
7007 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
7008 "%int_0 %int_0 %float_0 %int_4",
7009 "Offset"),
7010 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
7011 "%int_0 %int_0 %null %int_4",
7012 "Offset"),
7013 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
7014 "%int_0 %int_0 %int_0 %float_0",
7015 "Size"),
7016 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
7017 "%int_0 %int_0 %int_0 %null",
7018 "Size"),
7019 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %float_0 "
7020 "%int_0 %int_0 %int_0 %int_4",
7021 "Ordinal"),
7022 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %null "
7023 "%int_0 %int_0 %int_0 %int_4",
7024 "Ordinal"),
7025 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7026 "%float_0 %int_0 %int_0 %int_4",
7027 "DescriptorSet"),
7028 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7029 "%null %int_0 %int_0 %int_4",
7030 "DescriptorSet"),
7031 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7032 "%int_0 %float_0 %int_0 %int_4",
7033 "Binding"),
7034 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7035 "%int_0 %null %int_0 %int_4",
7036 "Binding"),
7037 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7038 "%int_0 %int_0 %float_0 %int_4",
7039 "Offset"),
7040 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7041 "%int_0 %int_0 %null %int_4",
7042 "Offset"),
7043 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7044 "%int_0 %int_0 %int_0 %float_0",
7045 "Size"),
7046 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7047 "%int_0 %int_0 %int_0 %null",
7048 "Size"),
7049 std::make_pair(
7050 "ArgumentStorageTexelBuffer %decl %float_0 %int_0 %int_0",
7051 "Ordinal"),
7052 std::make_pair("ArgumentStorageTexelBuffer %decl %null %int_0 %int_0",
7053 "Ordinal"),
7054 std::make_pair(
7055 "ArgumentStorageTexelBuffer %decl %int_0 %float_0 %int_0",
7056 "DescriptorSet"),
7057 std::make_pair("ArgumentStorageTexelBuffer %decl %int_0 %null %int_0",
7058 "DescriptorSet"),
7059 std::make_pair(
7060 "ArgumentStorageTexelBuffer %decl %int_0 %int_0 %float_0",
7061 "Binding"),
7062 std::make_pair("ArgumentStorageTexelBuffer %decl %int_0 %int_0 %null",
7063 "Binding"),
7064 std::make_pair(
7065 "ArgumentUniformTexelBuffer %decl %float_0 %int_0 %int_0",
7066 "Ordinal"),
7067 std::make_pair("ArgumentUniformTexelBuffer %decl %null %int_0 %int_0",
7068 "Ordinal"),
7069 std::make_pair(
7070 "ArgumentUniformTexelBuffer %decl %int_0 %float_0 %int_0",
7071 "DescriptorSet"),
7072 std::make_pair("ArgumentUniformTexelBuffer %decl %int_0 %null %int_0",
7073 "DescriptorSet"),
7074 std::make_pair(
7075 "ArgumentUniformTexelBuffer %decl %int_0 %int_0 %float_0",
7076 "Binding"),
7077 std::make_pair("ArgumentUniformTexelBuffer %decl %int_0 %int_0 %null",
7078 "Binding"),
7079 std::make_pair("ConstantDataPointerPushConstant %float_0 %int_4 %data",
7080 "Offset"),
7081 std::make_pair("ConstantDataPointerPushConstant %null %int_4 %data",
7082 "Offset"),
7083 std::make_pair("ConstantDataPointerPushConstant %int_0 %float_0 %data",
7084 "Size"),
7085 std::make_pair("ConstantDataPointerPushConstant %int_0 %null %data",
7086 "Size"),
7087 std::make_pair(
7088 "ProgramScopeVariablePointerPushConstant %float_0 %int_4 %data",
7089 "Offset"),
7090 std::make_pair(
7091 "ProgramScopeVariablePointerPushConstant %null %int_4 %data",
7092 "Offset"),
7093 std::make_pair(
7094 "ProgramScopeVariablePointerPushConstant %int_0 %float_0 %data",
7095 "Size"),
7096 std::make_pair(
7097 "ProgramScopeVariablePointerPushConstant %int_0 %null %data",
7098 "Size"),
7099 std::make_pair("PrintfInfo %float_0 %data %int_0 %int_0 %int_0",
7100 "PrintfID"),
7101 std::make_pair("PrintfInfo %null %data %int_0 %int_0 %int_0",
7102 "PrintfID"),
7103 std::make_pair("PrintfInfo %int_0 %data %float_0 %int_0 %int_0",
7104 "ArgumentSizes"),
7105 std::make_pair("PrintfInfo %int_0 %data %null %int_0 %int_0",
7106 "ArgumentSizes"),
7107 std::make_pair("PrintfInfo %int_0 %data %int_0 %float_0 %int_0",
7108 "ArgumentSizes"),
7109 std::make_pair("PrintfInfo %int_0 %data %int_0 %null %int_0",
7110 "ArgumentSizes"),
7111 std::make_pair("PrintfInfo %int_0 %data %int_0 %int_0 %null",
7112 "ArgumentSizes"),
7113 std::make_pair("PrintfInfo %int_0 %data %int_0 %int_0 %float_0",
7114 "ArgumentSizes"),
7115 std::make_pair("PrintfInfo %int_0 %data %int_0 %float_0",
7116 "ArgumentSizes"),
7117 std::make_pair("PrintfInfo %int_0 %data %int_0 %null", "ArgumentSizes"),
7118 std::make_pair("PrintfBufferStorageBuffer %float_0 %int_0 %int_4",
7119 "DescriptorSet"),
7120 std::make_pair("PrintfBufferStorageBuffer %null %int_0 %int_4",
7121 "DescriptorSet"),
7122 std::make_pair("PrintfBufferStorageBuffer %int_0 %float_0 %int_4",
7123 "Binding"),
7124 std::make_pair("PrintfBufferStorageBuffer %int_0 %null %int_4",
7125 "Binding"),
7126 std::make_pair("PrintfBufferStorageBuffer %int_0 %int_0 %float_0",
7127 "Size"),
7128 std::make_pair("PrintfBufferStorageBuffer %int_0 %int_0 %null", "Size"),
7129 std::make_pair("PrintfBufferPointerPushConstant %float_0 %int_0 %int_4",
7130 "Offset"),
7131 std::make_pair("PrintfBufferPointerPushConstant %null %int_0 %int_4",
7132 "Offset"),
7133 std::make_pair("PrintfBufferPointerPushConstant %int_0 %float_0 %int_4",
7134 "Size"),
7135 std::make_pair("PrintfBufferPointerPushConstant %int_0 %null %int_4",
7136 "Size"),
7137 std::make_pair("PrintfBufferPointerPushConstant %int_0 %int_0 %float_0",
7138 "BufferSize"),
7139 std::make_pair("PrintfBufferPointerPushConstant %int_0 %int_0 %null",
7140 "BufferSize")}));
7141
7142 TEST_P(Uint32Constant, Invalid) {
7143 const std::string ext_inst = std::get<0>(GetParam());
7144 const std::string name = std::get<1>(GetParam());
7145 const std::string text = R"(
7146 OpCapability Shader
7147 OpExtension "SPV_KHR_non_semantic_info"
7148 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
7149 OpMemoryModel Logical GLSL450
7150 OpEntryPoint GLCompute %foo "foo"
7151 OpExecutionMode %foo LocalSize 1 1 1
7152 %foo_name = OpString "foo"
7153 %data = OpString "1234"
7154 %void = OpTypeVoid
7155 %int = OpTypeInt 32 0
7156 %int_0 = OpConstant %int 0
7157 %int_1 = OpConstant %int 1
7158 %int_4 = OpConstant %int 4
7159 %null = OpConstantNull %int
7160 %float = OpTypeFloat 32
7161 %float_0 = OpConstant %float 0
7162 %void_fn = OpTypeFunction %void
7163 %foo = OpFunction %void None %void_fn
7164 %entry = OpLabel
7165 OpReturn
7166 OpFunctionEnd
7167 %decl = OpExtInst %void %ext Kernel %foo %foo_name
7168 %inst = OpExtInst %void %ext )" +
7169 ext_inst;
7170
7171 CompileSuccessfully(text);
7172 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
7173 EXPECT_THAT(
7174 getDiagnosticString(),
7175 HasSubstr(name + " must be a 32-bit unsigned integer OpConstant"));
7176 }
7177
7178 using StringOperand =
7179 spvtest::ValidateBase<std::pair<std::string, std::string>>;
7180
7181 INSTANTIATE_TEST_SUITE_P(
7182 ValidateClspvReflectionStringOperands, StringOperand,
7183 ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
7184 std::make_pair("ConstantDataStorageBuffer %int_0 %int_0 %int_0",
7185 "Data"),
7186 std::make_pair("ConstantDataUniform %int_0 %int_0 %int_0", "Data"),
7187 std::make_pair(
7188 "ProgramScopeVariablesStorageBuffer %int_0 %int_0 %int_0", "Data"),
7189 std::make_pair("ConstantDataPointerPushConstant %int_0 %int_0 %int_0",
7190 "Data"),
7191 std::make_pair(
7192 "ProgramScopeVariablePointerPushConstant %int_0 %int_0 %int_0",
7193 "Data"),
7194 std::make_pair("PrintfInfo %int_0 %int_0", "FormatString")}));
7195
7196 TEST_P(StringOperand, Invalid) {
7197 const std::string ext_inst = std::get<0>(GetParam());
7198 const std::string name = std::get<1>(GetParam());
7199 const std::string text = R"(
7200 OpCapability Shader
7201 OpExtension "SPV_KHR_non_semantic_info"
7202 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
7203 OpMemoryModel Logical GLSL450
7204 OpEntryPoint GLCompute %foo "foo"
7205 OpExecutionMode %foo LocalSize 1 1 1
7206 %foo_name = OpString "foo"
7207 %data = OpString "1234"
7208 %void = OpTypeVoid
7209 %int = OpTypeInt 32 0
7210 %int_0 = OpConstant %int 0
7211 %int_1 = OpConstant %int 1
7212 %int_4 = OpConstant %int 4
7213 %null = OpConstantNull %int
7214 %float = OpTypeFloat 32
7215 %float_0 = OpConstant %float 0
7216 %void_fn = OpTypeFunction %void
7217 %foo = OpFunction %void None %void_fn
7218 %entry = OpLabel
7219 OpReturn
7220 OpFunctionEnd
7221 %decl = OpExtInst %void %ext Kernel %foo %foo_name
7222 %inst = OpExtInst %void %ext )" +
7223 ext_inst;
7224
7225 CompileSuccessfully(text);
7226 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
7227 EXPECT_THAT(getDiagnosticString(), HasSubstr(name + " must be an OpString"));
7228 }
7229
7230 using VersionCheck = spvtest::ValidateBase<std::pair<std::string, uint32_t>>;
7231
7232 INSTANTIATE_TEST_SUITE_P(
7233 ValidateClspvReflectionVersionCheck, VersionCheck,
7234 ::testing::ValuesIn(std::vector<std::pair<std::string, uint32_t>>{
7235 std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %int_0", 1),
7236 std::make_pair("ArgumentUniform %decl %int_0 %int_0 %int_0", 1),
7237 std::make_pair(
7238 "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %int_0 %int_0",
7239 1),
7240 std::make_pair(
7241 "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %int_0", 1),
7242 std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %int_0", 1),
7243 std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %int_0", 1),
7244 std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %int_0", 1),
7245 std::make_pair("ArgumentSampler %decl %int_0 %int_0 %int_0", 1),
7246 std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %int_0", 1),
7247 std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %int_0", 1),
7248 std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %int_0", 1),
7249 std::make_pair("SpecConstantWorkDim %int_0", 1),
7250 std::make_pair("PushConstantGlobalOffset %int_0 %int_0", 1),
7251 std::make_pair("PushConstantEnqueuedLocalSize %int_0 %int_0", 1),
7252 std::make_pair("PushConstantGlobalSize %int_0 %int_0", 1),
7253 std::make_pair("PushConstantRegionOffset %int_0 %int_0", 1),
7254 std::make_pair("PushConstantNumWorkgroups %int_0 %int_0", 1),
7255 std::make_pair("PushConstantRegionGroupOffset %int_0 %int_0", 1),
7256 std::make_pair("ConstantDataStorageBuffer %int_0 %int_0 %data", 1),
7257 std::make_pair("ConstantDataUniform %int_0 %int_0 %data", 1),
7258 std::make_pair("LiteralSampler %int_0 %int_0 %int_0", 1),
7259 std::make_pair(
7260 "PropertyRequiredWorkgroupSize %decl %int_0 %int_0 %int_0", 1),
7261 std::make_pair("SpecConstantSubgroupMaxSize %int_0", 2),
7262 std::make_pair("ArgumentPointerPushConstant %decl %int_0 %int_0 %int_0",
7263 3),
7264 std::make_pair(
7265 "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %int_0 %int_0",
7266 3),
7267 std::make_pair("ProgramScopeVariablesStorageBuffer %int_0 %int_0 %data",
7268 3),
7269 std::make_pair(
7270 "ProgramScopeVariablePointerRelocation %int_0 %int_0 %int_0", 3),
7271 std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
7272 "%int_0 %int_0",
7273 3),
7274 std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
7275 "%int_0 %int_0 %int_0",
7276 3),
7277 std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
7278 "%int_0 %int_0 %int_0 %int_0",
7279 3),
7280 std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
7281 "%int_0 %int_0 %int_0 %int_0",
7282 3),
7283 std::make_pair("ArgumentStorageTexelBuffer %decl %int_0 %int_0 %int_0",
7284 4),
7285 std::make_pair("ArgumentUniformTexelBuffer %decl %int_0 %int_0 %int_0",
7286 4),
7287 std::make_pair("ConstantDataPointerPushConstant %int_0 %int_0 %data",
7288 5),
7289 std::make_pair(
7290 "ProgramScopeVariablePointerPushConstant %int_0 %int_0 %data", 5),
7291 std::make_pair("PrintfInfo %int_0 %data", 5),
7292 std::make_pair("PrintfBufferStorageBuffer %int_0 %int_0 %int_0", 5),
7293 std::make_pair("PrintfBufferPointerPushConstant %int_0 %int_0 %int_0",
7294 5)}));
7295
7296 TEST_P(VersionCheck, V1) {
7297 const std::string ext_inst = std::get<0>(GetParam());
7298 const uint32_t version = std::get<1>(GetParam());
7299 const std::string text = R"(
7300 OpCapability Shader
7301 OpExtension "SPV_KHR_non_semantic_info"
7302 %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
7303 OpMemoryModel Logical GLSL450
7304 OpEntryPoint GLCompute %foo "foo"
7305 OpExecutionMode %foo LocalSize 1 1 1
7306 %foo_name = OpString "foo"
7307 %data = OpString "1234"
7308 %void = OpTypeVoid
7309 %int = OpTypeInt 32 0
7310 %int_0 = OpConstant %int 0
7311 %int_1 = OpConstant %int 1
7312 %int_4 = OpConstant %int 4
7313 %null = OpConstantNull %int
7314 %float = OpTypeFloat 32
7315 %float_0 = OpConstant %float 0
7316 %void_fn = OpTypeFunction %void
7317 %foo = OpFunction %void None %void_fn
7318 %entry = OpLabel
7319 OpReturn
7320 OpFunctionEnd
7321 %decl = OpExtInst %void %ext Kernel %foo %foo_name
7322 %inst = OpExtInst %void %ext )" +
7323 ext_inst;
7324
7325 CompileSuccessfully(text);
7326 if (version <= 1) {
7327 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
7328 } else {
7329 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
7330 EXPECT_THAT(getDiagnosticString(),
7331 HasSubstr("requires version " + std::to_string(version) +
7332 ", but parsed version is 1"));
7333 }
7334 }
7335
7336 TEST_P(VersionCheck, V2) {
7337 const std::string ext_inst = std::get<0>(GetParam());
7338 const uint32_t version = std::get<1>(GetParam());
7339 const std::string text = R"(
7340 OpCapability Shader
7341 OpExtension "SPV_KHR_non_semantic_info"
7342 %ext = OpExtInstImport "NonSemantic.ClspvReflection.2"
7343 OpMemoryModel Logical GLSL450
7344 OpEntryPoint GLCompute %foo "foo"
7345 OpExecutionMode %foo LocalSize 1 1 1
7346 %foo_name = OpString "foo"
7347 %data = OpString "1234"
7348 %void = OpTypeVoid
7349 %int = OpTypeInt 32 0
7350 %int_0 = OpConstant %int 0
7351 %int_1 = OpConstant %int 1
7352 %int_4 = OpConstant %int 4
7353 %null = OpConstantNull %int
7354 %float = OpTypeFloat 32
7355 %float_0 = OpConstant %float 0
7356 %void_fn = OpTypeFunction %void
7357 %foo = OpFunction %void None %void_fn
7358 %entry = OpLabel
7359 OpReturn
7360 OpFunctionEnd
7361 %decl = OpExtInst %void %ext Kernel %foo %foo_name
7362 %inst = OpExtInst %void %ext )" +
7363 ext_inst;
7364
7365 CompileSuccessfully(text);
7366 if (version <= 2) {
7367 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
7368 } else {
7369 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
7370 EXPECT_THAT(getDiagnosticString(),
7371 HasSubstr("requires version " + std::to_string(version) +
7372 ", but parsed version is 2"));
7373 }
7374 }
7375
7376 TEST_P(VersionCheck, V3) {
7377 const std::string ext_inst = std::get<0>(GetParam());
7378 const uint32_t version = std::get<1>(GetParam());
7379 const std::string text = R"(
7380 OpCapability Shader
7381 OpExtension "SPV_KHR_non_semantic_info"
7382 %ext = OpExtInstImport "NonSemantic.ClspvReflection.3"
7383 OpMemoryModel Logical GLSL450
7384 OpEntryPoint GLCompute %foo "foo"
7385 OpExecutionMode %foo LocalSize 1 1 1
7386 %foo_name = OpString "foo"
7387 %data = OpString "1234"
7388 %void = OpTypeVoid
7389 %int = OpTypeInt 32 0
7390 %int_0 = OpConstant %int 0
7391 %int_1 = OpConstant %int 1
7392 %int_4 = OpConstant %int 4
7393 %null = OpConstantNull %int
7394 %float = OpTypeFloat 32
7395 %float_0 = OpConstant %float 0
7396 %void_fn = OpTypeFunction %void
7397 %foo = OpFunction %void None %void_fn
7398 %entry = OpLabel
7399 OpReturn
7400 OpFunctionEnd
7401 %decl = OpExtInst %void %ext Kernel %foo %foo_name
7402 %inst = OpExtInst %void %ext )" +
7403 ext_inst;
7404
7405 CompileSuccessfully(text);
7406 if (version <= 3) {
7407 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
7408 } else {
7409 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
7410 EXPECT_THAT(getDiagnosticString(),
7411 HasSubstr("requires version " + std::to_string(version) +
7412 ", but parsed version is 3"));
7413 }
7414 }
7415
7416 TEST_P(VersionCheck, V4) {
7417 const std::string ext_inst = std::get<0>(GetParam());
7418 const uint32_t version = std::get<1>(GetParam());
7419 const std::string text = R"(
7420 OpCapability Shader
7421 OpExtension "SPV_KHR_non_semantic_info"
7422 %ext = OpExtInstImport "NonSemantic.ClspvReflection.4"
7423 OpMemoryModel Logical GLSL450
7424 OpEntryPoint GLCompute %foo "foo"
7425 OpExecutionMode %foo LocalSize 1 1 1
7426 %foo_name = OpString "foo"
7427 %data = OpString "1234"
7428 %void = OpTypeVoid
7429 %int = OpTypeInt 32 0
7430 %int_0 = OpConstant %int 0
7431 %int_1 = OpConstant %int 1
7432 %int_4 = OpConstant %int 4
7433 %null = OpConstantNull %int
7434 %float = OpTypeFloat 32
7435 %float_0 = OpConstant %float 0
7436 %void_fn = OpTypeFunction %void
7437 %foo = OpFunction %void None %void_fn
7438 %entry = OpLabel
7439 OpReturn
7440 OpFunctionEnd
7441 %decl = OpExtInst %void %ext Kernel %foo %foo_name
7442 %inst = OpExtInst %void %ext )" +
7443 ext_inst;
7444
7445 CompileSuccessfully(text);
7446 if (version <= 4) {
7447 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
7448 } else {
7449 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
7450 EXPECT_THAT(getDiagnosticString(),
7451 HasSubstr("requires version " + std::to_string(version) +
7452 ", but parsed version is 4"));
7453 }
7454 }
7455
7456 TEST_P(VersionCheck, V5) {
7457 const std::string ext_inst = std::get<0>(GetParam());
7458 const uint32_t version = std::get<1>(GetParam());
7459 const std::string text = R"(
7460 OpCapability Shader
7461 OpExtension "SPV_KHR_non_semantic_info"
7462 %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
7463 OpMemoryModel Logical GLSL450
7464 OpEntryPoint GLCompute %foo "foo"
7465 OpExecutionMode %foo LocalSize 1 1 1
7466 %foo_name = OpString "foo"
7467 %data = OpString "1234"
7468 %void = OpTypeVoid
7469 %int = OpTypeInt 32 0
7470 %int_0 = OpConstant %int 0
7471 %int_1 = OpConstant %int 1
7472 %int_4 = OpConstant %int 4
7473 %null = OpConstantNull %int
7474 %float = OpTypeFloat 32
7475 %float_0 = OpConstant %float 0
7476 %void_fn = OpTypeFunction %void
7477 %foo = OpFunction %void None %void_fn
7478 %entry = OpLabel
7479 OpReturn
7480 OpFunctionEnd
7481 %decl = OpExtInst %void %ext Kernel %foo %foo_name
7482 %inst = OpExtInst %void %ext )" +
7483 ext_inst;
7484
7485 CompileSuccessfully(text);
7486 if (version <= 5) {
7487 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
7488 } else {
7489 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
7490 EXPECT_THAT(getDiagnosticString(),
7491 HasSubstr("requires version " + std::to_string(version) +
7492 ", but parsed version is 1"));
7493 }
7494 }
7495
7496 TEST_F(ValidateExtInst, OpExtInstWithForwardNotAllowedSemantic) {
7497 const std::string body = R"(
7498 OpCapability Shader
7499 OpExtension "SPV_KHR_non_semantic_info"
7500 OpExtension "SPV_KHR_relaxed_extended_instruction"
7501 %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
7502 %extinst = OpExtInstImport "GLSL.std.450"
7503 OpMemoryModel Logical GLSL450
7504 OpEntryPoint GLCompute %2 "main"
7505 OpExecutionMode %2 LocalSize 1 1 1
7506 %3 = OpString "sample"
7507 %void = OpTypeVoid
7508 %uint = OpTypeInt 32 0
7509 %f32 = OpTypeFloat 32
7510 %uint_0 = OpConstant %uint 0
7511 %f32_0 = OpConstant %f32 0
7512 %f32_1 = OpConstant %f32 1
7513 %7 = OpTypeFunction %void
7514 %8 = OpExtInst %void %1 DebugSource %3 %3
7515 %9 = OpExtInst %void %1 DebugCompilationUnit %uint_0 %uint_0 %8 %uint_0
7516 %10 = OpExtInstWithForwardRefsKHR %void %1 DebugTypeFunction %uint_0 %11
7517 %12 = OpExtInstWithForwardRefsKHR %void %1 DebugFunction %3 %10 %8 %uint_0 %uint_0 %11 %3 %uint_0 %uint_0
7518 %11 = OpExtInst %void %1 DebugTypeComposite %3 %uint_0 %8 %uint_0 %uint_0 %9 %3 %uint_0 %uint_0 %12
7519 %2 = OpFunction %void None %7
7520 %13 = OpLabel
7521 %18 = OpExtInstWithForwardRefsKHR %f32 %extinst FMin %f32_0 %19
7522 %19 = OpExtInst %f32 %extinst FMin %f32_0 %f32_1
7523 OpReturn
7524 OpFunctionEnd
7525 )";
7526
7527 CompileSuccessfully(body);
7528 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
7529 EXPECT_THAT(
7530 getDiagnosticString(),
7531 HasSubstr(
7532 "OpExtInstWithForwardRefsKHR is only allowed with non-semantic "
7533 "instructions.\n"
7534 " %18 = OpExtInstWithForwardRefsKHR %float %2 FMin %float_0 %19\n"));
7535 }
7536
7537 TEST_F(ValidateExtInst, OpExtInstRequiresNonSemanticBefore16) {
7538 const std::string body = R"(
7539 OpCapability Shader
7540 OpExtension "SPV_KHR_non_semantic_info"
7541 %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
7542 %extinst = OpExtInstImport "GLSL.std.450"
7543 OpMemoryModel Logical GLSL450
7544 OpEntryPoint GLCompute %2 "main"
7545 OpExecutionMode %2 LocalSize 1 1 1
7546 %3 = OpString "sample"
7547 %void = OpTypeVoid
7548 %uint = OpTypeInt 32 0
7549 %uint_0 = OpConstant %uint 0
7550 %7 = OpTypeFunction %void
7551 %8 = OpExtInst %void %1 DebugSource %3 %3
7552 %9 = OpExtInst %void %1 DebugCompilationUnit %uint_0 %uint_0 %8 %uint_0
7553 %10 = OpExtInstWithForwardRefsKHR %void %1 DebugTypeFunction %uint_0 %11
7554 %12 = OpExtInstWithForwardRefsKHR %void %1 DebugFunction %3 %10 %8 %uint_0 %uint_0 %11 %3 %uint_0 %uint_0
7555 %11 = OpExtInst %void %1 DebugTypeComposite %3 %uint_0 %8 %uint_0 %uint_0 %9 %3 %uint_0 %uint_0 %12
7556 %2 = OpFunction %void None %7
7557 %13 = OpLabel
7558 OpReturn
7559 OpFunctionEnd
7560 )";
7561
7562 CompileSuccessfully(body);
7563 ASSERT_EQ(SPV_ERROR_MISSING_EXTENSION, ValidateInstructions());
7564 EXPECT_THAT(
7565 getDiagnosticString(),
7566 HasSubstr("ExtInstWithForwardRefsKHR requires one of the following "
7567 "extensions: SPV_KHR_relaxed_extended_instruction \n"
7568 " %11 = OpExtInstWithForwardRefsKHR %void %1 "
7569 "DebugTypeFunction %uint_0 %12\n"));
7570 }
7571
7572 } // namespace
7573 } // namespace val
7574 } // namespace spvtools