Debian Codegraph @

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