Debian Codegraph @

test/val/val_storage_test.cpp

raw
1 // Copyright (c) 2015-2016 The Khronos Group Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Validation tests for OpVariable storage class
16
17 #include <sstream>
18 #include <string>
19 #include <tuple>
20
21 #include "gmock/gmock.h"
22 #include "test/val/val_fixtures.h"
23
24 namespace spvtools {
25 namespace val {
26 namespace {
27
28 using ::testing::HasSubstr;
29 using ::testing::Values;
30 using ValidateStorage = spvtest::ValidateBase<std::string>;
31 using ValidateStorageExecutionModel = spvtest::ValidateBase<std::string>;
32
33 TEST_F(ValidateStorage, FunctionStorageInsideFunction) {
34 char str[] = R"(
35 OpCapability Shader
36 OpCapability Linkage
37 OpMemoryModel Logical GLSL450
38 %intt = OpTypeInt 32 1
39 %voidt = OpTypeVoid
40 %vfunct = OpTypeFunction %voidt
41 %ptrt = OpTypePointer Function %intt
42 %func = OpFunction %voidt None %vfunct
43 %funcl = OpLabel
44 %var = OpVariable %ptrt Function
45 OpReturn
46 OpFunctionEnd
47 )";
48
49 CompileSuccessfully(str);
50 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
51 }
52
53 TEST_F(ValidateStorage, FunctionStorageOutsideFunction) {
54 char str[] = R"(
55 OpCapability Shader
56 OpCapability Linkage
57 OpMemoryModel Logical GLSL450
58 %intt = OpTypeInt 32 1
59 %voidt = OpTypeVoid
60 %vfunct = OpTypeFunction %voidt
61 %ptrt = OpTypePointer Function %intt
62 %var = OpVariable %ptrt Function
63 %func = OpFunction %voidt None %vfunct
64 %funcl = OpLabel
65 OpReturn
66 OpFunctionEnd
67 )";
68
69 CompileSuccessfully(str);
70 ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
71 EXPECT_THAT(getDiagnosticString(),
72 HasSubstr("Variables can not have a function[7] storage class "
73 "outside of a function"));
74 }
75
76 TEST_F(ValidateStorage, OtherStorageOutsideFunction) {
77 char str[] = R"(
78 OpCapability Shader
79 OpCapability Kernel
80 OpCapability AtomicStorage
81 OpCapability Linkage
82 OpMemoryModel Logical GLSL450
83 %intt = OpTypeInt 32 0
84 %voidt = OpTypeVoid
85 %vfunct = OpTypeFunction %voidt
86 %uniconptrt = OpTypePointer UniformConstant %intt
87 %unicon = OpVariable %uniconptrt UniformConstant
88 %inputptrt = OpTypePointer Input %intt
89 %input = OpVariable %inputptrt Input
90 %unifptrt = OpTypePointer Uniform %intt
91 %unif = OpVariable %unifptrt Uniform
92 %outputptrt = OpTypePointer Output %intt
93 %output = OpVariable %outputptrt Output
94 %wgroupptrt = OpTypePointer Workgroup %intt
95 %wgroup = OpVariable %wgroupptrt Workgroup
96 %xwgrpptrt = OpTypePointer CrossWorkgroup %intt
97 %xwgrp = OpVariable %xwgrpptrt CrossWorkgroup
98 %privptrt = OpTypePointer Private %intt
99 %priv = OpVariable %privptrt Private
100 %pushcoptrt = OpTypePointer PushConstant %intt
101 %pushco = OpVariable %pushcoptrt PushConstant
102 %atomcptrt = OpTypePointer AtomicCounter %intt
103 %atomct = OpVariable %atomcptrt AtomicCounter
104 %imageptrt = OpTypePointer Image %intt
105 %image = OpVariable %imageptrt Image
106 %func = OpFunction %voidt None %vfunct
107 %funcl = OpLabel
108 OpReturn
109 OpFunctionEnd
110 )";
111
112 CompileSuccessfully(str);
113 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
114 }
115
116 // clang-format off
117 TEST_P(ValidateStorage, OtherStorageInsideFunction) {
118 std::stringstream ss;
119 ss << R"(
120 OpCapability Shader
121 OpCapability Kernel
122 OpCapability AtomicStorage
123 OpCapability Linkage
124 OpMemoryModel Logical GLSL450
125 %intt = OpTypeInt 32 0
126 %voidt = OpTypeVoid
127 %vfunct = OpTypeFunction %voidt
128 %ptrt = OpTypePointer Function %intt
129 %func = OpFunction %voidt None %vfunct
130 %funcl = OpLabel
131 %var = OpVariable %ptrt )" << GetParam() << R"(
132 OpReturn
133 OpFunctionEnd
134 )";
135
136 CompileSuccessfully(ss.str());
137 ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
138 EXPECT_THAT(getDiagnosticString(), HasSubstr(
139 "Variables must have a function[7] storage class inside of a function"));
140 }
141
142 INSTANTIATE_TEST_SUITE_P(MatrixOp, ValidateStorage,
143 ::testing::Values(
144 "Input",
145 "Uniform",
146 "Output",
147 "Workgroup",
148 "CrossWorkgroup",
149 "Private",
150 "PushConstant",
151 "AtomicCounter",
152 "Image"));
153 // clang-format on
154
155 TEST_F(ValidateStorage, GenericVariableOutsideFunction) {
156 const auto str = R"(
157 OpCapability Kernel
158 OpCapability Linkage
159 OpCapability GenericPointer
160 OpMemoryModel Logical OpenCL
161 %intt = OpTypeInt 32 0
162 %ptrt = OpTypePointer Function %intt
163 %var = OpVariable %ptrt Generic
164 )";
165 CompileSuccessfully(str);
166 ASSERT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions());
167 EXPECT_THAT(getDiagnosticString(),
168 HasSubstr("Variable storage class cannot be Generic"));
169 }
170
171 TEST_F(ValidateStorage, GenericVariableInsideFunction) {
172 const auto str = R"(
173 OpCapability Shader
174 OpCapability Linkage
175 OpCapability GenericPointer
176 OpMemoryModel Logical GLSL450
177 %intt = OpTypeInt 32 1
178 %voidt = OpTypeVoid
179 %vfunct = OpTypeFunction %voidt
180 %ptrt = OpTypePointer Function %intt
181 %func = OpFunction %voidt None %vfunct
182 %funcl = OpLabel
183 %var = OpVariable %ptrt Generic
184 OpReturn
185 OpFunctionEnd
186 )";
187 CompileSuccessfully(str);
188 EXPECT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions());
189 EXPECT_THAT(getDiagnosticString(),
190 HasSubstr("Variable storage class cannot be Generic"));
191 }
192
193 TEST_F(ValidateStorage, RelaxedLogicalPointerFunctionParam) {
194 const auto str = R"(
195 OpCapability Shader
196 OpCapability Linkage
197 OpMemoryModel Logical GLSL450
198 %intt = OpTypeInt 32 1
199 %voidt = OpTypeVoid
200 %ptrt = OpTypePointer Function %intt
201 %vfunct = OpTypeFunction %voidt
202 %vifunct = OpTypeFunction %voidt %ptrt
203 %wgroupptrt = OpTypePointer Workgroup %intt
204 %wgroup = OpVariable %wgroupptrt Workgroup
205 %main = OpFunction %voidt None %vfunct
206 %mainl = OpLabel
207 %ret = OpFunctionCall %voidt %func %wgroup
208 OpReturn
209 OpFunctionEnd
210 %func = OpFunction %voidt None %vifunct
211 %arg = OpFunctionParameter %ptrt
212 %funcl = OpLabel
213 OpReturn
214 OpFunctionEnd
215 )";
216 CompileSuccessfully(str);
217 getValidatorOptions()->before_hlsl_legalization = true;
218 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
219 }
220
221 TEST_F(ValidateStorage, RelaxedLogicalPointerFunctionParamBad) {
222 const auto str = R"(
223 OpCapability Shader
224 OpCapability Linkage
225 OpMemoryModel Logical GLSL450
226 %floatt = OpTypeFloat 32
227 %intt = OpTypeInt 32 1
228 %voidt = OpTypeVoid
229 %ptrt = OpTypePointer Function %intt
230 %vfunct = OpTypeFunction %voidt
231 %vifunct = OpTypeFunction %voidt %ptrt
232 %wgroupptrt = OpTypePointer Workgroup %floatt
233 %wgroup = OpVariable %wgroupptrt Workgroup
234 %main = OpFunction %voidt None %vfunct
235 %mainl = OpLabel
236 %ret = OpFunctionCall %voidt %func %wgroup
237 OpReturn
238 OpFunctionEnd
239 %func = OpFunction %voidt None %vifunct
240 %arg = OpFunctionParameter %ptrt
241 %funcl = OpLabel
242 OpReturn
243 OpFunctionEnd
244 )";
245 CompileSuccessfully(str);
246 getValidatorOptions()->relax_logical_pointer = true;
247 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
248 EXPECT_THAT(getDiagnosticString(),
249 HasSubstr("OpFunctionCall Argument <id> '"));
250 }
251
252 TEST_F(ValidateStorage, TileAttachmentQCOMBad1) {
253 const std::string spirv = R"(
254 OpCapability Shader
255 OpCapability Sampled1D
256 OpCapability TileShadingQCOM
257 OpExtension "SPV_QCOM_tile_shading"
258 OpMemoryModel Logical GLSL450
259 OpEntryPoint Fragment %main "main"
260 OpExecutionMode %main OriginUpperLeft
261 OpSource GLSL 450
262 OpDecorate %color1 Binding 2
263 OpDecorate %color1 DescriptorSet 0
264 %void = OpTypeVoid
265 %int = OpTypeInt 32 1
266 %44 = OpTypeImage %int 1D 0 0 0 2 Rgba32i
267 %_ptr_TileAttachmentQCOM_44 = OpTypePointer TileAttachmentQCOM %44
268 %color1 = OpVariable %_ptr_TileAttachmentQCOM_44 TileAttachmentQCOM
269 %3 = OpTypeFunction %void
270 %main = OpFunction %void None %3
271 %5 = OpLabel
272 OpReturn
273 OpFunctionEnd
274 )";
275
276 spv_target_env env = SPV_ENV_VULKAN_1_4;
277 CompileSuccessfully(spirv, env);
278 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
279 EXPECT_THAT(getDiagnosticString(),
280 HasSubstr("Any OpTypeImage variable in the TileAttachmentQCOM "
281 "Storage Class must have 2D as its dimension"));
282 }
283
284 TEST_F(ValidateStorage, TileAttachmentQCOMBad2) {
285 const std::string spirv = R"(
286 OpCapability Shader
287 OpCapability TileShadingQCOM
288 OpExtension "SPV_QCOM_tile_shading"
289 OpMemoryModel Logical GLSL450
290 OpEntryPoint Fragment %main "main"
291 OpExecutionMode %main OriginUpperLeft
292 OpSource GLSL 450
293 OpDecorate %color1 Binding 2
294 %void = OpTypeVoid
295 %int = OpTypeInt 32 1
296 %44 = OpTypeImage %int 2D 0 0 0 2 Rgba32i
297 %_ptr_TileAttachmentQCOM_44 = OpTypePointer TileAttachmentQCOM %44
298 %color1 = OpVariable %_ptr_TileAttachmentQCOM_44 TileAttachmentQCOM
299 %3 = OpTypeFunction %void
300 %main = OpFunction %void None %3
301 %5 = OpLabel
302 OpReturn
303 OpFunctionEnd
304 )";
305
306 spv_target_env env = SPV_ENV_VULKAN_1_4;
307 CompileSuccessfully(spirv, env);
308 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
309 EXPECT_THAT(getDiagnosticString(),
310 HasSubstr("Any variable in the TileAttachmentQCOM Storage Class "
311 "must be decorated with DescriptorSet and Binding"));
312 }
313
314 TEST_F(ValidateStorage, TileAttachmentQCOMBad3) {
315 const std::string spirv = R"(
316 OpCapability Shader
317 OpCapability TileShadingQCOM
318 OpExtension "SPV_QCOM_tile_shading"
319 OpMemoryModel Logical GLSL450
320 OpEntryPoint Fragment %main "main"
321 OpExecutionMode %main OriginUpperLeft
322 OpSource GLSL 450
323 OpDecorate %color1 DescriptorSet 0
324 %void = OpTypeVoid
325 %int = OpTypeInt 32 1
326 %44 = OpTypeImage %int 2D 0 0 0 2 Rgba32i
327 %_ptr_TileAttachmentQCOM_44 = OpTypePointer TileAttachmentQCOM %44
328 %color1 = OpVariable %_ptr_TileAttachmentQCOM_44 TileAttachmentQCOM
329 %3 = OpTypeFunction %void
330 %main = OpFunction %void None %3
331 %5 = OpLabel
332 OpReturn
333 OpFunctionEnd
334 )";
335
336 spv_target_env env = SPV_ENV_VULKAN_1_4;
337 CompileSuccessfully(spirv, env);
338 EXPECT_THAT(SPV_ERROR_INVALID_ID, ValidateInstructions(env));
339 EXPECT_THAT(getDiagnosticString(),
340 HasSubstr("Any variable in the TileAttachmentQCOM Storage Class "
341 "must be decorated with DescriptorSet and Binding"));
342 }
343
344 TEST_F(ValidateStorage, TileAttachmentQCOMBad4) {
345 const std::string spirv = R"(
346 OpCapability Shader
347 OpCapability TileShadingQCOM
348 OpExtension "SPV_QCOM_tile_shading"
349 %1 = OpExtInstImport "GLSL.std.450"
350 OpMemoryModel Logical GLSL450
351 OpEntryPoint Fragment %main "main"
352 OpExecutionMode %main OriginUpperLeft
353 OpSource GLSL 450
354 OpDecorate %color1 Binding 2
355 OpDecorate %color1 DescriptorSet 0
356 %void = OpTypeVoid
357 %int = OpTypeInt 32 1
358 %44 = OpTypeImage %int 2D 0 0 0 0 Rgba32i
359 %_ptr_TileAttachmentQCOM_44 = OpTypePointer TileAttachmentQCOM %44
360 %color1 = OpVariable %_ptr_TileAttachmentQCOM_44 TileAttachmentQCOM
361 %3 = OpTypeFunction %void
362 %main = OpFunction %void None %3
363 %5 = OpLabel
364 OpReturn
365 OpFunctionEnd
366 )";
367
368 spv_target_env env = SPV_ENV_VULKAN_1_4;
369 CompileSuccessfully(spirv, env);
370 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
371 EXPECT_THAT(getDiagnosticString(),
372 AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04657"));
373 EXPECT_THAT(getDiagnosticString(),
374 HasSubstr("Sampled must be 1 or 2 in the Vulkan environment"));
375 }
376
377 TEST_F(ValidateStorage, TileAttachmentQCOMBad5) {
378 const std::string spirv = R"(
379 OpCapability Shader
380 OpCapability ImageQuery
381 OpCapability TileShadingQCOM
382 OpExtension "SPV_QCOM_tile_shading"
383 OpMemoryModel Logical GLSL450
384 OpEntryPoint Fragment %main "main"
385 OpExecutionMode %main OriginUpperLeft
386 OpDecorate %color1 Binding 2
387 OpDecorate %color1 DescriptorSet 0
388 %void = OpTypeVoid
389 %3 = OpTypeFunction %void
390 %int = OpTypeInt 32 1
391 %v2int = OpTypeVector %int 2
392 %int_2 = OpConstant %int 2
393 %44 = OpTypeImage %int 2D 0 0 0 2 Rgba32i
394 %_ptr_TileAttachmentQCOM_44 = OpTypePointer TileAttachmentQCOM %44
395 %color1 = OpVariable %_ptr_TileAttachmentQCOM_44 TileAttachmentQCOM
396 %main = OpFunction %void None %3
397 %5 = OpLabel
398 %154 = OpLoad %44 %color1
399 %156 = OpImageQuerySizeLod %v2int %154 %int_2
400 OpReturn
401 OpFunctionEnd
402 )";
403
404 spv_target_env env = SPV_ENV_VULKAN_1_4;
405 CompileSuccessfully(spirv, env);
406 EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
407 EXPECT_THAT(
408 getDiagnosticString(),
409 HasSubstr("Any variable in the TileAttachmentQCOM Storage Class "
410 "must not be consumed by an OpImageQuery* instruction"));
411 }
412
413 TEST_F(ValidateStorage, TileAttachmentQCOMBad6) {
414 const std::string spirv = R"(
415 OpCapability Shader
416 OpMemoryModel Logical GLSL450
417 OpEntryPoint Fragment %main "main"
418 OpExecutionMode %main OriginUpperLeft
419 OpDecorate %color1 Binding 2
420 OpDecorate %color1 DescriptorSet 0
421 %void = OpTypeVoid
422 %int = OpTypeInt 32 1
423 %44 = OpTypeImage %int 2D 0 0 0 2 Rgba32i
424 %_ptr_TileAttachmentQCOM_44 = OpTypePointer TileAttachmentQCOM %44
425 %color1 = OpVariable %_ptr_TileAttachmentQCOM_44 TileAttachmentQCOM
426 %3 = OpTypeFunction %void
427 %main = OpFunction %void None %3
428 %5 = OpLabel
429 OpReturn
430 OpFunctionEnd
431 )";
432
433 spv_target_env env = SPV_ENV_VULKAN_1_4;
434 CompileSuccessfully(spirv, env);
435 EXPECT_THAT(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions(env));
436 EXPECT_THAT(getDiagnosticString(),
437 HasSubstr("requires one of these capabilities: TileShadingQCOM"));
438 }
439
440 std::string GenerateExecutionModelCode(const std::string& execution_model,
441 const std::string& storage_class,
442 bool store) {
443 const std::string mode = (execution_model.compare("GLCompute") == 0)
444 ? "OpExecutionMode %func LocalSize 1 1 1"
445 : "";
446 const std::string operation =
447 (store) ? "OpStore %var %int0" : "%load = OpLoad %intt %var";
448 std::ostringstream ss;
449 ss << R"(
450 OpCapability Shader
451 OpCapability RayTracingKHR
452 OpExtension "SPV_KHR_ray_tracing"
453 OpMemoryModel Logical GLSL450
454 OpEntryPoint )"
455 << execution_model << R"( %func "func" %var
456 )"
457 << mode << R"(
458 OpDecorate %var Location 0
459 %intt = OpTypeInt 32 0
460 %int0 = OpConstant %intt 0
461 %voidt = OpTypeVoid
462 %vfunct = OpTypeFunction %voidt
463 %ptr = OpTypePointer )"
464 << storage_class << R"( %intt
465 %var = OpVariable %ptr )"
466 << storage_class << R"(
467 %func = OpFunction %voidt None %vfunct
468 %funcl = OpLabel
469 )"
470 << operation << R"(
471 OpReturn
472 OpFunctionEnd
473 )";
474
475 return ss.str();
476 }
477
478 TEST_P(ValidateStorageExecutionModel, VulkanOutsideStoreFailure) {
479 std::string execution_model = GetParam();
480 CompileSuccessfully(
481 GenerateExecutionModelCode(execution_model, "Output", true).c_str(),
482 SPV_ENV_VULKAN_1_0);
483 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_0));
484 EXPECT_THAT(getDiagnosticString(),
485 AnyVUID("VUID-StandaloneSpirv-None-04644"));
486 EXPECT_THAT(
487 getDiagnosticString(),
488 HasSubstr("in Vulkan environment, Output Storage Class must not be used "
489 "in GLCompute, RayGenerationKHR, IntersectionKHR, AnyHitKHR, "
490 "ClosestHitKHR, MissKHR, or CallableKHR execution models"));
491 }
492
493 TEST_P(ValidateStorageExecutionModel, CallableDataStore) {
494 std::string execution_model = GetParam();
495 CompileSuccessfully(
496 GenerateExecutionModelCode(execution_model, "CallableDataKHR", true)
497 .c_str(),
498 SPV_ENV_VULKAN_1_2);
499 if (execution_model.compare("RayGenerationKHR") == 0 ||
500 execution_model.compare("ClosestHitKHR") == 0 ||
501 execution_model.compare("CallableKHR") == 0 ||
502 execution_model.compare("MissKHR") == 0) {
503 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
504 } else {
505 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
506 EXPECT_THAT(getDiagnosticString(),
507 AnyVUID("VUID-StandaloneSpirv-CallableDataKHR-04704"));
508 EXPECT_THAT(
509 getDiagnosticString(),
510 HasSubstr(
511 "CallableDataKHR Storage Class is limited to RayGenerationKHR, "
512 "ClosestHitKHR, CallableKHR, and MissKHR execution model"));
513 }
514 }
515
516 TEST_P(ValidateStorageExecutionModel, CallableDataLoad) {
517 std::string execution_model = GetParam();
518 CompileSuccessfully(
519 GenerateExecutionModelCode(execution_model, "CallableDataKHR", false)
520 .c_str(),
521 SPV_ENV_VULKAN_1_2);
522 if (execution_model.compare("RayGenerationKHR") == 0 ||
523 execution_model.compare("ClosestHitKHR") == 0 ||
524 execution_model.compare("CallableKHR") == 0 ||
525 execution_model.compare("MissKHR") == 0) {
526 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
527 } else {
528 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
529 EXPECT_THAT(getDiagnosticString(),
530 AnyVUID("VUID-StandaloneSpirv-CallableDataKHR-04704"));
531 EXPECT_THAT(
532 getDiagnosticString(),
533 HasSubstr(
534 "CallableDataKHR Storage Class is limited to RayGenerationKHR, "
535 "ClosestHitKHR, CallableKHR, and MissKHR execution model"));
536 }
537 }
538
539 TEST_P(ValidateStorageExecutionModel, IncomingCallableDataStore) {
540 std::string execution_model = GetParam();
541 CompileSuccessfully(GenerateExecutionModelCode(
542 execution_model, "IncomingCallableDataKHR", true)
543 .c_str(),
544 SPV_ENV_VULKAN_1_2);
545 if (execution_model.compare("CallableKHR") == 0) {
546 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
547 } else {
548 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
549 EXPECT_THAT(getDiagnosticString(),
550 AnyVUID("VUID-StandaloneSpirv-IncomingCallableDataKHR-04705"));
551 EXPECT_THAT(getDiagnosticString(),
552 HasSubstr("IncomingCallableDataKHR Storage Class is limited to "
553 "CallableKHR execution model"));
554 }
555 }
556
557 TEST_P(ValidateStorageExecutionModel, IncomingCallableDataLoad) {
558 std::string execution_model = GetParam();
559 CompileSuccessfully(GenerateExecutionModelCode(
560 execution_model, "IncomingCallableDataKHR", false)
561 .c_str(),
562 SPV_ENV_VULKAN_1_2);
563 if (execution_model.compare("CallableKHR") == 0) {
564 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
565 } else {
566 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
567 EXPECT_THAT(getDiagnosticString(),
568 AnyVUID("VUID-StandaloneSpirv-IncomingCallableDataKHR-04705"));
569 EXPECT_THAT(getDiagnosticString(),
570 HasSubstr("IncomingCallableDataKHR Storage Class is limited to "
571 "CallableKHR execution model"));
572 }
573 }
574
575 TEST_P(ValidateStorageExecutionModel, RayPayloadStore) {
576 std::string execution_model = GetParam();
577 CompileSuccessfully(
578 GenerateExecutionModelCode(execution_model, "RayPayloadKHR", true)
579 .c_str(),
580 SPV_ENV_VULKAN_1_2);
581 if (execution_model.compare("RayGenerationKHR") == 0 ||
582 execution_model.compare("ClosestHitKHR") == 0 ||
583 execution_model.compare("MissKHR") == 0) {
584 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
585 } else {
586 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
587 EXPECT_THAT(getDiagnosticString(),
588 AnyVUID("VUID-StandaloneSpirv-RayPayloadKHR-04698"));
589 EXPECT_THAT(
590 getDiagnosticString(),
591 HasSubstr("RayPayloadKHR Storage Class is limited to RayGenerationKHR, "
592 "ClosestHitKHR, and MissKHR execution model"));
593 }
594 }
595
596 TEST_P(ValidateStorageExecutionModel, RayPayloadLoad) {
597 std::string execution_model = GetParam();
598 CompileSuccessfully(
599 GenerateExecutionModelCode(execution_model, "RayPayloadKHR", false)
600 .c_str(),
601 SPV_ENV_VULKAN_1_2);
602 if (execution_model.compare("RayGenerationKHR") == 0 ||
603 execution_model.compare("ClosestHitKHR") == 0 ||
604 execution_model.compare("MissKHR") == 0) {
605 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
606 } else {
607 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
608 EXPECT_THAT(getDiagnosticString(),
609 AnyVUID("VUID-StandaloneSpirv-RayPayloadKHR-04698"));
610 EXPECT_THAT(
611 getDiagnosticString(),
612 HasSubstr("RayPayloadKHR Storage Class is limited to RayGenerationKHR, "
613 "ClosestHitKHR, and MissKHR execution model"));
614 }
615 }
616
617 TEST_P(ValidateStorageExecutionModel, HitAttributeStore) {
618 std::string execution_model = GetParam();
619 CompileSuccessfully(
620 GenerateExecutionModelCode(execution_model, "HitAttributeKHR", true)
621 .c_str(),
622 SPV_ENV_VULKAN_1_2);
623 if (execution_model.compare("IntersectionKHR") == 0) {
624 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
625 } else if (execution_model.compare("AnyHitKHR") == 0 ||
626 execution_model.compare("ClosestHitKHR") == 0) {
627 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
628 EXPECT_THAT(getDiagnosticString(),
629 AnyVUID("VUID-StandaloneSpirv-HitAttributeKHR-04703"));
630 EXPECT_THAT(getDiagnosticString(),
631 HasSubstr("HitAttributeKHR Storage Class variables are read "
632 "only with AnyHitKHR and ClosestHitKHR"));
633 } else {
634 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
635 EXPECT_THAT(getDiagnosticString(),
636 AnyVUID("VUID-StandaloneSpirv-HitAttributeKHR-04701"));
637 EXPECT_THAT(
638 getDiagnosticString(),
639 HasSubstr(
640 "HitAttributeKHR Storage Class is limited to IntersectionKHR, "
641 "AnyHitKHR, sand ClosestHitKHR execution model"));
642 }
643 }
644
645 TEST_P(ValidateStorageExecutionModel, HitAttributeLoad) {
646 std::string execution_model = GetParam();
647 CompileSuccessfully(
648 GenerateExecutionModelCode(execution_model, "HitAttributeKHR", false)
649 .c_str(),
650 SPV_ENV_VULKAN_1_2);
651 if (execution_model.compare("IntersectionKHR") == 0 ||
652 execution_model.compare("AnyHitKHR") == 0 ||
653 execution_model.compare("ClosestHitKHR") == 0) {
654 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
655 } else {
656 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
657 EXPECT_THAT(getDiagnosticString(),
658 AnyVUID("VUID-StandaloneSpirv-HitAttributeKHR-04701"));
659 EXPECT_THAT(
660 getDiagnosticString(),
661 HasSubstr(
662 "HitAttributeKHR Storage Class is limited to IntersectionKHR, "
663 "AnyHitKHR, sand ClosestHitKHR execution model"));
664 }
665 }
666
667 TEST_P(ValidateStorageExecutionModel, IncomingRayPayloadStore) {
668 std::string execution_model = GetParam();
669 CompileSuccessfully(
670 GenerateExecutionModelCode(execution_model, "IncomingRayPayloadKHR", true)
671 .c_str(),
672 SPV_ENV_VULKAN_1_2);
673 if (execution_model.compare("AnyHitKHR") == 0 ||
674 execution_model.compare("ClosestHitKHR") == 0 ||
675 execution_model.compare("MissKHR") == 0) {
676 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
677 } else {
678 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
679 EXPECT_THAT(getDiagnosticString(),
680 AnyVUID("VUID-StandaloneSpirv-IncomingRayPayloadKHR-04699"));
681 EXPECT_THAT(
682 getDiagnosticString(),
683 HasSubstr("IncomingRayPayloadKHR Storage Class is limited to "
684 "AnyHitKHR, ClosestHitKHR, and MissKHR execution model"));
685 }
686 }
687
688 TEST_P(ValidateStorageExecutionModel, IncomingRayPayloadLoad) {
689 std::string execution_model = GetParam();
690 CompileSuccessfully(GenerateExecutionModelCode(execution_model,
691 "IncomingRayPayloadKHR", false)
692 .c_str(),
693 SPV_ENV_VULKAN_1_2);
694 if (execution_model.compare("AnyHitKHR") == 0 ||
695 execution_model.compare("ClosestHitKHR") == 0 ||
696 execution_model.compare("MissKHR") == 0) {
697 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
698 } else {
699 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
700 EXPECT_THAT(getDiagnosticString(),
701 AnyVUID("VUID-StandaloneSpirv-IncomingRayPayloadKHR-04699"));
702 EXPECT_THAT(
703 getDiagnosticString(),
704 HasSubstr("IncomingRayPayloadKHR Storage Class is limited to "
705 "AnyHitKHR, ClosestHitKHR, and MissKHR execution model"));
706 }
707 }
708
709 TEST_P(ValidateStorageExecutionModel, ShaderRecordBufferStore) {
710 std::string execution_model = GetParam();
711 CompileSuccessfully(
712 GenerateExecutionModelCode(execution_model, "ShaderRecordBufferKHR", true)
713 .c_str(),
714 SPV_ENV_VULKAN_1_2);
715 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
716 EXPECT_THAT(
717 getDiagnosticString(),
718 HasSubstr("ShaderRecordBufferKHR Storage Class variables are read only"));
719 }
720
721 TEST_P(ValidateStorageExecutionModel, ShaderRecordBufferLoad) {
722 std::string execution_model = GetParam();
723 CompileSuccessfully(GenerateExecutionModelCode(execution_model,
724 "ShaderRecordBufferKHR", false)
725 .c_str(),
726 SPV_ENV_VULKAN_1_2);
727 if (execution_model.compare("RayGenerationKHR") == 0 ||
728 execution_model.compare("IntersectionKHR") == 0 ||
729 execution_model.compare("AnyHitKHR") == 0 ||
730 execution_model.compare("ClosestHitKHR") == 0 ||
731 execution_model.compare("CallableKHR") == 0 ||
732 execution_model.compare("MissKHR") == 0) {
733 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_2));
734 } else {
735 ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions(SPV_ENV_VULKAN_1_2));
736 EXPECT_THAT(getDiagnosticString(),
737 AnyVUID("VUID-StandaloneSpirv-ShaderRecordBufferKHR-07119"));
738 EXPECT_THAT(
739 getDiagnosticString(),
740 HasSubstr("ShaderRecordBufferKHR Storage Class is limited to "
741 "RayGenerationKHR, IntersectionKHR, AnyHitKHR, "
742 "ClosestHitKHR, CallableKHR, and MissKHR execution model"));
743 }
744 }
745
746 INSTANTIATE_TEST_SUITE_P(MatrixExecutionModel, ValidateStorageExecutionModel,
747 ::testing::Values("RayGenerationKHR",
748 "IntersectionKHR", "AnyHitKHR",
749 "ClosestHitKHR", "MissKHR",
750 "CallableKHR", "GLCompute"));
751
752 } // namespace
753 } // namespace val
754 } // namespace spvtools