Debian Codegraph @

test/val/val_modes_test.cpp

raw
1 // Copyright (c) 2018 Google LLC.
2 // Modifications Copyright (C) 2024 Advanced Micro Devices, Inc. All rights
3 // reserved.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 #include <sstream>
18 #include <string>
19 #include <vector>
20
21 #include "gmock/gmock.h"
22 #include "source/spirv_target_env.h"
23 #include "test/unit_spirv.h"
24 #include "test/val/val_fixtures.h"
25
26 namespace spvtools {
27 namespace val {
28 namespace {
29
30 using ::testing::Combine;
31 using ::testing::HasSubstr;
32 using ::testing::Values;
33 using ::testing::ValuesIn;
34
35 using ValidateMode = spvtest::ValidateBase<bool>;
36
37 const std::string kVoidFunction = R"(%void = OpTypeVoid
38 %void_fn = OpTypeFunction %void
39 %main = OpFunction %void None %void_fn
40 %entry = OpLabel
41 OpReturn
42 OpFunctionEnd
43 )";
44
45 TEST_F(ValidateMode, GLComputeNoMode) {
46 const std::string spirv = R"(
47 OpCapability Shader
48 OpMemoryModel Logical GLSL450
49 OpEntryPoint GLCompute %main "main"
50 )" + kVoidFunction;
51
52 CompileSuccessfully(spirv);
53 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
54 }
55
56 TEST_F(ValidateMode, GLComputeNoModeVulkan) {
57 const std::string spirv = R"(
58 OpCapability Shader
59 OpMemoryModel Logical GLSL450
60 OpEntryPoint GLCompute %main "main"
61 )" + kVoidFunction;
62
63 spv_target_env env = SPV_ENV_VULKAN_1_0;
64 CompileSuccessfully(spirv, env);
65 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
66 EXPECT_THAT(getDiagnosticString(),
67 AnyVUID("VUID-StandaloneSpirv-None-10685"));
68 EXPECT_THAT(
69 getDiagnosticString(),
70 HasSubstr(
71 "In the Vulkan environment, GLCompute execution model entry "
72 "points require either the LocalSize or LocalSizeId execution mode "
73 "or an object decorated with WorkgroupSize must be specified."));
74 }
75
76 TEST_F(ValidateMode, MeshNoModeVulkan) {
77 const std::string spirv = R"(
78 OpCapability Shader
79 OpCapability MeshShadingEXT
80 OpExtension "SPV_EXT_mesh_shader"
81 OpMemoryModel Logical GLSL450
82 OpEntryPoint MeshEXT %main "main"
83 OpExecutionMode %main OutputVertices 81
84 OpExecutionMode %main OutputPrimitivesEXT 16
85 OpExecutionMode %main OutputPoints
86 )" + kVoidFunction;
87
88 spv_target_env env = SPV_ENV_VULKAN_1_3;
89 CompileSuccessfully(spirv, env);
90 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
91 EXPECT_THAT(getDiagnosticString(),
92 AnyVUID("VUID-StandaloneSpirv-None-10685"));
93 EXPECT_THAT(
94 getDiagnosticString(),
95 HasSubstr(
96 "In the Vulkan environment, MeshEXT execution model entry "
97 "points require either the LocalSize or LocalSizeId execution mode "
98 "or an object decorated with WorkgroupSize must be specified."));
99 }
100
101 TEST_F(ValidateMode, TaskNoModeVulkan) {
102 const std::string spirv = R"(
103 OpCapability Shader
104 OpCapability MeshShadingEXT
105 OpExtension "SPV_EXT_mesh_shader"
106 OpMemoryModel Logical GLSL450
107 OpEntryPoint TaskEXT %main "main"
108 )" + kVoidFunction;
109
110 spv_target_env env = SPV_ENV_VULKAN_1_3;
111 CompileSuccessfully(spirv, env);
112 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
113 EXPECT_THAT(getDiagnosticString(),
114 AnyVUID("VUID-StandaloneSpirv-None-10685"));
115 EXPECT_THAT(
116 getDiagnosticString(),
117 HasSubstr(
118 "In the Vulkan environment, TaskEXT execution model entry "
119 "points require either the LocalSize or LocalSizeId execution mode "
120 "or an object decorated with WorkgroupSize must be specified."));
121 }
122
123 TEST_F(ValidateMode, GLComputeNoModeVulkanWorkgroupSize) {
124 const std::string spirv = R"(
125 OpCapability Shader
126 OpMemoryModel Logical GLSL450
127 OpEntryPoint GLCompute %main "main"
128 OpDecorate %int3_1 BuiltIn WorkgroupSize
129 %int = OpTypeInt 32 0
130 %int3 = OpTypeVector %int 3
131 %int_1 = OpConstant %int 1
132 %int3_1 = OpConstantComposite %int3 %int_1 %int_1 %int_1
133 )" + kVoidFunction;
134
135 spv_target_env env = SPV_ENV_VULKAN_1_0;
136 CompileSuccessfully(spirv, env);
137 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
138 }
139
140 TEST_F(ValidateMode, GLComputeZeroWorkgroupSize) {
141 const std::string spirv = R"(
142 OpCapability Shader
143 OpMemoryModel Logical GLSL450
144 OpEntryPoint GLCompute %main "main"
145 OpDecorate %int3_1 BuiltIn WorkgroupSize
146 %int = OpTypeInt 32 0
147 %int3 = OpTypeVector %int 3
148 %int_0 = OpConstant %int 0
149 %int_1 = OpConstant %int 1
150 %int3_1 = OpConstantComposite %int3 %int_1 %int_0 %int_0
151 )" + kVoidFunction;
152
153 CompileSuccessfully(spirv);
154 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
155 EXPECT_THAT(
156 getDiagnosticString(),
157 HasSubstr(
158 "WorkgroupSize decorations must not have a static product of zero"));
159 }
160
161 TEST_F(ValidateMode, GLComputeZeroSpecWorkgroupSize) {
162 const std::string spirv = R"(
163 OpCapability Shader
164 OpMemoryModel Logical GLSL450
165 OpEntryPoint GLCompute %main "main"
166 OpDecorate %int3_1 BuiltIn WorkgroupSize
167 %int = OpTypeInt 32 0
168 %int3 = OpTypeVector %int 3
169 %int_0 = OpSpecConstant %int 0
170 %int_1 = OpConstant %int 1
171 %int3_1 = OpConstantComposite %int3 %int_1 %int_0 %int_0
172 )" + kVoidFunction;
173
174 CompileSuccessfully(spirv);
175 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
176 }
177
178 TEST_F(ValidateMode, GLComputeZeroSpecCompositeWorkgroupSize) {
179 const std::string spirv = R"(
180 OpCapability Shader
181 OpMemoryModel Logical GLSL450
182 OpEntryPoint GLCompute %main "main"
183 OpDecorate %int3_1 BuiltIn WorkgroupSize
184 %int = OpTypeInt 32 0
185 %int3 = OpTypeVector %int 3
186 %int_0 = OpSpecConstant %int 0
187 %int_1 = OpSpecConstant %int 1
188 %int3_1 = OpSpecConstantComposite %int3 %int_1 %int_0 %int_0
189 )" + kVoidFunction;
190
191 CompileSuccessfully(spirv);
192 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
193 }
194
195 TEST_F(ValidateMode, KernelZeroWorkgroupSizeConstant) {
196 const std::string spirv = R"(
197 OpCapability Addresses
198 OpCapability Linkage
199 OpCapability Kernel
200 OpMemoryModel Physical32 OpenCL
201 OpEntryPoint Kernel %main "main"
202 OpDecorate %int3_1 BuiltIn WorkgroupSize
203 %int = OpTypeInt 32 0
204 %int3 = OpTypeVector %int 3
205 %int_0 = OpConstant %int 0
206 %int_1 = OpConstant %int 1
207 %int3_1 = OpConstantComposite %int3 %int_1 %int_0 %int_0
208 )" + kVoidFunction;
209
210 CompileSuccessfully(spirv);
211 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions());
212 EXPECT_THAT(getDiagnosticString(), HasSubstr("must be a variable"));
213 }
214
215 TEST_F(ValidateMode, KernelZeroWorkgroupSizeVariable) {
216 const std::string spirv = R"(
217 OpCapability Addresses
218 OpCapability Linkage
219 OpCapability Kernel
220 OpMemoryModel Physical32 OpenCL
221 OpEntryPoint Kernel %main "main"
222 OpDecorate %var BuiltIn WorkgroupSize
223 %int = OpTypeInt 32 0
224 %int3 = OpTypeVector %int 3
225 %ptr = OpTypePointer Input %int3
226 %var = OpVariable %ptr Input
227 )" + kVoidFunction;
228
229 CompileSuccessfully(spirv);
230 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
231 }
232
233 TEST_F(ValidateMode, GLComputeWorkgroupSizeDerivativeGroupQuads) {
234 const std::string spirv = R"(
235 OpCapability Shader
236 OpCapability ComputeDerivativeGroupQuadsKHR
237 OpExtension "SPV_KHR_compute_shader_derivatives"
238 OpMemoryModel Logical GLSL450
239 OpEntryPoint GLCompute %main "main"
240 OpExecutionMode %main DerivativeGroupQuadsKHR
241 OpDecorate %int3_1 BuiltIn WorkgroupSize
242 %int = OpTypeInt 32 0
243 %int3 = OpTypeVector %int 3
244 %int_1 = OpConstant %int 1
245 %int_2 = OpConstant %int 2
246 %int3_1 = OpConstantComposite %int3 %int_1 %int_2 %int_1
247 )" + kVoidFunction;
248
249 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_1);
250 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
251 EXPECT_THAT(getDiagnosticString(),
252 AnyVUID("VUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151"));
253 EXPECT_THAT(
254 getDiagnosticString(),
255 HasSubstr("WorkgroupSize decorations has a static dimensions of (X = 1, "
256 "Y = 2) but Entry Point id 1 has an DerivativeGroupQuadsKHR "
257 "execution mode, so both dimensions must be a multiple of 2"));
258 }
259
260 TEST_F(ValidateMode, GLComputeWorkgroupSizeDerivativeGroupLinear) {
261 const std::string spirv = R"(
262 OpCapability Shader
263 OpCapability ComputeDerivativeGroupLinearKHR
264 OpExtension "SPV_KHR_compute_shader_derivatives"
265 OpMemoryModel Logical GLSL450
266 OpEntryPoint GLCompute %main "main"
267 OpExecutionMode %main DerivativeGroupLinearKHR
268 OpDecorate %int3_1 BuiltIn WorkgroupSize
269 %int = OpTypeInt 32 0
270 %uvec3 = OpTypeVector %int 3
271 %int_3 = OpConstant %int 3
272 %int_2 = OpConstant %int 2
273 %int3_1 = OpConstantComposite %uvec3 %int_3 %int_3 %int_2
274 )" + kVoidFunction;
275
276 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_1);
277 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
278 EXPECT_THAT(getDiagnosticString(),
279 AnyVUID("VUID-StandaloneSpirv-DerivativeGroupLinearKHR-10152"));
280 EXPECT_THAT(
281 getDiagnosticString(),
282 HasSubstr(
283 "WorkgroupSize decorations has a static dimensions of (X = 3, Y = 3, "
284 "Z = 2) but Entry Point id 1 has an DerivativeGroupLinearKHR "
285 "execution mode, so the product (18) must be a multiple of 4"));
286 }
287
288 TEST_F(ValidateMode, GLComputeWorkgroupSizeDerivativeGroupQuadsOverride) {
289 // "If an object is decorated with the WorkgroupSize decoration, this takes
290 // precedence over any LocalSize or LocalSizeId execution mode."
291 const std::string spirv = R"(
292 OpCapability Shader
293 OpCapability ComputeDerivativeGroupQuadsKHR
294 OpExtension "SPV_KHR_compute_shader_derivatives"
295 OpMemoryModel Logical GLSL450
296 OpEntryPoint GLCompute %main "main"
297 OpExecutionMode %main DerivativeGroupQuadsKHR
298 OpExecutionMode %main LocalSize 1 1 1
299 OpDecorate %int3_1 BuiltIn WorkgroupSize
300 %int = OpTypeInt 32 0
301 %int3 = OpTypeVector %int 3
302 %int_2 = OpConstant %int 2
303 %int3_1 = OpConstantComposite %int3 %int_2 %int_2 %int_2
304 )" + kVoidFunction;
305
306 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_1);
307 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
308 }
309
310 TEST_F(ValidateMode, GLComputeVulkanLocalSize) {
311 const std::string spirv = R"(
312 OpCapability Shader
313 OpMemoryModel Logical GLSL450
314 OpEntryPoint GLCompute %main "main"
315 OpExecutionMode %main LocalSize 1 1 1
316 )" + kVoidFunction;
317
318 spv_target_env env = SPV_ENV_VULKAN_1_0;
319 CompileSuccessfully(spirv, env);
320 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
321 }
322
323 TEST_F(ValidateMode, GLComputeZeroLocalSize) {
324 const std::string spirv = R"(
325 OpCapability Shader
326 OpMemoryModel Logical GLSL450
327 OpEntryPoint GLCompute %main "main"
328 OpExecutionMode %main LocalSize 1 1 0
329 )" + kVoidFunction;
330
331 CompileSuccessfully(spirv);
332 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
333 EXPECT_THAT(
334 getDiagnosticString(),
335 HasSubstr("Local Size execution mode must not have a product of zero"));
336 }
337
338 TEST_F(ValidateMode, KernelZeroLocalSize) {
339 const std::string spirv = R"(
340 OpCapability Addresses
341 OpCapability Linkage
342 OpCapability Kernel
343 OpMemoryModel Physical32 OpenCL
344 OpEntryPoint Kernel %main "main"
345 OpExecutionMode %main LocalSize 1 1 0
346 )" + kVoidFunction;
347
348 CompileSuccessfully(spirv);
349 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
350 EXPECT_THAT(
351 getDiagnosticString(),
352 HasSubstr("Local Size execution mode must not have a product of zero"));
353 }
354
355 TEST_F(ValidateMode, GLComputeLocalSizeDerivativeGroupQuads) {
356 const std::string spirv = R"(
357 OpCapability Shader
358 OpCapability ComputeDerivativeGroupQuadsKHR
359 OpExtension "SPV_KHR_compute_shader_derivatives"
360 OpMemoryModel Logical GLSL450
361 OpEntryPoint GLCompute %main "main"
362 OpExecutionMode %main LocalSize 1 1 1
363 OpExecutionMode %main DerivativeGroupQuadsKHR
364 )" + kVoidFunction;
365
366 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
367 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
368 EXPECT_THAT(getDiagnosticString(),
369 AnyVUID("VUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151"));
370 EXPECT_THAT(
371 getDiagnosticString(),
372 HasSubstr("Local Size execution mode dimensions is (X = 1, Y = 1) but "
373 "Entry Point id 1 also has an DerivativeGroupQuadsKHR "
374 "execution mode, so both dimensions must be a multiple of 2"));
375 }
376
377 TEST_F(ValidateMode, GLComputeLocalSizeDerivativeGroupLinear) {
378 const std::string spirv = R"(
379 OpCapability Shader
380 OpCapability ComputeDerivativeGroupLinearKHR
381 OpExtension "SPV_KHR_compute_shader_derivatives"
382 OpMemoryModel Logical GLSL450
383 OpEntryPoint GLCompute %main "main"
384 OpExecutionMode %main DerivativeGroupLinearKHR
385 OpExecutionMode %main LocalSize 3 3 3
386 )" + kVoidFunction;
387
388 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
389 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
390 EXPECT_THAT(getDiagnosticString(),
391 AnyVUID("VUID-StandaloneSpirv-DerivativeGroupLinearKHR-10152"));
392 EXPECT_THAT(
393 getDiagnosticString(),
394 HasSubstr("Local Size execution mode dimensions is (X = 3, Y = 3, Z = 3) "
395 "but Entry Point id 1 also has an DerivativeGroupLinearKHR "
396 "execution mode, so the product (27) must be a multiple of 4"));
397 }
398
399 TEST_F(ValidateMode, GLComputeLocalSizeDerivativeGroupQuadsCapabiltyOnly) {
400 // Declares capability but doesn't have OpExecutionMode
401 const std::string spirv = R"(
402 OpCapability Shader
403 OpCapability ComputeDerivativeGroupQuadsKHR
404 OpExtension "SPV_KHR_compute_shader_derivatives"
405 OpMemoryModel Logical GLSL450
406 OpEntryPoint GLCompute %main "main"
407 OpExecutionMode %main LocalSize 1 1 1
408 )" + kVoidFunction;
409
410 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
411 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
412 }
413
414 TEST_F(ValidateMode, GLComputeVulkanLocalSizeIdBad) {
415 const std::string spirv = R"(
416 OpCapability Shader
417 OpMemoryModel Logical GLSL450
418 OpEntryPoint GLCompute %main "main"
419 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
420 %int = OpTypeInt 32 0
421 %int_1 = OpConstant %int 1
422 )" + kVoidFunction;
423
424 spv_target_env env = SPV_ENV_VULKAN_1_1; // need SPIR-V 1.2
425 CompileSuccessfully(spirv, env);
426 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
427 EXPECT_THAT(
428 getDiagnosticString(),
429 HasSubstr("LocalSizeId mode is not allowed by the current environment."));
430 }
431
432 TEST_F(ValidateMode, GLComputeVulkanLocalSizeIdGood) {
433 const std::string spirv = R"(
434 OpCapability Shader
435 OpMemoryModel Logical GLSL450
436 OpEntryPoint GLCompute %main "main"
437 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
438 %int = OpTypeInt 32 0
439 %int_1 = OpConstant %int 1
440 )" + kVoidFunction;
441
442 spv_target_env env = SPV_ENV_VULKAN_1_1; // need SPIR-V 1.2
443 CompileSuccessfully(spirv, env);
444 spvValidatorOptionsSetAllowLocalSizeId(getValidatorOptions(), true);
445 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
446 }
447
448 TEST_F(ValidateMode, GLComputeZeroLocalSizeId) {
449 const std::string spirv = R"(
450 OpCapability Shader
451 OpMemoryModel Logical GLSL450
452 OpEntryPoint GLCompute %main "main"
453 OpExecutionModeId %main LocalSizeId %int_1 %int_0 %int_1
454 %int = OpTypeInt 32 0
455 %int_1 = OpConstant %int 1
456 %int_0 = OpConstant %int 0
457 )" + kVoidFunction;
458
459 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
460 CompileSuccessfully(spirv, env);
461 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
462 EXPECT_THAT(
463 getDiagnosticString(),
464 HasSubstr("LocalSizeId execution mode must not have a product of zero"));
465 }
466
467 TEST_F(ValidateMode, GLComputeZeroSpecLocalSizeId) {
468 const std::string spirv = R"(
469 OpCapability Shader
470 OpMemoryModel Logical GLSL450
471 OpEntryPoint GLCompute %main "main"
472 OpExecutionModeId %main LocalSizeId %int_1 %int_0 %int_1
473 %int = OpTypeInt 32 0
474 %int_1 = OpConstant %int 1
475 %int_0 = OpSpecConstant %int 0
476 )" + kVoidFunction;
477
478 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
479 CompileSuccessfully(spirv, env);
480 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(env));
481 }
482
483 TEST_F(ValidateMode, KernelZeroLocalSizeId) {
484 const std::string spirv = R"(
485 OpCapability Addresses
486 OpCapability Linkage
487 OpCapability Kernel
488 OpMemoryModel Physical32 OpenCL
489 OpEntryPoint Kernel %main "main"
490 OpExecutionModeId %main LocalSizeId %int_1 %int_0 %int_1
491 %int = OpTypeInt 32 0
492 %int_1 = OpConstant %int 1
493 %int_0 = OpConstant %int 0
494 )" + kVoidFunction;
495
496 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
497 CompileSuccessfully(spirv, env);
498 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
499 EXPECT_THAT(
500 getDiagnosticString(),
501 HasSubstr("LocalSizeId execution mode must not have a product of zero"));
502 }
503
504 // https://github.com/KhronosGroup/SPIRV-Tools/issues/5939
505 TEST_F(ValidateMode, KernelZeroLocalSize64) {
506 const std::string spirv = R"(
507 OpCapability Kernel
508 OpCapability Addresses
509 OpCapability Int64
510 OpCapability Linkage
511 OpMemoryModel Physical64 OpenCL
512 OpEntryPoint Kernel %test "test" %__spirv_BuiltInWorkgroupSize
513 OpExecutionMode %test ContractionOff
514 OpDecorate %__spirv_BuiltInWorkgroupSize Constant
515 OpDecorate %__spirv_BuiltInWorkgroupSize LinkageAttributes "__spirv_BuiltInWorkgroupSize" Import
516 OpDecorate %__spirv_BuiltInWorkgroupSize BuiltIn WorkgroupSize
517 %void = OpTypeVoid
518 %ulong = OpTypeInt 64 0
519 %v3ulong = OpTypeVector %ulong 3
520 %_ptr_Input_v3ulong = OpTypePointer Input %v3ulong
521 %8 = OpTypeFunction %void
522 %__spirv_BuiltInWorkgroupSize = OpVariable %_ptr_Input_v3ulong Input
523 %test = OpFunction %void None %8
524 %entry = OpLabel
525 %11 = OpLoad %v3ulong %__spirv_BuiltInWorkgroupSize Aligned 1
526 %12 = OpCompositeExtract %ulong %11 0
527 OpReturn
528 OpFunctionEnd
529 )";
530
531 CompileSuccessfully(spirv);
532 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
533 }
534
535 TEST_F(ValidateMode, GLComputeLocalSizeIdDerivativeGroupQuads) {
536 const std::string spirv = R"(
537 OpCapability Shader
538 OpCapability ComputeDerivativeGroupQuadsKHR
539 OpExtension "SPV_KHR_compute_shader_derivatives"
540 OpMemoryModel Logical GLSL450
541 OpEntryPoint GLCompute %main "main"
542 OpExecutionModeId %main LocalSizeId %int_2 %int_1 %int_2
543 OpExecutionMode %main DerivativeGroupQuadsKHR
544 %int = OpTypeInt 32 0
545 %int_1 = OpConstant %int 1
546 %int_2 = OpConstant %int 2
547 )" + kVoidFunction;
548
549 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_3);
550 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_3));
551 EXPECT_THAT(getDiagnosticString(),
552 AnyVUID("VUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151"));
553 EXPECT_THAT(
554 getDiagnosticString(),
555 HasSubstr("LocalSizeId execution mode dimensions is (X = 2, Y = 1) but "
556 "Entry Point id 1 also has an DerivativeGroupQuadsKHR "
557 "execution mode, so both dimensions must be a multiple of 2"));
558 }
559
560 TEST_F(ValidateMode, GLComputeLocalSizeIdDerivativeGroupLinear) {
561 const std::string spirv = R"(
562 OpCapability Shader
563 OpCapability ComputeDerivativeGroupLinearKHR
564 OpExtension "SPV_KHR_compute_shader_derivatives"
565 OpMemoryModel Logical GLSL450
566 OpEntryPoint GLCompute %main "main"
567 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
568 OpExecutionMode %main DerivativeGroupLinearKHR
569 %int = OpTypeInt 32 0
570 %int_1 = OpConstant %int 1
571 )" + kVoidFunction;
572
573 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_3);
574 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_3));
575 EXPECT_THAT(getDiagnosticString(),
576 AnyVUID("VUID-StandaloneSpirv-DerivativeGroupLinearKHR-10152"));
577 EXPECT_THAT(
578 getDiagnosticString(),
579 HasSubstr("LocalSizeId execution mode dimensions is (X = 1, Y = 1, Z = "
580 "1) but Entry Point id 1 also has an DerivativeGroupLinearKHR "
581 "execution mode, so the product (1) must be a multiple of 4"));
582 }
583
584 TEST_F(ValidateMode, FragmentOriginLowerLeftVulkan) {
585 const std::string spirv = R"(
586 OpCapability Shader
587 OpMemoryModel Logical GLSL450
588 OpEntryPoint Fragment %main "main"
589 OpExecutionMode %main OriginLowerLeft
590 )" + kVoidFunction;
591
592 spv_target_env env = SPV_ENV_VULKAN_1_0;
593 CompileSuccessfully(spirv, env);
594 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
595 EXPECT_THAT(getDiagnosticString(),
596 AnyVUID("VUID-StandaloneSpirv-OriginLowerLeft-04653"));
597 EXPECT_THAT(getDiagnosticString(),
598 HasSubstr("In the Vulkan environment, the OriginLowerLeft "
599 "execution mode must not be used."));
600 }
601
602 TEST_F(ValidateMode, FragmentPixelCenterIntegerVulkan) {
603 const std::string spirv = R"(
604 OpCapability Shader
605 OpMemoryModel Logical GLSL450
606 OpEntryPoint Fragment %main "main"
607 OpExecutionMode %main OriginUpperLeft
608 OpExecutionMode %main PixelCenterInteger
609 )" + kVoidFunction;
610
611 spv_target_env env = SPV_ENV_VULKAN_1_0;
612 CompileSuccessfully(spirv, env);
613 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
614 EXPECT_THAT(getDiagnosticString(),
615 AnyVUID("VUID-StandaloneSpirv-PixelCenterInteger-04654"));
616 EXPECT_THAT(getDiagnosticString(),
617 HasSubstr("In the Vulkan environment, the PixelCenterInteger "
618 "execution mode must not be used."));
619 }
620
621 TEST_F(ValidateMode, GeometryNoOutputMode) {
622 const std::string spirv = R"(
623 OpCapability Geometry
624 OpMemoryModel Logical GLSL450
625 OpEntryPoint Geometry %main "main"
626 OpExecutionMode %main InputPoints
627 )" + kVoidFunction;
628
629 CompileSuccessfully(spirv);
630 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
631 EXPECT_THAT(getDiagnosticString(),
632 HasSubstr("Geometry execution model entry points must specify "
633 "exactly one of OutputPoints, OutputLineStrip or "
634 "OutputTriangleStrip execution modes."));
635 }
636
637 TEST_F(ValidateMode, GeometryNoInputMode) {
638 const std::string spirv = R"(
639 OpCapability Geometry
640 OpMemoryModel Logical GLSL450
641 OpEntryPoint Geometry %main "main"
642 OpExecutionMode %main OutputPoints
643 )" + kVoidFunction;
644
645 CompileSuccessfully(spirv);
646 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
647 EXPECT_THAT(
648 getDiagnosticString(),
649 HasSubstr("Geometry execution model entry points must specify exactly "
650 "one of InputPoints, InputLines, InputLinesAdjacency, "
651 "Triangles or InputTrianglesAdjacency execution modes."));
652 }
653
654 TEST_F(ValidateMode, FragmentNoOrigin) {
655 const std::string spirv = R"(
656 OpCapability Shader
657 OpMemoryModel Logical GLSL450
658 OpEntryPoint Fragment %main "main"
659 )" + kVoidFunction;
660
661 CompileSuccessfully(spirv);
662 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
663 EXPECT_THAT(
664 getDiagnosticString(),
665 HasSubstr("Fragment execution model entry points require either an "
666 "OriginUpperLeft or OriginLowerLeft execution mode."));
667 }
668
669 TEST_F(ValidateMode, FragmentBothOrigins) {
670 const std::string spirv = R"(
671 OpCapability Shader
672 OpMemoryModel Logical GLSL450
673 OpEntryPoint Fragment %main "main"
674 OpExecutionMode %main OriginUpperLeft
675 OpExecutionMode %main OriginLowerLeft
676 )" + kVoidFunction;
677
678 CompileSuccessfully(spirv);
679 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
680 EXPECT_THAT(
681 getDiagnosticString(),
682 HasSubstr("Fragment execution model entry points can only specify one of "
683 "OriginUpperLeft or OriginLowerLeft execution modes."));
684 }
685
686 TEST_F(ValidateMode, FragmentDepthGreaterAndLess) {
687 const std::string spirv = R"(
688 OpCapability Shader
689 OpMemoryModel Logical GLSL450
690 OpEntryPoint Fragment %main "main"
691 OpExecutionMode %main OriginUpperLeft
692 OpExecutionMode %main DepthGreater
693 OpExecutionMode %main DepthLess
694 )" + kVoidFunction;
695
696 CompileSuccessfully(spirv);
697 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
698 EXPECT_THAT(getDiagnosticString(),
699 HasSubstr("Fragment execution model entry points can specify at "
700 "most one of DepthGreater, DepthLess or DepthUnchanged "
701 "execution modes."));
702 }
703
704 TEST_F(ValidateMode, FragmentDepthGreaterAndUnchanged) {
705 const std::string spirv = R"(
706 OpCapability Shader
707 OpMemoryModel Logical GLSL450
708 OpEntryPoint Fragment %main "main"
709 OpExecutionMode %main OriginUpperLeft
710 OpExecutionMode %main DepthGreater
711 OpExecutionMode %main DepthUnchanged
712 )" + kVoidFunction;
713
714 CompileSuccessfully(spirv);
715 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
716 EXPECT_THAT(getDiagnosticString(),
717 HasSubstr("Fragment execution model entry points can specify at "
718 "most one of DepthGreater, DepthLess or DepthUnchanged "
719 "execution modes."));
720 }
721
722 TEST_F(ValidateMode, FragmentDepthLessAndUnchanged) {
723 const std::string spirv = R"(
724 OpCapability Shader
725 OpMemoryModel Logical GLSL450
726 OpEntryPoint Fragment %main "main"
727 OpExecutionMode %main OriginUpperLeft
728 OpExecutionMode %main DepthLess
729 OpExecutionMode %main DepthUnchanged
730 )" + kVoidFunction;
731
732 CompileSuccessfully(spirv);
733 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
734 EXPECT_THAT(getDiagnosticString(),
735 HasSubstr("Fragment execution model entry points can specify at "
736 "most one of DepthGreater, DepthLess or DepthUnchanged "
737 "execution modes."));
738 }
739
740 TEST_F(ValidateMode, FragmentAllDepths) {
741 const std::string spirv = R"(
742 OpCapability Shader
743 OpMemoryModel Logical GLSL450
744 OpEntryPoint Fragment %main "main"
745 OpExecutionMode %main OriginUpperLeft
746 OpExecutionMode %main DepthGreater
747 OpExecutionMode %main DepthLess
748 OpExecutionMode %main DepthUnchanged
749 )" + kVoidFunction;
750
751 CompileSuccessfully(spirv);
752 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
753 EXPECT_THAT(getDiagnosticString(),
754 HasSubstr("Fragment execution model entry points can specify at "
755 "most one of DepthGreater, DepthLess or DepthUnchanged "
756 "execution modes."));
757 }
758
759 TEST_F(ValidateMode, TessellationControlSpacingEqualAndFractionalOdd) {
760 const std::string spirv = R"(
761 OpCapability Tessellation
762 OpMemoryModel Logical GLSL450
763 OpEntryPoint TessellationControl %main "main"
764 OpExecutionMode %main SpacingEqual
765 OpExecutionMode %main SpacingFractionalOdd
766 )" + kVoidFunction;
767
768 CompileSuccessfully(spirv);
769 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
770 EXPECT_THAT(getDiagnosticString(),
771 HasSubstr("Tessellation execution model entry points can specify "
772 "at most one of SpacingEqual, SpacingFractionalOdd or "
773 "SpacingFractionalEven execution modes."));
774 }
775
776 TEST_F(ValidateMode, TessellationControlSpacingEqualAndSpacingFractionalEven) {
777 const std::string spirv = R"(
778 OpCapability Tessellation
779 OpMemoryModel Logical GLSL450
780 OpEntryPoint TessellationControl %main "main"
781 OpExecutionMode %main SpacingEqual
782 OpExecutionMode %main SpacingFractionalEven
783 )" + kVoidFunction;
784
785 CompileSuccessfully(spirv);
786 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
787 EXPECT_THAT(getDiagnosticString(),
788 HasSubstr("Tessellation execution model entry points can specify "
789 "at most one of SpacingEqual, SpacingFractionalOdd or "
790 "SpacingFractionalEven execution modes."));
791 }
792
793 TEST_F(ValidateMode,
794 TessellationControlSpacingFractionalOddAndSpacingFractionalEven) {
795 const std::string spirv = R"(
796 OpCapability Tessellation
797 OpMemoryModel Logical GLSL450
798 OpEntryPoint TessellationControl %main "main"
799 OpExecutionMode %main SpacingFractionalOdd
800 OpExecutionMode %main SpacingFractionalEven
801 )" + kVoidFunction;
802
803 CompileSuccessfully(spirv);
804 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
805 EXPECT_THAT(getDiagnosticString(),
806 HasSubstr("Tessellation execution model entry points can specify "
807 "at most one of SpacingEqual, SpacingFractionalOdd or "
808 "SpacingFractionalEven execution modes."));
809 }
810
811 TEST_F(ValidateMode, TessellationControlAllSpacing) {
812 const std::string spirv = R"(
813 OpCapability Tessellation
814 OpMemoryModel Logical GLSL450
815 OpEntryPoint TessellationControl %main "main"
816 OpExecutionMode %main SpacingEqual
817 OpExecutionMode %main SpacingFractionalOdd
818 OpExecutionMode %main SpacingFractionalEven
819 )" + kVoidFunction;
820
821 CompileSuccessfully(spirv);
822 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
823 EXPECT_THAT(getDiagnosticString(),
824 HasSubstr("Tessellation execution model entry points can specify "
825 "at most one of SpacingEqual, SpacingFractionalOdd or "
826 "SpacingFractionalEven execution modes."));
827 }
828
829 TEST_F(ValidateMode,
830 TessellationEvaluationSpacingEqualAndSpacingFractionalOdd) {
831 const std::string spirv = R"(
832 OpCapability Tessellation
833 OpMemoryModel Logical GLSL450
834 OpEntryPoint TessellationEvaluation %main "main"
835 OpExecutionMode %main SpacingEqual
836 OpExecutionMode %main SpacingFractionalOdd
837 )" + kVoidFunction;
838
839 CompileSuccessfully(spirv);
840 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
841 EXPECT_THAT(getDiagnosticString(),
842 HasSubstr("Tessellation execution model entry points can specify "
843 "at most one of SpacingEqual, SpacingFractionalOdd or "
844 "SpacingFractionalEven execution modes."));
845 }
846
847 TEST_F(ValidateMode,
848 TessellationEvaluationSpacingEqualAndSpacingFractionalEven) {
849 const std::string spirv = R"(
850 OpCapability Tessellation
851 OpMemoryModel Logical GLSL450
852 OpEntryPoint TessellationEvaluation %main "main"
853 OpExecutionMode %main SpacingEqual
854 OpExecutionMode %main SpacingFractionalEven
855 )" + kVoidFunction;
856
857 CompileSuccessfully(spirv);
858 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
859 EXPECT_THAT(getDiagnosticString(),
860 HasSubstr("Tessellation execution model entry points can specify "
861 "at most one of SpacingEqual, SpacingFractionalOdd or "
862 "SpacingFractionalEven execution modes."));
863 }
864
865 TEST_F(ValidateMode,
866 TessellationEvaluationSpacingFractionalOddAndSpacingFractionalEven) {
867 const std::string spirv = R"(
868 OpCapability Tessellation
869 OpMemoryModel Logical GLSL450
870 OpEntryPoint TessellationEvaluation %main "main"
871 OpExecutionMode %main SpacingFractionalOdd
872 OpExecutionMode %main SpacingFractionalEven
873 )" + kVoidFunction;
874
875 CompileSuccessfully(spirv);
876 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
877 EXPECT_THAT(getDiagnosticString(),
878 HasSubstr("Tessellation execution model entry points can specify "
879 "at most one of SpacingEqual, SpacingFractionalOdd or "
880 "SpacingFractionalEven execution modes."));
881 }
882
883 TEST_F(ValidateMode, TessellationEvaluationAllSpacing) {
884 const std::string spirv = R"(
885 OpCapability Tessellation
886 OpMemoryModel Logical GLSL450
887 OpEntryPoint TessellationEvaluation %main "main"
888 OpExecutionMode %main SpacingEqual
889 OpExecutionMode %main SpacingFractionalOdd
890 OpExecutionMode %main SpacingFractionalEven
891 )" + kVoidFunction;
892
893 CompileSuccessfully(spirv);
894 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
895 EXPECT_THAT(getDiagnosticString(),
896 HasSubstr("Tessellation execution model entry points can specify "
897 "at most one of SpacingEqual, SpacingFractionalOdd or "
898 "SpacingFractionalEven execution modes."));
899 }
900
901 TEST_F(ValidateMode, TessellationControlBothVertex) {
902 const std::string spirv = R"(
903 OpCapability Tessellation
904 OpMemoryModel Logical GLSL450
905 OpEntryPoint TessellationControl %main "main"
906 OpExecutionMode %main VertexOrderCw
907 OpExecutionMode %main VertexOrderCcw
908 )" + kVoidFunction;
909
910 CompileSuccessfully(spirv);
911 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
912 EXPECT_THAT(
913 getDiagnosticString(),
914 HasSubstr("Tessellation execution model entry points can specify at most "
915 "one of VertexOrderCw or VertexOrderCcw execution modes."));
916 }
917
918 TEST_F(ValidateMode, TessellationEvaluationBothVertex) {
919 const std::string spirv = R"(
920 OpCapability Tessellation
921 OpMemoryModel Logical GLSL450
922 OpEntryPoint TessellationEvaluation %main "main"
923 OpExecutionMode %main VertexOrderCw
924 OpExecutionMode %main VertexOrderCcw
925 )" + kVoidFunction;
926
927 CompileSuccessfully(spirv);
928 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
929 EXPECT_THAT(
930 getDiagnosticString(),
931 HasSubstr("Tessellation execution model entry points can specify at most "
932 "one of VertexOrderCw or VertexOrderCcw execution modes."));
933 }
934
935 using ValidateModeGeometry = spvtest::ValidateBase<std::tuple<
936 std::tuple<std::string, std::string, std::string, std::string, std::string>,
937 std::tuple<std::string, std::string, std::string>>>;
938
939 TEST_P(ValidateModeGeometry, ExecutionMode) {
940 std::vector<std::string> input_modes;
941 std::vector<std::string> output_modes;
942 input_modes.push_back(std::get<0>(std::get<0>(GetParam())));
943 input_modes.push_back(std::get<1>(std::get<0>(GetParam())));
944 input_modes.push_back(std::get<2>(std::get<0>(GetParam())));
945 input_modes.push_back(std::get<3>(std::get<0>(GetParam())));
946 input_modes.push_back(std::get<4>(std::get<0>(GetParam())));
947 output_modes.push_back(std::get<0>(std::get<1>(GetParam())));
948 output_modes.push_back(std::get<1>(std::get<1>(GetParam())));
949 output_modes.push_back(std::get<2>(std::get<1>(GetParam())));
950
951 std::ostringstream sstr;
952 sstr << "OpCapability Geometry\n";
953 sstr << "OpMemoryModel Logical GLSL450\n";
954 sstr << "OpEntryPoint Geometry %main \"main\"\n";
955 size_t num_input_modes = 0;
956 for (auto input : input_modes) {
957 if (!input.empty()) {
958 num_input_modes++;
959 sstr << "OpExecutionMode %main " << input << "\n";
960 }
961 }
962 size_t num_output_modes = 0;
963 for (auto output : output_modes) {
964 if (!output.empty()) {
965 num_output_modes++;
966 sstr << "OpExecutionMode %main " << output << "\n";
967 }
968 }
969 sstr << "%void = OpTypeVoid\n";
970 sstr << "%void_fn = OpTypeFunction %void\n";
971 sstr << "%int = OpTypeInt 32 0\n";
972 sstr << "%int1 = OpConstant %int 1\n";
973 sstr << "%main = OpFunction %void None %void_fn\n";
974 sstr << "%entry = OpLabel\n";
975 sstr << "OpReturn\n";
976 sstr << "OpFunctionEnd\n";
977
978 CompileSuccessfully(sstr.str());
979 if (num_input_modes == 1 && num_output_modes == 1) {
980 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
981 } else {
982 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
983 if (num_input_modes != 1) {
984 EXPECT_THAT(getDiagnosticString(),
985 HasSubstr("Geometry execution model entry points must "
986 "specify exactly one of InputPoints, InputLines, "
987 "InputLinesAdjacency, Triangles or "
988 "InputTrianglesAdjacency execution modes."));
989 } else {
990 EXPECT_THAT(
991 getDiagnosticString(),
992 HasSubstr("Geometry execution model entry points must specify "
993 "exactly one of OutputPoints, OutputLineStrip or "
994 "OutputTriangleStrip execution modes."));
995 }
996 }
997 }
998
999 INSTANTIATE_TEST_SUITE_P(
1000 GeometryRequiredModes, ValidateModeGeometry,
1001 Combine(Combine(Values("InputPoints", ""), Values("InputLines", ""),
1002 Values("InputLinesAdjacency", ""), Values("Triangles", ""),
1003 Values("InputTrianglesAdjacency", "")),
1004 Combine(Values("OutputPoints", ""), Values("OutputLineStrip", ""),
1005 Values("OutputTriangleStrip", ""))));
1006
1007 using ValidateModeExecution =
1008 spvtest::ValidateBase<std::tuple<spv_result_t, std::string, std::string,
1009 std::string, spv_target_env>>;
1010
1011 TEST_P(ValidateModeExecution, ExecutionMode) {
1012 const spv_result_t expectation = std::get<0>(GetParam());
1013 const std::string error = std::get<1>(GetParam());
1014 const std::string model = std::get<2>(GetParam());
1015 const std::string mode = std::get<3>(GetParam());
1016 const spv_target_env env = std::get<4>(GetParam());
1017
1018 std::ostringstream sstr;
1019 sstr << "OpCapability Shader\n";
1020 sstr << "OpCapability Geometry\n";
1021 sstr << "OpCapability Tessellation\n";
1022 sstr << "OpCapability TransformFeedback\n";
1023 if (!spvIsVulkanEnv(env)) {
1024 sstr << "OpCapability Kernel\n";
1025 if (env == SPV_ENV_UNIVERSAL_1_3) {
1026 sstr << "OpCapability SubgroupDispatch\n";
1027 } else if (env == SPV_ENV_UNIVERSAL_1_5) {
1028 sstr << "OpCapability TileImageColorReadAccessEXT\n";
1029 sstr << "OpCapability TileImageDepthReadAccessEXT\n";
1030 sstr << "OpCapability TileImageStencilReadAccessEXT\n";
1031 sstr << "OpExtension \"SPV_EXT_shader_tile_image\"\n";
1032 }
1033 }
1034 sstr << "OpMemoryModel Logical GLSL450\n";
1035 sstr << "OpEntryPoint " << model << " %main \"main\"\n";
1036 if (mode.find("LocalSizeId") == 0 || mode.find("LocalSizeHintId") == 0 ||
1037 mode.find("SubgroupsPerWorkgroupId") == 0) {
1038 sstr << "OpExecutionModeId %main " << mode << "\n";
1039 } else {
1040 sstr << "OpExecutionMode %main " << mode << "\n";
1041 }
1042 if (model == "Geometry") {
1043 if (!(mode.find("InputPoints") == 0 || mode.find("InputLines") == 0 ||
1044 mode.find("InputLinesAdjacency") == 0 ||
1045 mode.find("Triangles") == 0 ||
1046 mode.find("InputTrianglesAdjacency") == 0)) {
1047 // Exactly one of the above modes is required for Geometry shaders.
1048 sstr << "OpExecutionMode %main InputPoints\n";
1049 }
1050 if (!(mode.find("OutputPoints") == 0 || mode.find("OutputLineStrip") == 0 ||
1051 mode.find("OutputTriangleStrip") == 0)) {
1052 // Exactly one of the above modes is required for Geometry shaders.
1053 sstr << "OpExecutionMode %main OutputPoints\n";
1054 }
1055 } else if (model == "Fragment") {
1056 if (!(mode.find("OriginUpperLeft") == 0 ||
1057 mode.find("OriginLowerLeft") == 0)) {
1058 // Exactly one of the above modes is required for Fragment shaders.
1059 sstr << "OpExecutionMode %main OriginUpperLeft\n";
1060 }
1061 }
1062 sstr << "%void = OpTypeVoid\n";
1063 sstr << "%void_fn = OpTypeFunction %void\n";
1064 sstr << "%int = OpTypeInt 32 0\n";
1065 sstr << "%int1 = OpConstant %int 1\n";
1066 sstr << "%main = OpFunction %void None %void_fn\n";
1067 sstr << "%entry = OpLabel\n";
1068 sstr << "OpReturn\n";
1069 sstr << "OpFunctionEnd\n";
1070
1071 CompileSuccessfully(sstr.str(), env);
1072 EXPECT_THAT(expectation, ValidateInstructions(env));
1073 if (expectation != SPV_SUCCESS) {
1074 EXPECT_THAT(getDiagnosticString(), HasSubstr(error));
1075 }
1076 }
1077
1078 INSTANTIATE_TEST_SUITE_P(
1079 ValidateModeGeometryOnlyGoodSpv10, ValidateModeExecution,
1080 Combine(Values(SPV_SUCCESS), Values(""), Values("Geometry"),
1081 Values("Invocations 3", "InputPoints", "InputLines",
1082 "InputLinesAdjacency", "InputTrianglesAdjacency",
1083 "OutputPoints", "OutputLineStrip", "OutputTriangleStrip"),
1084 Values(SPV_ENV_UNIVERSAL_1_0)));
1085
1086 INSTANTIATE_TEST_SUITE_P(
1087 ValidateModeGeometryOnlyBadSpv10, ValidateModeExecution,
1088 Combine(Values(SPV_ERROR_INVALID_DATA),
1089 Values("Execution mode can only be used with the Geometry "
1090 "execution model."),
1091 Values("Fragment", "TessellationEvaluation", "TessellationControl",
1092 "GLCompute", "Vertex", "Kernel"),
1093 Values("Invocations 3", "InputPoints", "InputLines",
1094 "InputLinesAdjacency", "InputTrianglesAdjacency",
1095 "OutputPoints", "OutputLineStrip", "OutputTriangleStrip"),
1096 Values(SPV_ENV_UNIVERSAL_1_0)));
1097
1098 INSTANTIATE_TEST_SUITE_P(
1099 ValidateModeTessellationOnlyGoodSpv10, ValidateModeExecution,
1100 Combine(Values(SPV_SUCCESS), Values(""),
1101 Values("TessellationControl", "TessellationEvaluation"),
1102 Values("SpacingEqual", "SpacingFractionalEven",
1103 "SpacingFractionalOdd", "VertexOrderCw", "VertexOrderCcw",
1104 "PointMode", "Quads", "Isolines"),
1105 Values(SPV_ENV_UNIVERSAL_1_0)));
1106
1107 INSTANTIATE_TEST_SUITE_P(
1108 ValidateModeTessellationOnlyBadSpv10, ValidateModeExecution,
1109 Combine(Values(SPV_ERROR_INVALID_DATA),
1110 Values("Execution mode can only be used with a tessellation "
1111 "execution model."),
1112 Values("Fragment", "Geometry", "GLCompute", "Vertex", "Kernel"),
1113 Values("SpacingEqual", "SpacingFractionalEven",
1114 "SpacingFractionalOdd", "VertexOrderCw", "VertexOrderCcw",
1115 "PointMode", "Quads", "Isolines"),
1116 Values(SPV_ENV_UNIVERSAL_1_0)));
1117
1118 INSTANTIATE_TEST_SUITE_P(ValidateModeGeometryAndTessellationGoodSpv10,
1119 ValidateModeExecution,
1120 Combine(Values(SPV_SUCCESS), Values(""),
1121 Values("TessellationControl",
1122 "TessellationEvaluation", "Geometry"),
1123 Values("Triangles", "OutputVertices 3"),
1124 Values(SPV_ENV_UNIVERSAL_1_0)));
1125
1126 INSTANTIATE_TEST_SUITE_P(
1127 ValidateModeGeometryAndTessellationBadSpv10, ValidateModeExecution,
1128 Combine(Values(SPV_ERROR_INVALID_DATA),
1129 Values("Execution mode can only be used with a Geometry or "
1130 "tessellation execution model."),
1131 Values("Fragment", "GLCompute", "Vertex", "Kernel"),
1132 Values("Triangles", "OutputVertices 3"),
1133 Values(SPV_ENV_UNIVERSAL_1_0)));
1134
1135 INSTANTIATE_TEST_SUITE_P(
1136 ValidateModeFragmentOnlyGoodSpv10, ValidateModeExecution,
1137 Combine(Values(SPV_SUCCESS), Values(""), Values("Fragment"),
1138 Values("PixelCenterInteger", "OriginUpperLeft", "OriginLowerLeft",
1139 "EarlyFragmentTests", "DepthReplacing", "DepthLess",
1140 "DepthUnchanged"),
1141 Values(SPV_ENV_UNIVERSAL_1_0)));
1142
1143 INSTANTIATE_TEST_SUITE_P(
1144 ValidateModeFragmentOnlyBadSpv10, ValidateModeExecution,
1145 Combine(Values(SPV_ERROR_INVALID_DATA),
1146 Values("Execution mode can only be used with the Fragment "
1147 "execution model."),
1148 Values("Geometry", "TessellationControl", "TessellationEvaluation",
1149 "GLCompute", "Vertex", "Kernel"),
1150 Values("PixelCenterInteger", "OriginUpperLeft", "OriginLowerLeft",
1151 "EarlyFragmentTests", "DepthReplacing", "DepthGreater",
1152 "DepthLess", "DepthUnchanged"),
1153 Values(SPV_ENV_UNIVERSAL_1_0)));
1154
1155 INSTANTIATE_TEST_SUITE_P(ValidateModeFragmentOnlyGoodSpv15,
1156 ValidateModeExecution,
1157 Combine(Values(SPV_SUCCESS), Values(""),
1158 Values("Fragment"),
1159 Values("NonCoherentColorAttachmentReadEXT",
1160 "NonCoherentDepthAttachmentReadEXT",
1161 "NonCoherentStencilAttachmentReadEXT"),
1162 Values(SPV_ENV_UNIVERSAL_1_5)));
1163
1164 INSTANTIATE_TEST_SUITE_P(
1165 ValidateModeFragmentOnlyBadSpv15, ValidateModeExecution,
1166 Combine(Values(SPV_ERROR_INVALID_DATA),
1167 Values("Execution mode can only be used with the Fragment "
1168 "execution model."),
1169 Values("Geometry", "TessellationControl", "TessellationEvaluation",
1170 "GLCompute", "Vertex", "Kernel"),
1171 Values("NonCoherentColorAttachmentReadEXT",
1172 "NonCoherentDepthAttachmentReadEXT",
1173 "NonCoherentStencilAttachmentReadEXT"),
1174 Values(SPV_ENV_UNIVERSAL_1_5)));
1175
1176 INSTANTIATE_TEST_SUITE_P(ValidateModeKernelOnlyGoodSpv13, ValidateModeExecution,
1177 Combine(Values(SPV_SUCCESS), Values(""),
1178 Values("Kernel"),
1179 Values("LocalSizeHint 1 1 1", "VecTypeHint 4",
1180 "ContractionOff",
1181 "LocalSizeHintId %int1 %int1 %int1"),
1182 Values(SPV_ENV_UNIVERSAL_1_3)));
1183
1184 INSTANTIATE_TEST_SUITE_P(
1185 ValidateModeKernelOnlyBadSpv13, ValidateModeExecution,
1186 Combine(
1187 Values(SPV_ERROR_INVALID_DATA),
1188 Values(
1189 "Execution mode can only be used with the Kernel execution model."),
1190 Values("Geometry", "TessellationControl", "TessellationEvaluation",
1191 "GLCompute", "Vertex", "Fragment"),
1192 Values("LocalSizeHint 1 1 1", "VecTypeHint 4", "ContractionOff",
1193 "LocalSizeHintId %int1 %int1 %int1"),
1194 Values(SPV_ENV_UNIVERSAL_1_3)));
1195
1196 INSTANTIATE_TEST_SUITE_P(
1197 ValidateModeGLComputeAndKernelGoodSpv13, ValidateModeExecution,
1198 Combine(Values(SPV_SUCCESS), Values(""), Values("Kernel", "GLCompute"),
1199 Values("LocalSize 1 1 1", "LocalSizeId %int1 %int1 %int1"),
1200 Values(SPV_ENV_UNIVERSAL_1_3)));
1201
1202 INSTANTIATE_TEST_SUITE_P(
1203 ValidateModeGLComputeAndKernelBadSpv13, ValidateModeExecution,
1204 Combine(Values(SPV_ERROR_INVALID_DATA),
1205 Values("Execution mode can only be used with a Kernel or GLCompute "
1206 "execution model."),
1207 Values("Geometry", "TessellationControl", "TessellationEvaluation",
1208 "Fragment", "Vertex"),
1209 Values("LocalSize 1 1 1", "LocalSizeId %int1 %int1 %int1"),
1210 Values(SPV_ENV_UNIVERSAL_1_3)));
1211
1212 INSTANTIATE_TEST_SUITE_P(
1213 ValidateModeAllGoodSpv13, ValidateModeExecution,
1214 Combine(Values(SPV_SUCCESS), Values(""),
1215 Values("Kernel", "GLCompute", "Geometry", "TessellationControl",
1216 "TessellationEvaluation", "Fragment", "Vertex"),
1217 Values("Xfb", "Initializer", "Finalizer", "SubgroupSize 1",
1218 "SubgroupsPerWorkgroup 1", "SubgroupsPerWorkgroupId %int1"),
1219 Values(SPV_ENV_UNIVERSAL_1_3)));
1220
1221 TEST_F(ValidateModeExecution, MeshNVLocalSize) {
1222 const std::string spirv = R"(
1223 OpCapability Shader
1224 OpCapability MeshShadingNV
1225 OpExtension "SPV_NV_mesh_shader"
1226 OpMemoryModel Logical GLSL450
1227 OpEntryPoint MeshNV %main "main"
1228 OpExecutionMode %main LocalSize 1 1 1
1229 )" + kVoidFunction;
1230
1231 CompileSuccessfully(spirv);
1232 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1233 }
1234
1235 TEST_F(ValidateModeExecution, TaskNVLocalSize) {
1236 const std::string spirv = R"(
1237 OpCapability Shader
1238 OpCapability MeshShadingNV
1239 OpExtension "SPV_NV_mesh_shader"
1240 OpMemoryModel Logical GLSL450
1241 OpEntryPoint TaskNV %main "main"
1242 OpExecutionMode %main LocalSize 1 1 1
1243 )" + kVoidFunction;
1244
1245 CompileSuccessfully(spirv);
1246 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1247 }
1248
1249 TEST_F(ValidateModeExecution, MeshNVOutputPoints) {
1250 const std::string spirv = R"(
1251 OpCapability Shader
1252 OpCapability MeshShadingNV
1253 OpExtension "SPV_NV_mesh_shader"
1254 OpMemoryModel Logical GLSL450
1255 OpEntryPoint MeshNV %main "main"
1256 OpExecutionMode %main OutputPoints
1257 )" + kVoidFunction;
1258
1259 CompileSuccessfully(spirv);
1260 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1261 }
1262
1263 TEST_F(ValidateModeExecution, MeshEXTOutputVertices) {
1264 const std::string spirv = R"(
1265 OpCapability MeshShadingEXT
1266 OpExtension "SPV_EXT_mesh_shader"
1267 %1 = OpExtInstImport "GLSL.std.450"
1268 OpMemoryModel Logical GLSL450
1269 OpEntryPoint MeshEXT %main "main"
1270 OpExecutionMode %main LocalSize 1 1 1
1271 OpExecutionMode %main OutputVertices 3
1272 OpExecutionMode %main OutputPrimitivesNV 1
1273 OpExecutionMode %main OutputTrianglesNV
1274 OpSource GLSL 460
1275 OpSourceExtension "GL_EXT_mesh_shader"
1276 OpName %main "main"
1277 OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
1278 %void = OpTypeVoid
1279 %3 = OpTypeFunction %void
1280 %uint = OpTypeInt 32 0
1281 %uint_3 = OpConstant %uint 3
1282 %uint_1 = OpConstant %uint 1
1283 %v3uint = OpTypeVector %uint 3
1284 %gl_WorkGroupSize = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
1285 %main = OpFunction %void None %3
1286 %5 = OpLabel
1287 OpSetMeshOutputsEXT %uint_3 %uint_1
1288 OpReturn
1289 OpFunctionEnd
1290 )";
1291
1292 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
1293 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
1294 }
1295
1296 TEST_F(ValidateModeExecution, VulkanBadMeshEXTOutputVertices) {
1297 const std::string spirv = R"(
1298 OpCapability MeshShadingEXT
1299 OpExtension "SPV_EXT_mesh_shader"
1300 %1 = OpExtInstImport "GLSL.std.450"
1301 OpMemoryModel Logical GLSL450
1302 OpEntryPoint MeshEXT %main "main"
1303 OpExecutionMode %main LocalSize 1 1 1
1304 OpExecutionMode %main OutputVertices 0
1305 OpExecutionMode %main OutputPrimitivesNV 1
1306 OpExecutionMode %main OutputTrianglesNV
1307 OpSource GLSL 460
1308 OpSourceExtension "GL_EXT_mesh_shader"
1309 OpName %main "main"
1310 OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
1311 %void = OpTypeVoid
1312 %3 = OpTypeFunction %void
1313 %uint = OpTypeInt 32 0
1314 %uint_3 = OpConstant %uint 3
1315 %uint_1 = OpConstant %uint 1
1316 %v3uint = OpTypeVector %uint 3
1317 %gl_WorkGroupSize = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
1318 %main = OpFunction %void None %3
1319 %5 = OpLabel
1320 OpSetMeshOutputsEXT %uint_3 %uint_1
1321 OpReturn
1322 OpFunctionEnd
1323 )";
1324
1325 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_2);
1326 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_2));
1327 EXPECT_THAT(getDiagnosticString(),
1328 AnyVUID("VUID-StandaloneSpirv-MeshEXT-07330"));
1329 }
1330
1331 TEST_F(ValidateModeExecution, VulkanBadMeshEXTOutputOutputPrimitivesEXT) {
1332 const std::string spirv = R"(
1333 OpCapability MeshShadingEXT
1334 OpExtension "SPV_EXT_mesh_shader"
1335 %1 = OpExtInstImport "GLSL.std.450"
1336 OpMemoryModel Logical GLSL450
1337 OpEntryPoint MeshEXT %main "main"
1338 OpExecutionMode %main LocalSize 1 1 1
1339 OpExecutionMode %main OutputVertices 1
1340 OpExecutionMode %main OutputPrimitivesNV 0
1341 OpExecutionMode %main OutputTrianglesNV
1342 OpSource GLSL 460
1343 OpSourceExtension "GL_EXT_mesh_shader"
1344 OpName %main "main"
1345 OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
1346 %void = OpTypeVoid
1347 %3 = OpTypeFunction %void
1348 %uint = OpTypeInt 32 0
1349 %uint_3 = OpConstant %uint 3
1350 %uint_1 = OpConstant %uint 1
1351 %v3uint = OpTypeVector %uint 3
1352 %gl_WorkGroupSize = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
1353 %main = OpFunction %void None %3
1354 %5 = OpLabel
1355 OpSetMeshOutputsEXT %uint_3 %uint_1
1356 OpReturn
1357 OpFunctionEnd
1358 )";
1359
1360 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_2);
1361 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_2));
1362 EXPECT_THAT(getDiagnosticString(),
1363 AnyVUID("VUID-StandaloneSpirv-MeshEXT-07331"));
1364 }
1365
1366 TEST_F(ValidateModeExecution, MeshNVOutputVertices) {
1367 const std::string spirv = R"(
1368 OpCapability Shader
1369 OpCapability MeshShadingNV
1370 OpExtension "SPV_NV_mesh_shader"
1371 OpMemoryModel Logical GLSL450
1372 OpEntryPoint MeshNV %main "main"
1373 OpExecutionMode %main OutputVertices 42
1374 )" + kVoidFunction;
1375
1376 CompileSuccessfully(spirv);
1377 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1378 }
1379
1380 TEST_F(ValidateModeExecution, MeshNVLocalSizeId) {
1381 const std::string spirv = R"(
1382 OpCapability Shader
1383 OpCapability MeshShadingNV
1384 OpExtension "SPV_NV_mesh_shader"
1385 OpMemoryModel Logical GLSL450
1386 OpEntryPoint MeshNV %main "main"
1387 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
1388 %int = OpTypeInt 32 0
1389 %int_1 = OpConstant %int 1
1390 )" + kVoidFunction;
1391
1392 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1393 CompileSuccessfully(spirv, env);
1394 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
1395 }
1396
1397 TEST_F(ValidateModeExecution, TaskNVLocalSizeId) {
1398 const std::string spirv = R"(
1399 OpCapability Shader
1400 OpCapability MeshShadingNV
1401 OpExtension "SPV_NV_mesh_shader"
1402 OpMemoryModel Logical GLSL450
1403 OpEntryPoint TaskNV %main "main"
1404 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
1405 %int = OpTypeInt 32 0
1406 %int_1 = OpConstant %int 1
1407 )" + kVoidFunction;
1408
1409 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1410 CompileSuccessfully(spirv, env);
1411 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
1412 }
1413
1414 TEST_F(ValidateModeExecution, ExecModeSubgroupsPerWorkgroupIdBad) {
1415 const std::string spirv = R"(
1416 OpCapability Shader
1417 OpCapability SubgroupDispatch
1418 OpMemoryModel Logical GLSL450
1419 OpEntryPoint Vertex %main "main"
1420 OpExecutionMode %main SubgroupsPerWorkgroupId %int_1
1421 %int = OpTypeInt 32 0
1422 %int_1 = OpConstant %int 1
1423 )" + kVoidFunction;
1424
1425 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1426 CompileSuccessfully(spirv, env);
1427 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
1428 EXPECT_THAT(getDiagnosticString(),
1429 HasSubstr("OpExecutionMode is only valid when the Mode operand "
1430 "is an execution mode that takes no Extra Operands"));
1431 }
1432
1433 TEST_F(ValidateModeExecution, ExecModeIdSubgroupsPerWorkgroupIdGood) {
1434 const std::string spirv = R"(
1435 OpCapability Shader
1436 OpCapability SubgroupDispatch
1437 OpMemoryModel Logical GLSL450
1438 OpEntryPoint Vertex %main "main"
1439 OpExecutionModeId %main SubgroupsPerWorkgroupId %int_1
1440 %int = OpTypeInt 32 0
1441 %int_1 = OpConstant %int 1
1442 )" + kVoidFunction;
1443
1444 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1445 CompileSuccessfully(spirv, env);
1446 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
1447 }
1448
1449 TEST_F(ValidateModeExecution, ExecModeIdSubgroupsPerWorkgroupIdNonConstantBad) {
1450 const std::string spirv = R"(
1451 OpCapability Shader
1452 OpCapability SubgroupDispatch
1453 OpMemoryModel Logical GLSL450
1454 OpEntryPoint Vertex %main "main"
1455 OpExecutionModeId %main SubgroupsPerWorkgroupId %int_1
1456 %int = OpTypeInt 32 0
1457 %int_ptr = OpTypePointer Private %int
1458 %int_1 = OpVariable %int_ptr Private
1459 )" + kVoidFunction;
1460
1461 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1462 CompileSuccessfully(spirv, env);
1463 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
1464 EXPECT_THAT(getDiagnosticString(),
1465 HasSubstr("For OpExecutionModeId all Extra Operand ids must be "
1466 "constant instructions."));
1467 }
1468
1469 TEST_F(ValidateModeExecution, ExecModeLocalSizeHintIdBad) {
1470 const std::string spirv = R"(
1471 OpCapability Kernel
1472 OpCapability Shader
1473 OpMemoryModel Logical GLSL450
1474 OpEntryPoint Kernel %main "main"
1475 OpExecutionMode %main LocalSizeHintId %int_1 %int_1 %int_1
1476 %int = OpTypeInt 32 0
1477 %int_1 = OpConstant %int 1
1478 )" + kVoidFunction;
1479
1480 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1481 CompileSuccessfully(spirv, env);
1482 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
1483 EXPECT_THAT(getDiagnosticString(),
1484 HasSubstr("OpExecutionMode is only valid when the Mode operand "
1485 "is an execution mode that takes no Extra Operands"));
1486 }
1487
1488 TEST_F(ValidateModeExecution, ExecModeIdLocalSizeHintIdGood) {
1489 const std::string spirv = R"(
1490 OpCapability Kernel
1491 OpCapability Shader
1492 OpMemoryModel Logical GLSL450
1493 OpEntryPoint Kernel %main "main"
1494 OpExecutionModeId %main LocalSizeHintId %int_1 %int_1 %int_1
1495 %int = OpTypeInt 32 0
1496 %int_1 = OpConstant %int 1
1497 )" + kVoidFunction;
1498
1499 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1500 CompileSuccessfully(spirv, env);
1501 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
1502 }
1503
1504 TEST_F(ValidateModeExecution, ExecModeIdLocalSizeHintIdNonConstantBad) {
1505 const std::string spirv = R"(
1506 OpCapability Kernel
1507 OpCapability Shader
1508 OpMemoryModel Logical GLSL450
1509 OpEntryPoint Vertex %main "main"
1510 OpExecutionModeId %main LocalSizeHintId %int_1 %int_1 %int_1
1511 %int = OpTypeInt 32 0
1512 %int_ptr = OpTypePointer Private %int
1513 %int_1 = OpVariable %int_ptr Private
1514 )" + kVoidFunction;
1515
1516 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1517 CompileSuccessfully(spirv, env);
1518 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
1519 EXPECT_THAT(getDiagnosticString(),
1520 HasSubstr("For OpExecutionModeId all Extra Operand ids must be "
1521 "constant instructions."));
1522 }
1523
1524 TEST_F(ValidateModeExecution, ExecModeLocalSizeIdBad) {
1525 const std::string spirv = R"(
1526 OpCapability Kernel
1527 OpCapability Shader
1528 OpMemoryModel Logical GLSL450
1529 OpEntryPoint Kernel %main "main"
1530 OpExecutionMode %main LocalSizeId %int_1 %int_1 %int_1
1531 %int = OpTypeInt 32 0
1532 %int_1 = OpConstant %int 1
1533 )" + kVoidFunction;
1534
1535 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1536 CompileSuccessfully(spirv, env);
1537 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
1538 EXPECT_THAT(getDiagnosticString(),
1539 HasSubstr("OpExecutionMode is only valid when the Mode operand "
1540 "is an execution mode that takes no Extra Operands"));
1541 }
1542
1543 TEST_F(ValidateModeExecution, ExecModeIdLocalSizeIdGood) {
1544 const std::string spirv = R"(
1545 OpCapability Kernel
1546 OpCapability Shader
1547 OpMemoryModel Logical GLSL450
1548 OpEntryPoint Kernel %main "main"
1549 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
1550 %int = OpTypeInt 32 0
1551 %int_1 = OpConstant %int 1
1552 )" + kVoidFunction;
1553
1554 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1555 CompileSuccessfully(spirv, env);
1556 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
1557 }
1558
1559 TEST_F(ValidateModeExecution, ExecModeIdLocalSizeIdNonConstantBad) {
1560 const std::string spirv = R"(
1561 OpCapability Kernel
1562 OpCapability Shader
1563 OpMemoryModel Logical GLSL450
1564 OpEntryPoint Vertex %main "main"
1565 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
1566 %int = OpTypeInt 32 0
1567 %int_ptr = OpTypePointer Private %int
1568 %int_1 = OpVariable %int_ptr Private
1569 )" + kVoidFunction;
1570
1571 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
1572 CompileSuccessfully(spirv, env);
1573 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
1574 EXPECT_THAT(getDiagnosticString(),
1575 HasSubstr("For OpExecutionModeId all Extra Operand ids must be "
1576 "constant instructions."));
1577 }
1578
1579 using AllowMultipleExecutionModes = spvtest::ValidateBase<std::string>;
1580
1581 TEST_P(AllowMultipleExecutionModes, DifferentOperand) {
1582 const std::string mode = GetParam();
1583 const std::string spirv = R"(
1584 OpCapability Shader
1585 OpCapability DenormPreserve
1586 OpCapability DenormFlushToZero
1587 OpCapability SignedZeroInfNanPreserve
1588 OpCapability RoundingModeRTE
1589 OpCapability RoundingModeRTZ
1590 OpExtension "SPV_KHR_float_controls"
1591 OpMemoryModel Logical GLSL450
1592 OpEntryPoint GLCompute %main "main"
1593 OpExecutionMode %main LocalSize 1 1 1
1594 OpExecutionMode %main )" + mode +
1595 R"( 16
1596 OpExecutionMode %main )" + mode +
1597 R"( 32
1598 %void = OpTypeVoid
1599 %void_fn = OpTypeFunction %void
1600 %main = OpFunction %void None %void_fn
1601 %entry = OpLabel
1602 OpReturn
1603 OpFunctionEnd
1604 )";
1605
1606 CompileSuccessfully(spirv);
1607 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1608 }
1609
1610 TEST_P(AllowMultipleExecutionModes, SameOperand) {
1611 const std::string mode = GetParam();
1612 const std::string spirv = R"(
1613 OpCapability Shader
1614 OpCapability DenormPreserve
1615 OpCapability DenormFlushToZero
1616 OpCapability SignedZeroInfNanPreserve
1617 OpCapability RoundingModeRTE
1618 OpCapability RoundingModeRTZ
1619 OpExtension "SPV_KHR_float_controls"
1620 OpMemoryModel Logical GLSL450
1621 OpEntryPoint GLCompute %main "main"
1622 OpExecutionMode %main LocalSize 1 1 1
1623 OpExecutionMode %main )" + mode +
1624 R"( 32
1625 OpExecutionMode %main )" + mode +
1626 R"( 32
1627 %void = OpTypeVoid
1628 %void_fn = OpTypeFunction %void
1629 %main = OpFunction %void None %void_fn
1630 %entry = OpLabel
1631 OpReturn
1632 OpFunctionEnd
1633 )";
1634
1635 CompileSuccessfully(spirv);
1636 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1637 EXPECT_THAT(getDiagnosticString(),
1638 HasSubstr("execution mode must not be specified multiple times "
1639 "for the same entry point and operands"));
1640 }
1641
1642 INSTANTIATE_TEST_SUITE_P(MultipleFloatControlsExecModes,
1643 AllowMultipleExecutionModes,
1644 Values("DenormPreserve", "DenormFlushToZero",
1645 "SignedZeroInfNanPreserve", "RoundingModeRTE",
1646 "RoundingModeRTZ"));
1647
1648 using MultipleExecModes = spvtest::ValidateBase<std::string>;
1649
1650 TEST_P(MultipleExecModes, DuplicateMode) {
1651 const std::string mode = GetParam();
1652 const std::string spirv = R"(
1653 OpCapability Shader
1654 OpMemoryModel Logical GLSL450
1655 OpEntryPoint Fragment %main "main"
1656 OpExecutionMode %main OriginUpperLeft
1657 OpExecutionMode %main )" + mode +
1658 R"(
1659 OpExecutionMode %main )" + mode +
1660 R"(
1661 %void = OpTypeVoid
1662 %void_fn = OpTypeFunction %void
1663 %main = OpFunction %void None %void_fn
1664 %entry = OpLabel
1665 OpReturn
1666 OpFunctionEnd
1667 )";
1668
1669 CompileSuccessfully(spirv);
1670 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
1671 EXPECT_THAT(getDiagnosticString(),
1672 HasSubstr("execution mode must not be specified multiple times "
1673 "per entry point"));
1674 }
1675
1676 INSTANTIATE_TEST_SUITE_P(MultipleFragmentExecMode, MultipleExecModes,
1677 Values("DepthReplacing", "DepthGreater", "DepthLess",
1678 "DepthUnchanged"));
1679
1680 TEST_F(ValidateMode, FloatControls2FPFastMathDefaultSameOperand) {
1681 const std::string spirv = R"(
1682 OpCapability Shader
1683 OpCapability FloatControls2
1684 OpExtension "SPV_KHR_float_controls2"
1685 OpMemoryModel Logical GLSL450
1686 OpEntryPoint GLCompute %main "main"
1687 OpExecutionMode %main LocalSize 1 1 1
1688 OpExecutionModeId %main FPFastMathDefault %float %none
1689 OpExecutionModeId %main FPFastMathDefault %float %none
1690 %void = OpTypeVoid
1691 %float = OpTypeFloat 32
1692 %int = OpTypeInt 32 0
1693 %none = OpConstant %int 0
1694 %void_fn = OpTypeFunction %void
1695 %main = OpFunction %void None %void_fn
1696 %entry = OpLabel
1697 OpReturn
1698 OpFunctionEnd
1699 )";
1700
1701 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_2);
1702 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_2));
1703 EXPECT_THAT(getDiagnosticString(),
1704 HasSubstr("execution mode must not be specified multiple times "
1705 "for the same entry point and operands"));
1706 }
1707
1708 TEST_F(ValidateMode, FloatControls2FPFastMathDefaultDifferentOperand) {
1709 const std::string spirv = R"(
1710 OpCapability Shader
1711 OpCapability Float16
1712 OpCapability FloatControls2
1713 OpExtension "SPV_KHR_float_controls2"
1714 OpMemoryModel Logical GLSL450
1715 OpEntryPoint GLCompute %main "main"
1716 OpExecutionMode %main LocalSize 1 1 1
1717 OpExecutionModeId %main FPFastMathDefault %float %none
1718 OpExecutionModeId %main FPFastMathDefault %half %none
1719 %void = OpTypeVoid
1720 %float = OpTypeFloat 32
1721 %int = OpTypeInt 32 0
1722 %none = OpConstant %int 0
1723 %half = OpTypeFloat 16
1724 %void_fn = OpTypeFunction %void
1725 %main = OpFunction %void None %void_fn
1726 %entry = OpLabel
1727 OpReturn
1728 OpFunctionEnd
1729 )";
1730
1731 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_2);
1732 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_2));
1733 }
1734
1735 TEST_F(ValidateMode, FragmentShaderInterlockVertexBad) {
1736 const std::string spirv = R"(
1737 OpCapability Shader
1738 OpCapability FragmentShaderPixelInterlockEXT
1739 OpExtension "SPV_EXT_fragment_shader_interlock"
1740 OpMemoryModel Logical GLSL450
1741 OpEntryPoint Vertex %main "main"
1742 OpExecutionMode %main PixelInterlockOrderedEXT
1743 )" + kVoidFunction;
1744
1745 CompileSuccessfully(spirv);
1746 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1747 EXPECT_THAT(
1748 getDiagnosticString(),
1749 HasSubstr(
1750 "Execution mode can only be used with the Fragment execution model"));
1751 }
1752
1753 TEST_F(ValidateMode, FragmentShaderInterlockTooManyModesBad) {
1754 const std::string spirv = R"(
1755 OpCapability Shader
1756 OpCapability FragmentShaderPixelInterlockEXT
1757 OpCapability FragmentShaderSampleInterlockEXT
1758 OpExtension "SPV_EXT_fragment_shader_interlock"
1759 OpMemoryModel Logical GLSL450
1760 OpEntryPoint Fragment %main "main"
1761 OpExecutionMode %main OriginUpperLeft
1762 OpExecutionMode %main PixelInterlockOrderedEXT
1763 OpExecutionMode %main SampleInterlockOrderedEXT
1764 )" + kVoidFunction;
1765
1766 CompileSuccessfully(spirv);
1767 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1768 EXPECT_THAT(
1769 getDiagnosticString(),
1770 HasSubstr("Fragment execution model entry points can specify at most "
1771 "one fragment shader interlock execution mode"));
1772 }
1773
1774 TEST_F(ValidateMode, FragmentShaderInterlockNoModeBad) {
1775 const std::string spirv = R"(
1776 OpCapability Shader
1777 OpCapability FragmentShaderPixelInterlockEXT
1778 OpExtension "SPV_EXT_fragment_shader_interlock"
1779 OpMemoryModel Logical GLSL450
1780 OpEntryPoint Fragment %main "main"
1781 OpExecutionMode %main OriginUpperLeft
1782 %void = OpTypeVoid
1783 %void_fn = OpTypeFunction %void
1784 %func = OpFunction %void None %void_fn
1785 %entryf = OpLabel
1786 OpBeginInvocationInterlockEXT
1787 OpEndInvocationInterlockEXT
1788 OpReturn
1789 OpFunctionEnd
1790 %main = OpFunction %void None %void_fn
1791 %entry = OpLabel
1792 %1 = OpFunctionCall %void %func
1793 OpReturn
1794 OpFunctionEnd
1795 )";
1796
1797 CompileSuccessfully(spirv);
1798 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions());
1799 EXPECT_THAT(
1800 getDiagnosticString(),
1801 HasSubstr(
1802 "OpBeginInvocationInterlockEXT/OpEndInvocationInterlockEXT require a "
1803 "fragment shader interlock execution mode"));
1804 }
1805
1806 TEST_F(ValidateMode, FragmentShaderInterlockGood) {
1807 const std::string spirv = R"(
1808 OpCapability Shader
1809 OpCapability FragmentShaderPixelInterlockEXT
1810 OpExtension "SPV_EXT_fragment_shader_interlock"
1811 OpMemoryModel Logical GLSL450
1812 OpEntryPoint Fragment %main "main"
1813 OpExecutionMode %main OriginUpperLeft
1814 OpExecutionMode %main PixelInterlockOrderedEXT
1815 %void = OpTypeVoid
1816 %void_fn = OpTypeFunction %void
1817 %func = OpFunction %void None %void_fn
1818 %entryf = OpLabel
1819 OpBeginInvocationInterlockEXT
1820 OpEndInvocationInterlockEXT
1821 OpReturn
1822 OpFunctionEnd
1823 %main = OpFunction %void None %void_fn
1824 %entry = OpLabel
1825 %1 = OpFunctionCall %void %func
1826 OpReturn
1827 OpFunctionEnd
1828 )";
1829
1830 CompileSuccessfully(spirv);
1831 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1832 }
1833
1834 TEST_F(ValidateMode, FragmentShaderStencilRefFrontTooManyModesBad) {
1835 const std::string spirv = R"(
1836 OpCapability Shader
1837 OpCapability StencilExportEXT
1838 OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
1839 OpExtension "SPV_EXT_shader_stencil_export"
1840 OpMemoryModel Logical GLSL450
1841 OpEntryPoint Fragment %main "main"
1842 OpExecutionMode %main OriginUpperLeft
1843 OpExecutionMode %main EarlyAndLateFragmentTestsAMD
1844 OpExecutionMode %main StencilRefLessFrontAMD
1845 OpExecutionMode %main StencilRefGreaterFrontAMD
1846 )" + kVoidFunction;
1847
1848 CompileSuccessfully(spirv);
1849 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1850 EXPECT_THAT(
1851 getDiagnosticString(),
1852 HasSubstr("Fragment execution model entry points can specify at most "
1853 "one of StencilRefUnchangedFrontAMD, "
1854 "StencilRefLessFrontAMD or StencilRefGreaterFrontAMD "
1855 "execution modes."));
1856 }
1857
1858 TEST_F(ValidateMode, FragmentShaderStencilRefBackTooManyModesBad) {
1859 const std::string spirv = R"(
1860 OpCapability Shader
1861 OpCapability StencilExportEXT
1862 OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
1863 OpExtension "SPV_EXT_shader_stencil_export"
1864 OpMemoryModel Logical GLSL450
1865 OpEntryPoint Fragment %main "main"
1866 OpExecutionMode %main OriginUpperLeft
1867 OpExecutionMode %main EarlyAndLateFragmentTestsAMD
1868 OpExecutionMode %main StencilRefLessBackAMD
1869 OpExecutionMode %main StencilRefGreaterBackAMD
1870 )" + kVoidFunction;
1871
1872 CompileSuccessfully(spirv);
1873 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1874 EXPECT_THAT(
1875 getDiagnosticString(),
1876 HasSubstr("Fragment execution model entry points can specify at most "
1877 "one of StencilRefUnchangedBackAMD, "
1878 "StencilRefLessBackAMD or StencilRefGreaterBackAMD "
1879 "execution modes."));
1880 }
1881
1882 TEST_F(ValidateMode, FragmentShaderStencilRefFrontGood) {
1883 const std::string spirv = R"(
1884 OpCapability Shader
1885 OpCapability StencilExportEXT
1886 OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
1887 OpExtension "SPV_EXT_shader_stencil_export"
1888 OpMemoryModel Logical GLSL450
1889 OpEntryPoint Fragment %main "main"
1890 OpExecutionMode %main OriginUpperLeft
1891 OpExecutionMode %main EarlyAndLateFragmentTestsAMD
1892 OpExecutionMode %main StencilRefLessFrontAMD
1893 )" + kVoidFunction;
1894
1895 CompileSuccessfully(spirv);
1896 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1897 }
1898
1899 TEST_F(ValidateMode, FragmentShaderStencilRefBackGood) {
1900 const std::string spirv = R"(
1901 OpCapability Shader
1902 OpCapability StencilExportEXT
1903 OpExtension "SPV_AMD_shader_early_and_late_fragment_tests"
1904 OpExtension "SPV_EXT_shader_stencil_export"
1905 OpMemoryModel Logical GLSL450
1906 OpEntryPoint Fragment %main "main"
1907 OpExecutionMode %main OriginUpperLeft
1908 OpExecutionMode %main EarlyAndLateFragmentTestsAMD
1909 OpExecutionMode %main StencilRefLessBackAMD
1910 )" + kVoidFunction;
1911
1912 CompileSuccessfully(spirv);
1913 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1914 }
1915
1916 TEST_F(ValidateMode, FragmentShaderDemoteVertexBad) {
1917 const std::string spirv = R"(
1918 OpCapability Shader
1919 OpCapability DemoteToHelperInvocationEXT
1920 OpExtension "SPV_EXT_demote_to_helper_invocation"
1921 OpMemoryModel Logical GLSL450
1922 OpEntryPoint Vertex %main "main"
1923 %bool = OpTypeBool
1924 %void = OpTypeVoid
1925 %void_fn = OpTypeFunction %void
1926 %main = OpFunction %void None %void_fn
1927 %entry = OpLabel
1928 OpDemoteToHelperInvocationEXT
1929 %1 = OpIsHelperInvocationEXT %bool
1930 OpReturn
1931 OpFunctionEnd
1932 )";
1933
1934 CompileSuccessfully(spirv);
1935 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions());
1936 EXPECT_THAT(
1937 getDiagnosticString(),
1938 HasSubstr(
1939 "OpDemoteToHelperInvocationEXT requires Fragment execution model"));
1940 EXPECT_THAT(
1941 getDiagnosticString(),
1942 HasSubstr("OpIsHelperInvocationEXT requires Fragment execution model"));
1943 }
1944
1945 TEST_F(ValidateMode, FragmentShaderDemoteGood) {
1946 const std::string spirv = R"(
1947 OpCapability Shader
1948 OpCapability DemoteToHelperInvocationEXT
1949 OpExtension "SPV_EXT_demote_to_helper_invocation"
1950 OpMemoryModel Logical GLSL450
1951 OpEntryPoint Fragment %main "main"
1952 OpExecutionMode %main OriginUpperLeft
1953 %bool = OpTypeBool
1954 %void = OpTypeVoid
1955 %void_fn = OpTypeFunction %void
1956 %main = OpFunction %void None %void_fn
1957 %entry = OpLabel
1958 OpDemoteToHelperInvocationEXT
1959 %1 = OpIsHelperInvocationEXT %bool
1960 OpReturn
1961 OpFunctionEnd
1962 )";
1963
1964 CompileSuccessfully(spirv);
1965 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions());
1966 }
1967
1968 TEST_F(ValidateMode, FragmentShaderDemoteBadType) {
1969 const std::string spirv = R"(
1970 OpCapability Shader
1971 OpCapability DemoteToHelperInvocationEXT
1972 OpExtension "SPV_EXT_demote_to_helper_invocation"
1973 OpMemoryModel Logical GLSL450
1974 OpEntryPoint Fragment %main "main"
1975 OpExecutionMode %main OriginUpperLeft
1976 %u32 = OpTypeInt 32 0
1977 %void = OpTypeVoid
1978 %void_fn = OpTypeFunction %void
1979 %main = OpFunction %void None %void_fn
1980 %entry = OpLabel
1981 OpDemoteToHelperInvocationEXT
1982 %1 = OpIsHelperInvocationEXT %u32
1983 OpReturn
1984 OpFunctionEnd
1985 )";
1986
1987 CompileSuccessfully(spirv);
1988 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1989 EXPECT_THAT(getDiagnosticString(),
1990 HasSubstr("Expected bool scalar type as Result Type"));
1991 }
1992
1993 TEST_F(ValidateMode, LocalSizeIdVulkan1p3DoesNotRequireOption) {
1994 const std::string spirv = R"(
1995 OpCapability Shader
1996 OpMemoryModel Logical GLSL450
1997 OpEntryPoint GLCompute %main "main"
1998 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
1999 %void = OpTypeVoid
2000 %int = OpTypeInt 32 0
2001 %int_1 = OpConstant %int 1
2002 %void_fn = OpTypeFunction %void
2003 %main = OpFunction %void None %void_fn
2004 %entry = OpLabel
2005 OpReturn
2006 OpFunctionEnd
2007 )";
2008
2009 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_3);
2010 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
2011 }
2012
2013 TEST_F(ValidateMode, MaximalReconvergenceRequiresExtension) {
2014 const std::string spirv = R"(
2015 OpCapability Shader
2016 OpMemoryModel Logical GLSL450
2017 OpEntryPoint GLCompute %main "main"
2018 OpExecutionMode %main LocalSize 1 1 1
2019 OpExecutionMode %main MaximallyReconvergesKHR
2020 %void = OpTypeVoid
2021 %void_fn = OpTypeFunction %void
2022 %main = OpFunction %void None %void_fn
2023 %entry = OpLabel
2024 OpReturn
2025 OpFunctionEnd
2026 )";
2027
2028 CompileSuccessfully(spirv);
2029 EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION, ValidateInstructions());
2030 EXPECT_THAT(getDiagnosticString(),
2031 HasSubstr("(6023) requires one of these extensions: "
2032 "SPV_KHR_maximal_reconvergence "));
2033 }
2034
2035 TEST_F(ValidateMode, FPFastMathDefaultNotExecutionModeId) {
2036 const std::string spirv = R"(
2037 OpCapability Shader
2038 OpCapability FloatControls2
2039 OpExtension "SPV_KHR_float_controls2"
2040 OpMemoryModel Logical GLSL450
2041 OpEntryPoint GLCompute %main "main"
2042 OpExecutionMode %main LocalSize 1 1 1
2043 OpExecutionMode %main FPFastMathDefault %int_0 %int_0
2044 %void = OpTypeVoid
2045 %int = OpTypeInt 32 0
2046 %int_0 = OpConstant %int 0
2047 %void_fn = OpTypeFunction %void
2048 %main = OpFunction %void None %void_fn
2049 %entry = OpLabel
2050 OpReturn
2051 OpFunctionEnd
2052 )";
2053
2054 CompileSuccessfully(spirv);
2055 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
2056 EXPECT_THAT(getDiagnosticString(),
2057 HasSubstr("OpExecutionMode is only valid when the Mode operand "
2058 "is an execution mode that takes no Extra Operands, or "
2059 "takes Extra Operands that are not id operands"));
2060 }
2061
2062 TEST_F(ValidateMode, FPFastMathDefaultNotAType) {
2063 const std::string spirv = R"(
2064 OpCapability Shader
2065 OpCapability FloatControls2
2066 OpExtension "SPV_KHR_float_controls2"
2067 OpMemoryModel Logical GLSL450
2068 OpEntryPoint GLCompute %main "main"
2069 OpExecutionMode %main LocalSize 1 1 1
2070 OpExecutionModeId %main FPFastMathDefault %int_0 %int_0
2071 %void = OpTypeVoid
2072 %int = OpTypeInt 32 0
2073 %int_0 = OpConstant %int 0
2074 %void_fn = OpTypeFunction %void
2075 %main = OpFunction %void None %void_fn
2076 %entry = OpLabel
2077 OpReturn
2078 OpFunctionEnd
2079 )";
2080
2081 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2082 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2083 EXPECT_THAT(
2084 getDiagnosticString(),
2085 HasSubstr(
2086 "The Target Type operand must be a floating-point scalar type"));
2087 }
2088
2089 TEST_F(ValidateMode, FPFastMathDefaultNotAFloatType) {
2090 const std::string spirv = R"(
2091 OpCapability Shader
2092 OpCapability FloatControls2
2093 OpExtension "SPV_KHR_float_controls2"
2094 OpMemoryModel Logical GLSL450
2095 OpEntryPoint GLCompute %main "main"
2096 OpExecutionMode %main LocalSize 1 1 1
2097 OpExecutionModeId %main FPFastMathDefault %int %int_0
2098 %void = OpTypeVoid
2099 %int = OpTypeInt 32 0
2100 %int_0 = OpConstant %int 0
2101 %void_fn = OpTypeFunction %void
2102 %main = OpFunction %void None %void_fn
2103 %entry = OpLabel
2104 OpReturn
2105 OpFunctionEnd
2106 )";
2107
2108 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2109 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2110 EXPECT_THAT(
2111 getDiagnosticString(),
2112 HasSubstr(
2113 "The Target Type operand must be a floating-point scalar type"));
2114 }
2115
2116 TEST_F(ValidateMode, FPFastMathDefaultNotAFloatScalarType) {
2117 const std::string spirv = R"(
2118 OpCapability Shader
2119 OpCapability FloatControls2
2120 OpExtension "SPV_KHR_float_controls2"
2121 OpMemoryModel Logical GLSL450
2122 OpEntryPoint GLCompute %main "main"
2123 OpExecutionMode %main LocalSize 1 1 1
2124 OpExecutionModeId %main FPFastMathDefault %float2 %int_0
2125 %void = OpTypeVoid
2126 %int = OpTypeInt 32 0
2127 %int_0 = OpConstant %int 0
2128 %float = OpTypeFloat 32
2129 %float2 = OpTypeVector %float 2
2130 %void_fn = OpTypeFunction %void
2131 %main = OpFunction %void None %void_fn
2132 %entry = OpLabel
2133 OpReturn
2134 OpFunctionEnd
2135 )";
2136
2137 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2138 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2139 EXPECT_THAT(
2140 getDiagnosticString(),
2141 HasSubstr(
2142 "The Target Type operand must be a floating-point scalar type"));
2143 }
2144
2145 TEST_F(ValidateMode, FPFastMathDefaultSpecConstant) {
2146 const std::string spirv = R"(
2147 OpCapability Shader
2148 OpCapability FloatControls2
2149 OpExtension "SPV_KHR_float_controls2"
2150 OpMemoryModel Logical GLSL450
2151 OpEntryPoint GLCompute %main "main"
2152 OpExecutionMode %main LocalSize 1 1 1
2153 OpExecutionModeId %main FPFastMathDefault %float %int_0
2154 %void = OpTypeVoid
2155 %int = OpTypeInt 32 0
2156 %int_0 = OpSpecConstant %int 0
2157 %float = OpTypeFloat 32
2158 %void_fn = OpTypeFunction %void
2159 %main = OpFunction %void None %void_fn
2160 %entry = OpLabel
2161 OpReturn
2162 OpFunctionEnd
2163 )";
2164
2165 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2166 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2167 EXPECT_THAT(getDiagnosticString(),
2168 HasSubstr("The Fast Math Default operand must be a "
2169 "non-specialization constant"));
2170 }
2171
2172 TEST_F(ValidateMode, FPFastMathDefaultInvalidMask) {
2173 const std::string spirv = R"(
2174 OpCapability Shader
2175 OpCapability FloatControls2
2176 OpExtension "SPV_KHR_float_controls2"
2177 OpMemoryModel Logical GLSL450
2178 OpEntryPoint GLCompute %main "main"
2179 OpExecutionMode %main LocalSize 1 1 1
2180 OpExecutionModeId %main FPFastMathDefault %float %constant
2181 %void = OpTypeVoid
2182 %int = OpTypeInt 32 0
2183 %constant = OpConstant %int 524288
2184 %float = OpTypeFloat 32
2185 %void_fn = OpTypeFunction %void
2186 %main = OpFunction %void None %void_fn
2187 %entry = OpLabel
2188 OpReturn
2189 OpFunctionEnd
2190 )";
2191
2192 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2193 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2194 EXPECT_THAT(
2195 getDiagnosticString(),
2196 HasSubstr("The Fast Math Default operand is an invalid bitmask value"));
2197 }
2198
2199 TEST_F(ValidateMode, FPFastMathDefaultContainsFast) {
2200 const std::string spirv = R"(
2201 OpCapability Shader
2202 OpCapability FloatControls2
2203 OpExtension "SPV_KHR_float_controls2"
2204 OpMemoryModel Logical GLSL450
2205 OpEntryPoint GLCompute %main "main"
2206 OpExecutionMode %main LocalSize 1 1 1
2207 OpExecutionModeId %main FPFastMathDefault %float %constant
2208 %void = OpTypeVoid
2209 %int = OpTypeInt 32 0
2210 %constant = OpConstant %int 16
2211 %float = OpTypeFloat 32
2212 %void_fn = OpTypeFunction %void
2213 %main = OpFunction %void None %void_fn
2214 %entry = OpLabel
2215 OpReturn
2216 OpFunctionEnd
2217 )";
2218
2219 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2220 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2221 EXPECT_THAT(getDiagnosticString(),
2222 HasSubstr("The Fast Math Default operand must not include Fast"));
2223 }
2224
2225 TEST_F(ValidateMode, FPFastMathDefaultAllowTransformMissingAllowReassoc) {
2226 const std::string spirv = R"(
2227 OpCapability Shader
2228 OpCapability FloatControls2
2229 OpExtension "SPV_KHR_float_controls2"
2230 OpMemoryModel Logical GLSL450
2231 OpEntryPoint GLCompute %main "main"
2232 OpExecutionMode %main LocalSize 1 1 1
2233 OpExecutionModeId %main FPFastMathDefault %float %constant
2234 %void = OpTypeVoid
2235 %int = OpTypeInt 32 0
2236 %constant = OpConstant %int 327680
2237 %float = OpTypeFloat 32
2238 %void_fn = OpTypeFunction %void
2239 %main = OpFunction %void None %void_fn
2240 %entry = OpLabel
2241 OpReturn
2242 OpFunctionEnd
2243 )";
2244
2245 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2246 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2247 EXPECT_THAT(
2248 getDiagnosticString(),
2249 HasSubstr("The Fast Math Default operand must include AllowContract and "
2250 "AllowReassoc when AllowTransform is specified"));
2251 }
2252
2253 TEST_F(ValidateMode, FPFastMathDefaultAllowTransformMissingAllowContract) {
2254 const std::string spirv = R"(
2255 OpCapability Shader
2256 OpCapability FloatControls2
2257 OpExtension "SPV_KHR_float_controls2"
2258 OpMemoryModel Logical GLSL450
2259 OpEntryPoint GLCompute %main "main"
2260 OpExecutionMode %main LocalSize 1 1 1
2261 OpExecutionModeId %main FPFastMathDefault %float %constant
2262 %void = OpTypeVoid
2263 %int = OpTypeInt 32 0
2264 %constant = OpConstant %int 393216
2265 %float = OpTypeFloat 32
2266 %void_fn = OpTypeFunction %void
2267 %main = OpFunction %void None %void_fn
2268 %entry = OpLabel
2269 OpReturn
2270 OpFunctionEnd
2271 )";
2272
2273 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2274 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2275 EXPECT_THAT(
2276 getDiagnosticString(),
2277 HasSubstr("The Fast Math Default operand must include AllowContract and "
2278 "AllowReassoc when AllowTransform is specified"));
2279 }
2280
2281 TEST_F(ValidateMode, FPFastMathDefaultAllowTransformMissingContractAndReassoc) {
2282 const std::string spirv = R"(
2283 OpCapability Shader
2284 OpCapability FloatControls2
2285 OpExtension "SPV_KHR_float_controls2"
2286 OpMemoryModel Logical GLSL450
2287 OpEntryPoint GLCompute %main "main"
2288 OpExecutionMode %main LocalSize 1 1 1
2289 OpExecutionModeId %main FPFastMathDefault %float %constant
2290 %void = OpTypeVoid
2291 %int = OpTypeInt 32 0
2292 %constant = OpConstant %int 262144
2293 %float = OpTypeFloat 32
2294 %void_fn = OpTypeFunction %void
2295 %main = OpFunction %void None %void_fn
2296 %entry = OpLabel
2297 OpReturn
2298 OpFunctionEnd
2299 )";
2300
2301 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2302 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2303 EXPECT_THAT(
2304 getDiagnosticString(),
2305 HasSubstr("The Fast Math Default operand must include AllowContract and "
2306 "AllowReassoc when AllowTransform is specified"));
2307 }
2308
2309 TEST_F(ValidateMode, FPFastMathDefaultSignedZeroInfNanPreserve) {
2310 const std::string spirv = R"(
2311 OpCapability Shader
2312 OpCapability FloatControls2
2313 OpCapability SignedZeroInfNanPreserve
2314 OpExtension "SPV_KHR_float_controls2"
2315 OpExtension "SPV_KHR_float_controls"
2316 OpMemoryModel Logical GLSL450
2317 OpEntryPoint GLCompute %main "main"
2318 OpExecutionMode %main LocalSize 1 1 1
2319 OpExecutionModeId %main FPFastMathDefault %float %constant
2320 OpExecutionMode %main SignedZeroInfNanPreserve 32
2321 %void = OpTypeVoid
2322 %int = OpTypeInt 32 0
2323 %constant = OpConstant %int 0
2324 %float = OpTypeFloat 32
2325 %void_fn = OpTypeFunction %void
2326 %main = OpFunction %void None %void_fn
2327 %entry = OpLabel
2328 OpReturn
2329 OpFunctionEnd
2330 )";
2331
2332 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2333 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2334 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2335 EXPECT_THAT(
2336 getDiagnosticString(),
2337 HasSubstr("FPFastMathDefault and SignedZeroInfNanPreserve execution "
2338 "modes cannot be applied to the same entry point"));
2339 }
2340
2341 TEST_F(ValidateMode, FPFastMathDefaultConractionOff) {
2342 const std::string spirv = R"(
2343 OpCapability Kernel
2344 OpCapability Addresses
2345 OpCapability FloatControls2
2346 OpCapability SignedZeroInfNanPreserve
2347 OpExtension "SPV_KHR_float_controls2"
2348 OpExtension "SPV_KHR_float_controls"
2349 OpMemoryModel Physical64 OpenCL
2350 OpEntryPoint Kernel %main "main"
2351 OpExecutionModeId %main FPFastMathDefault %float %constant
2352 OpExecutionMode %main ContractionOff
2353 %void = OpTypeVoid
2354 %int = OpTypeInt 32 0
2355 %constant = OpConstant %int 0
2356 %float = OpTypeFloat 32
2357 %void_fn = OpTypeFunction %void
2358 %main = OpFunction %void None %void_fn
2359 %entry = OpLabel
2360 OpReturn
2361 OpFunctionEnd
2362 )";
2363
2364 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2365 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2366 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2367 EXPECT_THAT(getDiagnosticString(),
2368 HasSubstr("FPFastMathDefault and ContractionOff execution modes "
2369 "cannot be applied to the same entry point"));
2370 }
2371
2372 TEST_F(ValidateMode, FPFastMathDefaultNoContractionNotInCallTree) {
2373 const std::string spirv = R"(
2374 OpCapability Shader
2375 OpCapability FloatControls2
2376 OpExtension "SPV_KHR_float_controls2"
2377 OpMemoryModel Logical GLSL450
2378 OpEntryPoint GLCompute %main "main"
2379 OpExecutionModeId %main FPFastMathDefault %float %constant
2380 OpExecutionMode %main LocalSize 1 1 1
2381 OpDecorate %add NoContraction
2382 %void = OpTypeVoid
2383 %int = OpTypeInt 32 0
2384 %constant = OpConstant %int 0
2385 %float = OpTypeFloat 32
2386 %zero = OpConstant %float 0
2387 %void_fn = OpTypeFunction %void
2388 %main = OpFunction %void None %void_fn
2389 %entry = OpLabel
2390 OpReturn
2391 OpFunctionEnd
2392 %func = OpFunction %void None %void_fn
2393 %func_entry = OpLabel
2394 %add = OpFAdd %float %zero %zero
2395 OpReturn
2396 OpFunctionEnd
2397 )";
2398
2399 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2400 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2401 }
2402
2403 TEST_F(ValidateMode, FPFastMathDefaultNoContractionInCallTree) {
2404 const std::string spirv = R"(
2405 OpCapability Shader
2406 OpCapability FloatControls2
2407 OpExtension "SPV_KHR_float_controls2"
2408 OpMemoryModel Logical GLSL450
2409 OpEntryPoint GLCompute %main "main"
2410 OpExecutionModeId %main FPFastMathDefault %float %constant
2411 OpExecutionMode %main LocalSize 1 1 1
2412 OpDecorate %add NoContraction
2413 %void = OpTypeVoid
2414 %int = OpTypeInt 32 0
2415 %constant = OpConstant %int 0
2416 %float = OpTypeFloat 32
2417 %zero = OpConstant %float 0
2418 %void_fn = OpTypeFunction %void
2419 %main = OpFunction %void None %void_fn
2420 %entry = OpLabel
2421 %call = OpFunctionCall %void %func
2422 OpReturn
2423 OpFunctionEnd
2424 %func = OpFunction %void None %void_fn
2425 %func_entry = OpLabel
2426 %add = OpFAdd %float %zero %zero
2427 OpReturn
2428 OpFunctionEnd
2429 )";
2430
2431 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2432 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2433 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2434 EXPECT_THAT(getDiagnosticString(),
2435 HasSubstr("NoContraction cannot be used by an entry point with "
2436 "the FPFastMathDefault execution mode"));
2437 }
2438
2439 TEST_F(ValidateMode, FPFastMathDefaultNoContractionInCallTree2) {
2440 const std::string spirv = R"(
2441 OpCapability Shader
2442 OpCapability Kernel
2443 OpCapability Addresses
2444 OpCapability FloatControls2
2445 OpExtension "SPV_KHR_float_controls2"
2446 OpMemoryModel Physical64 OpenCL
2447 OpEntryPoint Kernel %main "main"
2448 OpExecutionModeId %main FPFastMathDefault %float %constant
2449 OpDecorate %const NoContraction
2450 %void = OpTypeVoid
2451 %int = OpTypeInt 32 0
2452 %constant = OpConstant %int 0
2453 %float = OpTypeFloat 32
2454 %zero = OpConstant %float 0
2455 %const = OpSpecConstantOp %float FAdd %zero %zero
2456 %void_fn = OpTypeFunction %void
2457 %main = OpFunction %void None %void_fn
2458 %entry = OpLabel
2459 %call = OpFunctionCall %void %func
2460 OpReturn
2461 OpFunctionEnd
2462 %func = OpFunction %void None %void_fn
2463 %func_entry = OpLabel
2464 %add = OpFAdd %float %const %zero
2465 OpReturn
2466 OpFunctionEnd
2467 )";
2468
2469 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2470 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2471 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2472 EXPECT_THAT(getDiagnosticString(),
2473 HasSubstr("NoContraction cannot be used by an entry point with "
2474 "the FPFastMathDefault execution mode"));
2475 }
2476
2477 TEST_F(ValidateMode, FPFastMathDefaultFastMathFastNotInCallTree) {
2478 const std::string spirv = R"(
2479 OpCapability Shader
2480 OpCapability FloatControls2
2481 OpExtension "SPV_KHR_float_controls2"
2482 OpMemoryModel Logical GLSL450
2483 OpEntryPoint GLCompute %main "main"
2484 OpExecutionModeId %main FPFastMathDefault %float %constant
2485 OpExecutionMode %main LocalSize 1 1 1
2486 OpDecorate %add FPFastMathMode Fast
2487 %void = OpTypeVoid
2488 %int = OpTypeInt 32 0
2489 %constant = OpConstant %int 0
2490 %float = OpTypeFloat 32
2491 %zero = OpConstant %float 0
2492 %void_fn = OpTypeFunction %void
2493 %main = OpFunction %void None %void_fn
2494 %entry = OpLabel
2495 OpReturn
2496 OpFunctionEnd
2497 %func = OpFunction %void None %void_fn
2498 %func_entry = OpLabel
2499 %add = OpFAdd %float %zero %zero
2500 OpReturn
2501 OpFunctionEnd
2502 )";
2503
2504 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2505 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2506 }
2507
2508 TEST_F(ValidateMode, FPFastMathDefaultFastMathFastInCallTree) {
2509 const std::string spirv = R"(
2510 OpCapability Shader
2511 OpCapability FloatControls2
2512 OpExtension "SPV_KHR_float_controls2"
2513 OpMemoryModel Logical GLSL450
2514 OpEntryPoint GLCompute %main "main"
2515 OpExecutionModeId %main FPFastMathDefault %float %constant
2516 OpExecutionMode %main LocalSize 1 1 1
2517 OpDecorate %add FPFastMathMode Fast
2518 %void = OpTypeVoid
2519 %int = OpTypeInt 32 0
2520 %constant = OpConstant %int 0
2521 %float = OpTypeFloat 32
2522 %zero = OpConstant %float 0
2523 %void_fn = OpTypeFunction %void
2524 %main = OpFunction %void None %void_fn
2525 %entry = OpLabel
2526 %call = OpFunctionCall %void %func
2527 OpReturn
2528 OpFunctionEnd
2529 %func = OpFunction %void None %void_fn
2530 %func_entry = OpLabel
2531 %add = OpFAdd %float %zero %zero
2532 OpReturn
2533 OpFunctionEnd
2534 )";
2535
2536 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2537 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2538 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2539 EXPECT_THAT(getDiagnosticString(),
2540 HasSubstr("FPFastMathMode Fast cannot be used by an entry point "
2541 "with the FPFastMathDefault execution mode"));
2542 }
2543
2544 TEST_F(ValidateMode, FPFastMathDefaultFastMathFastInCallTree2) {
2545 const std::string spirv = R"(
2546 OpCapability Kernel
2547 OpCapability Addresses
2548 OpCapability FloatControls2
2549 OpExtension "SPV_KHR_float_controls2"
2550 OpMemoryModel Physical64 OpenCL
2551 OpEntryPoint Kernel %main "main"
2552 OpExecutionModeId %main FPFastMathDefault %float %constant
2553 OpDecorate %const FPFastMathMode Fast
2554 %void = OpTypeVoid
2555 %int = OpTypeInt 32 0
2556 %constant = OpConstant %int 0
2557 %float = OpTypeFloat 32
2558 %zero = OpConstant %float 0
2559 %const = OpSpecConstantOp %float FAdd %zero %zero
2560 %void_fn = OpTypeFunction %void
2561 %main = OpFunction %void None %void_fn
2562 %entry = OpLabel
2563 %call = OpFunctionCall %void %func
2564 OpReturn
2565 OpFunctionEnd
2566 %func = OpFunction %void None %void_fn
2567 %func_entry = OpLabel
2568 %add = OpFAdd %float %const %zero
2569 OpReturn
2570 OpFunctionEnd
2571 )";
2572
2573 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2574 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2575 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2576 EXPECT_THAT(getDiagnosticString(),
2577 HasSubstr("FPFastMathMode Fast cannot be used by an entry point "
2578 "with the FPFastMathDefault execution mode"));
2579 }
2580
2581 TEST_F(ValidateMode, FragmentShaderRequireFullQuadsKHR) {
2582 const std::string spirv = R"(
2583 OpCapability Shader
2584 OpCapability GroupNonUniform
2585 OpCapability GroupNonUniformVote
2586 OpCapability GroupNonUniformBallot
2587 OpCapability QuadControlKHR
2588 OpExtension "SPV_KHR_quad_control"
2589 %1 = OpExtInstImport "GLSL.std.450"
2590 OpMemoryModel Logical GLSL450
2591 OpEntryPoint GLCompute %4 "main"
2592 OpExecutionMode %4 OriginUpperLeft
2593 OpExecutionMode %4 RequireFullQuadsKHR
2594 OpDecorate %17 Location 0
2595 OpDecorate %31 BuiltIn HelperInvocation
2596 OpDecorate %40 Location 0
2597 OpDecorate %44 DescriptorSet 0
2598 OpDecorate %44 Binding 0
2599 %2 = OpTypeVoid
2600 %3 = OpTypeFunction %2
2601 %6 = OpTypeInt 32 0
2602 %7 = OpTypeVector %6 4
2603 %8 = OpTypePointer Function %7
2604 %10 = OpTypeBool
2605 %11 = OpConstantTrue %10
2606 %12 = OpConstant %6 7
2607 %14 = OpTypeFloat 32
2608 %15 = OpTypeVector %14 4
2609 %16 = OpTypePointer Output %15
2610 %17 = OpVariable %16 Output
2611 %18 = OpConstant %14 1
2612 %19 = OpConstant %14 0
2613 %20 = OpConstantComposite %15 %18 %19 %19 %18
2614 %23 = OpConstant %6 4
2615 %27 = OpConstant %6 1
2616 %28 = OpTypePointer Output %14
2617 %30 = OpTypePointer Input %10
2618 %31 = OpVariable %30 Input
2619 %36 = OpConstant %6 2
2620 %38 = OpTypeVector %14 2
2621 %39 = OpTypePointer Input %38
2622 %40 = OpVariable %39 Input
2623 %41 = OpTypeImage %14 2D 0 0 0 1 Unknown
2624 %42 = OpTypeSampledImage %41
2625 %43 = OpTypePointer UniformConstant %42
2626 %44 = OpVariable %43 UniformConstant
2627 %4 = OpFunction %2 None %3
2628 %5 = OpLabel
2629 %9 = OpVariable %8 Function
2630 %13 = OpGroupNonUniformBallot %7 %12 %11
2631 OpStore %9 %13
2632 OpStore %17 %20
2633 %21 = OpLoad %7 %9
2634 %22 = OpGroupNonUniformBallotBitCount %6 %12 Reduce %21
2635 %24 = OpIEqual %10 %22 %23
2636 OpSelectionMerge %26 None
2637 OpBranchConditional %24 %25 %26
2638 %25 = OpLabel
2639 %29 = OpAccessChain %28 %17 %27
2640 OpStore %29 %18
2641 OpBranch %26
2642 %26 = OpLabel
2643 %32 = OpLoad %10 %31
2644 %33 = OpGroupNonUniformAny %10 %12 %32
2645 OpSelectionMerge %35 None
2646 OpBranchConditional %33 %34 %35
2647 %34 = OpLabel
2648 %37 = OpAccessChain %28 %17 %36
2649 OpStore %37 %18
2650 OpBranch %35
2651 %35 = OpLabel
2652 OpReturn
2653 OpFunctionEnd
2654 )";
2655
2656 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2657 EXPECT_THAT(SPV_ERROR_INVALID_DATA,
2658 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2659 EXPECT_THAT(
2660 getDiagnosticString(),
2661 HasSubstr(
2662 "Execution mode can only be used with the Fragment execution model"));
2663 }
2664
2665 TEST_F(ValidateMode, FragmentShaderQuadDerivativesKHR) {
2666 const std::string spirv = R"(
2667 OpCapability Shader
2668 OpCapability GroupNonUniform
2669 OpCapability GroupNonUniformVote
2670 OpCapability QuadControlKHR
2671 OpExtension "SPV_KHR_quad_control"
2672 %1 = OpExtInstImport "GLSL.std.450"
2673 OpMemoryModel Logical GLSL450
2674 OpEntryPoint GLCompute %4 "main"
2675 OpExecutionMode %4 OriginUpperLeft
2676 OpExecutionMode %4 QuadDerivativesKHR
2677 OpDecorate %12 BuiltIn FragCoord
2678 OpDecorate %41 Location 0
2679 OpDecorate %45 DescriptorSet 0
2680 OpDecorate %45 Binding 0
2681 OpDecorate %49 Location 0
2682 %2 = OpTypeVoid
2683 %3 = OpTypeFunction %2
2684 %6 = OpTypeBool
2685 %7 = OpTypePointer Function %6
2686 %9 = OpTypeFloat 32
2687 %10 = OpTypeVector %9 4
2688 %11 = OpTypePointer Input %10
2689 %12 = OpVariable %11 Input
2690 %13 = OpTypeInt 32 0
2691 %14 = OpConstant %13 1
2692 %15 = OpTypePointer Input %9
2693 %18 = OpConstant %9 8.5
2694 %21 = OpConstant %9 0.100000001
2695 %25 = OpConstant %13 0
2696 %28 = OpConstant %9 3.5
2697 %30 = OpConstant %9 6
2698 %36 = OpConstant %13 7
2699 %40 = OpTypePointer Output %10
2700 %41 = OpVariable %40 Output
2701 %42 = OpTypeImage %9 2D 0 0 0 1 Unknown
2702 %43 = OpTypeSampledImage %42
2703 %44 = OpTypePointer UniformConstant %43
2704 %45 = OpVariable %44 UniformConstant
2705 %47 = OpTypeVector %9 2
2706 %48 = OpTypePointer Input %47
2707 %49 = OpVariable %48 Input
2708 %53 = OpConstant %9 0.899999976
2709 %54 = OpConstant %9 0.200000003
2710 %55 = OpConstant %9 1
2711 %56 = OpConstantComposite %10 %53 %54 %54 %55
2712 %4 = OpFunction %2 None %3
2713 %5 = OpLabel
2714 %8 = OpVariable %7 Function
2715 %16 = OpAccessChain %15 %12 %14
2716 %17 = OpLoad %9 %16
2717 %19 = OpFSub %9 %17 %18
2718 %20 = OpExtInst %9 %1 FAbs %19
2719 %22 = OpFOrdLessThan %6 %20 %21
2720 OpSelectionMerge %24 None
2721 OpBranchConditional %22 %23 %24
2722 %23 = OpLabel
2723 %26 = OpAccessChain %15 %12 %25
2724 %27 = OpLoad %9 %26
2725 %29 = OpFSub %9 %27 %28
2726 %31 = OpFMod %9 %29 %30
2727 %33 = OpFOrdLessThan %6 %31 %21
2728 OpBranch %24
2729 %24 = OpLabel
2730 %34 = OpPhi %6 %22 %5 %33 %23
2731 OpStore %8 %34
2732 %35 = OpLoad %6 %8
2733 %37 = OpGroupNonUniformAny %6 %36 %35
2734 OpSelectionMerge %39 None
2735 OpBranchConditional %37 %38 %52
2736 %38 = OpLabel
2737 %46 = OpLoad %43 %45
2738 %50 = OpLoad %47 %49
2739 %51 = OpImageSampleImplicitLod %10 %46 %50
2740 OpStore %41 %51
2741 OpBranch %39
2742 %52 = OpLabel
2743 OpStore %41 %56
2744 OpBranch %39
2745 %39 = OpLabel
2746 OpReturn
2747 OpFunctionEnd
2748 )";
2749
2750 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2751 EXPECT_THAT(SPV_ERROR_INVALID_DATA,
2752 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2753 EXPECT_THAT(
2754 getDiagnosticString(),
2755 HasSubstr(
2756 "Execution mode can only be used with the Fragment execution model"));
2757 }
2758
2759 const std::string kNodeShaderPrelude = R"(
2760 OpCapability Shader
2761 OpCapability ShaderEnqueueAMDX
2762 OpExtension "SPV_AMDX_shader_enqueue"
2763 OpMemoryModel Logical GLSL450
2764 OpEntryPoint GLCompute %main "main"
2765 OpEntryPoint GLCompute %other "other"
2766 )";
2767
2768 const std::string kNodeShaderPostlude = R"(
2769 %uint = OpTypeInt 32 0
2770 %uint_0 = OpConstant %uint 0
2771 %uint_1 = OpConstant %uint 1
2772 %node0 = OpConstantStringAMDX "node0"
2773 %node1 = OpConstantStringAMDX "node1"
2774 %node2 = OpConstantStringAMDX "node2"
2775 %S = OpTypeStruct
2776 %_payloadarr_S_0 = OpTypeNodePayloadArrayAMDX %S
2777 %_payloadarr_S = OpTypeNodePayloadArrayAMDX %S
2778 %bool = OpTypeBool
2779 %true = OpConstantTrue %bool
2780 %void = OpTypeVoid
2781 %void_fn = OpTypeFunction %void
2782 %main = OpFunction %void None %void_fn
2783 %entry = OpLabel
2784 OpReturn
2785 OpFunctionEnd
2786 %other = OpFunction %void None %void_fn
2787 %entry0 = OpLabel
2788 OpReturn
2789 OpFunctionEnd
2790 )";
2791
2792 TEST_F(ValidateMode, NodeShader) {
2793 const std::string spirv = kNodeShaderPrelude + R"(
2794 OpExecutionModeId %main ShaderIndexAMDX %uint_0
2795 OpExecutionModeId %main IsApiEntryAMDX %true
2796 OpExecutionModeId %main MaxNodeRecursionAMDX %uint_1
2797 OpExecutionModeId %main MaxNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2798 OpExecutionModeId %main SharesInputWithAMDX %node0 %uint_0
2799 OpExecutionModeId %other ShaderIndexAMDX %uint_0
2800 OpExecutionModeId %other StaticNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2801 OpDecorateId %_payloadarr_S PayloadNodeNameAMDX %node1
2802 OpDecorateId %_payloadarr_S_0 PayloadNodeNameAMDX %node2
2803 OpDecorateId %_payloadarr_S PayloadNodeBaseIndexAMDX %uint_0
2804 OpDecorateId %_payloadarr_S PayloadNodeArraySizeAMDX %uint_1
2805 OpDecorateId %_payloadarr_S NodeSharesPayloadLimitsWithAMDX %_payloadarr_S_0
2806 )" + kNodeShaderPostlude;
2807
2808 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
2809 CompileSuccessfully(spirv, env);
2810 EXPECT_THAT(SPV_SUCCESS, ValidateInstructions(env));
2811 }
2812
2813 TEST_F(ValidateMode, NodeShaderModeShaderIndex) {
2814 const std::string spirv = kNodeShaderPrelude + R"(
2815 OpExecutionMode %main ShaderIndexAMDX %uint_0
2816 OpExecutionModeId %main IsApiEntryAMDX %true
2817 OpExecutionModeId %main MaxNodeRecursionAMDX %uint_1
2818 OpExecutionModeId %main MaxNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2819 OpExecutionModeId %main SharesInputWithAMDX %node0 %uint_0
2820 OpExecutionMode %other ShaderIndexAMDX %uint_0
2821 OpExecutionModeId %other StaticNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2822 OpDecorateId %_payloadarr_S PayloadNodeNameAMDX %node1
2823 OpDecorateId %_payloadarr_S_0 PayloadNodeNameAMDX %node2
2824 OpDecorateId %_payloadarr_S PayloadNodeBaseIndexAMDX %uint_0
2825 OpDecorateId %_payloadarr_S PayloadNodeArraySizeAMDX %uint_1
2826 OpDecorateId %_payloadarr_S NodeSharesPayloadLimitsWithAMDX %_payloadarr_S_0
2827 )" + kNodeShaderPostlude;
2828
2829 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
2830 CompileSuccessfully(spirv, env);
2831 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
2832 EXPECT_THAT(
2833 getDiagnosticString(),
2834 HasSubstr("OpExecutionMode is only valid when the Mode operand is an "
2835 "execution mode that takes no Extra Operands, or takes Extra "
2836 "Operands that are not id operands"));
2837 }
2838
2839 TEST_F(ValidateMode, NodeShaderModeIsApiEntry) {
2840 const std::string spirv = kNodeShaderPrelude + R"(
2841 OpExecutionModeId %main ShaderIndexAMDX %uint_0
2842 OpExecutionMode %main IsApiEntryAMDX %true
2843 OpExecutionModeId %main MaxNodeRecursionAMDX %uint_1
2844 OpExecutionModeId %main MaxNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2845 OpExecutionModeId %main SharesInputWithAMDX %node0 %uint_0
2846 OpExecutionModeId %other ShaderIndexAMDX %uint_0
2847 OpExecutionModeId %other StaticNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2848 OpDecorateId %_payloadarr_S PayloadNodeNameAMDX %node1
2849 OpDecorateId %_payloadarr_S_0 PayloadNodeNameAMDX %node2
2850 OpDecorateId %_payloadarr_S PayloadNodeBaseIndexAMDX %uint_0
2851 OpDecorateId %_payloadarr_S PayloadNodeArraySizeAMDX %uint_1
2852 OpDecorateId %_payloadarr_S NodeSharesPayloadLimitsWithAMDX %_payloadarr_S_0
2853 )" + kNodeShaderPostlude;
2854
2855 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
2856 CompileSuccessfully(spirv, env);
2857 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
2858 EXPECT_THAT(
2859 getDiagnosticString(),
2860 HasSubstr("OpExecutionMode is only valid when the Mode operand is an "
2861 "execution mode that takes no Extra Operands, or takes Extra "
2862 "Operands that are not id operands"));
2863 }
2864
2865 TEST_F(ValidateMode, NodeShaderModeMaxNodeRecursion) {
2866 const std::string spirv = kNodeShaderPrelude + R"(
2867 OpExecutionModeId %main ShaderIndexAMDX %uint_0
2868 OpExecutionModeId %main IsApiEntryAMDX %true
2869 OpExecutionMode %main MaxNodeRecursionAMDX %uint_1
2870 OpExecutionModeId %main MaxNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2871 OpExecutionModeId %main SharesInputWithAMDX %node0 %uint_0
2872 OpExecutionModeId %other ShaderIndexAMDX %uint_0
2873 OpExecutionModeId %other StaticNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2874 OpDecorateId %_payloadarr_S PayloadNodeNameAMDX %node1
2875 OpDecorateId %_payloadarr_S_0 PayloadNodeNameAMDX %node2
2876 OpDecorateId %_payloadarr_S PayloadNodeBaseIndexAMDX %uint_0
2877 OpDecorateId %_payloadarr_S PayloadNodeArraySizeAMDX %uint_1
2878 OpDecorateId %_payloadarr_S NodeSharesPayloadLimitsWithAMDX %_payloadarr_S_0
2879 )" + kNodeShaderPostlude;
2880
2881 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
2882 CompileSuccessfully(spirv, env);
2883 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
2884 EXPECT_THAT(
2885 getDiagnosticString(),
2886 HasSubstr("OpExecutionMode is only valid when the Mode operand is an "
2887 "execution mode that takes no Extra Operands, or takes Extra "
2888 "Operands that are not id operands"));
2889 }
2890
2891 TEST_F(ValidateMode, NodeShaderModeMaxNumWorkgroups) {
2892 const std::string spirv = kNodeShaderPrelude + R"(
2893 OpExecutionModeId %main ShaderIndexAMDX %uint_0
2894 OpExecutionModeId %main IsApiEntryAMDX %true
2895 OpExecutionModeId %main MaxNodeRecursionAMDX %uint_1
2896 OpExecutionMode %main MaxNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2897 OpExecutionModeId %main SharesInputWithAMDX %node0 %uint_0
2898 OpExecutionModeId %other ShaderIndexAMDX %uint_0
2899 OpExecutionModeId %other StaticNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2900 OpDecorateId %_payloadarr_S PayloadNodeNameAMDX %node1
2901 OpDecorateId %_payloadarr_S_0 PayloadNodeNameAMDX %node2
2902 OpDecorateId %_payloadarr_S PayloadNodeBaseIndexAMDX %uint_0
2903 OpDecorateId %_payloadarr_S PayloadNodeArraySizeAMDX %uint_1
2904 OpDecorateId %_payloadarr_S NodeSharesPayloadLimitsWithAMDX %_payloadarr_S_0
2905 )" + kNodeShaderPostlude;
2906
2907 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
2908 CompileSuccessfully(spirv, env);
2909 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
2910 EXPECT_THAT(
2911 getDiagnosticString(),
2912 HasSubstr("OpExecutionMode is only valid when the Mode operand is an "
2913 "execution mode that takes no Extra Operands, or takes Extra "
2914 "Operands that are not id operands"));
2915 }
2916
2917 TEST_F(ValidateMode, NodeShaderModeStaticNumWorkgroups) {
2918 const std::string spirv = kNodeShaderPrelude + R"(
2919 OpExecutionModeId %main ShaderIndexAMDX %uint_0
2920 OpExecutionModeId %main IsApiEntryAMDX %true
2921 OpExecutionModeId %main MaxNodeRecursionAMDX %uint_1
2922 OpExecutionModeId %main MaxNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2923 OpExecutionModeId %main SharesInputWithAMDX %node0 %uint_0
2924 OpExecutionModeId %other ShaderIndexAMDX %uint_0
2925 OpExecutionMode %other StaticNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2926 OpDecorateId %_payloadarr_S PayloadNodeNameAMDX %node1
2927 OpDecorateId %_payloadarr_S_0 PayloadNodeNameAMDX %node2
2928 OpDecorateId %_payloadarr_S PayloadNodeBaseIndexAMDX %uint_0
2929 OpDecorateId %_payloadarr_S PayloadNodeArraySizeAMDX %uint_1
2930 OpDecorateId %_payloadarr_S NodeSharesPayloadLimitsWithAMDX %_payloadarr_S_0
2931 )" + kNodeShaderPostlude;
2932
2933 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
2934 CompileSuccessfully(spirv, env);
2935 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
2936 EXPECT_THAT(
2937 getDiagnosticString(),
2938 HasSubstr("OpExecutionMode is only valid when the Mode operand is an "
2939 "execution mode that takes no Extra Operands, or takes Extra "
2940 "Operands that are not id operands"));
2941 }
2942
2943 TEST_F(ValidateMode, NodeShaderModeSharesInputWith) {
2944 const std::string spirv = kNodeShaderPrelude + R"(
2945 OpExecutionModeId %main ShaderIndexAMDX %uint_0
2946 OpExecutionModeId %main IsApiEntryAMDX %true
2947 OpExecutionModeId %main MaxNodeRecursionAMDX %uint_1
2948 OpExecutionModeId %main MaxNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2949 OpExecutionMode %main SharesInputWithAMDX %node0 %uint_0
2950 OpExecutionModeId %other ShaderIndexAMDX %uint_0
2951 OpExecutionModeId %other StaticNumWorkgroupsAMDX %uint_1 %uint_1 %uint_1
2952 OpDecorateId %_payloadarr_S PayloadNodeNameAMDX %node1
2953 OpDecorateId %_payloadarr_S_0 PayloadNodeNameAMDX %node2
2954 OpDecorateId %_payloadarr_S PayloadNodeBaseIndexAMDX %uint_0
2955 OpDecorateId %_payloadarr_S PayloadNodeArraySizeAMDX %uint_1
2956 OpDecorateId %_payloadarr_S NodeSharesPayloadLimitsWithAMDX %_payloadarr_S_0
2957 )" + kNodeShaderPostlude;
2958
2959 spv_target_env env = SPV_ENV_UNIVERSAL_1_3;
2960 CompileSuccessfully(spirv, env);
2961 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
2962 EXPECT_THAT(
2963 getDiagnosticString(),
2964 HasSubstr("OpExecutionMode is only valid when the Mode operand is an "
2965 "execution mode that takes no Extra Operands, or takes Extra "
2966 "Operands that are not id operands"));
2967 }
2968
2969 TEST_F(ValidateMode, GLComputeNoModeVulkanQCOM) {
2970 const std::string spirv = R"(
2971 OpCapability Shader
2972 OpCapability TileShadingQCOM
2973 OpExtension "SPV_QCOM_tile_shading"
2974 OpMemoryModel Logical GLSL450
2975 OpEntryPoint GLCompute %main "main"
2976 )" + kVoidFunction;
2977
2978 spv_target_env env = SPV_ENV_VULKAN_1_4;
2979 CompileSuccessfully(spirv, env);
2980 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
2981 EXPECT_THAT(getDiagnosticString(),
2982 AnyVUID("VUID-StandaloneSpirv-None-10685"));
2983 EXPECT_THAT(
2984 getDiagnosticString(),
2985 HasSubstr("In the Vulkan environment, GLCompute execution model entry "
2986 "points require either the TileShadingRateQCOM, LocalSize or "
2987 "LocalSizeId execution mode or an object decorated with "
2988 "WorkgroupSize "
2989 "must be specified."));
2990 }
2991
2992 TEST_F(ValidateMode, GLComputeVulkanLocalSizeBadQCOM) {
2993 const std::string spirv = R"(
2994 OpCapability Shader
2995 OpCapability TileShadingQCOM
2996 OpExtension "SPV_QCOM_tile_shading"
2997 OpMemoryModel Logical GLSL450
2998 OpEntryPoint GLCompute %main "main"
2999 OpExecutionMode %main TileShadingRateQCOM 2 2 3
3000 OpExecutionMode %main LocalSize 16 16 1
3001 )" + kVoidFunction;
3002
3003 spv_target_env env = SPV_ENV_VULKAN_1_4;
3004 CompileSuccessfully(spirv, env);
3005 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3006 EXPECT_THAT(getDiagnosticString(),
3007 HasSubstr("If the TileShadingRateQCOM execution mode is used, "
3008 "LocalSize and LocalSizeId must not be specified."));
3009 }
3010
3011 TEST_F(ValidateMode, GLComputeVulkanLocalSizeIdBadQCOM) {
3012 const std::string spirv = R"(
3013 OpCapability Shader
3014 OpCapability TileShadingQCOM
3015 OpExtension "SPV_QCOM_tile_shading"
3016 OpMemoryModel Logical GLSL450
3017 OpEntryPoint GLCompute %main "main"
3018 OpExecutionMode %main TileShadingRateQCOM 2 2 3
3019 OpExecutionModeId %main LocalSizeId %int_1 %int_1 %int_1
3020 %int = OpTypeInt 32 0
3021 %int_1 = OpConstant %int 1
3022 )" + kVoidFunction;
3023
3024 spv_target_env env = SPV_ENV_VULKAN_1_4;
3025 CompileSuccessfully(spirv, env);
3026 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3027 EXPECT_THAT(getDiagnosticString(),
3028 HasSubstr("If the TileShadingRateQCOM execution mode is used, "
3029 "LocalSize and LocalSizeId must not be specified."));
3030 }
3031
3032 TEST_F(ValidateMode, NonCoherentTileAttachmentReadQCOMBad1) {
3033 const std::string spirv = R"(
3034 OpCapability Shader
3035 OpMemoryModel Logical GLSL450
3036 OpEntryPoint Fragment %main "main"
3037 OpExecutionMode %main NonCoherentTileAttachmentReadQCOM
3038 OpExecutionMode %main OriginUpperLeft
3039 )" + kVoidFunction;
3040
3041 spv_target_env env = SPV_ENV_VULKAN_1_4;
3042 CompileSuccessfully(spirv, env);
3043 EXPECT_THAT(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions(env));
3044 EXPECT_THAT(getDiagnosticString(),
3045 HasSubstr("requires one of these capabilities: TileShadingQCOM"));
3046 }
3047
3048 TEST_F(ValidateMode, NonCoherentTileAttachmentReadQCOMBad2) {
3049 const std::string spirv = R"(
3050 OpCapability Shader
3051 OpCapability TileShadingQCOM
3052 OpExtension "SPV_QCOM_tile_shading"
3053 OpMemoryModel Logical GLSL450
3054 OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
3055 OpExecutionMode %main LocalSize 16 16 1
3056 OpExecutionMode %main NonCoherentTileAttachmentReadQCOM
3057 OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
3058 %uint = OpTypeInt 32 0
3059 %v3uint = OpTypeVector %uint 3
3060 %_ptr_Input_v3uint = OpTypePointer Input %v3uint
3061 %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
3062 )" + kVoidFunction;
3063
3064 spv_target_env env = SPV_ENV_VULKAN_1_4;
3065 CompileSuccessfully(spirv, env);
3066 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3067 EXPECT_THAT(getDiagnosticString(),
3068 HasSubstr("The NonCoherentTileAttachmentQCOM execution mode must "
3069 "not be used in any stage other than fragment"));
3070 }
3071
3072 TEST_F(ValidateMode, TileShadingRateQCOMBad1) {
3073 const std::string spirv = R"(
3074 OpCapability Shader
3075 OpMemoryModel Logical GLSL450
3076 OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
3077 OpExecutionMode %main TileShadingRateQCOM 2 2 3
3078 OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
3079 %uint = OpTypeInt 32 0
3080 %v3uint = OpTypeVector %uint 3
3081 %_ptr_Input_v3uint = OpTypePointer Input %v3uint
3082 %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
3083 )" + kVoidFunction;
3084
3085 spv_target_env env = SPV_ENV_VULKAN_1_4;
3086 CompileSuccessfully(spirv, env);
3087 EXPECT_THAT(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions(env));
3088 EXPECT_THAT(getDiagnosticString(),
3089 HasSubstr("requires one of these capabilities: TileShadingQCOM"));
3090 }
3091
3092 TEST_F(ValidateMode, TileShadingRateQCOMBad2) {
3093 const std::string spirv = R"(
3094 OpCapability Shader
3095 OpCapability TileShadingQCOM
3096 OpExtension "SPV_QCOM_tile_shading"
3097 OpMemoryModel Logical GLSL450
3098 OpEntryPoint Fragment %main "main"
3099 OpExecutionMode %main TileShadingRateQCOM 2 2 3
3100 OpExecutionMode %main OriginUpperLeft
3101 )" + kVoidFunction;
3102
3103 spv_target_env env = SPV_ENV_VULKAN_1_4;
3104 CompileSuccessfully(spirv, env);
3105 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3106 EXPECT_THAT(getDiagnosticString(),
3107 HasSubstr("The TileShadingRateQCOM execution mode must not be "
3108 "used in any stage other than compute"));
3109 }
3110
3111 TEST_F(ValidateMode, TileShadingRateQCOMBad3) {
3112 const std::string spirv = R"(
3113 OpCapability Shader
3114 OpCapability TileShadingQCOM
3115 OpExtension "SPV_QCOM_tile_shading"
3116 OpMemoryModel Logical GLSL450
3117 OpEntryPoint GLCompute %main "main"
3118 OpExecutionMode %main TileShadingRateQCOM 3 2 3
3119 )" + kVoidFunction;
3120
3121 spv_target_env env = SPV_ENV_VULKAN_1_4;
3122 CompileSuccessfully(spirv, env);
3123 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3124 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3125 EXPECT_THAT(getDiagnosticString(),
3126 HasSubstr("The TileShadingRateQCOM execution mode's x and y "
3127 "values must be powers of 2"));
3128 }
3129
3130 TEST_F(ValidateMode, TileShadingRateQCOMBad4) {
3131 const std::string spirv = R"(
3132 OpCapability Shader
3133 OpCapability TileShadingQCOM
3134 OpExtension "SPV_QCOM_tile_shading"
3135 OpMemoryModel Logical GLSL450
3136 OpEntryPoint GLCompute %main "main"
3137 OpExecutionMode %main TileShadingRateQCOM 2 3 3
3138 )" + kVoidFunction;
3139
3140 spv_target_env env = SPV_ENV_VULKAN_1_4;
3141 CompileSuccessfully(spirv, env);
3142 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3143 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
3144 EXPECT_THAT(getDiagnosticString(),
3145 HasSubstr("The TileShadingRateQCOM execution mode's x and y "
3146 "values must be powers of 2"));
3147 }
3148
3149 } // namespace
3150 } // namespace val
3151 } // namespace spvtools