Debian Codegraph @

third_party/spirv-tools/test/val/val_barriers_test.cpp

raw
1 // Copyright (c) 2018 Google LLC.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <sstream>
16 #include <string>
17
18 #include "gmock/gmock.h"
19 #include "test/unit_spirv.h"
20 #include "test/val/val_fixtures.h"
21
22 namespace spvtools {
23 namespace val {
24 namespace {
25
26 using ::testing::HasSubstr;
27 using ::testing::Not;
28
29 using ValidateBarriers = spvtest::ValidateBase<bool>;
30
31 std::string GenerateShaderCodeImpl(
32 const std::string& body, const std::string& capabilities_and_extensions,
33 const std::string& definitions, const std::string& execution_model,
34 const std::string& memory_model) {
35 std::ostringstream ss;
36 ss << R"(
37 OpCapability Shader
38 )";
39
40 ss << capabilities_and_extensions;
41 ss << memory_model << std::endl;
42 ss << "OpEntryPoint " << execution_model << " %main \"main\"\n";
43 if (execution_model == "Fragment") {
44 ss << "OpExecutionMode %main OriginUpperLeft\n";
45 } else if (execution_model == "Geometry") {
46 ss << "OpExecutionMode %main InputPoints\n";
47 ss << "OpExecutionMode %main OutputPoints\n";
48 } else if (execution_model == "GLCompute") {
49 ss << "OpExecutionMode %main LocalSize 1 1 1\n";
50 }
51
52 ss << R"(
53 %void = OpTypeVoid
54 %func = OpTypeFunction %void
55 %bool = OpTypeBool
56 %f32 = OpTypeFloat 32
57 %u32 = OpTypeInt 32 0
58
59 %f32_0 = OpConstant %f32 0
60 %f32_1 = OpConstant %f32 1
61 %u32_0 = OpConstant %u32 0
62 %u32_1 = OpConstant %u32 1
63 %u32_4 = OpConstant %u32 4
64 )";
65 ss << definitions;
66 ss << R"(
67 %cross_device = OpConstant %u32 0
68 %device = OpConstant %u32 1
69 %workgroup = OpConstant %u32 2
70 %subgroup = OpConstant %u32 3
71 %invocation = OpConstant %u32 4
72 %queuefamily = OpConstant %u32 5
73 %shadercall = OpConstant %u32 6
74
75 %none = OpConstant %u32 0
76 %acquire = OpConstant %u32 2
77 %release = OpConstant %u32 4
78 %acquire_release = OpConstant %u32 8
79 %acquire_and_release = OpConstant %u32 6
80 %sequentially_consistent = OpConstant %u32 16
81 %acquire_release_uniform_workgroup = OpConstant %u32 328
82 %acquire_uniform_workgroup = OpConstant %u32 322
83 %release_uniform_workgroup = OpConstant %u32 324
84 %acquire_and_release_uniform = OpConstant %u32 70
85 %acquire_release_subgroup = OpConstant %u32 136
86 %acquire_release_workgroup = OpConstant %u32 264
87 %uniform = OpConstant %u32 64
88 %uniform_workgroup = OpConstant %u32 320
89 %workgroup_memory = OpConstant %u32 256
90 %image_memory = OpConstant %u32 2048
91 %uniform_image_memory = OpConstant %u32 2112
92
93 %main = OpFunction %void None %func
94 %main_entry = OpLabel
95 )";
96
97 ss << body;
98
99 ss << R"(
100 OpReturn
101 OpFunctionEnd)";
102
103 return ss.str();
104 }
105
106 std::string GenerateShaderCode(
107 const std::string& body,
108 const std::string& capabilities_and_extensions = "",
109 const std::string& execution_model = "GLCompute") {
110 const std::string int64_capability = R"(
111 OpCapability Int64
112 )";
113 const std::string int64_declarations = R"(
114 %u64 = OpTypeInt 64 0
115 %u64_0 = OpConstant %u64 0
116 %u64_1 = OpConstant %u64 1
117 )";
118 const std::string memory_model = "OpMemoryModel Logical GLSL450";
119 return GenerateShaderCodeImpl(
120 body, int64_capability + capabilities_and_extensions, int64_declarations,
121 execution_model, memory_model);
122 }
123
124 std::string GenerateWebGPUComputeShaderCode(
125 const std::string& body,
126 const std::string& capabilities_and_extensions = "",
127 const std::string& execution_model = "GLCompute") {
128 const std::string vulkan_memory_capability = R"(
129 OpCapability VulkanMemoryModelKHR
130 )";
131 const std::string vulkan_memory_extension = R"(
132 OpExtension "SPV_KHR_vulkan_memory_model"
133 )";
134 const std::string memory_model = "OpMemoryModel Logical VulkanKHR";
135 return GenerateShaderCodeImpl(body,
136 vulkan_memory_capability +
137 capabilities_and_extensions +
138 vulkan_memory_extension,
139 "", execution_model, memory_model);
140 }
141
142 std::string GenerateWebGPUVertexShaderCode(
143 const std::string& body,
144 const std::string& capabilities_and_extensions = "",
145 const std::string& execution_model = "Vertex") {
146 const std::string vulkan_memory_capability = R"(
147 OpCapability VulkanMemoryModelKHR
148 )";
149 const std::string vulkan_memory_extension = R"(
150 OpExtension "SPV_KHR_vulkan_memory_model"
151 )";
152 const std::string memory_model = "OpMemoryModel Logical VulkanKHR";
153 return GenerateShaderCodeImpl(body,
154 vulkan_memory_capability +
155 capabilities_and_extensions +
156 vulkan_memory_extension,
157 "", execution_model, memory_model);
158 }
159
160 std::string GenerateKernelCode(
161 const std::string& body,
162 const std::string& capabilities_and_extensions = "") {
163 std::ostringstream ss;
164 ss << R"(
165 OpCapability Addresses
166 OpCapability Kernel
167 OpCapability Linkage
168 OpCapability Int64
169 OpCapability NamedBarrier
170 )";
171
172 ss << capabilities_and_extensions;
173 ss << R"(
174 OpMemoryModel Physical32 OpenCL
175 %void = OpTypeVoid
176 %func = OpTypeFunction %void
177 %bool = OpTypeBool
178 %f32 = OpTypeFloat 32
179 %u32 = OpTypeInt 32 0
180 %u64 = OpTypeInt 64 0
181
182 %f32_0 = OpConstant %f32 0
183 %f32_1 = OpConstant %f32 1
184 %f32_4 = OpConstant %f32 4
185 %u32_0 = OpConstant %u32 0
186 %u32_1 = OpConstant %u32 1
187 %u32_4 = OpConstant %u32 4
188 %u64_0 = OpConstant %u64 0
189 %u64_1 = OpConstant %u64 1
190 %u64_4 = OpConstant %u64 4
191
192 %cross_device = OpConstant %u32 0
193 %device = OpConstant %u32 1
194 %workgroup = OpConstant %u32 2
195 %subgroup = OpConstant %u32 3
196 %invocation = OpConstant %u32 4
197
198 %none = OpConstant %u32 0
199 %acquire = OpConstant %u32 2
200 %release = OpConstant %u32 4
201 %acquire_release = OpConstant %u32 8
202 %acquire_and_release = OpConstant %u32 6
203 %sequentially_consistent = OpConstant %u32 16
204 %acquire_release_workgroup = OpConstant %u32 264
205
206 %named_barrier = OpTypeNamedBarrier
207
208 %main = OpFunction %void None %func
209 %main_entry = OpLabel
210 )";
211
212 ss << body;
213
214 ss << R"(
215 OpReturn
216 OpFunctionEnd)";
217
218 return ss.str();
219 }
220
221 TEST_F(ValidateBarriers, OpControlBarrierGLComputeSuccess) {
222 const std::string body = R"(
223 OpControlBarrier %device %device %none
224 OpControlBarrier %workgroup %workgroup %acquire
225 OpControlBarrier %workgroup %device %release
226 OpControlBarrier %cross_device %cross_device %acquire_release
227 OpControlBarrier %cross_device %cross_device %sequentially_consistent
228 OpControlBarrier %cross_device %cross_device %acquire_release_uniform_workgroup
229 )";
230
231 CompileSuccessfully(GenerateShaderCode(body));
232 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
233 }
234
235 TEST_F(ValidateBarriers, OpControlBarrierKernelSuccess) {
236 const std::string body = R"(
237 OpControlBarrier %device %device %none
238 OpControlBarrier %workgroup %workgroup %acquire
239 OpControlBarrier %workgroup %device %release
240 OpControlBarrier %cross_device %cross_device %acquire_release
241 OpControlBarrier %cross_device %cross_device %sequentially_consistent
242 OpControlBarrier %cross_device %cross_device %acquire_release_workgroup
243 )";
244
245 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
246 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
247 }
248
249 TEST_F(ValidateBarriers, OpControlBarrierTesselationControlSuccess) {
250 const std::string body = R"(
251 OpControlBarrier %device %device %none
252 OpControlBarrier %workgroup %workgroup %acquire
253 OpControlBarrier %workgroup %device %release
254 OpControlBarrier %cross_device %cross_device %acquire_release
255 OpControlBarrier %cross_device %cross_device %sequentially_consistent
256 OpControlBarrier %cross_device %cross_device %acquire_release_uniform_workgroup
257 )";
258
259 CompileSuccessfully(GenerateShaderCode(body, "OpCapability Tessellation\n",
260 "TessellationControl"));
261 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
262 }
263
264 TEST_F(ValidateBarriers, OpControlBarrierVulkanSuccess) {
265 const std::string body = R"(
266 OpControlBarrier %workgroup %device %none
267 OpControlBarrier %workgroup %workgroup %acquire_release_uniform_workgroup
268 )";
269
270 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
271 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
272 }
273
274 TEST_F(ValidateBarriers, OpControlBarrierWebGPUAcquireReleaseSuccess) {
275 const std::string body = R"(
276 OpControlBarrier %workgroup %workgroup %acquire_release_workgroup
277 )";
278
279 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
280 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_WEBGPU_0));
281 }
282
283 TEST_F(ValidateBarriers, OpControlBarrierWebGPURelaxedFailure) {
284 const std::string body = R"(
285 OpControlBarrier %workgroup %workgroup %workgroup
286 )";
287
288 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
289 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
290 EXPECT_THAT(getDiagnosticString(),
291 HasSubstr("For WebGPU, AcquireRelease must be set for Memory "
292 "Semantics of OpControlBarrier"));
293 }
294
295 TEST_F(ValidateBarriers, OpControlBarrierWebGPUMissingWorkgroupFailure) {
296 const std::string body = R"(
297 OpControlBarrier %workgroup %workgroup %acquire_release
298 )";
299
300 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
301 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
302 EXPECT_THAT(getDiagnosticString(),
303 HasSubstr("For WebGPU, WorkgroupMemory must be set for Memory "
304 "Semantics"));
305 }
306
307 TEST_F(ValidateBarriers, OpControlBarrierWebGPUUniformFailure) {
308 const std::string body = R"(
309 OpControlBarrier %workgroup %workgroup %acquire_release_uniform_workgroup
310 )";
311
312 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
313 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
314 EXPECT_THAT(
315 getDiagnosticString(),
316 HasSubstr("For WebGPU only WorkgroupMemory and AcquireRelease may be set "
317 "for Memory Semantics of OpControlBarrier."));
318 }
319
320 TEST_F(ValidateBarriers, OpControlBarrierWebGPUReleaseFailure) {
321 const std::string body = R"(
322 OpControlBarrier %workgroup %workgroup %release_uniform_workgroup
323 )";
324
325 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
326 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
327 EXPECT_THAT(getDiagnosticString(),
328 HasSubstr("For WebGPU, AcquireRelease must be set for Memory "
329 "Semantics of OpControlBarrier"));
330 }
331
332 TEST_F(ValidateBarriers, OpControlBarrierExecutionModelFragmentSpirv12) {
333 const std::string body = R"(
334 OpControlBarrier %device %device %none
335 )";
336
337 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment"),
338 SPV_ENV_UNIVERSAL_1_2);
339 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_2));
340 EXPECT_THAT(
341 getDiagnosticString(),
342 HasSubstr("OpControlBarrier requires one of the following Execution "
343 "Models: TessellationControl, GLCompute or Kernel"));
344 }
345
346 TEST_F(ValidateBarriers, OpControlBarrierExecutionModelFragmentSpirv13) {
347 const std::string body = R"(
348 OpControlBarrier %device %device %none
349 )";
350
351 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment"),
352 SPV_ENV_UNIVERSAL_1_3);
353 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
354 }
355
356 TEST_F(ValidateBarriers, OpControlBarrierFloatExecutionScope) {
357 const std::string body = R"(
358 OpControlBarrier %f32_1 %device %none
359 )";
360
361 CompileSuccessfully(GenerateShaderCode(body));
362 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
363 EXPECT_THAT(getDiagnosticString(),
364 HasSubstr("ControlBarrier: expected scope to be a 32-bit int"));
365 }
366
367 TEST_F(ValidateBarriers, OpControlBarrierU64ExecutionScope) {
368 const std::string body = R"(
369 OpControlBarrier %u64_1 %device %none
370 )";
371
372 CompileSuccessfully(GenerateShaderCode(body));
373 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
374 EXPECT_THAT(getDiagnosticString(),
375 HasSubstr("ControlBarrier: expected scope to be a 32-bit int"));
376 }
377
378 TEST_F(ValidateBarriers, OpControlBarrierFloatMemoryScope) {
379 const std::string body = R"(
380 OpControlBarrier %device %f32_1 %none
381 )";
382
383 CompileSuccessfully(GenerateShaderCode(body));
384 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
385 EXPECT_THAT(getDiagnosticString(),
386 HasSubstr("ControlBarrier: expected scope to be a 32-bit int"));
387 }
388
389 TEST_F(ValidateBarriers, OpControlBarrierU64MemoryScope) {
390 const std::string body = R"(
391 OpControlBarrier %device %u64_1 %none
392 )";
393
394 CompileSuccessfully(GenerateShaderCode(body));
395 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
396 EXPECT_THAT(getDiagnosticString(),
397 HasSubstr("ControlBarrier: expected scope to be a 32-bit int"));
398 }
399
400 TEST_F(ValidateBarriers, OpControlBarrierFloatMemorySemantics) {
401 const std::string body = R"(
402 OpControlBarrier %device %device %f32_0
403 )";
404
405 CompileSuccessfully(GenerateShaderCode(body));
406 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
407 EXPECT_THAT(
408 getDiagnosticString(),
409 HasSubstr(
410 "ControlBarrier: expected Memory Semantics to be a 32-bit int"));
411 }
412
413 TEST_F(ValidateBarriers, OpControlBarrierU64MemorySemantics) {
414 const std::string body = R"(
415 OpControlBarrier %device %device %u64_0
416 )";
417
418 CompileSuccessfully(GenerateShaderCode(body));
419 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
420 EXPECT_THAT(
421 getDiagnosticString(),
422 HasSubstr(
423 "ControlBarrier: expected Memory Semantics to be a 32-bit int"));
424 }
425
426 TEST_F(ValidateBarriers, OpControlBarrierVulkanExecutionScopeDevice) {
427 const std::string body = R"(
428 OpControlBarrier %device %workgroup %none
429 )";
430
431 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
432 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
433 EXPECT_THAT(getDiagnosticString(),
434 HasSubstr("ControlBarrier: in Vulkan environment Execution Scope "
435 "is limited to Workgroup and Subgroup"));
436 }
437
438 TEST_F(ValidateBarriers, OpControlBarrierWebGPUExecutionScopeDeviceBad) {
439 const std::string body = R"(
440 OpControlBarrier %device %workgroup %none
441 )";
442
443 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
444 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
445 EXPECT_THAT(getDiagnosticString(),
446 HasSubstr("ControlBarrier: in WebGPU environment Execution Scope "
447 "is limited to Workgroup"));
448 }
449
450 TEST_F(ValidateBarriers, OpControlBarrierWebGPUExecutionScopeSubgroupBad) {
451 const std::string body = R"(
452 OpControlBarrier %subgroup %workgroup %none
453 )";
454
455 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
456 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
457 EXPECT_THAT(getDiagnosticString(),
458 HasSubstr("ControlBarrier: in WebGPU environment Execution Scope "
459 "is limited to Workgroup"));
460 }
461
462 TEST_F(ValidateBarriers,
463 OpControlBarrierWebGPUExecutionScopeWorkgroupNonComputeBad) {
464 const std::string body = R"(
465 OpControlBarrier %workgroup %workgroup %acquire_release_workgroup
466 )";
467
468 CompileSuccessfully(GenerateWebGPUVertexShaderCode(body), SPV_ENV_WEBGPU_0);
469 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_WEBGPU_0));
470 EXPECT_THAT(
471 getDiagnosticString(),
472 HasSubstr(
473 "Workgroup Execution Scope is limited to GLCompute execution model"));
474 }
475
476 TEST_F(ValidateBarriers, OpControlBarrierVulkanMemoryScopeSubgroup) {
477 const std::string body = R"(
478 OpControlBarrier %subgroup %subgroup %none
479 )";
480
481 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
482 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
483 EXPECT_THAT(
484 getDiagnosticString(),
485 HasSubstr("ControlBarrier: in Vulkan 1.0 environment Memory Scope is "
486 "limited to Device, Workgroup and Invocation"));
487 }
488
489 TEST_F(ValidateBarriers, OpControlBarrierVulkan1p1MemoryScopeSubgroup) {
490 const std::string body = R"(
491 OpControlBarrier %subgroup %subgroup %none
492 )";
493
494 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_1);
495 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
496 }
497
498 TEST_F(ValidateBarriers, OpControlBarrierVulkan1p1MemoryScopeCrossDevice) {
499 const std::string body = R"(
500 OpControlBarrier %subgroup %cross_device %none
501 )";
502
503 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_1);
504 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
505 EXPECT_THAT(getDiagnosticString(),
506 HasSubstr("ControlBarrier: in Vulkan environment, Memory Scope "
507 "cannot be CrossDevice"));
508 }
509
510 TEST_F(ValidateBarriers, OpControlBarrierWebGPUMemoryScopeNonWorkgroup) {
511 const std::string body = R"(
512 OpControlBarrier %workgroup %subgroup %acquire_release_workgroup
513 )";
514
515 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
516 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
517 EXPECT_THAT(getDiagnosticString(),
518 HasSubstr("ControlBarrier: in WebGPU environment Memory Scope is "
519 "limited to Workgroup for OpControlBarrier"));
520 }
521
522 TEST_F(ValidateBarriers, OpControlBarrierAcquireAndRelease) {
523 const std::string body = R"(
524 OpControlBarrier %device %device %acquire_and_release_uniform
525 )";
526
527 CompileSuccessfully(GenerateShaderCode(body));
528 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
529 EXPECT_THAT(getDiagnosticString(),
530 HasSubstr("ControlBarrier: Memory Semantics can have at most one "
531 "of the following bits set: Acquire, Release, "
532 "AcquireRelease or SequentiallyConsistent"));
533 }
534
535 // TODO([email protected]): the corresponding check fails Vulkan CTS,
536 // reenable once fixed.
537 TEST_F(ValidateBarriers, DISABLED_OpControlBarrierVulkanSubgroupStorageClass) {
538 const std::string body = R"(
539 OpControlBarrier %workgroup %device %acquire_release_subgroup
540 )";
541
542 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
543 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
544 EXPECT_THAT(
545 getDiagnosticString(),
546 HasSubstr(
547 "ControlBarrier: expected Memory Semantics to include a "
548 "Vulkan-supported storage class if Memory Semantics is not None"));
549 }
550
551 TEST_F(ValidateBarriers, OpControlBarrierSubgroupExecutionFragment1p1) {
552 const std::string body = R"(
553 OpControlBarrier %subgroup %subgroup %acquire_release_subgroup
554 )";
555
556 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment"),
557 SPV_ENV_VULKAN_1_1);
558 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
559 }
560
561 TEST_F(ValidateBarriers, OpControlBarrierWorkgroupExecutionFragment1p1) {
562 const std::string body = R"(
563 OpControlBarrier %workgroup %workgroup %acquire_release
564 )";
565
566 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment"),
567 SPV_ENV_VULKAN_1_1);
568 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
569 EXPECT_THAT(getDiagnosticString(),
570 HasSubstr("OpControlBarrier execution scope must be Subgroup for "
571 "Fragment, Vertex, Geometry and TessellationEvaluation "
572 "execution models"));
573 }
574
575 TEST_F(ValidateBarriers, OpControlBarrierSubgroupExecutionFragment1p0) {
576 const std::string body = R"(
577 OpControlBarrier %subgroup %workgroup %acquire_release
578 )";
579
580 CompileSuccessfully(GenerateShaderCode(body, "", "Fragment"),
581 SPV_ENV_VULKAN_1_0);
582 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
583 EXPECT_THAT(
584 getDiagnosticString(),
585 HasSubstr("OpControlBarrier requires one of the following Execution "
586 "Models: TessellationControl, GLCompute or Kernel"));
587 }
588
589 TEST_F(ValidateBarriers, OpControlBarrierSubgroupExecutionVertex1p1) {
590 const std::string body = R"(
591 OpControlBarrier %subgroup %subgroup %acquire_release_subgroup
592 )";
593
594 CompileSuccessfully(GenerateShaderCode(body, "", "Vertex"),
595 SPV_ENV_VULKAN_1_1);
596 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
597 }
598
599 TEST_F(ValidateBarriers, OpControlBarrierWorkgroupExecutionVertex1p1) {
600 const std::string body = R"(
601 OpControlBarrier %workgroup %workgroup %acquire_release
602 )";
603
604 CompileSuccessfully(GenerateShaderCode(body, "", "Vertex"),
605 SPV_ENV_VULKAN_1_1);
606 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
607 EXPECT_THAT(getDiagnosticString(),
608 HasSubstr("OpControlBarrier execution scope must be Subgroup for "
609 "Fragment, Vertex, Geometry and TessellationEvaluation "
610 "execution models"));
611 }
612
613 TEST_F(ValidateBarriers, OpControlBarrierSubgroupExecutionVertex1p0) {
614 const std::string body = R"(
615 OpControlBarrier %subgroup %workgroup %acquire_release
616 )";
617
618 CompileSuccessfully(GenerateShaderCode(body, "", "Vertex"),
619 SPV_ENV_VULKAN_1_0);
620 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
621 EXPECT_THAT(
622 getDiagnosticString(),
623 HasSubstr("OpControlBarrier requires one of the following Execution "
624 "Models: TessellationControl, GLCompute or Kernel"));
625 }
626
627 TEST_F(ValidateBarriers, OpControlBarrierSubgroupExecutionGeometry1p1) {
628 const std::string body = R"(
629 OpControlBarrier %subgroup %subgroup %acquire_release_subgroup
630 )";
631
632 CompileSuccessfully(
633 GenerateShaderCode(body, "OpCapability Geometry\n", "Geometry"),
634 SPV_ENV_VULKAN_1_1);
635 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
636 }
637
638 TEST_F(ValidateBarriers, OpControlBarrierWorkgroupExecutionGeometry1p1) {
639 const std::string body = R"(
640 OpControlBarrier %workgroup %workgroup %acquire_release
641 )";
642
643 CompileSuccessfully(
644 GenerateShaderCode(body, "OpCapability Geometry\n", "Geometry"),
645 SPV_ENV_VULKAN_1_1);
646 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
647 EXPECT_THAT(getDiagnosticString(),
648 HasSubstr("OpControlBarrier execution scope must be Subgroup for "
649 "Fragment, Vertex, Geometry and TessellationEvaluation "
650 "execution models"));
651 }
652
653 TEST_F(ValidateBarriers, OpControlBarrierSubgroupExecutionGeometry1p0) {
654 const std::string body = R"(
655 OpControlBarrier %subgroup %workgroup %acquire_release
656 )";
657
658 CompileSuccessfully(
659 GenerateShaderCode(body, "OpCapability Geometry\n", "Geometry"),
660 SPV_ENV_VULKAN_1_0);
661 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
662 EXPECT_THAT(
663 getDiagnosticString(),
664 HasSubstr("OpControlBarrier requires one of the following Execution "
665 "Models: TessellationControl, GLCompute or Kernel"));
666 }
667
668 TEST_F(ValidateBarriers,
669 OpControlBarrierSubgroupExecutionTessellationEvaluation1p1) {
670 const std::string body = R"(
671 OpControlBarrier %subgroup %subgroup %acquire_release_subgroup
672 )";
673
674 CompileSuccessfully(GenerateShaderCode(body, "OpCapability Tessellation\n",
675 "TessellationEvaluation"),
676 SPV_ENV_VULKAN_1_1);
677 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
678 }
679
680 TEST_F(ValidateBarriers,
681 OpControlBarrierWorkgroupExecutionTessellationEvaluation1p1) {
682 const std::string body = R"(
683 OpControlBarrier %workgroup %workgroup %acquire_release
684 )";
685
686 CompileSuccessfully(GenerateShaderCode(body, "OpCapability Tessellation\n",
687 "TessellationEvaluation"),
688 SPV_ENV_VULKAN_1_1);
689 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
690 EXPECT_THAT(getDiagnosticString(),
691 HasSubstr("OpControlBarrier execution scope must be Subgroup for "
692 "Fragment, Vertex, Geometry and TessellationEvaluation "
693 "execution models"));
694 }
695
696 TEST_F(ValidateBarriers,
697 OpControlBarrierSubgroupExecutionTessellationEvaluation1p0) {
698 const std::string body = R"(
699 OpControlBarrier %subgroup %workgroup %acquire_release
700 )";
701
702 CompileSuccessfully(GenerateShaderCode(body, "OpCapability Tessellation\n",
703 "TessellationEvaluation"),
704 SPV_ENV_VULKAN_1_0);
705 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
706 EXPECT_THAT(
707 getDiagnosticString(),
708 HasSubstr("OpControlBarrier requires one of the following Execution "
709 "Models: TessellationControl, GLCompute or Kernel"));
710 }
711
712 TEST_F(ValidateBarriers, OpMemoryBarrierSuccess) {
713 const std::string body = R"(
714 OpMemoryBarrier %cross_device %acquire_release_uniform_workgroup
715 OpMemoryBarrier %device %uniform
716 )";
717
718 CompileSuccessfully(GenerateShaderCode(body));
719 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
720 }
721
722 TEST_F(ValidateBarriers, OpMemoryBarrierKernelSuccess) {
723 const std::string body = R"(
724 OpMemoryBarrier %cross_device %acquire_release_workgroup
725 OpMemoryBarrier %device %none
726 )";
727
728 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
729 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
730 }
731
732 TEST_F(ValidateBarriers, OpMemoryBarrierVulkanSuccess) {
733 const std::string body = R"(
734 OpMemoryBarrier %workgroup %acquire_release_uniform_workgroup
735 )";
736
737 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
738 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
739 }
740
741 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPUImageMemorySuccess) {
742 const std::string body = R"(
743 OpMemoryBarrier %workgroup %image_memory
744 )";
745
746 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
747 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_WEBGPU_0));
748 }
749
750 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPUDeviceFailure) {
751 const std::string body = R"(
752 OpMemoryBarrier %subgroup %image_memory
753 )";
754
755 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
756 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
757 EXPECT_THAT(getDiagnosticString(),
758 HasSubstr("in WebGPU environment Memory Scope is limited to "
759 "Workgroup for OpMemoryBarrier"));
760 }
761
762 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPUAcquireReleaseFailure) {
763 const std::string body = R"(
764 OpMemoryBarrier %workgroup %acquire_release_uniform_workgroup
765 )";
766
767 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
768 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
769 EXPECT_THAT(getDiagnosticString(),
770 HasSubstr("ImageMemory must be set for Memory Semantics of "
771 "OpMemoryBarrier"));
772 }
773
774 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPURelaxedFailure) {
775 const std::string body = R"(
776 OpMemoryBarrier %workgroup %uniform_workgroup
777 )";
778
779 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
780 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
781 EXPECT_THAT(getDiagnosticString(),
782 HasSubstr("ImageMemory must be set for Memory Semantics of "
783 "OpMemoryBarrier"));
784 }
785
786 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPUAcquireFailure) {
787 const std::string body = R"(
788 OpMemoryBarrier %workgroup %acquire_uniform_workgroup
789 )";
790
791 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
792 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
793 EXPECT_THAT(getDiagnosticString(),
794 HasSubstr("ImageMemory must be set for Memory Semantics of "
795 "OpMemoryBarrier"));
796 }
797
798 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPUReleaseFailure) {
799 const std::string body = R"(
800 OpMemoryBarrier %workgroup %release_uniform_workgroup
801 )";
802
803 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
804 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
805 EXPECT_THAT(getDiagnosticString(),
806 HasSubstr("ImageMemory must be set for Memory Semantics of "
807 "OpMemoryBarrier"));
808 }
809
810 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPUUniformFailure) {
811 const std::string body = R"(
812 OpMemoryBarrier %workgroup %uniform_image_memory
813 )";
814
815 CompileSuccessfully(GenerateWebGPUComputeShaderCode(body), SPV_ENV_WEBGPU_0);
816 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_WEBGPU_0));
817 EXPECT_THAT(getDiagnosticString(),
818 HasSubstr("only ImageMemory may be set for Memory Semantics of "
819 "OpMemoryBarrier"));
820 }
821
822 TEST_F(ValidateBarriers, OpMemoryBarrierWebGPUWorkgroupNonComputeFailure) {
823 const std::string body = R"(
824 OpMemoryBarrier %workgroup %image_memory
825 )";
826
827 CompileSuccessfully(GenerateWebGPUVertexShaderCode(body), SPV_ENV_WEBGPU_0);
828 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_WEBGPU_0));
829 EXPECT_THAT(
830 getDiagnosticString(),
831 HasSubstr(
832 "Workgroup Memory Scope is limited to GLCompute execution model"));
833 }
834
835 TEST_F(ValidateBarriers, OpMemoryBarrierFloatMemoryScope) {
836 const std::string body = R"(
837 OpMemoryBarrier %f32_1 %acquire_release_uniform_workgroup
838 )";
839
840 CompileSuccessfully(GenerateShaderCode(body));
841 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
842 EXPECT_THAT(getDiagnosticString(),
843 HasSubstr("MemoryBarrier: expected scope to be a 32-bit int"));
844 }
845
846 TEST_F(ValidateBarriers, OpMemoryBarrierU64MemoryScope) {
847 const std::string body = R"(
848 OpMemoryBarrier %u64_1 %acquire_release_uniform_workgroup
849 )";
850
851 CompileSuccessfully(GenerateShaderCode(body));
852 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
853 EXPECT_THAT(getDiagnosticString(),
854 HasSubstr("MemoryBarrier: expected scope to be a 32-bit int"));
855 }
856
857 TEST_F(ValidateBarriers, OpMemoryBarrierFloatMemorySemantics) {
858 const std::string body = R"(
859 OpMemoryBarrier %device %f32_0
860 )";
861
862 CompileSuccessfully(GenerateShaderCode(body));
863 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
864 EXPECT_THAT(
865 getDiagnosticString(),
866 HasSubstr("MemoryBarrier: expected Memory Semantics to be a 32-bit int"));
867 }
868
869 TEST_F(ValidateBarriers, OpMemoryBarrierU64MemorySemantics) {
870 const std::string body = R"(
871 OpMemoryBarrier %device %u64_0
872 )";
873
874 CompileSuccessfully(GenerateShaderCode(body));
875 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
876 EXPECT_THAT(
877 getDiagnosticString(),
878 HasSubstr("MemoryBarrier: expected Memory Semantics to be a 32-bit int"));
879 }
880
881 TEST_F(ValidateBarriers, OpMemoryBarrierVulkanMemoryScopeSubgroup) {
882 const std::string body = R"(
883 OpMemoryBarrier %subgroup %acquire_release_uniform_workgroup
884 )";
885
886 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
887 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
888 EXPECT_THAT(
889 getDiagnosticString(),
890 HasSubstr("MemoryBarrier: in Vulkan 1.0 environment Memory Scope is "
891 "limited to Device, Workgroup and Invocation"));
892 }
893
894 TEST_F(ValidateBarriers, OpMemoryBarrierVulkan1p1MemoryScopeSubgroup) {
895 const std::string body = R"(
896 OpMemoryBarrier %subgroup %acquire_release_uniform_workgroup
897 )";
898
899 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_1);
900 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
901 }
902
903 TEST_F(ValidateBarriers, OpMemoryBarrierAcquireAndRelease) {
904 const std::string body = R"(
905 OpMemoryBarrier %device %acquire_and_release_uniform
906 )";
907
908 CompileSuccessfully(GenerateShaderCode(body));
909 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
910 EXPECT_THAT(getDiagnosticString(),
911 HasSubstr("MemoryBarrier: Memory Semantics can have at most one "
912 "of the following bits set: Acquire, Release, "
913 "AcquireRelease or SequentiallyConsistent"));
914 }
915
916 TEST_F(ValidateBarriers, OpMemoryBarrierVulkanMemorySemanticsNone) {
917 const std::string body = R"(
918 OpMemoryBarrier %device %none
919 )";
920
921 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
922 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
923 EXPECT_THAT(
924 getDiagnosticString(),
925 HasSubstr("MemoryBarrier: Vulkan specification requires Memory Semantics "
926 "to have one of the following bits set: Acquire, Release, "
927 "AcquireRelease or SequentiallyConsistent"));
928 }
929
930 TEST_F(ValidateBarriers, OpMemoryBarrierVulkanMemorySemanticsAcquire) {
931 const std::string body = R"(
932 OpMemoryBarrier %device %acquire
933 )";
934
935 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
936 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
937 EXPECT_THAT(getDiagnosticString(),
938 HasSubstr("MemoryBarrier: expected Memory Semantics to include a "
939 "Vulkan-supported storage class"));
940 }
941
942 TEST_F(ValidateBarriers, OpMemoryBarrierVulkanSubgroupStorageClass) {
943 const std::string body = R"(
944 OpMemoryBarrier %device %acquire_release_subgroup
945 )";
946
947 CompileSuccessfully(GenerateShaderCode(body), SPV_ENV_VULKAN_1_0);
948 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
949 EXPECT_THAT(getDiagnosticString(),
950 HasSubstr("MemoryBarrier: expected Memory Semantics to include a "
951 "Vulkan-supported storage class"));
952 }
953
954 TEST_F(ValidateBarriers, OpNamedBarrierInitializeSuccess) {
955 const std::string body = R"(
956 %barrier = OpNamedBarrierInitialize %named_barrier %u32_4
957 )";
958
959 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
960 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
961 }
962
963 TEST_F(ValidateBarriers, OpNamedBarrierInitializeWrongResultType) {
964 const std::string body = R"(
965 %barrier = OpNamedBarrierInitialize %u32 %u32_4
966 )";
967
968 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
969 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
970 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
971 EXPECT_THAT(getDiagnosticString(),
972 HasSubstr("NamedBarrierInitialize: expected Result Type to be "
973 "OpTypeNamedBarrier"));
974 }
975
976 TEST_F(ValidateBarriers, OpNamedBarrierInitializeFloatSubgroupCount) {
977 const std::string body = R"(
978 %barrier = OpNamedBarrierInitialize %named_barrier %f32_4
979 )";
980
981 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
982 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
983 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
984 EXPECT_THAT(getDiagnosticString(),
985 HasSubstr("NamedBarrierInitialize: expected Subgroup Count to be "
986 "a 32-bit int"));
987 }
988
989 TEST_F(ValidateBarriers, OpNamedBarrierInitializeU64SubgroupCount) {
990 const std::string body = R"(
991 %barrier = OpNamedBarrierInitialize %named_barrier %u64_4
992 )";
993
994 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
995 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
996 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
997 EXPECT_THAT(getDiagnosticString(),
998 HasSubstr("NamedBarrierInitialize: expected Subgroup Count to be "
999 "a 32-bit int"));
1000 }
1001
1002 TEST_F(ValidateBarriers, OpMemoryNamedBarrierSuccess) {
1003 const std::string body = R"(
1004 %barrier = OpNamedBarrierInitialize %named_barrier %u32_4
1005 OpMemoryNamedBarrier %barrier %workgroup %acquire_release_workgroup
1006 )";
1007
1008 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
1009 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
1010 }
1011
1012 TEST_F(ValidateBarriers, OpMemoryNamedBarrierNotNamedBarrier) {
1013 const std::string body = R"(
1014 OpMemoryNamedBarrier %u32_1 %workgroup %acquire_release_workgroup
1015 )";
1016
1017 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
1018 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
1019 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
1020 EXPECT_THAT(getDiagnosticString(),
1021 HasSubstr("MemoryNamedBarrier: expected Named Barrier to be of "
1022 "type OpTypeNamedBarrier"));
1023 }
1024
1025 TEST_F(ValidateBarriers, OpMemoryNamedBarrierFloatMemoryScope) {
1026 const std::string body = R"(
1027 %barrier = OpNamedBarrierInitialize %named_barrier %u32_4
1028 OpMemoryNamedBarrier %barrier %f32_1 %acquire_release_workgroup
1029 )";
1030
1031 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
1032 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
1033 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
1034 EXPECT_THAT(
1035 getDiagnosticString(),
1036 HasSubstr("MemoryNamedBarrier: expected scope to be a 32-bit int"));
1037 }
1038
1039 TEST_F(ValidateBarriers, OpMemoryNamedBarrierFloatMemorySemantics) {
1040 const std::string body = R"(
1041 %barrier = OpNamedBarrierInitialize %named_barrier %u32_4
1042 OpMemoryNamedBarrier %barrier %workgroup %f32_0
1043 )";
1044
1045 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
1046 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
1047 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
1048 EXPECT_THAT(
1049 getDiagnosticString(),
1050 HasSubstr(
1051 "MemoryNamedBarrier: expected Memory Semantics to be a 32-bit int"));
1052 }
1053
1054 TEST_F(ValidateBarriers, OpMemoryNamedBarrierAcquireAndRelease) {
1055 const std::string body = R"(
1056 %barrier = OpNamedBarrierInitialize %named_barrier %u32_4
1057 OpMemoryNamedBarrier %barrier %workgroup %acquire_and_release
1058 )";
1059
1060 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
1061 ASSERT_EQ(SPV_ERROR_INVALID_DATA,
1062 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
1063 EXPECT_THAT(getDiagnosticString(),
1064 HasSubstr("MemoryNamedBarrier: Memory Semantics can have at most "
1065 "one of the following bits set: Acquire, Release, "
1066 "AcquireRelease or SequentiallyConsistent"));
1067 }
1068
1069 TEST_F(ValidateBarriers, TypeAsMemoryScope) {
1070 const std::string body = R"(
1071 OpMemoryBarrier %u32 %u32_0
1072 )";
1073
1074 CompileSuccessfully(GenerateKernelCode(body), SPV_ENV_UNIVERSAL_1_1);
1075 EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
1076 EXPECT_THAT(getDiagnosticString(), HasSubstr("Operand 5[%uint] cannot be a "
1077 "type"));
1078 }
1079
1080 TEST_F(ValidateBarriers,
1081 OpControlBarrierVulkanMemoryModelBanSequentiallyConsistent) {
1082 const std::string text = R"(
1083 OpCapability Shader
1084 OpCapability VulkanMemoryModelKHR
1085 OpExtension "SPV_KHR_vulkan_memory_model"
1086 OpMemoryModel Logical VulkanKHR
1087 OpEntryPoint Fragment %1 "func"
1088 OpExecutionMode %1 OriginUpperLeft
1089 %2 = OpTypeVoid
1090 %3 = OpTypeInt 32 0
1091 %4 = OpConstant %3 16
1092 %5 = OpTypeFunction %2
1093 %6 = OpConstant %3 5
1094 %1 = OpFunction %2 None %5
1095 %7 = OpLabel
1096 OpControlBarrier %6 %6 %4
1097 OpReturn
1098 OpFunctionEnd
1099 )";
1100
1101 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1102 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1103 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1104 EXPECT_THAT(getDiagnosticString(),
1105 HasSubstr("SequentiallyConsistent memory semantics cannot be "
1106 "used with the VulkanKHR memory model."));
1107 }
1108
1109 TEST_F(ValidateBarriers,
1110 OpMemoryBarrierVulkanMemoryModelBanSequentiallyConsistent) {
1111 const std::string text = R"(
1112 OpCapability Shader
1113 OpCapability VulkanMemoryModelKHR
1114 OpExtension "SPV_KHR_vulkan_memory_model"
1115 OpMemoryModel Logical VulkanKHR
1116 OpEntryPoint Fragment %1 "func"
1117 OpExecutionMode %1 OriginUpperLeft
1118 %2 = OpTypeVoid
1119 %3 = OpTypeInt 32 0
1120 %4 = OpConstant %3 16
1121 %5 = OpTypeFunction %2
1122 %6 = OpConstant %3 5
1123 %1 = OpFunction %2 None %5
1124 %7 = OpLabel
1125 OpMemoryBarrier %6 %4
1126 OpReturn
1127 OpFunctionEnd
1128 )";
1129
1130 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1131 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1132 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1133 EXPECT_THAT(getDiagnosticString(),
1134 HasSubstr("SequentiallyConsistent memory semantics cannot be "
1135 "used with the VulkanKHR memory model."));
1136 }
1137
1138 TEST_F(ValidateBarriers, OutputMemoryKHRRequireVulkanMemoryModelKHR) {
1139 const std::string text = R"(
1140 OpCapability Shader
1141 OpMemoryModel Logical GLSL450
1142 OpEntryPoint Fragment %1 "func"
1143 OpExecutionMode %1 OriginUpperLeft
1144 %2 = OpTypeVoid
1145 %3 = OpTypeInt 32 0
1146 %semantics = OpConstant %3 4104
1147 %5 = OpTypeFunction %2
1148 %device = OpConstant %3 1
1149 %1 = OpFunction %2 None %5
1150 %7 = OpLabel
1151 OpControlBarrier %device %device %semantics
1152 OpReturn
1153 OpFunctionEnd
1154 )";
1155
1156 CompileSuccessfully(text);
1157 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1158 EXPECT_THAT(getDiagnosticString(),
1159 HasSubstr("ControlBarrier: Memory Semantics OutputMemoryKHR "
1160 "requires capability VulkanMemoryModelKHR"));
1161 }
1162
1163 TEST_F(ValidateBarriers, MakeAvailableKHRRequireVulkanMemoryModelKHR) {
1164 const std::string text = R"(
1165 OpCapability Shader
1166 OpMemoryModel Logical GLSL450
1167 OpEntryPoint Fragment %1 "func"
1168 OpExecutionMode %1 OriginUpperLeft
1169 %2 = OpTypeVoid
1170 %3 = OpTypeInt 32 0
1171 %semantics = OpConstant %3 8264
1172 %5 = OpTypeFunction %2
1173 %device = OpConstant %3 1
1174 %1 = OpFunction %2 None %5
1175 %7 = OpLabel
1176 OpControlBarrier %device %device %semantics
1177 OpReturn
1178 OpFunctionEnd
1179 )";
1180
1181 CompileSuccessfully(text);
1182 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1183 EXPECT_THAT(getDiagnosticString(),
1184 HasSubstr("ControlBarrier: Memory Semantics MakeAvailableKHR "
1185 "requires capability VulkanMemoryModelKHR"));
1186 }
1187
1188 TEST_F(ValidateBarriers, MakeVisibleKHRRequireVulkanMemoryModelKHR) {
1189 const std::string text = R"(
1190 OpCapability Shader
1191 OpMemoryModel Logical GLSL450
1192 OpEntryPoint Fragment %1 "func"
1193 OpExecutionMode %1 OriginUpperLeft
1194 %2 = OpTypeVoid
1195 %3 = OpTypeInt 32 0
1196 %semantics = OpConstant %3 16456
1197 %5 = OpTypeFunction %2
1198 %device = OpConstant %3 1
1199 %1 = OpFunction %2 None %5
1200 %7 = OpLabel
1201 OpControlBarrier %device %device %semantics
1202 OpReturn
1203 OpFunctionEnd
1204 )";
1205
1206 CompileSuccessfully(text);
1207 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1208 EXPECT_THAT(getDiagnosticString(),
1209 HasSubstr("ControlBarrier: Memory Semantics MakeVisibleKHR "
1210 "requires capability VulkanMemoryModelKHR"));
1211 }
1212
1213 TEST_F(ValidateBarriers, MakeAvailableKHRRequiresReleaseSemantics) {
1214 const std::string text = R"(
1215 OpCapability Shader
1216 OpCapability VulkanMemoryModelKHR
1217 OpExtension "SPV_KHR_vulkan_memory_model"
1218 OpMemoryModel Logical VulkanKHR
1219 OpEntryPoint Fragment %func "func"
1220 OpExecutionMode %func OriginUpperLeft
1221 %void = OpTypeVoid
1222 %int = OpTypeInt 32 0
1223 %workgroup = OpConstant %int 2
1224 %semantics = OpConstant %int 8448
1225 %functy = OpTypeFunction %void
1226 %func = OpFunction %void None %functy
1227 %1 = OpLabel
1228 OpControlBarrier %workgroup %workgroup %semantics
1229 OpReturn
1230 OpFunctionEnd
1231 )";
1232
1233 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1234 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1235 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1236 EXPECT_THAT(
1237 getDiagnosticString(),
1238 HasSubstr("ControlBarrier: MakeAvailableKHR Memory Semantics also "
1239 "requires either Release or AcquireRelease Memory Semantics"));
1240 }
1241
1242 TEST_F(ValidateBarriers, MakeVisibleKHRRequiresAcquireSemantics) {
1243 const std::string text = R"(
1244 OpCapability Shader
1245 OpCapability VulkanMemoryModelKHR
1246 OpExtension "SPV_KHR_vulkan_memory_model"
1247 OpMemoryModel Logical VulkanKHR
1248 OpEntryPoint Fragment %func "func"
1249 OpExecutionMode %func OriginUpperLeft
1250 %void = OpTypeVoid
1251 %int = OpTypeInt 32 0
1252 %workgroup = OpConstant %int 2
1253 %semantics = OpConstant %int 16640
1254 %functy = OpTypeFunction %void
1255 %func = OpFunction %void None %functy
1256 %1 = OpLabel
1257 OpControlBarrier %workgroup %workgroup %semantics
1258 OpReturn
1259 OpFunctionEnd
1260 )";
1261
1262 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1263 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1264 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1265 EXPECT_THAT(
1266 getDiagnosticString(),
1267 HasSubstr("ControlBarrier: MakeVisibleKHR Memory Semantics also requires "
1268 "either Acquire or AcquireRelease Memory Semantics"));
1269 }
1270
1271 TEST_F(ValidateBarriers, MakeAvailableKHRRequiresStorageSemantics) {
1272 const std::string text = R"(
1273 OpCapability Shader
1274 OpCapability VulkanMemoryModelKHR
1275 OpExtension "SPV_KHR_vulkan_memory_model"
1276 OpMemoryModel Logical VulkanKHR
1277 OpEntryPoint Fragment %func "func"
1278 OpExecutionMode %func OriginUpperLeft
1279 %void = OpTypeVoid
1280 %int = OpTypeInt 32 0
1281 %workgroup = OpConstant %int 2
1282 %semantics = OpConstant %int 8196
1283 %functy = OpTypeFunction %void
1284 %func = OpFunction %void None %functy
1285 %1 = OpLabel
1286 OpMemoryBarrier %workgroup %semantics
1287 OpReturn
1288 OpFunctionEnd
1289 )";
1290
1291 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1292 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1293 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1294 EXPECT_THAT(getDiagnosticString(),
1295 HasSubstr("MemoryBarrier: expected Memory Semantics to include a "
1296 "storage class"));
1297 }
1298
1299 TEST_F(ValidateBarriers, MakeVisibleKHRRequiresStorageSemantics) {
1300 const std::string text = R"(
1301 OpCapability Shader
1302 OpCapability VulkanMemoryModelKHR
1303 OpExtension "SPV_KHR_vulkan_memory_model"
1304 OpMemoryModel Logical VulkanKHR
1305 OpEntryPoint Fragment %func "func"
1306 OpExecutionMode %func OriginUpperLeft
1307 %void = OpTypeVoid
1308 %int = OpTypeInt 32 0
1309 %workgroup = OpConstant %int 2
1310 %semantics = OpConstant %int 16386
1311 %functy = OpTypeFunction %void
1312 %func = OpFunction %void None %functy
1313 %1 = OpLabel
1314 OpMemoryBarrier %workgroup %semantics
1315 OpReturn
1316 OpFunctionEnd
1317 )";
1318
1319 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1320 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1321 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1322 EXPECT_THAT(getDiagnosticString(),
1323 HasSubstr("MemoryBarrier: expected Memory Semantics to include a "
1324 "storage class"));
1325 }
1326
1327 TEST_F(ValidateBarriers, SemanticsSpecConstantShader) {
1328 const std::string spirv = R"(
1329 OpCapability Shader
1330 OpMemoryModel Logical GLSL450
1331 OpEntryPoint Fragment %func "func"
1332 OpExecutionMode %func OriginUpperLeft
1333 %void = OpTypeVoid
1334 %int = OpTypeInt 32 0
1335 %ptr_int_workgroup = OpTypePointer Workgroup %int
1336 %var = OpVariable %ptr_int_workgroup Workgroup
1337 %voidfn = OpTypeFunction %void
1338 %spec_const = OpSpecConstant %int 0
1339 %workgroup = OpConstant %int 2
1340 %func = OpFunction %void None %voidfn
1341 %entry = OpLabel
1342 OpMemoryBarrier %workgroup %spec_const
1343 OpReturn
1344 OpFunctionEnd
1345 )";
1346
1347 CompileSuccessfully(spirv);
1348 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1349 EXPECT_THAT(getDiagnosticString(),
1350 HasSubstr("Memory Semantics ids must be OpConstant when Shader "
1351 "capability is present"));
1352 }
1353
1354 TEST_F(ValidateBarriers, SemanticsSpecConstantKernel) {
1355 const std::string spirv = R"(
1356 OpCapability Kernel
1357 OpCapability Linkage
1358 OpMemoryModel Logical OpenCL
1359 %void = OpTypeVoid
1360 %int = OpTypeInt 32 0
1361 %ptr_int_workgroup = OpTypePointer Workgroup %int
1362 %var = OpVariable %ptr_int_workgroup Workgroup
1363 %voidfn = OpTypeFunction %void
1364 %spec_const = OpSpecConstant %int 0
1365 %workgroup = OpConstant %int 2
1366 %func = OpFunction %void None %voidfn
1367 %entry = OpLabel
1368 OpMemoryBarrier %workgroup %spec_const
1369 OpReturn
1370 OpFunctionEnd
1371 )";
1372
1373 CompileSuccessfully(spirv);
1374 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1375 }
1376
1377 TEST_F(ValidateBarriers, ScopeSpecConstantShader) {
1378 const std::string spirv = R"(
1379 OpCapability Shader
1380 OpMemoryModel Logical GLSL450
1381 OpEntryPoint Fragment %func "func"
1382 OpExecutionMode %func OriginUpperLeft
1383 %void = OpTypeVoid
1384 %int = OpTypeInt 32 0
1385 %ptr_int_workgroup = OpTypePointer Workgroup %int
1386 %var = OpVariable %ptr_int_workgroup Workgroup
1387 %voidfn = OpTypeFunction %void
1388 %spec_const = OpSpecConstant %int 0
1389 %relaxed = OpConstant %int 0
1390 %func = OpFunction %void None %voidfn
1391 %entry = OpLabel
1392 OpMemoryBarrier %spec_const %relaxed
1393 OpReturn
1394 OpFunctionEnd
1395 )";
1396
1397 CompileSuccessfully(spirv);
1398 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1399 EXPECT_THAT(getDiagnosticString(),
1400 HasSubstr("Scope ids must be OpConstant when Shader "
1401 "capability is present"));
1402 }
1403
1404 TEST_F(ValidateBarriers, ScopeSpecConstantKernel) {
1405 const std::string spirv = R"(
1406 OpCapability Kernel
1407 OpCapability Linkage
1408 OpMemoryModel Logical OpenCL
1409 %void = OpTypeVoid
1410 %int = OpTypeInt 32 0
1411 %ptr_int_workgroup = OpTypePointer Workgroup %int
1412 %var = OpVariable %ptr_int_workgroup Workgroup
1413 %voidfn = OpTypeFunction %void
1414 %spec_const = OpSpecConstant %int 0
1415 %relaxed = OpConstant %int 0
1416 %func = OpFunction %void None %voidfn
1417 %entry = OpLabel
1418 OpMemoryBarrier %spec_const %relaxed
1419 OpReturn
1420 OpFunctionEnd
1421 )";
1422
1423 CompileSuccessfully(spirv);
1424 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1425 }
1426
1427 TEST_F(ValidateBarriers, VulkanMemoryModelDeviceScopeBad) {
1428 const std::string text = R"(
1429 OpCapability Shader
1430 OpCapability VulkanMemoryModelKHR
1431 OpExtension "SPV_KHR_vulkan_memory_model"
1432 OpMemoryModel Logical VulkanKHR
1433 OpEntryPoint Fragment %func "func"
1434 OpExecutionMode %func OriginUpperLeft
1435 %void = OpTypeVoid
1436 %int = OpTypeInt 32 0
1437 %device = OpConstant %int 1
1438 %semantics = OpConstant %int 0
1439 %functy = OpTypeFunction %void
1440 %func = OpFunction %void None %functy
1441 %1 = OpLabel
1442 OpMemoryBarrier %device %semantics
1443 OpReturn
1444 OpFunctionEnd
1445 )";
1446
1447 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1448 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
1449 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1450 EXPECT_THAT(
1451 getDiagnosticString(),
1452 HasSubstr("Use of device scope with VulkanKHR memory model requires the "
1453 "VulkanMemoryModelDeviceScopeKHR capability"));
1454 }
1455
1456 TEST_F(ValidateBarriers, VulkanMemoryModelDeviceScopeGood) {
1457 const std::string text = R"(
1458 OpCapability Shader
1459 OpCapability VulkanMemoryModelKHR
1460 OpCapability VulkanMemoryModelDeviceScopeKHR
1461 OpExtension "SPV_KHR_vulkan_memory_model"
1462 OpMemoryModel Logical VulkanKHR
1463 OpEntryPoint Fragment %func "func"
1464 OpExecutionMode %func OriginUpperLeft
1465 %void = OpTypeVoid
1466 %int = OpTypeInt 32 0
1467 %device = OpConstant %int 1
1468 %semantics = OpConstant %int 0
1469 %functy = OpTypeFunction %void
1470 %func = OpFunction %void None %functy
1471 %1 = OpLabel
1472 OpMemoryBarrier %device %semantics
1473 OpReturn
1474 OpFunctionEnd
1475 )";
1476
1477 CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_3);
1478 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
1479 }
1480
1481 TEST_F(ValidateBarriers, VolatileMemoryBarrier) {
1482 const std::string text = R"(
1483 OpCapability Shader
1484 OpCapability VulkanMemoryModelKHR
1485 OpCapability VulkanMemoryModelDeviceScopeKHR
1486 OpCapability Linkage
1487 OpExtension "SPV_KHR_vulkan_memory_model"
1488 OpMemoryModel Logical VulkanKHR
1489 %void = OpTypeVoid
1490 %int = OpTypeInt 32 0
1491 %device = OpConstant %int 1
1492 %semantics = OpConstant %int 32768
1493 %functy = OpTypeFunction %void
1494 %func = OpFunction %void None %functy
1495 %1 = OpLabel
1496 OpMemoryBarrier %device %semantics
1497 OpReturn
1498 OpFunctionEnd
1499 )";
1500
1501 CompileSuccessfully(text);
1502 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1503 EXPECT_THAT(getDiagnosticString(),
1504 HasSubstr("Memory Semantics Volatile can only be used with "
1505 "atomic instructions"));
1506 }
1507
1508 TEST_F(ValidateBarriers, VolatileControlBarrier) {
1509 const std::string text = R"(
1510 OpCapability Shader
1511 OpCapability VulkanMemoryModelKHR
1512 OpCapability VulkanMemoryModelDeviceScopeKHR
1513 OpCapability Linkage
1514 OpExtension "SPV_KHR_vulkan_memory_model"
1515 OpMemoryModel Logical VulkanKHR
1516 %void = OpTypeVoid
1517 %int = OpTypeInt 32 0
1518 %device = OpConstant %int 1
1519 %semantics = OpConstant %int 32768
1520 %functy = OpTypeFunction %void
1521 %func = OpFunction %void None %functy
1522 %1 = OpLabel
1523 OpControlBarrier %device %device %semantics
1524 OpReturn
1525 OpFunctionEnd
1526 )";
1527
1528 CompileSuccessfully(text);
1529 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1530 EXPECT_THAT(getDiagnosticString(),
1531 HasSubstr("Memory Semantics Volatile can only be used with "
1532 "atomic instructions"));
1533 }
1534
1535 TEST_F(ValidateBarriers, CooperativeMatrixSpecConstantVolatile) {
1536 const std::string text = R"(
1537 OpCapability Shader
1538 OpCapability VulkanMemoryModelKHR
1539 OpCapability VulkanMemoryModelDeviceScopeKHR
1540 OpCapability CooperativeMatrixNV
1541 OpCapability Linkage
1542 OpExtension "SPV_KHR_vulkan_memory_model"
1543 OpExtension "SPV_NV_cooperative_matrix"
1544 OpMemoryModel Logical VulkanKHR
1545 %void = OpTypeVoid
1546 %int = OpTypeInt 32 0
1547 %device = OpConstant %int 1
1548 %semantics = OpSpecConstant %int 32768
1549 %functy = OpTypeFunction %void
1550 %func = OpFunction %void None %functy
1551 %1 = OpLabel
1552 OpControlBarrier %device %device %semantics
1553 OpReturn
1554 OpFunctionEnd
1555 )";
1556
1557 CompileSuccessfully(text);
1558 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
1559 }
1560
1561 TEST_F(ValidateBarriers, CooperativeMatrixNonConstantSemantics) {
1562 const std::string text = R"(
1563 OpCapability Shader
1564 OpCapability VulkanMemoryModelKHR
1565 OpCapability VulkanMemoryModelDeviceScopeKHR
1566 OpCapability CooperativeMatrixNV
1567 OpCapability Linkage
1568 OpExtension "SPV_KHR_vulkan_memory_model"
1569 OpExtension "SPV_NV_cooperative_matrix"
1570 OpMemoryModel Logical VulkanKHR
1571 %void = OpTypeVoid
1572 %int = OpTypeInt 32 0
1573 %device = OpConstant %int 1
1574 %semantics = OpUndef %int
1575 %functy = OpTypeFunction %void
1576 %func = OpFunction %void None %functy
1577 %1 = OpLabel
1578 OpControlBarrier %device %device %semantics
1579 OpReturn
1580 OpFunctionEnd
1581 )";
1582
1583 CompileSuccessfully(text);
1584 EXPECT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
1585 EXPECT_THAT(getDiagnosticString(),
1586 HasSubstr("Memory Semantics must be a constant instruction when "
1587 "CooperativeMatrixNV capability is present"));
1588 }
1589
1590 TEST_F(ValidateBarriers, OpMemoryBarrierShaderCallRayGenSuccess) {
1591 const std::string body =
1592 "OpMemoryBarrier %shadercall %release_uniform_workgroup";
1593
1594 CompileSuccessfully(GenerateShaderCodeImpl(body,
1595 // capabilities_and_extensions
1596 R"(
1597 OpCapability VulkanMemoryModelKHR
1598 OpCapability RayTracingProvisionalKHR
1599 OpExtension "SPV_KHR_vulkan_memory_model"
1600 OpExtension "SPV_KHR_ray_tracing"
1601 )",
1602 // definitions
1603 "",
1604 // execution_model
1605 "RayGenerationKHR",
1606 // memory_model
1607 "OpMemoryModel Logical VulkanKHR"),
1608 SPV_ENV_VULKAN_1_1);
1609
1610 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_1));
1611 }
1612
1613 TEST_F(ValidateBarriers, OpMemoryBarrierShaderCallComputeFailure) {
1614 const std::string body =
1615 "OpMemoryBarrier %shadercall %release_uniform_workgroup";
1616
1617 CompileSuccessfully(GenerateShaderCodeImpl(body,
1618 // capabilities_and_extensions
1619 R"(
1620 OpCapability VulkanMemoryModelKHR
1621 OpExtension "SPV_KHR_vulkan_memory_model"
1622 )",
1623 // definitions
1624 "",
1625 // execution_model
1626 "GLCompute",
1627 // memory_model
1628 "OpMemoryModel Logical VulkanKHR"),
1629 SPV_ENV_VULKAN_1_1);
1630
1631 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_1));
1632 EXPECT_THAT(
1633 getDiagnosticString(),
1634 HasSubstr(
1635 "ShaderCallKHR Memory Scope requires a ray tracing execution model"));
1636 }
1637
1638 TEST_F(ValidateBarriers, OpControlBarrierShaderCallRayGenFailure) {
1639 const std::string body = "OpControlBarrier %shadercall %shadercall %none";
1640
1641 CompileSuccessfully(GenerateShaderCodeImpl(body,
1642 // capabilities_and_extensions
1643 R"(
1644 OpCapability VulkanMemoryModelKHR
1645 OpCapability RayTracingProvisionalKHR
1646 OpExtension "SPV_KHR_vulkan_memory_model"
1647 OpExtension "SPV_KHR_ray_tracing"
1648 )",
1649 // definitions
1650 "",
1651 // execution_model
1652 "RayGenerationKHR",
1653 // memory_model
1654 "OpMemoryModel Logical VulkanKHR"),
1655 SPV_ENV_VULKAN_1_1);
1656
1657 ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_1));
1658 EXPECT_THAT(getDiagnosticString(),
1659 HasSubstr("in Vulkan environment Execution Scope is limited to "
1660 "Workgroup and Subgroup"));
1661 }
1662
1663 } // namespace
1664 } // namespace val
1665 } // namespace spvtools