Debian Codegraph @

third_party/spirv-tools/test/val/val_capability_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 Logical Layout
16
17 #include <sstream>
18 #include <string>
19 #include <tuple>
20 #include <utility>
21 #include <vector>
22
23 #include "gmock/gmock.h"
24 #include "source/assembly_grammar.h"
25 #include "source/spirv_target_env.h"
26 #include "spirv-tools/libspirv.h"
27 #include "test/test_fixture.h"
28 #include "test/unit_spirv.h"
29 #include "test/val/val_fixtures.h"
30
31 namespace spvtools {
32 namespace val {
33 namespace {
34
35 using spvtest::ScopedContext;
36 using testing::Combine;
37 using testing::Eq;
38 using testing::HasSubstr;
39 using testing::Values;
40 using testing::ValuesIn;
41
42 // Parameter for validation test fixtures. The first std::string is a
43 // capability name that will begin the assembly under test, the second the
44 // remainder assembly, and the std::vector at the end determines whether the
45 // test expects success or failure. See below for details and convenience
46 // methods to access each one.
47 //
48 // The assembly to test is composed from a variable top line and a fixed
49 // remainder. The top line will be an OpCapability instruction, while the
50 // remainder will be some assembly text that succeeds or fails to assemble
51 // depending on which capability was chosen. For instance, the following will
52 // succeed:
53 //
54 // OpCapability Pipes ; implies Kernel
55 // OpLifetimeStop %1 0 ; requires Kernel
56 //
57 // and the following will fail:
58 //
59 // OpCapability Kernel
60 // %1 = OpTypeNamedBarrier ; requires NamedBarrier
61 //
62 // So how does the test parameter capture which capabilities should cause
63 // success and which shouldn't? The answer is in the last element: it's a
64 // std::vector of capabilities that make the remainder assembly succeed. So if
65 // the first-line capability exists in that std::vector, success is expected;
66 // otherwise, failure is expected in the tests.
67 //
68 // We will use testing::Combine() to vary the first line: when we combine
69 // AllCapabilities() with a single remainder assembly, we generate enough test
70 // cases to try the assembly with every possible capability that could be
71 // declared. However, Combine() only produces tuples -- it cannot produce, say,
72 // a struct. Therefore, this type must be a tuple.
73 using CapTestParameter =
74 std::tuple<std::string, std::pair<std::string, std::vector<std::string>>>;
75
76 const std::string& Capability(const CapTestParameter& p) {
77 return std::get<0>(p);
78 }
79 const std::string& Remainder(const CapTestParameter& p) {
80 return std::get<1>(p).first;
81 }
82 const std::vector<std::string>& MustSucceed(const CapTestParameter& p) {
83 return std::get<1>(p).second;
84 }
85
86 // Creates assembly to test from p.
87 std::string MakeAssembly(const CapTestParameter& p) {
88 std::ostringstream ss;
89 const std::string& capability = Capability(p);
90 if (!capability.empty()) {
91 ss << "OpCapability " << capability << "\n";
92 }
93 ss << Remainder(p);
94 return ss.str();
95 }
96
97 // Expected validation result for p.
98 spv_result_t ExpectedResult(const CapTestParameter& p) {
99 const auto& caps = MustSucceed(p);
100 auto found = find(begin(caps), end(caps), Capability(p));
101 return (found == end(caps)) ? SPV_ERROR_INVALID_CAPABILITY : SPV_SUCCESS;
102 }
103
104 // Assembles using v1.0, unless the parameter's capability requires v1.1.
105 using ValidateCapability = spvtest::ValidateBase<CapTestParameter>;
106
107 // Always assembles using v1.1.
108 using ValidateCapabilityV11 = spvtest::ValidateBase<CapTestParameter>;
109
110 // Always assembles using Vulkan 1.0.
111 // TODO(dneto): Refactor all these tests to scale better across environments.
112 using ValidateCapabilityVulkan10 = spvtest::ValidateBase<CapTestParameter>;
113 // Always assembles using OpenGL 4.0.
114 using ValidateCapabilityOpenGL40 = spvtest::ValidateBase<CapTestParameter>;
115 // Always assembles using Vulkan 1.1.
116 using ValidateCapabilityVulkan11 = spvtest::ValidateBase<CapTestParameter>;
117 // Always assembles using Vulkan 1.2.
118 using ValidateCapabilityVulkan12 = spvtest::ValidateBase<CapTestParameter>;
119 // Always assembles using WebGPU.
120 using ValidateCapabilityWebGPU = spvtest::ValidateBase<CapTestParameter>;
121
122 TEST_F(ValidateCapability, Default) {
123 const char str[] = R"(
124 OpCapability Kernel
125 OpCapability Linkage
126 OpCapability Matrix
127 OpMemoryModel Logical OpenCL
128 %f32 = OpTypeFloat 32
129 %vec3 = OpTypeVector %f32 3
130 %mat33 = OpTypeMatrix %vec3 3
131 )";
132
133 CompileSuccessfully(str);
134 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
135 }
136
137 // clang-format off
138 const std::vector<std::string>& AllCapabilities() {
139 static const auto r = new std::vector<std::string>{
140 "",
141 "Matrix",
142 "Shader",
143 "Geometry",
144 "Tessellation",
145 "Addresses",
146 "Linkage",
147 "Kernel",
148 "Vector16",
149 "Float16Buffer",
150 "Float16",
151 "Float64",
152 "Int64",
153 "Int64Atomics",
154 "ImageBasic",
155 "ImageReadWrite",
156 "ImageMipmap",
157 "Pipes",
158 "Groups",
159 "DeviceEnqueue",
160 "LiteralSampler",
161 "AtomicStorage",
162 "Int16",
163 "TessellationPointSize",
164 "GeometryPointSize",
165 "ImageGatherExtended",
166 "StorageImageMultisample",
167 "UniformBufferArrayDynamicIndexing",
168 "SampledImageArrayDynamicIndexing",
169 "StorageBufferArrayDynamicIndexing",
170 "StorageImageArrayDynamicIndexing",
171 "ClipDistance",
172 "CullDistance",
173 "ImageCubeArray",
174 "SampleRateShading",
175 "ImageRect",
176 "SampledRect",
177 "GenericPointer",
178 "Int8",
179 "InputAttachment",
180 "SparseResidency",
181 "MinLod",
182 "Sampled1D",
183 "Image1D",
184 "SampledCubeArray",
185 "SampledBuffer",
186 "ImageBuffer",
187 "ImageMSArray",
188 "StorageImageExtendedFormats",
189 "ImageQuery",
190 "DerivativeControl",
191 "InterpolationFunction",
192 "TransformFeedback",
193 "GeometryStreams",
194 "StorageImageReadWithoutFormat",
195 "StorageImageWriteWithoutFormat",
196 "MultiViewport",
197 "SubgroupDispatch",
198 "NamedBarrier",
199 "PipeStorage",
200 "GroupNonUniform",
201 "GroupNonUniformVote",
202 "GroupNonUniformArithmetic",
203 "GroupNonUniformBallot",
204 "GroupNonUniformShuffle",
205 "GroupNonUniformShuffleRelative",
206 "GroupNonUniformClustered",
207 "GroupNonUniformQuad",
208 "DrawParameters",
209 "StorageBuffer16BitAccess",
210 "StorageUniformBufferBlock16",
211 "UniformAndStorageBuffer16BitAccess",
212 "StorageUniform16",
213 "StoragePushConstant16",
214 "StorageInputOutput16",
215 "DeviceGroup",
216 "MultiView",
217 "VariablePointersStorageBuffer",
218 "VariablePointers"};
219 return *r;
220 }
221
222 const std::vector<std::string>& AllSpirV15Capabilities() {
223 static const auto r = new std::vector<std::string>{
224 "",
225 "Matrix",
226 "Shader",
227 "Geometry",
228 "Tessellation",
229 "Addresses",
230 "Linkage",
231 "Kernel",
232 "Vector16",
233 "Float16Buffer",
234 "Float16",
235 "Float64",
236 "Int64",
237 "Int64Atomics",
238 "ImageBasic",
239 "ImageReadWrite",
240 "ImageMipmap",
241 "Pipes",
242 "Groups",
243 "DeviceEnqueue",
244 "LiteralSampler",
245 "AtomicStorage",
246 "Int16",
247 "TessellationPointSize",
248 "GeometryPointSize",
249 "ImageGatherExtended",
250 "StorageImageMultisample",
251 "UniformBufferArrayDynamicIndexing",
252 "SampledImageArrayDynamicIndexing",
253 "StorageBufferArrayDynamicIndexing",
254 "StorageImageArrayDynamicIndexing",
255 "ClipDistance",
256 "CullDistance",
257 "ImageCubeArray",
258 "SampleRateShading",
259 "ImageRect",
260 "SampledRect",
261 "GenericPointer",
262 "Int8",
263 "InputAttachment",
264 "SparseResidency",
265 "MinLod",
266 "Sampled1D",
267 "Image1D",
268 "SampledCubeArray",
269 "SampledBuffer",
270 "ImageBuffer",
271 "ImageMSArray",
272 "StorageImageExtendedFormats",
273 "ImageQuery",
274 "DerivativeControl",
275 "InterpolationFunction",
276 "TransformFeedback",
277 "GeometryStreams",
278 "StorageImageReadWithoutFormat",
279 "StorageImageWriteWithoutFormat",
280 "MultiViewport",
281 "SubgroupDispatch",
282 "NamedBarrier",
283 "PipeStorage",
284 "GroupNonUniform",
285 "GroupNonUniformVote",
286 "GroupNonUniformArithmetic",
287 "GroupNonUniformBallot",
288 "GroupNonUniformShuffle",
289 "GroupNonUniformShuffleRelative",
290 "GroupNonUniformClustered",
291 "GroupNonUniformQuad",
292 "DrawParameters",
293 "StorageBuffer16BitAccess",
294 "StorageUniformBufferBlock16",
295 "UniformAndStorageBuffer16BitAccess",
296 "StorageUniform16",
297 "StoragePushConstant16",
298 "StorageInputOutput16",
299 "DeviceGroup",
300 "MultiView",
301 "VariablePointersStorageBuffer",
302 "VariablePointers",
303 "DenormPreserve",
304 "DenormFlushToZero",
305 "SignedZeroInfNanPreserve",
306 "RoundingModeRTE",
307 "RoundingModeRTZ",
308 // Omitted due to extra validation requirements on memory model.
309 //"VulkanMemoryModel",
310 //"VulkanMemoryModelDeviceScope",
311 "StorageBuffer8BitAccess",
312 "UniformAndStorageBuffer8BitAccess",
313 "StoragePushConstant8",
314 "ShaderViewportIndex",
315 "ShaderLayer",
316 "PhysicalStorageBufferAddresses",
317 "RuntimeDescriptorArray",
318 "UniformTexelBufferArrayDynamicIndexing",
319 "StorageTexelBufferArrayDynamicIndexing",
320 "UniformBufferArrayNonUniformIndexing",
321 "SampledImageArrayNonUniformIndexing",
322 "StorageBufferArrayNonUniformIndexing",
323 "StorageImageArrayNonUniformIndexing",
324 "InputAttachmentArrayNonUniformIndexing",
325 "UniformTexelBufferArrayNonUniformIndexing",
326 "StorageTexelBufferArrayNonUniformIndexing"};
327 return *r;
328 }
329
330 const std::vector<std::string>& AllSpirV10Capabilities() {
331 static const auto r = new std::vector<std::string>{
332 "",
333 "Matrix",
334 "Shader",
335 "Geometry",
336 "Tessellation",
337 "Addresses",
338 "Linkage",
339 "Kernel",
340 "Vector16",
341 "Float16Buffer",
342 "Float16",
343 "Float64",
344 "Int64",
345 "Int64Atomics",
346 "ImageBasic",
347 "ImageReadWrite",
348 "ImageMipmap",
349 "Pipes",
350 "Groups",
351 "DeviceEnqueue",
352 "LiteralSampler",
353 "AtomicStorage",
354 "Int16",
355 "TessellationPointSize",
356 "GeometryPointSize",
357 "ImageGatherExtended",
358 "StorageImageMultisample",
359 "UniformBufferArrayDynamicIndexing",
360 "SampledImageArrayDynamicIndexing",
361 "StorageBufferArrayDynamicIndexing",
362 "StorageImageArrayDynamicIndexing",
363 "ClipDistance",
364 "CullDistance",
365 "ImageCubeArray",
366 "SampleRateShading",
367 "ImageRect",
368 "SampledRect",
369 "GenericPointer",
370 "Int8",
371 "InputAttachment",
372 "SparseResidency",
373 "MinLod",
374 "Sampled1D",
375 "Image1D",
376 "SampledCubeArray",
377 "SampledBuffer",
378 "ImageBuffer",
379 "ImageMSArray",
380 "StorageImageExtendedFormats",
381 "ImageQuery",
382 "DerivativeControl",
383 "InterpolationFunction",
384 "TransformFeedback",
385 "GeometryStreams",
386 "StorageImageReadWithoutFormat",
387 "StorageImageWriteWithoutFormat",
388 "MultiViewport"};
389 return *r;
390 }
391
392 const std::vector<std::string>& AllVulkan10Capabilities() {
393 static const auto r = new std::vector<std::string>{
394 "",
395 "Matrix",
396 "Shader",
397 "InputAttachment",
398 "Sampled1D",
399 "Image1D",
400 "SampledBuffer",
401 "ImageBuffer",
402 "ImageQuery",
403 "DerivativeControl",
404 "Geometry",
405 "Tessellation",
406 "Float16",
407 "Float64",
408 "Int64",
409 "Int64Atomics",
410 "Int16",
411 "TessellationPointSize",
412 "GeometryPointSize",
413 "ImageGatherExtended",
414 "StorageImageMultisample",
415 "UniformBufferArrayDynamicIndexing",
416 "SampledImageArrayDynamicIndexing",
417 "StorageBufferArrayDynamicIndexing",
418 "StorageImageArrayDynamicIndexing",
419 "ClipDistance",
420 "CullDistance",
421 "ImageCubeArray",
422 "SampleRateShading",
423 "Int8",
424 "SparseResidency",
425 "MinLod",
426 "SampledCubeArray",
427 "ImageMSArray",
428 "StorageImageExtendedFormats",
429 "InterpolationFunction",
430 "StorageImageReadWithoutFormat",
431 "StorageImageWriteWithoutFormat",
432 "MultiViewport",
433 "TransformFeedback",
434 "GeometryStreams"};
435 return *r;
436 }
437
438 const std::vector<std::string>& AllVulkan11Capabilities() {
439 static const auto r = new std::vector<std::string>{
440 "",
441 "Matrix",
442 "Shader",
443 "InputAttachment",
444 "Sampled1D",
445 "Image1D",
446 "SampledBuffer",
447 "ImageBuffer",
448 "ImageQuery",
449 "DerivativeControl",
450 "Geometry",
451 "Tessellation",
452 "Float16",
453 "Float64",
454 "Int64",
455 "Int64Atomics",
456 "Int16",
457 "TessellationPointSize",
458 "GeometryPointSize",
459 "ImageGatherExtended",
460 "StorageImageMultisample",
461 "UniformBufferArrayDynamicIndexing",
462 "SampledImageArrayDynamicIndexing",
463 "StorageBufferArrayDynamicIndexing",
464 "StorageImageArrayDynamicIndexing",
465 "ClipDistance",
466 "CullDistance",
467 "ImageCubeArray",
468 "SampleRateShading",
469 "Int8",
470 "SparseResidency",
471 "MinLod",
472 "SampledCubeArray",
473 "ImageMSArray",
474 "StorageImageExtendedFormats",
475 "InterpolationFunction",
476 "StorageImageReadWithoutFormat",
477 "StorageImageWriteWithoutFormat",
478 "MultiViewport",
479 "GroupNonUniform",
480 "GroupNonUniformVote",
481 "GroupNonUniformArithmetic",
482 "GroupNonUniformBallot",
483 "GroupNonUniformShuffle",
484 "GroupNonUniformShuffleRelative",
485 "GroupNonUniformClustered",
486 "GroupNonUniformQuad",
487 "DrawParameters",
488 "StorageBuffer16BitAccess",
489 "StorageUniformBufferBlock16",
490 "UniformAndStorageBuffer16BitAccess",
491 "StorageUniform16",
492 "StoragePushConstant16",
493 "StorageInputOutput16",
494 "DeviceGroup",
495 "MultiView",
496 "VariablePointersStorageBuffer",
497 "VariablePointers",
498 "TransformFeedback",
499 "GeometryStreams"};
500 return *r;
501 }
502
503 const std::vector<std::string>& AllVulkan12Capabilities() {
504 static const auto r = new std::vector<std::string>{
505 "",
506 "Matrix",
507 "Shader",
508 "InputAttachment",
509 "Sampled1D",
510 "Image1D",
511 "SampledBuffer",
512 "ImageBuffer",
513 "ImageQuery",
514 "DerivativeControl",
515 "Geometry",
516 "Tessellation",
517 "Float16",
518 "Float64",
519 "Int64",
520 "Int64Atomics",
521 "Int16",
522 "TessellationPointSize",
523 "GeometryPointSize",
524 "ImageGatherExtended",
525 "StorageImageMultisample",
526 "UniformBufferArrayDynamicIndexing",
527 "SampledImageArrayDynamicIndexing",
528 "StorageBufferArrayDynamicIndexing",
529 "StorageImageArrayDynamicIndexing",
530 "ClipDistance",
531 "CullDistance",
532 "ImageCubeArray",
533 "SampleRateShading",
534 "Int8",
535 "SparseResidency",
536 "MinLod",
537 "SampledCubeArray",
538 "ImageMSArray",
539 "StorageImageExtendedFormats",
540 "InterpolationFunction",
541 "StorageImageReadWithoutFormat",
542 "StorageImageWriteWithoutFormat",
543 "MultiViewport",
544 "GroupNonUniform",
545 "GroupNonUniformVote",
546 "GroupNonUniformArithmetic",
547 "GroupNonUniformBallot",
548 "GroupNonUniformShuffle",
549 "GroupNonUniformShuffleRelative",
550 "GroupNonUniformClustered",
551 "GroupNonUniformQuad",
552 "DrawParameters",
553 "StorageBuffer16BitAccess",
554 "StorageUniformBufferBlock16",
555 "UniformAndStorageBuffer16BitAccess",
556 "StorageUniform16",
557 "StoragePushConstant16",
558 "StorageInputOutput16",
559 "DeviceGroup",
560 "MultiView",
561 "VariablePointersStorageBuffer",
562 "VariablePointers",
563 "TransformFeedback",
564 "GeometryStreams",
565 "DenormPreserve",
566 "DenormFlushToZero",
567 "SignedZeroInfNanPreserve",
568 "RoundingModeRTE",
569 "RoundingModeRTZ",
570 "VulkanMemoryModel",
571 "VulkanMemoryModelDeviceScope",
572 "StorageBuffer8BitAccess",
573 "UniformAndStorageBuffer8BitAccess",
574 "StoragePushConstant8",
575 "ShaderViewportIndex",
576 "ShaderLayer",
577 "PhysicalStorageBufferAddresses",
578 "RuntimeDescriptorArray",
579 "UniformTexelBufferArrayDynamicIndexing",
580 "StorageTexelBufferArrayDynamicIndexing",
581 "UniformBufferArrayNonUniformIndexing",
582 "SampledImageArrayNonUniformIndexing",
583 "StorageBufferArrayNonUniformIndexing",
584 "StorageImageArrayNonUniformIndexing",
585 "InputAttachmentArrayNonUniformIndexing",
586 "UniformTexelBufferArrayNonUniformIndexing",
587 "StorageTexelBufferArrayNonUniformIndexing"};
588 return *r;
589 }
590
591 const std::vector<std::string>& AllWebGPUCapabilities() {
592 static const auto r = new std::vector<std::string>{
593 "",
594 "Shader",
595 "Matrix",
596 "Sampled1D",
597 "Image1D",
598 "ImageQuery",
599 "DerivativeControl"};
600 return *r;
601 }
602
603 const std::vector<std::string>& MatrixDependencies() {
604 static const auto r = new std::vector<std::string>{
605 "Matrix",
606 "Shader",
607 "Geometry",
608 "Tessellation",
609 "AtomicStorage",
610 "TessellationPointSize",
611 "GeometryPointSize",
612 "ImageGatherExtended",
613 "StorageImageMultisample",
614 "UniformBufferArrayDynamicIndexing",
615 "SampledImageArrayDynamicIndexing",
616 "StorageBufferArrayDynamicIndexing",
617 "StorageImageArrayDynamicIndexing",
618 "ClipDistance",
619 "CullDistance",
620 "ImageCubeArray",
621 "SampleRateShading",
622 "ImageRect",
623 "SampledRect",
624 "InputAttachment",
625 "SparseResidency",
626 "MinLod",
627 "SampledCubeArray",
628 "ImageMSArray",
629 "StorageImageExtendedFormats",
630 "ImageQuery",
631 "DerivativeControl",
632 "InterpolationFunction",
633 "TransformFeedback",
634 "GeometryStreams",
635 "StorageImageReadWithoutFormat",
636 "StorageImageWriteWithoutFormat",
637 "MultiViewport",
638 "DrawParameters",
639 "MultiView",
640 "VariablePointersStorageBuffer",
641 "VariablePointers"};
642 return *r;
643 }
644
645 const std::vector<std::string>& ShaderDependencies() {
646 static const auto r = new std::vector<std::string>{
647 "Shader",
648 "Geometry",
649 "Tessellation",
650 "AtomicStorage",
651 "TessellationPointSize",
652 "GeometryPointSize",
653 "ImageGatherExtended",
654 "StorageImageMultisample",
655 "UniformBufferArrayDynamicIndexing",
656 "SampledImageArrayDynamicIndexing",
657 "StorageBufferArrayDynamicIndexing",
658 "StorageImageArrayDynamicIndexing",
659 "ClipDistance",
660 "CullDistance",
661 "ImageCubeArray",
662 "SampleRateShading",
663 "ImageRect",
664 "SampledRect",
665 "InputAttachment",
666 "SparseResidency",
667 "MinLod",
668 "SampledCubeArray",
669 "ImageMSArray",
670 "StorageImageExtendedFormats",
671 "ImageQuery",
672 "DerivativeControl",
673 "InterpolationFunction",
674 "TransformFeedback",
675 "GeometryStreams",
676 "StorageImageReadWithoutFormat",
677 "StorageImageWriteWithoutFormat",
678 "MultiViewport",
679 "DrawParameters",
680 "MultiView",
681 "VariablePointersStorageBuffer",
682 "VariablePointers"};
683 return *r;
684 }
685
686 const std::vector<std::string>& TessellationDependencies() {
687 static const auto r = new std::vector<std::string>{
688 "Tessellation",
689 "TessellationPointSize"};
690 return *r;
691 }
692
693 const std::vector<std::string>& GeometryDependencies() {
694 static const auto r = new std::vector<std::string>{
695 "Geometry",
696 "GeometryPointSize",
697 "GeometryStreams",
698 "MultiViewport"};
699 return *r;
700 }
701
702 const std::vector<std::string>& GeometryTessellationDependencies() {
703 static const auto r = new std::vector<std::string>{
704 "Tessellation",
705 "TessellationPointSize",
706 "Geometry",
707 "GeometryPointSize",
708 "GeometryStreams",
709 "MultiViewport"};
710 return *r;
711 }
712
713 // Returns the names of capabilities that directly depend on Kernel,
714 // plus itself.
715 const std::vector<std::string>& KernelDependencies() {
716 static const auto r = new std::vector<std::string>{
717 "Kernel",
718 "Vector16",
719 "Float16Buffer",
720 "ImageBasic",
721 "ImageReadWrite",
722 "ImageMipmap",
723 "Pipes",
724 "DeviceEnqueue",
725 "LiteralSampler",
726 "SubgroupDispatch",
727 "NamedBarrier",
728 "PipeStorage"};
729 return *r;
730 }
731
732 const std::vector<std::string>& KernelAndGroupNonUniformDependencies() {
733 static const auto r = new std::vector<std::string>{
734 "Kernel",
735 "Vector16",
736 "Float16Buffer",
737 "ImageBasic",
738 "ImageReadWrite",
739 "ImageMipmap",
740 "Pipes",
741 "DeviceEnqueue",
742 "LiteralSampler",
743 "SubgroupDispatch",
744 "NamedBarrier",
745 "PipeStorage",
746 "GroupNonUniform",
747 "GroupNonUniformVote",
748 "GroupNonUniformArithmetic",
749 "GroupNonUniformBallot",
750 "GroupNonUniformShuffle",
751 "GroupNonUniformShuffleRelative",
752 "GroupNonUniformClustered",
753 "GroupNonUniformQuad"};
754 return *r;
755 }
756
757 const std::vector<std::string>& AddressesDependencies() {
758 static const auto r = new std::vector<std::string>{
759 "Addresses",
760 "GenericPointer"};
761 return *r;
762 }
763
764 const std::vector<std::string>& Sampled1DDependencies() {
765 static const auto r = new std::vector<std::string>{
766 "Sampled1D",
767 "Image1D"};
768 return *r;
769 }
770
771 const std::vector<std::string>& SampledRectDependencies() {
772 static const auto r = new std::vector<std::string>{
773 "SampledRect",
774 "ImageRect"};
775 return *r;
776 }
777
778 const std::vector<std::string>& SampledBufferDependencies() {
779 static const auto r = new std::vector<std::string>{
780 "SampledBuffer",
781 "ImageBuffer"};
782 return *r;
783 }
784
785 const char kOpenCLMemoryModel[] = \
786 " OpCapability Kernel"
787 " OpMemoryModel Logical OpenCL ";
788
789 const char kGLSL450MemoryModel[] = \
790 " OpCapability Shader"
791 " OpMemoryModel Logical GLSL450 ";
792
793 const char kVulkanMemoryModel[] = \
794 " OpCapability Shader"
795 " OpCapability VulkanMemoryModelKHR"
796 " OpExtension \"SPV_KHR_vulkan_memory_model\""
797 " OpMemoryModel Logical VulkanKHR ";
798
799 const char kVoidFVoid[] = \
800 " %void = OpTypeVoid"
801 " %void_f = OpTypeFunction %void"
802 " %func = OpFunction %void None %void_f"
803 " %label = OpLabel"
804 " OpReturn"
805 " OpFunctionEnd ";
806
807 const char kVoidFVoid2[] = \
808 " %void_f = OpTypeFunction %voidt"
809 " %func = OpFunction %voidt None %void_f"
810 " %label = OpLabel"
811 " OpReturn"
812 " OpFunctionEnd ";
813
814 INSTANTIATE_TEST_SUITE_P(ExecutionModel, ValidateCapability,
815 Combine(
816 ValuesIn(AllCapabilities()),
817 Values(
818 std::make_pair(std::string(kOpenCLMemoryModel) +
819 " OpEntryPoint Vertex %func \"shader\"" +
820 std::string(kVoidFVoid), ShaderDependencies()),
821 std::make_pair(std::string(kOpenCLMemoryModel) +
822 " OpEntryPoint TessellationControl %func \"shader\"" +
823 std::string(kVoidFVoid), TessellationDependencies()),
824 std::make_pair(std::string(kOpenCLMemoryModel) +
825 " OpEntryPoint TessellationEvaluation %func \"shader\"" +
826 std::string(kVoidFVoid), TessellationDependencies()),
827 std::make_pair(std::string(kOpenCLMemoryModel) +
828 " OpEntryPoint Geometry %func \"shader\"" +
829 " OpExecutionMode %func InputPoints" +
830 " OpExecutionMode %func OutputPoints" +
831 std::string(kVoidFVoid), GeometryDependencies()),
832 std::make_pair(std::string(kOpenCLMemoryModel) +
833 " OpEntryPoint Fragment %func \"shader\"" +
834 " OpExecutionMode %func OriginUpperLeft" +
835 std::string(kVoidFVoid), ShaderDependencies()),
836 std::make_pair(std::string(kOpenCLMemoryModel) +
837 " OpEntryPoint GLCompute %func \"shader\"" +
838 std::string(kVoidFVoid), ShaderDependencies()),
839 std::make_pair(std::string(kGLSL450MemoryModel) +
840 " OpEntryPoint Kernel %func \"shader\"" +
841 std::string(kVoidFVoid), KernelDependencies())
842 )));
843
844 INSTANTIATE_TEST_SUITE_P(AddressingAndMemoryModel, ValidateCapability,
845 Combine(
846 ValuesIn(AllCapabilities()),
847 Values(
848 std::make_pair(" OpCapability Shader"
849 " OpMemoryModel Logical Simple"
850 " OpEntryPoint Vertex %func \"shader\"" +
851 std::string(kVoidFVoid), AllCapabilities()),
852 std::make_pair(" OpCapability Shader"
853 " OpMemoryModel Logical GLSL450"
854 " OpEntryPoint Vertex %func \"shader\"" +
855 std::string(kVoidFVoid), AllCapabilities()),
856 std::make_pair(" OpCapability Kernel"
857 " OpMemoryModel Logical OpenCL"
858 " OpEntryPoint Kernel %func \"compute\"" +
859 std::string(kVoidFVoid), AllCapabilities()),
860 std::make_pair(" OpCapability Shader"
861 " OpMemoryModel Physical32 Simple"
862 " OpEntryPoint Vertex %func \"shader\"" +
863 std::string(kVoidFVoid), AddressesDependencies()),
864 std::make_pair(" OpCapability Shader"
865 " OpMemoryModel Physical32 GLSL450"
866 " OpEntryPoint Vertex %func \"shader\"" +
867 std::string(kVoidFVoid), AddressesDependencies()),
868 std::make_pair(" OpCapability Kernel"
869 " OpMemoryModel Physical32 OpenCL"
870 " OpEntryPoint Kernel %func \"compute\"" +
871 std::string(kVoidFVoid), AddressesDependencies()),
872 std::make_pair(" OpCapability Shader"
873 " OpMemoryModel Physical64 Simple"
874 " OpEntryPoint Vertex %func \"shader\"" +
875 std::string(kVoidFVoid), AddressesDependencies()),
876 std::make_pair(" OpCapability Shader"
877 " OpMemoryModel Physical64 GLSL450"
878 " OpEntryPoint Vertex %func \"shader\"" +
879 std::string(kVoidFVoid), AddressesDependencies()),
880 std::make_pair(" OpCapability Kernel"
881 " OpMemoryModel Physical64 OpenCL"
882 " OpEntryPoint Kernel %func \"compute\"" +
883 std::string(kVoidFVoid), AddressesDependencies())
884 )));
885
886 INSTANTIATE_TEST_SUITE_P(ExecutionMode, ValidateCapability,
887 Combine(
888 ValuesIn(AllCapabilities()),
889 Values(
890 std::make_pair(std::string(kOpenCLMemoryModel) +
891 "OpEntryPoint Geometry %func \"shader\" "
892 "OpExecutionMode %func Invocations 42" +
893 " OpExecutionMode %func InputPoints" +
894 " OpExecutionMode %func OutputPoints" +
895 std::string(kVoidFVoid), GeometryDependencies()),
896 std::make_pair(std::string(kOpenCLMemoryModel) +
897 "OpEntryPoint TessellationControl %func \"shader\" "
898 "OpExecutionMode %func SpacingEqual" +
899 std::string(kVoidFVoid), TessellationDependencies()),
900 std::make_pair(std::string(kOpenCLMemoryModel) +
901 "OpEntryPoint TessellationControl %func \"shader\" "
902 "OpExecutionMode %func SpacingFractionalEven" +
903 std::string(kVoidFVoid), TessellationDependencies()),
904 std::make_pair(std::string(kOpenCLMemoryModel) +
905 "OpEntryPoint TessellationControl %func \"shader\" "
906 "OpExecutionMode %func SpacingFractionalOdd" +
907 std::string(kVoidFVoid), TessellationDependencies()),
908 std::make_pair(std::string(kOpenCLMemoryModel) +
909 "OpEntryPoint TessellationControl %func \"shader\" "
910 "OpExecutionMode %func VertexOrderCw" +
911 std::string(kVoidFVoid), TessellationDependencies()),
912 std::make_pair(std::string(kOpenCLMemoryModel) +
913 "OpEntryPoint TessellationControl %func \"shader\" "
914 "OpExecutionMode %func VertexOrderCcw" +
915 std::string(kVoidFVoid), TessellationDependencies()),
916 std::make_pair(std::string(kOpenCLMemoryModel) +
917 "OpEntryPoint Fragment %func \"shader\" "
918 "OpExecutionMode %func PixelCenterInteger" +
919 " OpExecutionMode %func OriginUpperLeft" +
920 std::string(kVoidFVoid), ShaderDependencies()),
921 std::make_pair(std::string(kOpenCLMemoryModel) +
922 "OpEntryPoint Fragment %func \"shader\" "
923 "OpExecutionMode %func OriginUpperLeft" +
924 std::string(kVoidFVoid), ShaderDependencies()),
925 std::make_pair(std::string(kOpenCLMemoryModel) +
926 "OpEntryPoint Fragment %func \"shader\" "
927 "OpExecutionMode %func OriginLowerLeft" +
928 std::string(kVoidFVoid), ShaderDependencies()),
929 std::make_pair(std::string(kOpenCLMemoryModel) +
930 "OpEntryPoint Fragment %func \"shader\" "
931 "OpExecutionMode %func EarlyFragmentTests" +
932 " OpExecutionMode %func OriginUpperLeft" +
933 std::string(kVoidFVoid), ShaderDependencies()),
934 std::make_pair(std::string(kOpenCLMemoryModel) +
935 "OpEntryPoint TessellationControl %func \"shader\" "
936 "OpExecutionMode %func PointMode" +
937 std::string(kVoidFVoid), TessellationDependencies()),
938 std::make_pair(std::string(kOpenCLMemoryModel) +
939 "OpEntryPoint Vertex %func \"shader\" "
940 "OpExecutionMode %func Xfb" +
941 std::string(kVoidFVoid), std::vector<std::string>{"TransformFeedback"}),
942 std::make_pair(std::string(kOpenCLMemoryModel) +
943 "OpEntryPoint Fragment %func \"shader\" "
944 "OpExecutionMode %func DepthReplacing" +
945 " OpExecutionMode %func OriginUpperLeft" +
946 std::string(kVoidFVoid), ShaderDependencies()),
947 std::make_pair(std::string(kOpenCLMemoryModel) +
948 "OpEntryPoint Fragment %func \"shader\" "
949 "OpExecutionMode %func DepthGreater" +
950 " OpExecutionMode %func OriginUpperLeft" +
951 std::string(kVoidFVoid), ShaderDependencies()),
952 std::make_pair(std::string(kOpenCLMemoryModel) +
953 "OpEntryPoint Fragment %func \"shader\" "
954 "OpExecutionMode %func DepthLess" +
955 " OpExecutionMode %func OriginUpperLeft" +
956 std::string(kVoidFVoid), ShaderDependencies()),
957 std::make_pair(std::string(kOpenCLMemoryModel) +
958 "OpEntryPoint Fragment %func \"shader\" "
959 "OpExecutionMode %func DepthUnchanged" +
960 " OpExecutionMode %func OriginUpperLeft" +
961 std::string(kVoidFVoid), ShaderDependencies()),
962 std::make_pair(std::string(kOpenCLMemoryModel) +
963 "OpEntryPoint Kernel %func \"shader\" "
964 "OpExecutionMode %func LocalSize 42 42 42" +
965 std::string(kVoidFVoid), AllCapabilities()),
966 std::make_pair(std::string(kGLSL450MemoryModel) +
967 "OpEntryPoint Kernel %func \"shader\" "
968 "OpExecutionMode %func LocalSizeHint 42 42 42" +
969 std::string(kVoidFVoid), KernelDependencies()),
970 std::make_pair(std::string(kOpenCLMemoryModel) +
971 "OpEntryPoint Geometry %func \"shader\" "
972 "OpExecutionMode %func InputPoints" +
973 " OpExecutionMode %func OutputPoints" +
974 std::string(kVoidFVoid), GeometryDependencies()),
975 std::make_pair(std::string(kOpenCLMemoryModel) +
976 "OpEntryPoint Geometry %func \"shader\" "
977 "OpExecutionMode %func InputLines" +
978 " OpExecutionMode %func OutputLineStrip" +
979 std::string(kVoidFVoid), GeometryDependencies()),
980 std::make_pair(std::string(kOpenCLMemoryModel) +
981 "OpEntryPoint Geometry %func \"shader\" "
982 "OpExecutionMode %func InputLinesAdjacency" +
983 " OpExecutionMode %func OutputLineStrip" +
984 std::string(kVoidFVoid), GeometryDependencies()),
985 std::make_pair(std::string(kOpenCLMemoryModel) +
986 "OpEntryPoint Geometry %func \"shader\" "
987 "OpExecutionMode %func Triangles" +
988 " OpExecutionMode %func OutputTriangleStrip" +
989 std::string(kVoidFVoid), GeometryDependencies()),
990 std::make_pair(std::string(kOpenCLMemoryModel) +
991 "OpEntryPoint TessellationControl %func \"shader\" "
992 "OpExecutionMode %func Triangles" +
993 std::string(kVoidFVoid), TessellationDependencies()),
994 std::make_pair(std::string(kOpenCLMemoryModel) +
995 "OpEntryPoint Geometry %func \"shader\" "
996 "OpExecutionMode %func InputTrianglesAdjacency" +
997 " OpExecutionMode %func OutputTriangleStrip" +
998 std::string(kVoidFVoid), GeometryDependencies()),
999 std::make_pair(std::string(kOpenCLMemoryModel) +
1000 "OpEntryPoint TessellationControl %func \"shader\" "
1001 "OpExecutionMode %func Quads" +
1002 std::string(kVoidFVoid), TessellationDependencies()),
1003 std::make_pair(std::string(kOpenCLMemoryModel) +
1004 "OpEntryPoint TessellationControl %func \"shader\" "
1005 "OpExecutionMode %func Isolines" +
1006 std::string(kVoidFVoid), TessellationDependencies()),
1007 std::make_pair(std::string(kOpenCLMemoryModel) +
1008 "OpEntryPoint Geometry %func \"shader\" "
1009 "OpExecutionMode %func OutputVertices 42" +
1010 " OpExecutionMode %func OutputPoints" +
1011 " OpExecutionMode %func InputPoints" +
1012 std::string(kVoidFVoid), GeometryDependencies()),
1013 std::make_pair(std::string(kOpenCLMemoryModel) +
1014 "OpEntryPoint TessellationControl %func \"shader\" "
1015 "OpExecutionMode %func OutputVertices 42" +
1016 std::string(kVoidFVoid), TessellationDependencies()),
1017 std::make_pair(std::string(kOpenCLMemoryModel) +
1018 "OpEntryPoint Geometry %func \"shader\" "
1019 "OpExecutionMode %func OutputPoints" +
1020 " OpExecutionMode %func InputPoints" +
1021 std::string(kVoidFVoid), GeometryDependencies()),
1022 std::make_pair(std::string(kOpenCLMemoryModel) +
1023 "OpEntryPoint Geometry %func \"shader\" "
1024 "OpExecutionMode %func OutputLineStrip" +
1025 " OpExecutionMode %func InputLines" +
1026 std::string(kVoidFVoid), GeometryDependencies()),
1027 std::make_pair(std::string(kOpenCLMemoryModel) +
1028 "OpEntryPoint Geometry %func \"shader\" "
1029 "OpExecutionMode %func OutputTriangleStrip" +
1030 " OpExecutionMode %func Triangles" +
1031 std::string(kVoidFVoid), GeometryDependencies()),
1032 std::make_pair(std::string(kGLSL450MemoryModel) +
1033 "OpEntryPoint Kernel %func \"shader\" "
1034 "OpExecutionMode %func VecTypeHint 2" +
1035 std::string(kVoidFVoid), KernelDependencies()),
1036 std::make_pair(std::string(kGLSL450MemoryModel) +
1037 "OpEntryPoint Kernel %func \"shader\" "
1038 "OpExecutionMode %func ContractionOff" +
1039 std::string(kVoidFVoid), KernelDependencies()))));
1040
1041 // clang-format on
1042
1043 INSTANTIATE_TEST_SUITE_P(
1044 ExecutionModeV11, ValidateCapabilityV11,
1045 Combine(ValuesIn(AllCapabilities()),
1046 Values(std::make_pair(std::string(kOpenCLMemoryModel) +
1047 "OpEntryPoint Kernel %func \"shader\" "
1048 "OpExecutionMode %func SubgroupSize 1" +
1049 std::string(kVoidFVoid),
1050 std::vector<std::string>{"SubgroupDispatch"}),
1051 std::make_pair(
1052 std::string(kOpenCLMemoryModel) +
1053 "OpEntryPoint Kernel %func \"shader\" "
1054 "OpExecutionMode %func SubgroupsPerWorkgroup 65535" +
1055 std::string(kVoidFVoid),
1056 std::vector<std::string>{"SubgroupDispatch"}))));
1057 // clang-format off
1058
1059 INSTANTIATE_TEST_SUITE_P(StorageClass, ValidateCapability,
1060 Combine(
1061 ValuesIn(AllCapabilities()),
1062 Values(
1063 std::make_pair(std::string(kGLSL450MemoryModel) +
1064 " OpEntryPoint Vertex %func \"shader\"" +
1065 " %intt = OpTypeInt 32 0\n"
1066 " %ptrt = OpTypePointer UniformConstant %intt\n"
1067 " %var = OpVariable %ptrt UniformConstant\n" + std::string(kVoidFVoid),
1068 AllCapabilities()),
1069 std::make_pair(std::string(kOpenCLMemoryModel) +
1070 " OpEntryPoint Kernel %func \"compute\"" +
1071 " %intt = OpTypeInt 32 0\n"
1072 " %ptrt = OpTypePointer Input %intt"
1073 " %var = OpVariable %ptrt Input\n" + std::string(kVoidFVoid),
1074 AllCapabilities()),
1075 std::make_pair(std::string(kOpenCLMemoryModel) +
1076 " OpEntryPoint Vertex %func \"shader\"" +
1077 " %intt = OpTypeInt 32 0\n"
1078 " %ptrt = OpTypePointer Uniform %intt\n"
1079 " %var = OpVariable %ptrt Uniform\n" + std::string(kVoidFVoid),
1080 ShaderDependencies()),
1081 std::make_pair(std::string(kOpenCLMemoryModel) +
1082 " OpEntryPoint Vertex %func \"shader\"" +
1083 " %intt = OpTypeInt 32 0\n"
1084 " %ptrt = OpTypePointer Output %intt\n"
1085 " %var = OpVariable %ptrt Output\n" + std::string(kVoidFVoid),
1086 ShaderDependencies()),
1087 std::make_pair(std::string(kGLSL450MemoryModel) +
1088 " OpEntryPoint Vertex %func \"shader\"" +
1089 " %intt = OpTypeInt 32 0\n"
1090 " %ptrt = OpTypePointer Workgroup %intt\n"
1091 " %var = OpVariable %ptrt Workgroup\n" + std::string(kVoidFVoid),
1092 AllCapabilities()),
1093 std::make_pair(std::string(kGLSL450MemoryModel) +
1094 " OpEntryPoint Vertex %func \"shader\"" +
1095 " %intt = OpTypeInt 32 0\n"
1096 " %ptrt = OpTypePointer CrossWorkgroup %intt\n"
1097 " %var = OpVariable %ptrt CrossWorkgroup\n" + std::string(kVoidFVoid),
1098 AllCapabilities()),
1099 std::make_pair(std::string(kOpenCLMemoryModel) +
1100 " OpEntryPoint Kernel %func \"compute\"" +
1101 " %intt = OpTypeInt 32 0\n"
1102 " %ptrt = OpTypePointer Private %intt\n"
1103 " %var = OpVariable %ptrt Private\n" + std::string(kVoidFVoid),
1104 ShaderDependencies()),
1105 std::make_pair(std::string(kOpenCLMemoryModel) +
1106 " OpEntryPoint Kernel %func \"compute\"" +
1107 " %intt = OpTypeInt 32 0\n"
1108 " %ptrt = OpTypePointer PushConstant %intt\n"
1109 " %var = OpVariable %ptrt PushConstant\n" + std::string(kVoidFVoid),
1110 ShaderDependencies()),
1111 std::make_pair(std::string(kGLSL450MemoryModel) +
1112 " OpEntryPoint Vertex %func \"shader\"" +
1113 " %intt = OpTypeInt 32 0\n"
1114 " %ptrt = OpTypePointer AtomicCounter %intt\n"
1115 " %var = OpVariable %ptrt AtomicCounter\n" + std::string(kVoidFVoid),
1116 std::vector<std::string>{"AtomicStorage"}),
1117 std::make_pair(std::string(kGLSL450MemoryModel) +
1118 " OpEntryPoint Vertex %func \"shader\"" +
1119 " %intt = OpTypeInt 32 0\n"
1120 " %ptrt = OpTypePointer Image %intt\n"
1121 " %var = OpVariable %ptrt Image\n" + std::string(kVoidFVoid),
1122 AllCapabilities())
1123 )));
1124
1125 INSTANTIATE_TEST_SUITE_P(Dim, ValidateCapability,
1126 Combine(
1127 ValuesIn(AllCapabilities()),
1128 Values(
1129 std::make_pair(" OpCapability ImageBasic" +
1130 std::string(kOpenCLMemoryModel) +
1131 std::string(" OpEntryPoint Kernel %func \"compute\"") +
1132 " %voidt = OpTypeVoid"
1133 " %imgt = OpTypeImage %voidt 1D 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
1134 Sampled1DDependencies()),
1135 std::make_pair(" OpCapability ImageBasic" +
1136 std::string(kOpenCLMemoryModel) +
1137 std::string(" OpEntryPoint Kernel %func \"compute\"") +
1138 " %voidt = OpTypeVoid"
1139 " %imgt = OpTypeImage %voidt 2D 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
1140 AllCapabilities()),
1141 std::make_pair(" OpCapability ImageBasic" +
1142 std::string(kOpenCLMemoryModel) +
1143 std::string(" OpEntryPoint Kernel %func \"compute\"") +
1144 " %voidt = OpTypeVoid"
1145 " %imgt = OpTypeImage %voidt 3D 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
1146 AllCapabilities()),
1147 std::make_pair(" OpCapability ImageBasic" +
1148 std::string(kOpenCLMemoryModel) +
1149 std::string(" OpEntryPoint Kernel %func \"compute\"") +
1150 " %voidt = OpTypeVoid"
1151 " %imgt = OpTypeImage %voidt Cube 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
1152 ShaderDependencies()),
1153 std::make_pair(" OpCapability ImageBasic" +
1154 std::string(kOpenCLMemoryModel) +
1155 std::string(" OpEntryPoint Kernel %func \"compute\"") +
1156 " %voidt = OpTypeVoid"
1157 " %imgt = OpTypeImage %voidt Rect 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
1158 SampledRectDependencies()),
1159 std::make_pair(" OpCapability ImageBasic" +
1160 std::string(kOpenCLMemoryModel) +
1161 std::string(" OpEntryPoint Kernel %func \"compute\"") +
1162 " %voidt = OpTypeVoid"
1163 " %imgt = OpTypeImage %voidt Buffer 0 0 0 0 Unknown" + std::string(kVoidFVoid2),
1164 SampledBufferDependencies()),
1165 std::make_pair(" OpCapability ImageBasic" +
1166 std::string(kOpenCLMemoryModel) +
1167 std::string(" OpEntryPoint Kernel %func \"compute\"") +
1168 " %voidt = OpTypeVoid"
1169 " %imgt = OpTypeImage %voidt SubpassData 0 0 0 2 Unknown" + std::string(kVoidFVoid2),
1170 std::vector<std::string>{"InputAttachment"})
1171 )));
1172
1173 // NOTE: All Sampler Address Modes require kernel capabilities but the
1174 // OpConstantSampler requires LiteralSampler which depends on Kernel
1175 INSTANTIATE_TEST_SUITE_P(SamplerAddressingMode, ValidateCapability,
1176 Combine(
1177 ValuesIn(AllCapabilities()),
1178 Values(
1179 std::make_pair(std::string(kGLSL450MemoryModel) +
1180 " OpEntryPoint Vertex %func \"shader\""
1181 " %samplert = OpTypeSampler"
1182 " %sampler = OpConstantSampler %samplert None 1 Nearest" +
1183 std::string(kVoidFVoid),
1184 std::vector<std::string>{"LiteralSampler"}),
1185 std::make_pair(std::string(kGLSL450MemoryModel) +
1186 " OpEntryPoint Vertex %func \"shader\""
1187 " %samplert = OpTypeSampler"
1188 " %sampler = OpConstantSampler %samplert ClampToEdge 1 Nearest" +
1189 std::string(kVoidFVoid),
1190 std::vector<std::string>{"LiteralSampler"}),
1191 std::make_pair(std::string(kGLSL450MemoryModel) +
1192 " OpEntryPoint Vertex %func \"shader\""
1193 " %samplert = OpTypeSampler"
1194 " %sampler = OpConstantSampler %samplert Clamp 1 Nearest" +
1195 std::string(kVoidFVoid),
1196 std::vector<std::string>{"LiteralSampler"}),
1197 std::make_pair(std::string(kGLSL450MemoryModel) +
1198 " OpEntryPoint Vertex %func \"shader\""
1199 " %samplert = OpTypeSampler"
1200 " %sampler = OpConstantSampler %samplert Repeat 1 Nearest" +
1201 std::string(kVoidFVoid),
1202 std::vector<std::string>{"LiteralSampler"}),
1203 std::make_pair(std::string(kGLSL450MemoryModel) +
1204 " OpEntryPoint Vertex %func \"shader\""
1205 " %samplert = OpTypeSampler"
1206 " %sampler = OpConstantSampler %samplert RepeatMirrored 1 Nearest" +
1207 std::string(kVoidFVoid),
1208 std::vector<std::string>{"LiteralSampler"})
1209 )));
1210
1211 // TODO(umar): Sampler Filter Mode
1212 // TODO(umar): Image Format
1213 // TODO(umar): Image Channel Order
1214 // TODO(umar): Image Channel Data Type
1215 // TODO(umar): Image Operands
1216 // TODO(umar): FP Fast Math Mode
1217 // TODO(umar): FP Rounding Mode
1218 // TODO(umar): Linkage Type
1219 // TODO(umar): Access Qualifier
1220 // TODO(umar): Function Parameter Attribute
1221
1222 INSTANTIATE_TEST_SUITE_P(Decoration, ValidateCapability,
1223 Combine(
1224 ValuesIn(AllCapabilities()),
1225 Values(
1226 std::make_pair(std::string(kOpenCLMemoryModel) +
1227 "OpEntryPoint Kernel %func \"compute\" \n"
1228 "OpDecorate %intt RelaxedPrecision\n"
1229 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1230 ShaderDependencies()),
1231 std::make_pair(std::string(kOpenCLMemoryModel) +
1232 // Block applies to struct type.
1233 "OpEntryPoint Kernel %func \"compute\" \n"
1234 "OpDecorate %block Block\n"
1235 "%intt = OpTypeInt 32 0\n"
1236 "%block = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
1237 ShaderDependencies()),
1238 std::make_pair(std::string(kOpenCLMemoryModel) +
1239 // BufferBlock applies to struct type.
1240 "OpEntryPoint Kernel %func \"compute\" \n"
1241 "OpDecorate %block BufferBlock\n"
1242 "%intt = OpTypeInt 32 0\n"
1243 "%block = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
1244 ShaderDependencies()),
1245 std::make_pair(std::string(kOpenCLMemoryModel) +
1246 "OpEntryPoint Kernel %func \"compute\" \n"
1247 "OpDecorate %intt RowMajor\n"
1248 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1249 MatrixDependencies()),
1250 std::make_pair(std::string(kOpenCLMemoryModel) +
1251 "OpEntryPoint Kernel %func \"compute\" \n"
1252 "OpDecorate %intt ColMajor\n"
1253 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1254 MatrixDependencies()),
1255 std::make_pair(std::string(kOpenCLMemoryModel) +
1256 "OpEntryPoint Kernel %func \"compute\" \n"
1257 "OpDecorate %intt ArrayStride 1\n"
1258 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1259 ShaderDependencies()),
1260 std::make_pair(std::string(kOpenCLMemoryModel) +
1261 "OpEntryPoint Kernel %func \"compute\" \n"
1262 "OpDecorate %intt MatrixStride 1\n"
1263 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1264 MatrixDependencies()),
1265 std::make_pair(std::string(kOpenCLMemoryModel) +
1266 "OpEntryPoint Kernel %func \"compute\" \n"
1267 "OpDecorate %intt GLSLShared\n"
1268 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1269 ShaderDependencies()),
1270 std::make_pair(std::string(kOpenCLMemoryModel) +
1271 "OpEntryPoint Kernel %func \"compute\" \n"
1272 "OpDecorate %intt GLSLPacked\n"
1273 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1274 ShaderDependencies()),
1275 std::make_pair(std::string(kGLSL450MemoryModel) +
1276 "OpEntryPoint Vertex %func \"shader\" \n"
1277 "OpDecorate %intt CPacked\n"
1278 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1279 KernelDependencies()),
1280 std::make_pair(std::string(kOpenCLMemoryModel) +
1281 "OpEntryPoint Kernel %func \"compute\" \n"
1282 "OpDecorate %intt NoPerspective\n"
1283 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1284 ShaderDependencies()),
1285 std::make_pair(std::string(kOpenCLMemoryModel) +
1286 "OpEntryPoint Kernel %func \"compute\" \n"
1287 "OpDecorate %intt Flat\n"
1288 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1289 ShaderDependencies()),
1290 std::make_pair(std::string(kOpenCLMemoryModel) +
1291 "OpEntryPoint Kernel %func \"compute\" \n"
1292 "OpDecorate %intt Patch\n"
1293 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1294 TessellationDependencies()),
1295 std::make_pair(std::string(kOpenCLMemoryModel) +
1296 "OpEntryPoint Kernel %func \"compute\" \n"
1297 "OpDecorate %intt Centroid\n"
1298 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1299 ShaderDependencies()),
1300 std::make_pair(std::string(kOpenCLMemoryModel) +
1301 "OpEntryPoint Kernel %func \"compute\" \n"
1302 "OpDecorate %intt Sample\n"
1303 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1304 std::vector<std::string>{"SampleRateShading"}),
1305 std::make_pair(std::string(kOpenCLMemoryModel) +
1306 "OpEntryPoint Kernel %func \"compute\" \n"
1307 "OpDecorate %intt Invariant\n"
1308 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1309 ShaderDependencies()),
1310 std::make_pair(std::string(kOpenCLMemoryModel) +
1311 "OpEntryPoint Kernel %func \"compute\" \n"
1312 "OpDecorate %intt Restrict\n"
1313 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1314 AllCapabilities()),
1315 std::make_pair(std::string(kOpenCLMemoryModel) +
1316 "OpEntryPoint Kernel %func \"compute\" \n"
1317 "OpDecorate %intt Aliased\n"
1318 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1319 AllCapabilities()),
1320 std::make_pair(std::string(kOpenCLMemoryModel) +
1321 "OpEntryPoint Kernel %func \"compute\" \n"
1322 "OpDecorate %intt Volatile\n"
1323 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1324 AllCapabilities()),
1325 std::make_pair(std::string(kGLSL450MemoryModel) +
1326 "OpEntryPoint Vertex %func \"shader\" \n"
1327 "OpDecorate %intt Constant\n"
1328 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1329 KernelDependencies()),
1330 std::make_pair(std::string(kOpenCLMemoryModel) +
1331 "OpEntryPoint Kernel %func \"compute\" \n"
1332 "OpDecorate %intt Coherent\n"
1333 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1334 AllCapabilities()),
1335 std::make_pair(std::string(kOpenCLMemoryModel) +
1336 // NonWritable must target something valid, such as a storage image.
1337 "OpEntryPoint Kernel %func \"compute\" \n"
1338 "OpDecorate %var NonWritable "
1339 "%float = OpTypeFloat 32 "
1340 "%imstor = OpTypeImage %float 2D 0 0 0 2 Unknown "
1341 "%ptr = OpTypePointer UniformConstant %imstor "
1342 "%var = OpVariable %ptr UniformConstant "
1343 + std::string(kVoidFVoid),
1344 AllCapabilities()),
1345 std::make_pair(std::string(kOpenCLMemoryModel) +
1346 "OpEntryPoint Kernel %func \"compute\" \n"
1347 "OpDecorate %intt NonReadable\n"
1348 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1349 AllCapabilities()),
1350 std::make_pair(std::string(kOpenCLMemoryModel) +
1351 // Uniform must target a non-void value.
1352 "OpEntryPoint Kernel %func \"compute\" \n"
1353 "OpDecorate %int0 Uniform\n"
1354 "%intt = OpTypeInt 32 0\n" +
1355 "%int0 = OpConstantNull %intt"
1356 + std::string(kVoidFVoid),
1357 ShaderDependencies()),
1358 std::make_pair(std::string(kGLSL450MemoryModel) +
1359 "OpEntryPoint Vertex %func \"shader\" \n"
1360 "OpDecorate %intt SaturatedConversion\n"
1361 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1362 KernelDependencies()),
1363 std::make_pair(std::string(kOpenCLMemoryModel) +
1364 "OpEntryPoint Kernel %func \"compute\" \n"
1365 "OpDecorate %intt Stream 0\n"
1366 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1367 std::vector<std::string>{"GeometryStreams"}),
1368 std::make_pair(std::string(kOpenCLMemoryModel) +
1369 "OpEntryPoint Kernel %func \"compute\" \n"
1370 "OpMemberDecorate %struct 0 Location 0\n"
1371 "%intt = OpTypeInt 32 0\n"
1372 "%struct = OpTypeStruct %intt\n" + std::string(kVoidFVoid),
1373 ShaderDependencies()),
1374 std::make_pair(std::string(kOpenCLMemoryModel) +
1375 "OpEntryPoint Kernel %func \"compute\" \n"
1376 "OpDecorate %var Component 0\n"
1377 "%intt = OpTypeInt 32 0\n"
1378 "%ptr = OpTypePointer Input %intt\n"
1379 "%var = OpVariable %ptr Input\n" + std::string(kVoidFVoid),
1380 ShaderDependencies()),
1381 std::make_pair(std::string(kOpenCLMemoryModel) +
1382 "OpEntryPoint Kernel %func \"compute\" \n"
1383 "OpDecorate %intt Index 0\n"
1384 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1385 ShaderDependencies()),
1386 std::make_pair(std::string(kOpenCLMemoryModel) +
1387 "OpEntryPoint Kernel %func \"compute\" \n"
1388 "OpDecorate %intt Binding 0\n"
1389 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1390 ShaderDependencies()),
1391 std::make_pair(std::string(kOpenCLMemoryModel) +
1392 "OpEntryPoint Kernel %func \"compute\" \n"
1393 "OpDecorate %intt DescriptorSet 0\n"
1394 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1395 ShaderDependencies()),
1396 std::make_pair(std::string(kOpenCLMemoryModel) +
1397 "OpEntryPoint Kernel %func \"compute\" \n"
1398 "OpDecorate %intt Offset 0\n"
1399 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1400 ShaderDependencies()),
1401 std::make_pair(std::string(kOpenCLMemoryModel) +
1402 "OpEntryPoint Kernel %func \"compute\" \n"
1403 "OpDecorate %intt XfbBuffer 0\n"
1404 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1405 std::vector<std::string>{"TransformFeedback"}),
1406 std::make_pair(std::string(kOpenCLMemoryModel) +
1407 "OpEntryPoint Kernel %func \"compute\" \n"
1408 "OpDecorate %intt XfbStride 0\n"
1409 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1410 std::vector<std::string>{"TransformFeedback"}),
1411 std::make_pair(std::string(kGLSL450MemoryModel) +
1412 "OpEntryPoint Vertex %func \"shader\" \n"
1413 "OpDecorate %intt FuncParamAttr Zext\n"
1414 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1415 KernelDependencies()),
1416 std::make_pair(std::string(kGLSL450MemoryModel) +
1417 "OpEntryPoint Vertex %func \"shader\" \n"
1418 "OpDecorate %intt FPFastMathMode Fast\n"
1419 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1420 KernelDependencies()),
1421 std::make_pair(std::string(kOpenCLMemoryModel) +
1422 "OpEntryPoint Kernel %func \"compute\" \n"
1423 "OpDecorate %intt LinkageAttributes \"other\" Import\n"
1424 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1425 std::vector<std::string>{"Linkage"}),
1426 std::make_pair(std::string(kOpenCLMemoryModel) +
1427 "OpEntryPoint Kernel %func \"compute\" \n"
1428 "OpDecorate %intt NoContraction\n"
1429 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1430 ShaderDependencies()),
1431 std::make_pair(std::string(kOpenCLMemoryModel) +
1432 "OpEntryPoint Kernel %func \"compute\" \n"
1433 "OpDecorate %intt InputAttachmentIndex 0\n"
1434 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1435 std::vector<std::string>{"InputAttachment"}),
1436 std::make_pair(std::string(kGLSL450MemoryModel) +
1437 "OpEntryPoint Vertex %func \"shader\" \n"
1438 "OpDecorate %intt Alignment 4\n"
1439 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1440 KernelDependencies())
1441 )));
1442
1443 // clang-format on
1444 INSTANTIATE_TEST_SUITE_P(
1445 DecorationSpecId, ValidateCapability,
1446 Combine(
1447 ValuesIn(AllSpirV10Capabilities()),
1448 Values(std::make_pair(std::string(kOpenCLMemoryModel) +
1449 "OpEntryPoint Vertex %func \"shader\" \n" +
1450 "OpDecorate %1 SpecId 1\n"
1451 "%intt = OpTypeInt 32 0\n"
1452 "%1 = OpSpecConstant %intt 0\n" +
1453 std::string(kVoidFVoid),
1454 ShaderDependencies()))));
1455
1456 INSTANTIATE_TEST_SUITE_P(
1457 DecorationV11, ValidateCapabilityV11,
1458 Combine(ValuesIn(AllCapabilities()),
1459 Values(std::make_pair(std::string(kOpenCLMemoryModel) +
1460 "OpEntryPoint Kernel %func \"compute\" \n"
1461 "OpDecorate %p MaxByteOffset 0 "
1462 "%i32 = OpTypeInt 32 0 "
1463 "%pi32 = OpTypePointer Workgroup %i32 "
1464 "%p = OpVariable %pi32 Workgroup " +
1465 std::string(kVoidFVoid),
1466 AddressesDependencies()),
1467 // Trying to test OpDecorate here, but if this fails due to
1468 // incorrect OpMemoryModel validation, that must also be
1469 // fixed.
1470 std::make_pair(
1471 std::string("OpMemoryModel Logical OpenCL "
1472 "OpEntryPoint Kernel %func \"compute\" \n"
1473 "OpDecorate %1 SpecId 1 "
1474 "%intt = OpTypeInt 32 0 "
1475 "%1 = OpSpecConstant %intt 0") +
1476 std::string(kVoidFVoid),
1477 KernelDependencies()),
1478 std::make_pair(
1479 std::string("OpMemoryModel Logical Simple "
1480 "OpEntryPoint Vertex %func \"shader\" \n"
1481 "OpDecorate %1 SpecId 1 "
1482 "%intt = OpTypeInt 32 0 "
1483 "%1 = OpSpecConstant %intt 0") +
1484 std::string(kVoidFVoid),
1485 ShaderDependencies()))));
1486 // clang-format off
1487
1488 INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapability,
1489 Combine(
1490 ValuesIn(AllCapabilities()),
1491 Values(
1492 std::make_pair(std::string(kOpenCLMemoryModel) +
1493 "OpEntryPoint Kernel %func \"compute\" \n" +
1494 "OpDecorate %int0 BuiltIn Position\n"
1495 "%intt = OpTypeInt 32 0\n"
1496 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1497 ShaderDependencies()),
1498 // Just mentioning PointSize, ClipDistance, or CullDistance as a BuiltIn does
1499 // not trigger the requirement for the associated capability.
1500 // See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
1501 std::make_pair(std::string(kOpenCLMemoryModel) +
1502 "OpEntryPoint Kernel %func \"compute\" \n" +
1503 "OpDecorate %int0 BuiltIn PointSize\n"
1504 "%intt = OpTypeInt 32 0\n"
1505 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1506 AllCapabilities()),
1507 std::make_pair(std::string(kOpenCLMemoryModel) +
1508 "OpEntryPoint Kernel %func \"compute\" \n" +
1509 "OpDecorate %int0 BuiltIn ClipDistance\n"
1510 "%intt = OpTypeInt 32 0\n"
1511 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1512 AllCapabilities()),
1513 std::make_pair(std::string(kOpenCLMemoryModel) +
1514 "OpEntryPoint Kernel %func \"compute\" \n" +
1515 "OpDecorate %int0 BuiltIn CullDistance\n"
1516 "%intt = OpTypeInt 32 0\n"
1517 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1518 AllCapabilities()),
1519 std::make_pair(std::string(kOpenCLMemoryModel) +
1520 "OpEntryPoint Kernel %func \"compute\" \n" +
1521 "OpDecorate %int0 BuiltIn VertexId\n"
1522 "%intt = OpTypeInt 32 0\n"
1523 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1524 ShaderDependencies()),
1525 std::make_pair(std::string(kOpenCLMemoryModel) +
1526 "OpEntryPoint Kernel %func \"compute\" \n" +
1527 "OpDecorate %int0 BuiltIn InstanceId\n"
1528 "%intt = OpTypeInt 32 0\n"
1529 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1530 ShaderDependencies()),
1531 std::make_pair(std::string(kOpenCLMemoryModel) +
1532 "OpEntryPoint Kernel %func \"compute\" \n" +
1533 "OpDecorate %int0 BuiltIn PrimitiveId\n"
1534 "%intt = OpTypeInt 32 0\n"
1535 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1536 GeometryTessellationDependencies()),
1537 std::make_pair(std::string(kOpenCLMemoryModel) +
1538 "OpEntryPoint Kernel %func \"compute\" \n" +
1539 "OpDecorate %int0 BuiltIn InvocationId\n"
1540 "%intt = OpTypeInt 32 0\n"
1541 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1542 GeometryTessellationDependencies()),
1543 std::make_pair(std::string(kOpenCLMemoryModel) +
1544 "OpEntryPoint Kernel %func \"compute\" \n" +
1545 "OpDecorate %int0 BuiltIn Layer\n"
1546 "%intt = OpTypeInt 32 0\n"
1547 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1548 GeometryDependencies()),
1549 std::make_pair(std::string(kOpenCLMemoryModel) +
1550 "OpEntryPoint Kernel %func \"compute\" \n" +
1551 "OpDecorate %int0 BuiltIn ViewportIndex\n"
1552 "%intt = OpTypeInt 32 0\n"
1553 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1554 std::vector<std::string>{"MultiViewport"}),
1555 std::make_pair(std::string(kOpenCLMemoryModel) +
1556 "OpEntryPoint Kernel %func \"compute\" \n" +
1557 "OpDecorate %int0 BuiltIn TessLevelOuter\n"
1558 "%intt = OpTypeInt 32 0\n"
1559 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1560 TessellationDependencies()),
1561 std::make_pair(std::string(kOpenCLMemoryModel) +
1562 "OpEntryPoint Kernel %func \"compute\" \n" +
1563 "OpDecorate %int0 BuiltIn TessLevelInner\n"
1564 "%intt = OpTypeInt 32 0\n"
1565 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1566 TessellationDependencies()),
1567 std::make_pair(std::string(kOpenCLMemoryModel) +
1568 "OpEntryPoint Kernel %func \"compute\" \n" +
1569 "OpDecorate %int0 BuiltIn TessCoord\n"
1570 "%intt = OpTypeInt 32 0\n"
1571 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1572 TessellationDependencies()),
1573 std::make_pair(std::string(kOpenCLMemoryModel) +
1574 "OpEntryPoint Kernel %func \"compute\" \n" +
1575 "OpDecorate %int0 BuiltIn PatchVertices\n"
1576 "%intt = OpTypeInt 32 0\n"
1577 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1578 TessellationDependencies()),
1579 std::make_pair(std::string(kOpenCLMemoryModel) +
1580 "OpEntryPoint Kernel %func \"compute\" \n" +
1581 "OpDecorate %int0 BuiltIn FragCoord\n"
1582 "%intt = OpTypeInt 32 0\n"
1583 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1584 ShaderDependencies()),
1585 std::make_pair(std::string(kOpenCLMemoryModel) +
1586 "OpEntryPoint Kernel %func \"compute\" \n" +
1587 "OpDecorate %int0 BuiltIn PointCoord\n"
1588 "%intt = OpTypeInt 32 0\n"
1589 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1590 ShaderDependencies()),
1591 std::make_pair(std::string(kOpenCLMemoryModel) +
1592 "OpEntryPoint Kernel %func \"compute\" \n" +
1593 "OpDecorate %int0 BuiltIn FrontFacing\n"
1594 "%intt = OpTypeInt 32 0\n"
1595 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1596 ShaderDependencies()),
1597 std::make_pair(std::string(kOpenCLMemoryModel) +
1598 "OpEntryPoint Kernel %func \"compute\" \n" +
1599 "OpDecorate %int0 BuiltIn SampleId\n"
1600 "%intt = OpTypeInt 32 0\n"
1601 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1602 std::vector<std::string>{"SampleRateShading"}),
1603 std::make_pair(std::string(kOpenCLMemoryModel) +
1604 "OpEntryPoint Kernel %func \"compute\" \n" +
1605 "OpDecorate %int0 BuiltIn SamplePosition\n"
1606 "%intt = OpTypeInt 32 0\n"
1607 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1608 std::vector<std::string>{"SampleRateShading"}),
1609 std::make_pair(std::string(kOpenCLMemoryModel) +
1610 "OpEntryPoint Kernel %func \"compute\" \n" +
1611 "OpDecorate %int0 BuiltIn SampleMask\n"
1612 "%intt = OpTypeInt 32 0\n"
1613 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1614 ShaderDependencies()),
1615 std::make_pair(std::string(kOpenCLMemoryModel) +
1616 "OpEntryPoint Kernel %func \"compute\" \n" +
1617 "OpDecorate %int0 BuiltIn FragDepth\n"
1618 "%intt = OpTypeInt 32 0\n"
1619 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1620 ShaderDependencies()),
1621 std::make_pair(std::string(kOpenCLMemoryModel) +
1622 "OpEntryPoint Kernel %func \"compute\" \n" +
1623 "OpDecorate %int0 BuiltIn HelperInvocation\n"
1624 "%intt = OpTypeInt 32 0\n"
1625 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1626 ShaderDependencies()),
1627 std::make_pair(std::string(kOpenCLMemoryModel) +
1628 "OpEntryPoint Kernel %func \"compute\" \n" +
1629 "OpDecorate %int0 BuiltIn VertexIndex\n"
1630 "%intt = OpTypeInt 32 0\n"
1631 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1632 ShaderDependencies()),
1633 std::make_pair(std::string(kOpenCLMemoryModel) +
1634 "OpEntryPoint Kernel %func \"compute\" \n" +
1635 "OpDecorate %int0 BuiltIn InstanceIndex\n"
1636 "%intt = OpTypeInt 32 0\n"
1637 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1638 ShaderDependencies()),
1639 std::make_pair(std::string(kOpenCLMemoryModel) +
1640 "OpEntryPoint Kernel %func \"compute\" \n" +
1641 "OpDecorate %int0 BuiltIn NumWorkgroups\n"
1642 "%intt = OpTypeInt 32 0\n"
1643 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1644 AllCapabilities()),
1645 std::make_pair(std::string(kOpenCLMemoryModel) +
1646 "OpEntryPoint Kernel %func \"compute\" \n" +
1647 "OpDecorate %int0 BuiltIn WorkgroupSize\n"
1648 "%intt = OpTypeInt 32 0\n"
1649 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1650 AllCapabilities()),
1651 std::make_pair(std::string(kOpenCLMemoryModel) +
1652 "OpEntryPoint Kernel %func \"compute\" \n" +
1653 "OpDecorate %int0 BuiltIn WorkgroupId\n"
1654 "%intt = OpTypeInt 32 0\n"
1655 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1656 AllCapabilities()),
1657 std::make_pair(std::string(kOpenCLMemoryModel) +
1658 "OpEntryPoint Kernel %func \"compute\" \n" +
1659 "OpDecorate %int0 BuiltIn LocalInvocationId\n"
1660 "%intt = OpTypeInt 32 0\n"
1661 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1662 AllCapabilities()),
1663 std::make_pair(std::string(kOpenCLMemoryModel) +
1664 "OpEntryPoint Kernel %func \"compute\" \n" +
1665 "OpDecorate %int0 BuiltIn GlobalInvocationId\n"
1666 "%intt = OpTypeInt 32 0\n"
1667 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1668 AllCapabilities()),
1669 std::make_pair(std::string(kOpenCLMemoryModel) +
1670 "OpEntryPoint Kernel %func \"compute\" \n" +
1671 "OpDecorate %int0 BuiltIn LocalInvocationIndex\n"
1672 "%intt = OpTypeInt 32 0\n"
1673 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1674 AllCapabilities()),
1675 std::make_pair(std::string(kGLSL450MemoryModel) +
1676 "OpEntryPoint Vertex %func \"shader\" \n" +
1677 "OpDecorate %int0 BuiltIn WorkDim\n"
1678 "%intt = OpTypeInt 32 0\n"
1679 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1680 KernelDependencies()),
1681 std::make_pair(std::string(kGLSL450MemoryModel) +
1682 "OpEntryPoint Vertex %func \"shader\" \n" +
1683 "OpDecorate %int0 BuiltIn GlobalSize\n"
1684 "%intt = OpTypeInt 32 0\n"
1685 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1686 KernelDependencies()),
1687 std::make_pair(std::string(kGLSL450MemoryModel) +
1688 "OpEntryPoint Vertex %func \"shader\" \n" +
1689 "OpDecorate %int0 BuiltIn EnqueuedWorkgroupSize\n"
1690 "%intt = OpTypeInt 32 0\n"
1691 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1692 KernelDependencies()),
1693 std::make_pair(std::string(kGLSL450MemoryModel) +
1694 "OpEntryPoint Vertex %func \"shader\" \n" +
1695 "OpDecorate %int0 BuiltIn GlobalOffset\n"
1696 "%intt = OpTypeInt 32 0\n"
1697 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1698 KernelDependencies()),
1699 std::make_pair(std::string(kGLSL450MemoryModel) +
1700 "OpEntryPoint Vertex %func \"shader\" \n" +
1701 "OpDecorate %int0 BuiltIn GlobalLinearId\n"
1702 "%intt = OpTypeInt 32 0\n"
1703 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1704 KernelDependencies()),
1705 std::make_pair(std::string(kGLSL450MemoryModel) +
1706 "OpEntryPoint Vertex %func \"shader\" \n" +
1707 "OpDecorate %int0 BuiltIn SubgroupSize\n"
1708 "%intt = OpTypeInt 32 0\n"
1709 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1710 KernelAndGroupNonUniformDependencies()),
1711 std::make_pair(std::string(kGLSL450MemoryModel) +
1712 "OpEntryPoint Vertex %func \"shader\" \n" +
1713 "OpDecorate %int0 BuiltIn SubgroupMaxSize\n"
1714 "%intt = OpTypeInt 32 0\n"
1715 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1716 KernelDependencies()),
1717 std::make_pair(std::string(kGLSL450MemoryModel) +
1718 "OpEntryPoint Vertex %func \"shader\" \n" +
1719 "OpDecorate %int0 BuiltIn NumSubgroups\n"
1720 "%intt = OpTypeInt 32 0\n"
1721 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1722 KernelAndGroupNonUniformDependencies()),
1723 std::make_pair(std::string(kGLSL450MemoryModel) +
1724 "OpEntryPoint Vertex %func \"shader\" \n" +
1725 "OpDecorate %int0 BuiltIn NumEnqueuedSubgroups\n"
1726 "%intt = OpTypeInt 32 0\n"
1727 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1728 KernelDependencies()),
1729 std::make_pair(std::string(kGLSL450MemoryModel) +
1730 "OpEntryPoint Vertex %func \"shader\" \n" +
1731 "OpDecorate %int0 BuiltIn SubgroupId\n"
1732 "%intt = OpTypeInt 32 0\n"
1733 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1734 KernelAndGroupNonUniformDependencies()),
1735 std::make_pair(std::string(kGLSL450MemoryModel) +
1736 "OpEntryPoint Vertex %func \"shader\" \n" +
1737 "OpDecorate %int0 BuiltIn SubgroupLocalInvocationId\n"
1738 "%intt = OpTypeInt 32 0\n"
1739 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1740 KernelAndGroupNonUniformDependencies()),
1741 std::make_pair(std::string(kOpenCLMemoryModel) +
1742 "OpEntryPoint Kernel %func \"compute\" \n" +
1743 "OpDecorate %int0 BuiltIn VertexIndex\n"
1744 "%intt = OpTypeInt 32 0\n"
1745 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1746 ShaderDependencies()),
1747 std::make_pair(std::string(kOpenCLMemoryModel) +
1748 "OpEntryPoint Kernel %func \"compute\" \n" +
1749 "OpDecorate %int0 BuiltIn InstanceIndex\n"
1750 "%intt = OpTypeInt 32 0\n"
1751 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1752 ShaderDependencies())
1753 )));
1754
1755 // Ensure that mere mention of PointSize, ClipDistance, or CullDistance as
1756 // BuiltIns does not trigger the requirement for the associated
1757 // capability.
1758 // See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
1759 INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapabilityVulkan10,
1760 Combine(
1761 // All capabilities to try.
1762 ValuesIn(AllSpirV10Capabilities()),
1763 Values(
1764 std::make_pair(std::string(kGLSL450MemoryModel) +
1765 "OpEntryPoint Vertex %func \"shader\" \n"
1766 "OpMemberDecorate %block 0 BuiltIn PointSize\n"
1767 "%f32 = OpTypeFloat 32\n"
1768 "%block = OpTypeStruct %f32\n"
1769 "%intt = OpTypeInt 32 0\n" + std::string(kVoidFVoid),
1770 // Capabilities which should succeed.
1771 AllVulkan10Capabilities()),
1772 std::make_pair(std::string(kGLSL450MemoryModel) +
1773 "OpEntryPoint Vertex %func \"shader\" \n"
1774 "OpMemberDecorate %block 0 BuiltIn ClipDistance\n"
1775 "%f32 = OpTypeFloat 32\n"
1776 "%intt = OpTypeInt 32 0\n"
1777 "%intt_4 = OpConstant %intt 4\n"
1778 "%f32arr4 = OpTypeArray %f32 %intt_4\n"
1779 "%block = OpTypeStruct %f32arr4\n" + std::string(kVoidFVoid),
1780 AllVulkan10Capabilities()),
1781 std::make_pair(std::string(kGLSL450MemoryModel) +
1782 "OpEntryPoint Vertex %func \"shader\" \n"
1783 "OpMemberDecorate %block 0 BuiltIn CullDistance\n"
1784 "%f32 = OpTypeFloat 32\n"
1785 "%intt = OpTypeInt 32 0\n"
1786 "%intt_4 = OpConstant %intt 4\n"
1787 "%f32arr4 = OpTypeArray %f32 %intt_4\n"
1788 "%block = OpTypeStruct %f32arr4\n" + std::string(kVoidFVoid),
1789 AllVulkan10Capabilities())
1790 )));
1791
1792 INSTANTIATE_TEST_SUITE_P(BuiltIn, ValidateCapabilityOpenGL40,
1793 Combine(
1794 // OpenGL 4.0 is based on SPIR-V 1.0
1795 ValuesIn(AllSpirV10Capabilities()),
1796 Values(
1797 std::make_pair(std::string(kGLSL450MemoryModel) +
1798 "OpEntryPoint Vertex %func \"shader\" \n" +
1799 "OpDecorate %int0 BuiltIn PointSize\n"
1800 "%intt = OpTypeInt 32 0\n"
1801 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1802 AllSpirV10Capabilities()),
1803 std::make_pair(std::string(kGLSL450MemoryModel) +
1804 "OpEntryPoint Vertex %func \"shader\" \n" +
1805 "OpDecorate %int0 BuiltIn ClipDistance\n"
1806 "%intt = OpTypeInt 32 0\n"
1807 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1808 AllSpirV10Capabilities()),
1809 std::make_pair(std::string(kGLSL450MemoryModel) +
1810 "OpEntryPoint Vertex %func \"shader\" \n" +
1811 "OpDecorate %int0 BuiltIn CullDistance\n"
1812 "%intt = OpTypeInt 32 0\n"
1813 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1814 AllSpirV10Capabilities())
1815 )));
1816
1817 INSTANTIATE_TEST_SUITE_P(Capabilities, ValidateCapabilityWebGPU,
1818 Combine(
1819 // All capabilities to try.
1820 ValuesIn(AllCapabilities()),
1821 Values(
1822 std::make_pair(std::string(kVulkanMemoryModel) +
1823 "OpEntryPoint Vertex %func \"shader\" \n" + std::string(kVoidFVoid),
1824 AllWebGPUCapabilities())
1825 )));
1826
1827 INSTANTIATE_TEST_SUITE_P(Capabilities, ValidateCapabilityVulkan11,
1828 Combine(
1829 // All capabilities to try.
1830 ValuesIn(AllCapabilities()),
1831 Values(
1832 std::make_pair(std::string(kGLSL450MemoryModel) +
1833 "OpEntryPoint Vertex %func \"shader\" \n" +
1834 "OpDecorate %int0 BuiltIn PointSize\n"
1835 "%intt = OpTypeInt 32 0\n"
1836 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1837 AllVulkan11Capabilities()),
1838 std::make_pair(std::string(kGLSL450MemoryModel) +
1839 "OpEntryPoint Vertex %func \"shader\" \n" +
1840 "OpDecorate %int0 BuiltIn CullDistance\n"
1841 "%intt = OpTypeInt 32 0\n"
1842 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1843 AllVulkan11Capabilities())
1844 )));
1845
1846 INSTANTIATE_TEST_SUITE_P(Capabilities, ValidateCapabilityVulkan12,
1847 Combine(
1848 // All capabilities to try.
1849 ValuesIn(AllSpirV15Capabilities()),
1850 Values(
1851 std::make_pair(std::string(kGLSL450MemoryModel) +
1852 "OpEntryPoint Vertex %func \"shader\" \n" +
1853 "OpDecorate %int0 BuiltIn PointSize\n"
1854 "%intt = OpTypeInt 32 0\n"
1855 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1856 AllVulkan12Capabilities()),
1857 std::make_pair(std::string(kGLSL450MemoryModel) +
1858 "OpEntryPoint Vertex %func \"shader\" \n" +
1859 "OpDecorate %int0 BuiltIn CullDistance\n"
1860 "%intt = OpTypeInt 32 0\n"
1861 "%int0 = OpConstant %intt 0\n" + std::string(kVoidFVoid),
1862 AllVulkan12Capabilities())
1863 )));
1864
1865 // TODO(umar): Selection Control
1866 // TODO(umar): Loop Control
1867 // TODO(umar): Function Control
1868 // TODO(umar): Memory Semantics
1869 // TODO(umar): Memory Access
1870 // TODO(umar): Scope
1871 // TODO(umar): Group Operation
1872 // TODO(umar): Kernel Enqueue Flags
1873 // TODO(umar): Kernel Profiling Flags
1874
1875 INSTANTIATE_TEST_SUITE_P(MatrixOp, ValidateCapability,
1876 Combine(
1877 ValuesIn(AllCapabilities()),
1878 Values(
1879 std::make_pair(std::string(kOpenCLMemoryModel) +
1880 "OpEntryPoint Kernel %func \"compute\" \n" +
1881 "%f32 = OpTypeFloat 32\n"
1882 "%vec3 = OpTypeVector %f32 3\n"
1883 "%mat33 = OpTypeMatrix %vec3 3\n" + std::string(kVoidFVoid),
1884 MatrixDependencies()))));
1885 // clang-format on
1886
1887 #if 0
1888 // TODO([email protected]) The following test is not valid as it generates
1889 // invalid combinations of images, instructions and image operands.
1890 //
1891 // Creates assembly containing an OpImageFetch instruction using operands for
1892 // the image-operands part. The assembly defines constants %fzero and %izero
1893 // that can be used for operands where IDs are required. The assembly is valid,
1894 // apart from not declaring any capabilities required by the operands.
1895 string ImageOperandsTemplate(const std::string& operands) {
1896 ostringstream ss;
1897 // clang-format off
1898 ss << R"(
1899 OpCapability Kernel
1900 OpCapability Linkage
1901 OpMemoryModel Logical OpenCL
1902
1903 %i32 = OpTypeInt 32 0
1904 %f32 = OpTypeFloat 32
1905 %v4i32 = OpTypeVector %i32 4
1906 %timg = OpTypeImage %i32 2D 0 0 0 0 Unknown
1907 %pimg = OpTypePointer UniformConstant %timg
1908 %tfun = OpTypeFunction %i32
1909
1910 %vimg = OpVariable %pimg UniformConstant
1911 %izero = OpConstant %i32 0
1912 %fzero = OpConstant %f32 0.
1913
1914 %main = OpFunction %i32 None %tfun
1915 %lbl = OpLabel
1916 %img = OpLoad %timg %vimg
1917 %r1 = OpImageFetch %v4i32 %img %izero )" << operands << R"(
1918 OpReturnValue %izero
1919 OpFunctionEnd
1920 )";
1921 // clang-format on
1922 return ss.str();
1923 }
1924
1925 INSTANTIATE_TEST_SUITE_P(
1926 TwoImageOperandsMask, ValidateCapability,
1927 Combine(
1928 ValuesIn(AllCapabilities()),
1929 Values(std::make_pair(ImageOperandsTemplate("Bias|Lod %fzero %fzero"),
1930 ShaderDependencies()),
1931 std::make_pair(ImageOperandsTemplate("Lod|Offset %fzero %izero"),
1932 std::vector<std::string>{"ImageGatherExtended"}),
1933 std::make_pair(ImageOperandsTemplate("Sample|MinLod %izero %fzero"),
1934 std::vector<std::string>{"MinLod"}),
1935 std::make_pair(ImageOperandsTemplate("Lod|Sample %fzero %izero"),
1936 AllCapabilities()))), );
1937 #endif
1938
1939 // TODO(umar): Instruction capability checks
1940
1941 spv_result_t spvCoreOperandTableNameLookup(spv_target_env env,
1942 const spv_operand_table table,
1943 const spv_operand_type_t type,
1944 const char* name,
1945 const size_t nameLength) {
1946 if (!table) return SPV_ERROR_INVALID_TABLE;
1947 if (!name) return SPV_ERROR_INVALID_POINTER;
1948
1949 for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) {
1950 const auto& group = table->types[typeIndex];
1951 if (type != group.type) continue;
1952 for (uint64_t index = 0; index < group.count; ++index) {
1953 const auto& entry = group.entries[index];
1954 // Check for min version only.
1955 if (spvVersionForTargetEnv(env) >= entry.minVersion &&
1956 nameLength == strlen(entry.name) &&
1957 !strncmp(entry.name, name, nameLength)) {
1958 return SPV_SUCCESS;
1959 }
1960 }
1961 }
1962
1963 return SPV_ERROR_INVALID_LOOKUP;
1964 }
1965
1966 // True if capability exists in core spec of env.
1967 bool Exists(const std::string& capability, spv_target_env env) {
1968 ScopedContext sc(env);
1969 return SPV_SUCCESS ==
1970 spvCoreOperandTableNameLookup(env, sc.context->operand_table,
1971 SPV_OPERAND_TYPE_CAPABILITY,
1972 capability.c_str(), capability.size());
1973 }
1974
1975 TEST_P(ValidateCapability, Capability) {
1976 const std::string capability = Capability(GetParam());
1977 spv_target_env env = SPV_ENV_UNIVERSAL_1_0;
1978 if (!capability.empty()) {
1979 if (Exists(capability, SPV_ENV_UNIVERSAL_1_0))
1980 env = SPV_ENV_UNIVERSAL_1_0;
1981 else if (Exists(capability, SPV_ENV_UNIVERSAL_1_1))
1982 env = SPV_ENV_UNIVERSAL_1_1;
1983 else if (Exists(capability, SPV_ENV_UNIVERSAL_1_2))
1984 env = SPV_ENV_UNIVERSAL_1_2;
1985 else
1986 env = SPV_ENV_UNIVERSAL_1_3;
1987 }
1988 const std::string test_code = MakeAssembly(GetParam());
1989 CompileSuccessfully(test_code, env);
1990 ASSERT_EQ(ExpectedResult(GetParam()), ValidateInstructions(env))
1991 << "target env: " << spvTargetEnvDescription(env) << "\ntest code:\n"
1992 << test_code;
1993 }
1994
1995 TEST_P(ValidateCapabilityV11, Capability) {
1996 const std::string capability = Capability(GetParam());
1997 if (Exists(capability, SPV_ENV_UNIVERSAL_1_1)) {
1998 const std::string test_code = MakeAssembly(GetParam());
1999 CompileSuccessfully(test_code, SPV_ENV_UNIVERSAL_1_1);
2000 ASSERT_EQ(ExpectedResult(GetParam()),
2001 ValidateInstructions(SPV_ENV_UNIVERSAL_1_1))
2002 << test_code;
2003 }
2004 }
2005
2006 TEST_P(ValidateCapabilityVulkan10, Capability) {
2007 const std::string capability = Capability(GetParam());
2008 if (Exists(capability, SPV_ENV_VULKAN_1_0)) {
2009 const std::string test_code = MakeAssembly(GetParam());
2010 CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_0);
2011 ASSERT_EQ(ExpectedResult(GetParam()),
2012 ValidateInstructions(SPV_ENV_VULKAN_1_0))
2013 << test_code;
2014 }
2015 }
2016
2017 TEST_P(ValidateCapabilityVulkan11, Capability) {
2018 const std::string capability = Capability(GetParam());
2019 if (Exists(capability, SPV_ENV_VULKAN_1_1)) {
2020 const std::string test_code = MakeAssembly(GetParam());
2021 CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_1);
2022 ASSERT_EQ(ExpectedResult(GetParam()),
2023 ValidateInstructions(SPV_ENV_VULKAN_1_1))
2024 << test_code;
2025 }
2026 }
2027
2028 TEST_P(ValidateCapabilityVulkan12, Capability) {
2029 const std::string capability = Capability(GetParam());
2030 if (Exists(capability, SPV_ENV_VULKAN_1_2)) {
2031 const std::string test_code = MakeAssembly(GetParam());
2032 CompileSuccessfully(test_code, SPV_ENV_VULKAN_1_2);
2033 ASSERT_EQ(ExpectedResult(GetParam()),
2034 ValidateInstructions(SPV_ENV_VULKAN_1_2))
2035 << test_code;
2036 }
2037 }
2038
2039 TEST_P(ValidateCapabilityOpenGL40, Capability) {
2040 const std::string capability = Capability(GetParam());
2041 if (Exists(capability, SPV_ENV_OPENGL_4_0)) {
2042 const std::string test_code = MakeAssembly(GetParam());
2043 CompileSuccessfully(test_code, SPV_ENV_OPENGL_4_0);
2044 ASSERT_EQ(ExpectedResult(GetParam()),
2045 ValidateInstructions(SPV_ENV_OPENGL_4_0))
2046 << test_code;
2047 }
2048 }
2049
2050 TEST_P(ValidateCapabilityWebGPU, Capability) {
2051 const std::string capability = Capability(GetParam());
2052 if (Exists(capability, SPV_ENV_WEBGPU_0)) {
2053 const std::string test_code = MakeAssembly(GetParam());
2054 CompileSuccessfully(test_code, SPV_ENV_WEBGPU_0);
2055 ASSERT_EQ(ExpectedResult(GetParam()),
2056 ValidateInstructions(SPV_ENV_WEBGPU_0))
2057 << test_code;
2058 }
2059 }
2060
2061 TEST_F(ValidateCapability, SemanticsIdIsAnIdNotALiteral) {
2062 // From https://github.com/KhronosGroup/SPIRV-Tools/issues/248
2063 // The validator was interpreting the memory semantics ID number
2064 // as the value to be checked rather than an ID that references
2065 // another value to be checked.
2066 // In this case a raw ID of 64 was mistaken to mean a literal
2067 // semantic value of UniformMemory, which would require the Shader
2068 // capability.
2069 const char str[] = R"(
2070 OpCapability Kernel
2071 OpCapability Linkage
2072 OpMemoryModel Logical OpenCL
2073
2074 ; %i32 has ID 1
2075 %i32 = OpTypeInt 32 0
2076 %tf = OpTypeFunction %i32
2077 %pi32 = OpTypePointer CrossWorkgroup %i32
2078 %var = OpVariable %pi32 CrossWorkgroup
2079 %c = OpConstant %i32 100
2080 %scope = OpConstant %i32 1 ; Device scope
2081
2082 ; Fake an instruction with 64 as the result id.
2083 ; !64 = OpConstantNull %i32
2084 !0x3002e !1 !64
2085
2086 %f = OpFunction %i32 None %tf
2087 %l = OpLabel
2088 %result = OpAtomicIAdd %i32 %var %scope !64 %c
2089 OpReturnValue %result
2090 OpFunctionEnd
2091 )";
2092
2093 CompileSuccessfully(str);
2094
2095 // Since we are forcing usage of <id> 64, the "id bound" in the binary header
2096 // must be overwritten so that <id> 64 is considered within bound.
2097 // ID Bound is at index 3 of the binary. Set it to 65.
2098 OverwriteAssembledBinary(3, 65);
2099
2100 ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
2101 }
2102
2103 TEST_F(ValidateCapability, IntSignednessKernelGood) {
2104 const std::string spirv = R"(
2105 OpCapability Kernel
2106 OpCapability Linkage
2107 OpMemoryModel Logical OpenCL
2108 %i32 = OpTypeInt 32 0
2109 )";
2110 CompileSuccessfully(spirv);
2111 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
2112 }
2113
2114 TEST_F(ValidateCapability, IntSignednessKernelBad) {
2115 const std::string spirv = R"(
2116 OpCapability Kernel
2117 OpCapability Linkage
2118 OpMemoryModel Logical OpenCL
2119 %i32 = OpTypeInt 32 1
2120 )";
2121 CompileSuccessfully(spirv);
2122 EXPECT_EQ(SPV_ERROR_INVALID_BINARY, ValidateInstructions());
2123 EXPECT_THAT(getDiagnosticString(),
2124 HasSubstr("The Signedness in OpTypeInt must always be 0 when "
2125 "Kernel capability is used."));
2126 }
2127
2128 TEST_F(ValidateCapability, IntSignednessShaderGood) {
2129 const std::string spirv = R"(
2130 OpCapability Shader
2131 OpCapability Linkage
2132 OpMemoryModel Logical GLSL450
2133 %u32 = OpTypeInt 32 0
2134 %i32 = OpTypeInt 32 1
2135 )";
2136 CompileSuccessfully(spirv);
2137 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
2138 }
2139
2140 TEST_F(ValidateCapability, NonVulkan10Capability) {
2141 const std::string spirv = R"(
2142 OpCapability Shader
2143 OpCapability Linkage
2144 OpMemoryModel Logical GLSL450
2145 %u32 = OpTypeInt 32 0
2146 %i32 = OpTypeInt 32 1
2147 )";
2148 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
2149 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2150 ValidateInstructions(SPV_ENV_VULKAN_1_0));
2151 EXPECT_THAT(getDiagnosticString(),
2152 HasSubstr("Capability Linkage is not allowed by Vulkan 1.0"));
2153 }
2154
2155 TEST_F(ValidateCapability, Vulkan10EnabledByExtension) {
2156 const std::string spirv = R"(
2157 OpCapability Shader
2158 OpCapability DrawParameters
2159 OpExtension "SPV_KHR_shader_draw_parameters"
2160 OpMemoryModel Logical GLSL450
2161 OpEntryPoint Vertex %func "shader"
2162 OpMemberDecorate %block 0 BuiltIn PointSize
2163 %f32 = OpTypeFloat 32
2164 %block = OpTypeStruct %f32
2165 )" + std::string(kVoidFVoid);
2166
2167 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
2168 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
2169 }
2170
2171 TEST_F(ValidateCapability, Vulkan10NotEnabledByExtension) {
2172 const std::string spirv = R"(
2173 OpCapability Shader
2174 OpCapability DrawParameters
2175 OpMemoryModel Logical GLSL450
2176 OpEntryPoint Vertex %func "shader"
2177 OpDecorate %intt BuiltIn PointSize
2178 %intt = OpTypeInt 32 0
2179 )" + std::string(kVoidFVoid);
2180
2181 CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
2182 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2183 ValidateInstructions(SPV_ENV_VULKAN_1_0));
2184 EXPECT_THAT(
2185 getDiagnosticString(),
2186 HasSubstr("Capability DrawParameters is not allowed by Vulkan 1.0"));
2187 }
2188
2189 TEST_F(ValidateCapability, NonOpenCL12FullCapability) {
2190 const std::string spirv = R"(
2191 OpCapability Kernel
2192 OpCapability Addresses
2193 OpCapability Linkage
2194 OpCapability Pipes
2195 OpMemoryModel Physical64 OpenCL
2196 %u32 = OpTypeInt 32 0
2197 )";
2198 CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
2199 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2200 ValidateInstructions(SPV_ENV_OPENCL_1_2));
2201 EXPECT_THAT(
2202 getDiagnosticString(),
2203 HasSubstr("Capability Pipes is not allowed by OpenCL 1.2 Full Profile"));
2204 }
2205
2206 TEST_F(ValidateCapability, OpenCL12FullEnabledByCapability) {
2207 const std::string spirv = R"(
2208 OpCapability Kernel
2209 OpCapability Addresses
2210 OpCapability Linkage
2211 OpCapability ImageBasic
2212 OpCapability Sampled1D
2213 OpMemoryModel Physical64 OpenCL
2214 %u32 = OpTypeInt 32 0
2215 )" + std::string(kVoidFVoid);
2216
2217 CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
2218 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_1_2));
2219 }
2220
2221 TEST_F(ValidateCapability, OpenCL12FullNotEnabledByCapability) {
2222 const std::string spirv = R"(
2223 OpCapability Kernel
2224 OpCapability Addresses
2225 OpCapability Linkage
2226 OpCapability Sampled1D
2227 OpMemoryModel Physical64 OpenCL
2228 %u32 = OpTypeInt 32 0
2229 )" + std::string(kVoidFVoid);
2230
2231 CompileSuccessfully(spirv, SPV_ENV_OPENCL_1_2);
2232 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2233 ValidateInstructions(SPV_ENV_OPENCL_1_2));
2234 EXPECT_THAT(
2235 getDiagnosticString(),
2236 HasSubstr(
2237 "Capability Sampled1D is not allowed by OpenCL 1.2 Full Profile"));
2238 }
2239
2240 TEST_F(ValidateCapability, NonOpenCL12EmbeddedCapability) {
2241 const std::string spirv = R"(
2242 OpCapability Kernel
2243 OpCapability Addresses
2244 OpCapability Linkage
2245 OpCapability Int64
2246 OpMemoryModel Physical64 OpenCL
2247 %u32 = OpTypeInt 32 0
2248 )";
2249 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
2250 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2251 ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
2252 EXPECT_THAT(
2253 getDiagnosticString(),
2254 HasSubstr(
2255 "Capability Int64 is not allowed by OpenCL 1.2 Embedded Profile"));
2256 }
2257
2258 TEST_F(ValidateCapability, OpenCL12EmbeddedEnabledByCapability) {
2259 const std::string spirv = R"(
2260 OpCapability Kernel
2261 OpCapability Addresses
2262 OpCapability Linkage
2263 OpCapability ImageBasic
2264 OpCapability Sampled1D
2265 OpMemoryModel Physical64 OpenCL
2266 %u32 = OpTypeInt 32 0
2267 )" + std::string(kVoidFVoid);
2268
2269 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
2270 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
2271 }
2272
2273 TEST_F(ValidateCapability, OpenCL12EmbeddedNotEnabledByCapability) {
2274 const std::string spirv = R"(
2275 OpCapability Kernel
2276 OpCapability Addresses
2277 OpCapability Linkage
2278 OpCapability Sampled1D
2279 OpMemoryModel Physical64 OpenCL
2280 %u32 = OpTypeInt 32 0
2281 )" + std::string(kVoidFVoid);
2282
2283 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
2284 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2285 ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
2286 EXPECT_THAT(getDiagnosticString(),
2287 HasSubstr("Capability Sampled1D is not allowed by OpenCL 1.2 "
2288 "Embedded Profile"));
2289 }
2290
2291 TEST_F(ValidateCapability, OpenCL12EmbeddedNoLongerEnabledByCapability) {
2292 const std::string spirv = R"(
2293 OpCapability Kernel
2294 OpCapability Addresses
2295 OpCapability Linkage
2296 OpCapability Pipes
2297 OpMemoryModel Physical64 OpenCL
2298 %u32 = OpTypeInt 32 0
2299 )" + std::string(kVoidFVoid);
2300
2301 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_1_2);
2302 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2303 ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_1_2));
2304 EXPECT_THAT(getDiagnosticString(),
2305 HasSubstr("Capability Pipes is not allowed by OpenCL 1.2 "
2306 "Embedded Profile"));
2307 }
2308
2309 TEST_F(ValidateCapability, OpenCL20FullCapability) {
2310 const std::string spirv = R"(
2311 OpCapability Kernel
2312 OpCapability Addresses
2313 OpCapability Linkage
2314 OpCapability Groups
2315 OpCapability Pipes
2316 OpMemoryModel Physical64 OpenCL
2317 %u32 = OpTypeInt 32 0
2318 )";
2319 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
2320 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_0));
2321 }
2322
2323 TEST_F(ValidateCapability, NonOpenCL20FullCapability) {
2324 const std::string spirv = R"(
2325 OpCapability Kernel
2326 OpCapability Addresses
2327 OpCapability Linkage
2328 OpCapability Matrix
2329 OpMemoryModel Physical64 OpenCL
2330 %u32 = OpTypeInt 32 0
2331 )";
2332 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
2333 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2334 ValidateInstructions(SPV_ENV_OPENCL_2_0));
2335 EXPECT_THAT(
2336 getDiagnosticString(),
2337 HasSubstr(
2338 "Capability Matrix is not allowed by OpenCL 2.0/2.1 Full Profile"));
2339 }
2340
2341 TEST_F(ValidateCapability, OpenCL20FullEnabledByCapability) {
2342 const std::string spirv = R"(
2343 OpCapability Kernel
2344 OpCapability Addresses
2345 OpCapability Linkage
2346 OpCapability ImageBasic
2347 OpCapability Sampled1D
2348 OpMemoryModel Physical64 OpenCL
2349 %u32 = OpTypeInt 32 0
2350 )" + std::string(kVoidFVoid);
2351
2352 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
2353 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_0));
2354 }
2355
2356 TEST_F(ValidateCapability, OpenCL20FullNotEnabledByCapability) {
2357 const std::string spirv = R"(
2358 OpCapability Kernel
2359 OpCapability Addresses
2360 OpCapability Linkage
2361 OpCapability Sampled1D
2362 OpMemoryModel Physical64 OpenCL
2363 %u32 = OpTypeInt 32 0
2364 )" + std::string(kVoidFVoid);
2365
2366 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_0);
2367 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2368 ValidateInstructions(SPV_ENV_OPENCL_2_0));
2369 EXPECT_THAT(getDiagnosticString(),
2370 HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.0/2.1 "
2371 "Full Profile"));
2372 }
2373
2374 TEST_F(ValidateCapability, NonOpenCL20EmbeddedCapability) {
2375 const std::string spirv = R"(
2376 OpCapability Kernel
2377 OpCapability Addresses
2378 OpCapability Linkage
2379 OpCapability Int64
2380 OpMemoryModel Physical64 OpenCL
2381 %u32 = OpTypeInt 32 0
2382 )";
2383 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
2384 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2385 ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
2386 EXPECT_THAT(getDiagnosticString(),
2387 HasSubstr("Capability Int64 is not allowed by OpenCL 2.0/2.1 "
2388 "Embedded Profile"));
2389 }
2390
2391 TEST_F(ValidateCapability, OpenCL20EmbeddedEnabledByCapability) {
2392 const std::string spirv = R"(
2393 OpCapability Kernel
2394 OpCapability Addresses
2395 OpCapability Linkage
2396 OpCapability ImageBasic
2397 OpCapability Sampled1D
2398 OpMemoryModel Physical64 OpenCL
2399 %u32 = OpTypeInt 32 0
2400 )" + std::string(kVoidFVoid);
2401
2402 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
2403 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
2404 }
2405
2406 TEST_F(ValidateCapability, OpenCL20EmbeddedNotEnabledByCapability) {
2407 const std::string spirv = R"(
2408 OpCapability Kernel
2409 OpCapability Addresses
2410 OpCapability Linkage
2411 OpCapability Sampled1D
2412 OpMemoryModel Physical64 OpenCL
2413 %u32 = OpTypeInt 32 0
2414 )" + std::string(kVoidFVoid);
2415
2416 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_0);
2417 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2418 ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_0));
2419 EXPECT_THAT(getDiagnosticString(),
2420 HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.0/2.1 "
2421 "Embedded Profile"));
2422 }
2423
2424 TEST_F(ValidateCapability, OpenCL22FullCapability) {
2425 const std::string spirv = R"(
2426 OpCapability Kernel
2427 OpCapability Addresses
2428 OpCapability Linkage
2429 OpCapability PipeStorage
2430 OpMemoryModel Physical64 OpenCL
2431 %u32 = OpTypeInt 32 0
2432 )";
2433 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
2434 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_2));
2435 }
2436
2437 TEST_F(ValidateCapability, NonOpenCL22FullCapability) {
2438 const std::string spirv = R"(
2439 OpCapability Kernel
2440 OpCapability Addresses
2441 OpCapability Linkage
2442 OpCapability Matrix
2443 OpMemoryModel Physical64 OpenCL
2444 %u32 = OpTypeInt 32 0
2445 )";
2446 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
2447 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2448 ValidateInstructions(SPV_ENV_OPENCL_2_2));
2449 EXPECT_THAT(
2450 getDiagnosticString(),
2451 HasSubstr("Capability Matrix is not allowed by OpenCL 2.2 Full Profile"));
2452 }
2453
2454 TEST_F(ValidateCapability, OpenCL22FullEnabledByCapability) {
2455 const std::string spirv = R"(
2456 OpCapability Kernel
2457 OpCapability Addresses
2458 OpCapability Linkage
2459 OpCapability ImageBasic
2460 OpCapability Sampled1D
2461 OpMemoryModel Physical64 OpenCL
2462 %u32 = OpTypeInt 32 0
2463 )" + std::string(kVoidFVoid);
2464
2465 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
2466 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_2));
2467 }
2468
2469 TEST_F(ValidateCapability, OpenCL22FullNotEnabledByCapability) {
2470 const std::string spirv = R"(
2471 OpCapability Kernel
2472 OpCapability Addresses
2473 OpCapability Linkage
2474 OpCapability Sampled1D
2475 OpMemoryModel Physical64 OpenCL
2476 %u32 = OpTypeInt 32 0
2477 )" + std::string(kVoidFVoid);
2478
2479 CompileSuccessfully(spirv, SPV_ENV_OPENCL_2_2);
2480 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2481 ValidateInstructions(SPV_ENV_OPENCL_2_2));
2482 EXPECT_THAT(
2483 getDiagnosticString(),
2484 HasSubstr(
2485 "Capability Sampled1D is not allowed by OpenCL 2.2 Full Profile"));
2486 }
2487
2488 TEST_F(ValidateCapability, NonOpenCL22EmbeddedCapability) {
2489 const std::string spirv = R"(
2490 OpCapability Kernel
2491 OpCapability Addresses
2492 OpCapability Linkage
2493 OpCapability Int64
2494 OpMemoryModel Physical64 OpenCL
2495 %u32 = OpTypeInt 32 0
2496 )";
2497 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
2498 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2499 ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
2500 EXPECT_THAT(
2501 getDiagnosticString(),
2502 HasSubstr(
2503 "Capability Int64 is not allowed by OpenCL 2.2 Embedded Profile"));
2504 }
2505
2506 TEST_F(ValidateCapability, OpenCL22EmbeddedEnabledByCapability) {
2507 const std::string spirv = R"(
2508 OpCapability Kernel
2509 OpCapability Addresses
2510 OpCapability Linkage
2511 OpCapability ImageBasic
2512 OpCapability Sampled1D
2513 OpMemoryModel Physical64 OpenCL
2514 %u32 = OpTypeInt 32 0
2515 )" + std::string(kVoidFVoid);
2516
2517 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
2518 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
2519 }
2520
2521 TEST_F(ValidateCapability, OpenCL22EmbeddedNotEnabledByCapability) {
2522 const std::string spirv = R"(
2523 OpCapability Kernel
2524 OpCapability Addresses
2525 OpCapability Linkage
2526 OpCapability Sampled1D
2527 OpMemoryModel Physical64 OpenCL
2528 %u32 = OpTypeInt 32 0
2529 )" + std::string(kVoidFVoid);
2530
2531 CompileSuccessfully(spirv, SPV_ENV_OPENCL_EMBEDDED_2_2);
2532 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2533 ValidateInstructions(SPV_ENV_OPENCL_EMBEDDED_2_2));
2534 EXPECT_THAT(getDiagnosticString(),
2535 HasSubstr("Capability Sampled1D is not allowed by OpenCL 2.2 "
2536 "Embedded Profile"));
2537 }
2538
2539 // Three tests to check enablement of an enum (a decoration) which is not
2540 // in core, and is directly enabled by a capability, but not directly enabled
2541 // by an extension. See https://github.com/KhronosGroup/SPIRV-Tools/issues/1596
2542
2543 TEST_F(ValidateCapability, DecorationFromExtensionMissingEnabledByCapability) {
2544 // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
2545 // turn is enabled by SPV_NV_viewport_array2.
2546 const std::string spirv = R"(
2547 OpCapability Shader
2548 OpMemoryModel Logical Simple
2549 OpDecorate %void ViewportRelativeNV
2550 )" + std::string(kVoidFVoid);
2551
2552 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
2553 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2554 ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
2555 EXPECT_THAT(getDiagnosticString(),
2556 HasSubstr("Operand 2 of Decorate requires one of these "
2557 "capabilities: ShaderViewportMaskNV"));
2558 }
2559
2560 TEST_F(ValidateCapability, CapabilityEnabledByMissingExtension) {
2561 // Capability ShaderViewportMaskNV is enabled by SPV_NV_viewport_array2.
2562 const std::string spirv = R"(
2563 OpCapability Shader
2564 OpCapability ShaderViewportMaskNV
2565 OpMemoryModel Logical Simple
2566 )" + std::string(kVoidFVoid);
2567
2568 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
2569 EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
2570 ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
2571 EXPECT_THAT(getDiagnosticString(),
2572 HasSubstr("operand ShaderViewportMaskNV(5255) requires one of "
2573 "these extensions: SPV_NV_viewport_array2"));
2574 }
2575
2576 TEST_F(ValidateCapability,
2577 DecorationEnabledByCapabilityEnabledByPresentExtension) {
2578 // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
2579 // turn is enabled by SPV_NV_viewport_array2.
2580 const std::string spirv = R"(
2581 OpCapability Shader
2582 OpCapability Linkage
2583 OpCapability ShaderViewportMaskNV
2584 OpExtension "SPV_NV_viewport_array2"
2585 OpMemoryModel Logical Simple
2586 OpDecorate %void ViewportRelativeNV
2587 %void = OpTypeVoid
2588 )";
2589
2590 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
2591 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
2592 << getDiagnosticString();
2593 }
2594
2595 // Three tests to check enablement of an instruction which is not in core, and
2596 // is directly enabled by a capability, but not directly enabled by an
2597 // extension. See https://github.com/KhronosGroup/SPIRV-Tools/issues/1624
2598 // Instruction OpSubgroupShuffleINTEL is enabled by SubgroupShuffleINTEL, which
2599 // in turn is enabled by SPV_INTEL_subgroups.
2600
2601 TEST_F(ValidateCapability, InstructionFromExtensionMissingEnabledByCapability) {
2602 // Decoration ViewportRelativeNV is enabled by ShaderViewportMaskNV, which in
2603 // turn is enabled by SPV_NV_viewport_array2.
2604 const std::string spirv = R"(
2605 OpCapability Kernel
2606 OpCapability Addresses
2607 ; OpCapability SubgroupShuffleINTEL
2608 OpExtension "SPV_INTEL_subgroups"
2609 OpMemoryModel Physical32 OpenCL
2610 OpEntryPoint Kernel %main "main"
2611 %void = OpTypeVoid
2612 %uint = OpTypeInt 32 0
2613 %voidfn = OpTypeFunction %void
2614 %zero = OpConstant %uint 0
2615 %main = OpFunction %void None %voidfn
2616 %entry = OpLabel
2617 %foo = OpSubgroupShuffleINTEL %uint %zero %zero
2618 OpReturn
2619 OpFunctionEnd
2620 )";
2621
2622 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
2623 EXPECT_EQ(SPV_ERROR_INVALID_CAPABILITY,
2624 ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
2625 EXPECT_THAT(getDiagnosticString(),
2626 HasSubstr("Opcode SubgroupShuffleINTEL requires one of these "
2627 "capabilities: SubgroupShuffleINTEL"));
2628 }
2629
2630 TEST_F(ValidateCapability,
2631 InstructionEnablingCapabilityEnabledByMissingExtension) {
2632 const std::string spirv = R"(
2633 OpCapability Kernel
2634 OpCapability Addresses
2635 OpCapability SubgroupShuffleINTEL
2636 ; OpExtension "SPV_INTEL_subgroups"
2637 OpMemoryModel Physical32 OpenCL
2638 OpEntryPoint Kernel %main "main"
2639 %void = OpTypeVoid
2640 %uint = OpTypeInt 32 0
2641 %voidfn = OpTypeFunction %void
2642 %zero = OpConstant %uint 0
2643 %main = OpFunction %void None %voidfn
2644 %entry = OpLabel
2645 %foo = OpSubgroupShuffleINTEL %uint %zero %zero
2646 OpReturn
2647 OpFunctionEnd
2648 )";
2649
2650 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
2651 EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
2652 ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
2653 EXPECT_THAT(getDiagnosticString(),
2654 HasSubstr("operand SubgroupShuffleINTEL(5568) requires one of "
2655 "these extensions: SPV_INTEL_subgroups"));
2656 }
2657
2658 TEST_F(ValidateCapability,
2659 InstructionEnabledByCapabilityEnabledByPresentExtension) {
2660 const std::string spirv = R"(
2661 OpCapability Kernel
2662 OpCapability Addresses
2663 OpCapability SubgroupShuffleINTEL
2664 OpExtension "SPV_INTEL_subgroups"
2665 OpMemoryModel Physical32 OpenCL
2666 OpEntryPoint Kernel %main "main"
2667 %void = OpTypeVoid
2668 %uint = OpTypeInt 32 0
2669 %voidfn = OpTypeFunction %void
2670 %zero = OpConstant %uint 0
2671 %main = OpFunction %void None %voidfn
2672 %entry = OpLabel
2673 %foo = OpSubgroupShuffleINTEL %uint %zero %zero
2674 OpReturn
2675 OpFunctionEnd
2676 )";
2677
2678 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
2679 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
2680 << getDiagnosticString();
2681 }
2682
2683 TEST_F(ValidateCapability, VulkanMemoryModelWithVulkanKHR) {
2684 const std::string spirv = R"(
2685 OpCapability Shader
2686 OpCapability VulkanMemoryModelKHR
2687 OpCapability Linkage
2688 OpExtension "SPV_KHR_vulkan_memory_model"
2689 OpMemoryModel Logical VulkanKHR
2690 )";
2691
2692 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2693 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3))
2694 << getDiagnosticString();
2695 }
2696
2697 TEST_F(ValidateCapability, VulkanMemoryModelWithGLSL450) {
2698 const std::string spirv = R"(
2699 OpCapability Shader
2700 OpCapability VulkanMemoryModelKHR
2701 OpCapability Linkage
2702 OpExtension "SPV_KHR_vulkan_memory_model"
2703 OpMemoryModel Logical GLSL450
2704 )";
2705
2706 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_3);
2707 EXPECT_EQ(SPV_ERROR_INVALID_DATA,
2708 ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
2709 EXPECT_THAT(getDiagnosticString(),
2710 HasSubstr("VulkanMemoryModelKHR capability must only be "
2711 "specified if the VulkanKHR memory model is used"));
2712 }
2713
2714 // In the grammar, SubgroupEqMask and SubgroupMaskKHR have different enabling
2715 // lists of extensions.
2716 TEST_F(ValidateCapability, SubgroupEqMaskEnabledByExtension) {
2717 const std::string spirv = R"(
2718 OpCapability Shader
2719 OpCapability SubgroupBallotKHR
2720 OpExtension "SPV_KHR_shader_ballot"
2721 OpMemoryModel Logical Simple
2722 OpEntryPoint GLCompute %main "main"
2723 OpDecorate %var BuiltIn SubgroupEqMask
2724 %void = OpTypeVoid
2725 %uint = OpTypeInt 32 0
2726 %ptr_uint = OpTypePointer Private %uint
2727 %var = OpVariable %ptr_uint Private
2728 %fn = OpTypeFunction %void
2729 %main = OpFunction %void None %fn
2730 %entry = OpLabel
2731 %val = OpLoad %uint %var
2732 OpReturn
2733 OpFunctionEnd
2734 )";
2735
2736 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_0);
2737 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0))
2738 << getDiagnosticString();
2739 }
2740
2741 // Test that extensions incorporated into SPIR-V 1.5 no longer require
2742 // the associated OpExtension instruction. Test one capability per extension.
2743
2744 struct CapabilityExtensionVersionCase {
2745 std::string capability;
2746 std::string capability_new_name;
2747 std::string extension;
2748 spv_target_env last_version_requiring_extension;
2749 spv_target_env first_version_in_core;
2750 };
2751
2752 using ValidateCapabilityExtensionVersionTest =
2753 spvtest::ValidateBase<CapabilityExtensionVersionCase>;
2754
2755 // Returns a minimal shader module with the given capability instruction.
2756 std::string MinimalShaderModuleWithCapability(std::string cap) {
2757 std::string mem_model =
2758 (cap.find("VulkanMemory") == 0) ? "VulkanKHR" : "GLSL450";
2759 std::string extra_cap = (cap.find("VulkanMemoryModelDeviceScope") == 0)
2760 ? "\nOpCapability VulkanMemoryModelKHR\n"
2761 : "";
2762 return std::string("OpCapability ") + cap + extra_cap + R"(
2763 OpCapability Shader
2764 OpMemoryModel Logical )" + mem_model + R"(
2765 OpEntryPoint Vertex %main "main"
2766 %void = OpTypeVoid
2767 %void_fn = OpTypeFunction %void
2768 %main = OpFunction %void None %void_fn
2769 %entry = OpLabel
2770 OpReturn
2771 OpFunctionEnd
2772 )";
2773 }
2774
2775 TEST_P(ValidateCapabilityExtensionVersionTest, FailsInOlderSpirvVersion) {
2776 const auto spirv = MinimalShaderModuleWithCapability(GetParam().capability);
2777 CompileSuccessfully(spirv, GetParam().last_version_requiring_extension);
2778 EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
2779 ValidateInstructions(GetParam().last_version_requiring_extension));
2780 EXPECT_THAT(getDiagnosticString(),
2781 HasSubstr(std::string("1st operand of Capability: operand ") +
2782 GetParam().capability_new_name))
2783 << spirv << "\n";
2784 EXPECT_THAT(getDiagnosticString(),
2785 HasSubstr(std::string("requires one of these extensions: ") +
2786 GetParam().extension));
2787 }
2788
2789 TEST_P(ValidateCapabilityExtensionVersionTest,
2790 SucceedsInNewerSpirvVersionWithOldName) {
2791 const auto spirv = MinimalShaderModuleWithCapability(GetParam().capability);
2792 CompileSuccessfully(spirv, GetParam().first_version_in_core);
2793 EXPECT_EQ(SPV_SUCCESS,
2794 ValidateInstructions(GetParam().first_version_in_core));
2795 EXPECT_THAT(getDiagnosticString(), Eq("")) << spirv << "\n";
2796 }
2797
2798 TEST_P(ValidateCapabilityExtensionVersionTest,
2799 SucceedsInNewerSpirvVersionWithNewName) {
2800 const auto spirv =
2801 MinimalShaderModuleWithCapability(GetParam().capability_new_name);
2802 CompileSuccessfully(spirv, GetParam().first_version_in_core);
2803 EXPECT_EQ(SPV_SUCCESS,
2804 ValidateInstructions(GetParam().first_version_in_core));
2805 EXPECT_THAT(getDiagnosticString(), Eq("")) << spirv << "\n";
2806 }
2807
2808 std::vector<CapabilityExtensionVersionCase> CapVersionCases1_5() {
2809 #define IN15NOSUFFIX(C, E) \
2810 { C, C, E, SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_5 }
2811 #define IN15(C, C_WITHOUT_SUFFIX, E) \
2812 { C, C_WITHOUT_SUFFIX, E, SPV_ENV_UNIVERSAL_1_4, SPV_ENV_UNIVERSAL_1_5 }
2813 return std::vector<CapabilityExtensionVersionCase>{
2814 // SPV_KHR_8bit_storage
2815 IN15NOSUFFIX("StorageBuffer8BitAccess", "SPV_KHR_8bit_storage"),
2816 IN15NOSUFFIX("UniformAndStorageBuffer8BitAccess", "SPV_KHR_8bit_storage"),
2817 IN15NOSUFFIX("StoragePushConstant8", "SPV_KHR_8bit_storage"),
2818 // SPV_EXT_descriptor_indexing
2819 IN15("ShaderNonUniformEXT", "ShaderNonUniform",
2820 "SPV_EXT_descriptor_indexing"),
2821 IN15("RuntimeDescriptorArrayEXT", "RuntimeDescriptorArray",
2822 "SPV_EXT_descriptor_indexing"),
2823 IN15("InputAttachmentArrayDynamicIndexingEXT",
2824 "InputAttachmentArrayDynamicIndexing",
2825 "SPV_EXT_descriptor_indexing"),
2826 IN15("UniformTexelBufferArrayDynamicIndexingEXT",
2827 "UniformTexelBufferArrayDynamicIndexing",
2828 "SPV_EXT_descriptor_indexing"),
2829 IN15("StorageTexelBufferArrayDynamicIndexingEXT",
2830 "StorageTexelBufferArrayDynamicIndexing",
2831 "SPV_EXT_descriptor_indexing"),
2832 IN15("UniformBufferArrayNonUniformIndexingEXT",
2833 "UniformBufferArrayNonUniformIndexing",
2834 "SPV_EXT_descriptor_indexing"),
2835 IN15("SampledImageArrayNonUniformIndexingEXT",
2836 "SampledImageArrayNonUniformIndexing",
2837 "SPV_EXT_descriptor_indexing"),
2838 IN15("StorageBufferArrayNonUniformIndexingEXT",
2839 "StorageBufferArrayNonUniformIndexing",
2840 "SPV_EXT_descriptor_indexing"),
2841 IN15("StorageImageArrayNonUniformIndexingEXT",
2842 "StorageImageArrayNonUniformIndexing",
2843 "SPV_EXT_descriptor_indexing"),
2844 IN15("InputAttachmentArrayNonUniformIndexingEXT",
2845 "InputAttachmentArrayNonUniformIndexing",
2846 "SPV_EXT_descriptor_indexing"),
2847 IN15("UniformTexelBufferArrayNonUniformIndexingEXT",
2848 "UniformTexelBufferArrayNonUniformIndexing",
2849 "SPV_EXT_descriptor_indexing"),
2850 IN15("StorageTexelBufferArrayNonUniformIndexingEXT",
2851 "StorageTexelBufferArrayNonUniformIndexing",
2852 "SPV_EXT_descriptor_indexing"),
2853 // SPV_EXT_physical_storage_buffer
2854 IN15("PhysicalStorageBufferAddressesEXT",
2855 "PhysicalStorageBufferAddresses", "SPV_EXT_physical_storage_buffer"),
2856 // SPV_KHR_vulkan_memory_model
2857 IN15("VulkanMemoryModelKHR", "VulkanMemoryModel",
2858 "SPV_KHR_vulkan_memory_model"),
2859 IN15("VulkanMemoryModelDeviceScopeKHR", "VulkanMemoryModelDeviceScope",
2860 "SPV_KHR_vulkan_memory_model"),
2861 };
2862 #undef IN15
2863 }
2864
2865 INSTANTIATE_TEST_SUITE_P(NewInSpirv1_5, ValidateCapabilityExtensionVersionTest,
2866 ValuesIn(CapVersionCases1_5()));
2867
2868 TEST_P(ValidateCapability,
2869 CapShaderViewportIndexLayerFailsInOlderSpirvVersion) {
2870 const auto spirv =
2871 MinimalShaderModuleWithCapability("ShaderViewportIndexLayerEXT");
2872 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_4);
2873 EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
2874 ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
2875 EXPECT_THAT(
2876 getDiagnosticString(),
2877 HasSubstr(
2878 "1st operand of Capability: operand ShaderViewportIndexLayerEXT"));
2879 EXPECT_THAT(getDiagnosticString(),
2880 HasSubstr("requires one of these extensions: "
2881 "SPV_EXT_shader_viewport_index_layer"));
2882 }
2883
2884 TEST_P(ValidateCapability, CapShaderViewportIndexLayerFailsInNewSpirvVersion) {
2885 const auto spirv =
2886 MinimalShaderModuleWithCapability("ShaderViewportIndexLayerEXT");
2887 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
2888 EXPECT_EQ(SPV_ERROR_MISSING_EXTENSION,
2889 ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
2890 EXPECT_THAT(
2891 getDiagnosticString(),
2892 HasSubstr(
2893 "1st operand of Capability: operand ShaderViewportIndexLayerEXT"));
2894 EXPECT_THAT(getDiagnosticString(),
2895 HasSubstr("requires one of these extensions: "
2896 "SPV_EXT_shader_viewport_index_layer"));
2897 }
2898
2899 TEST_F(ValidateCapability, CapShaderViewportIndexSucceedsInNewSpirvVersion) {
2900 const auto spirv = MinimalShaderModuleWithCapability("ShaderViewportIndex");
2901 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
2902 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
2903 EXPECT_THAT(getDiagnosticString(), Eq(""));
2904 }
2905
2906 TEST_F(ValidateCapability, CapShaderLayerSucceedsInNewSpirvVersion) {
2907 const auto spirv = MinimalShaderModuleWithCapability("ShaderLayer");
2908 CompileSuccessfully(spirv, SPV_ENV_UNIVERSAL_1_5);
2909 EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_5));
2910 EXPECT_THAT(getDiagnosticString(), Eq(""));
2911 }
2912
2913 } // namespace
2914 } // namespace val
2915 } // namespace spvtools