• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "source/val/validation_state.h"
16 
17 #include <cassert>
18 #include <stack>
19 #include <utility>
20 
21 #include "source/opcode.h"
22 #include "source/spirv_constant.h"
23 #include "source/spirv_target_env.h"
24 #include "source/util/make_unique.h"
25 #include "source/val/basic_block.h"
26 #include "source/val/construct.h"
27 #include "source/val/function.h"
28 #include "spirv-tools/libspirv.h"
29 
30 namespace spvtools {
31 namespace val {
32 namespace {
33 
InstructionLayoutSection(ModuleLayoutSection current_section,spv::Op op)34 ModuleLayoutSection InstructionLayoutSection(
35     ModuleLayoutSection current_section, spv::Op op) {
36   // See Section 2.4
37   if (spvOpcodeGeneratesType(op) || spvOpcodeIsConstant(op))
38     return kLayoutTypes;
39 
40   switch (op) {
41     case spv::Op::OpCapability:
42       return kLayoutCapabilities;
43     case spv::Op::OpExtension:
44       return kLayoutExtensions;
45     case spv::Op::OpExtInstImport:
46       return kLayoutExtInstImport;
47     case spv::Op::OpMemoryModel:
48       return kLayoutMemoryModel;
49     case spv::Op::OpEntryPoint:
50       return kLayoutEntryPoint;
51     case spv::Op::OpExecutionMode:
52     case spv::Op::OpExecutionModeId:
53       return kLayoutExecutionMode;
54     case spv::Op::OpSourceContinued:
55     case spv::Op::OpSource:
56     case spv::Op::OpSourceExtension:
57     case spv::Op::OpString:
58       return kLayoutDebug1;
59     case spv::Op::OpName:
60     case spv::Op::OpMemberName:
61       return kLayoutDebug2;
62     case spv::Op::OpModuleProcessed:
63       return kLayoutDebug3;
64     case spv::Op::OpDecorate:
65     case spv::Op::OpMemberDecorate:
66     case spv::Op::OpGroupDecorate:
67     case spv::Op::OpGroupMemberDecorate:
68     case spv::Op::OpDecorationGroup:
69     case spv::Op::OpDecorateId:
70     case spv::Op::OpDecorateStringGOOGLE:
71     case spv::Op::OpMemberDecorateStringGOOGLE:
72       return kLayoutAnnotations;
73     case spv::Op::OpTypeForwardPointer:
74       return kLayoutTypes;
75     case spv::Op::OpVariable:
76       if (current_section == kLayoutTypes) return kLayoutTypes;
77       return kLayoutFunctionDefinitions;
78     case spv::Op::OpExtInst:
79     case spv::Op::OpExtInstWithForwardRefsKHR:
80       // spv::Op::OpExtInst is only allowed in types section for certain
81       // extended instruction sets. This will be checked separately.
82       if (current_section == kLayoutTypes) return kLayoutTypes;
83       return kLayoutFunctionDefinitions;
84     case spv::Op::OpLine:
85     case spv::Op::OpNoLine:
86     case spv::Op::OpUndef:
87       if (current_section == kLayoutTypes) return kLayoutTypes;
88       return kLayoutFunctionDefinitions;
89     case spv::Op::OpFunction:
90     case spv::Op::OpFunctionParameter:
91     case spv::Op::OpFunctionEnd:
92       if (current_section == kLayoutFunctionDeclarations)
93         return kLayoutFunctionDeclarations;
94       return kLayoutFunctionDefinitions;
95     case spv::Op::OpSamplerImageAddressingModeNV:
96       return kLayoutSamplerImageAddressMode;
97     default:
98       break;
99   }
100   return kLayoutFunctionDefinitions;
101 }
102 
IsInstructionInLayoutSection(ModuleLayoutSection layout,spv::Op op)103 bool IsInstructionInLayoutSection(ModuleLayoutSection layout, spv::Op op) {
104   return layout == InstructionLayoutSection(layout, op);
105 }
106 
107 // Counts the number of instructions and functions in the file.
CountInstructions(void * user_data,const spv_parsed_instruction_t * inst)108 spv_result_t CountInstructions(void* user_data,
109                                const spv_parsed_instruction_t* inst) {
110   ValidationState_t& _ = *(reinterpret_cast<ValidationState_t*>(user_data));
111   if (spv::Op(inst->opcode) == spv::Op::OpFunction) {
112     _.increment_total_functions();
113   }
114   _.increment_total_instructions();
115 
116   return SPV_SUCCESS;
117 }
118 
setHeader(void * user_data,spv_endianness_t,uint32_t,uint32_t version,uint32_t generator,uint32_t id_bound,uint32_t)119 spv_result_t setHeader(void* user_data, spv_endianness_t, uint32_t,
120                        uint32_t version, uint32_t generator, uint32_t id_bound,
121                        uint32_t) {
122   ValidationState_t& vstate =
123       *(reinterpret_cast<ValidationState_t*>(user_data));
124   vstate.setIdBound(id_bound);
125   vstate.setGenerator(generator);
126   vstate.setVersion(version);
127 
128   return SPV_SUCCESS;
129 }
130 
131 // Add features based on SPIR-V core version number.
UpdateFeaturesBasedOnSpirvVersion(ValidationState_t::Feature * features,uint32_t version)132 void UpdateFeaturesBasedOnSpirvVersion(ValidationState_t::Feature* features,
133                                        uint32_t version) {
134   assert(features);
135   if (version >= SPV_SPIRV_VERSION_WORD(1, 4)) {
136     features->select_between_composites = true;
137     features->copy_memory_permits_two_memory_accesses = true;
138     features->uconvert_spec_constant_op = true;
139     features->nonwritable_var_in_function_or_private = true;
140   }
141 }
142 
143 }  // namespace
144 
ValidationState_t(const spv_const_context ctx,const spv_const_validator_options opt,const uint32_t * words,const size_t num_words,const uint32_t max_warnings)145 ValidationState_t::ValidationState_t(const spv_const_context ctx,
146                                      const spv_const_validator_options opt,
147                                      const uint32_t* words,
148                                      const size_t num_words,
149                                      const uint32_t max_warnings)
150     : context_(ctx),
151       options_(opt),
152       words_(words),
153       num_words_(num_words),
154       unresolved_forward_ids_{},
155       operand_names_{},
156       current_layout_section_(kLayoutCapabilities),
157       module_functions_(),
158       module_capabilities_(),
159       module_extensions_(),
160       ordered_instructions_(),
161       all_definitions_(),
162       global_vars_(),
163       local_vars_(),
164       struct_nesting_depth_(),
165       struct_has_nested_blockorbufferblock_struct_(),
166       grammar_(ctx),
167       addressing_model_(spv::AddressingModel::Max),
168       memory_model_(spv::MemoryModel::Max),
169       pointer_size_and_alignment_(0),
170       sampler_image_addressing_mode_(0),
171       in_function_(false),
172       num_of_warnings_(0),
173       max_num_of_warnings_(max_warnings) {
174   assert(opt && "Validator options may not be Null.");
175 
176   const auto env = context_->target_env;
177 
178   if (spvIsVulkanEnv(env)) {
179     // Vulkan 1.1 includes VK_KHR_relaxed_block_layout in core.
180     if (env != SPV_ENV_VULKAN_1_0) {
181       features_.env_relaxed_block_layout = true;
182     }
183   }
184 
185   // LocalSizeId is only disallowed prior to Vulkan 1.3 without maintenance4.
186   switch (env) {
187     case SPV_ENV_VULKAN_1_0:
188     case SPV_ENV_VULKAN_1_1:
189     case SPV_ENV_VULKAN_1_1_SPIRV_1_4:
190     case SPV_ENV_VULKAN_1_2:
191       features_.env_allow_localsizeid = false;
192       break;
193     default:
194       features_.env_allow_localsizeid = true;
195       break;
196   }
197 
198   // Only attempt to count if we have words, otherwise let the other validation
199   // fail and generate an error.
200   if (num_words > 0) {
201     // Count the number of instructions in the binary.
202     // This parse should not produce any error messages. Hijack the context and
203     // replace the message consumer so that we do not pollute any state in input
204     // consumer.
205     spv_context_t hijacked_context = *ctx;
206     hijacked_context.consumer = [](spv_message_level_t, const char*,
__anonf46b2e5a0202(spv_message_level_t, const char*, const spv_position_t&, const char*) 207                                    const spv_position_t&, const char*) {};
208     spvBinaryParse(&hijacked_context, this, words, num_words, setHeader,
209                    CountInstructions,
210                    /* diagnostic = */ nullptr);
211     preallocateStorage();
212   }
213   UpdateFeaturesBasedOnSpirvVersion(&features_, version_);
214 
215   name_mapper_ = spvtools::GetTrivialNameMapper();
216   if (options_->use_friendly_names) {
217     friendly_mapper_ = spvtools::MakeUnique<spvtools::FriendlyNameMapper>(
218         context_, words_, num_words_);
219     name_mapper_ = friendly_mapper_->GetNameMapper();
220   }
221 }
222 
preallocateStorage()223 void ValidationState_t::preallocateStorage() {
224   ordered_instructions_.reserve(total_instructions_);
225   module_functions_.reserve(total_functions_);
226 }
227 
ForwardDeclareId(uint32_t id)228 spv_result_t ValidationState_t::ForwardDeclareId(uint32_t id) {
229   unresolved_forward_ids_.insert(id);
230   return SPV_SUCCESS;
231 }
232 
RemoveIfForwardDeclared(uint32_t id)233 spv_result_t ValidationState_t::RemoveIfForwardDeclared(uint32_t id) {
234   unresolved_forward_ids_.erase(id);
235   return SPV_SUCCESS;
236 }
237 
RegisterForwardPointer(uint32_t id)238 spv_result_t ValidationState_t::RegisterForwardPointer(uint32_t id) {
239   forward_pointer_ids_.insert(id);
240   return SPV_SUCCESS;
241 }
242 
IsForwardPointer(uint32_t id) const243 bool ValidationState_t::IsForwardPointer(uint32_t id) const {
244   return (forward_pointer_ids_.find(id) != forward_pointer_ids_.end());
245 }
246 
AssignNameToId(uint32_t id,std::string name)247 void ValidationState_t::AssignNameToId(uint32_t id, std::string name) {
248   operand_names_[id] = name;
249 }
250 
getIdName(uint32_t id) const251 std::string ValidationState_t::getIdName(uint32_t id) const {
252   const std::string id_name = name_mapper_(id);
253 
254   std::stringstream out;
255   out << "'" << id << "[%" << id_name << "]'";
256   return out.str();
257 }
258 
unresolved_forward_id_count() const259 size_t ValidationState_t::unresolved_forward_id_count() const {
260   return unresolved_forward_ids_.size();
261 }
262 
UnresolvedForwardIds() const263 std::vector<uint32_t> ValidationState_t::UnresolvedForwardIds() const {
264   std::vector<uint32_t> out(std::begin(unresolved_forward_ids_),
265                             std::end(unresolved_forward_ids_));
266   return out;
267 }
268 
IsDefinedId(uint32_t id) const269 bool ValidationState_t::IsDefinedId(uint32_t id) const {
270   return all_definitions_.find(id) != std::end(all_definitions_);
271 }
272 
FindDef(uint32_t id) const273 const Instruction* ValidationState_t::FindDef(uint32_t id) const {
274   auto it = all_definitions_.find(id);
275   if (it == all_definitions_.end()) return nullptr;
276   return it->second;
277 }
278 
FindDef(uint32_t id)279 Instruction* ValidationState_t::FindDef(uint32_t id) {
280   auto it = all_definitions_.find(id);
281   if (it == all_definitions_.end()) return nullptr;
282   return it->second;
283 }
284 
current_layout_section() const285 ModuleLayoutSection ValidationState_t::current_layout_section() const {
286   return current_layout_section_;
287 }
288 
ProgressToNextLayoutSectionOrder()289 void ValidationState_t::ProgressToNextLayoutSectionOrder() {
290   // Guard against going past the last element(kLayoutFunctionDefinitions)
291   if (current_layout_section_ <= kLayoutFunctionDefinitions) {
292     current_layout_section_ =
293         static_cast<ModuleLayoutSection>(current_layout_section_ + 1);
294   }
295 }
296 
IsOpcodeInPreviousLayoutSection(spv::Op op)297 bool ValidationState_t::IsOpcodeInPreviousLayoutSection(spv::Op op) {
298   ModuleLayoutSection section =
299       InstructionLayoutSection(current_layout_section_, op);
300   return section < current_layout_section_;
301 }
302 
IsOpcodeInCurrentLayoutSection(spv::Op op)303 bool ValidationState_t::IsOpcodeInCurrentLayoutSection(spv::Op op) {
304   return IsInstructionInLayoutSection(current_layout_section_, op);
305 }
306 
diag(spv_result_t error_code,const Instruction * inst)307 DiagnosticStream ValidationState_t::diag(spv_result_t error_code,
308                                          const Instruction* inst) {
309   if (error_code == SPV_WARNING) {
310     if (num_of_warnings_ == max_num_of_warnings_) {
311       DiagnosticStream({0, 0, 0}, context_->consumer, "", error_code)
312           << "Other warnings have been suppressed.\n";
313     }
314     if (num_of_warnings_ >= max_num_of_warnings_) {
315       return DiagnosticStream({0, 0, 0}, nullptr, "", error_code);
316     }
317     ++num_of_warnings_;
318   }
319 
320   std::string disassembly;
321   if (inst) disassembly = Disassemble(*inst);
322 
323   return DiagnosticStream({0, 0, inst ? inst->LineNum() : 0},
324                           context_->consumer, disassembly, error_code);
325 }
326 
functions()327 std::vector<Function>& ValidationState_t::functions() {
328   return module_functions_;
329 }
330 
current_function()331 Function& ValidationState_t::current_function() {
332   assert(in_function_body());
333   return module_functions_.back();
334 }
335 
current_function() const336 const Function& ValidationState_t::current_function() const {
337   assert(in_function_body());
338   return module_functions_.back();
339 }
340 
function(uint32_t id) const341 const Function* ValidationState_t::function(uint32_t id) const {
342   const auto it = id_to_function_.find(id);
343   if (it == id_to_function_.end()) return nullptr;
344   return it->second;
345 }
346 
function(uint32_t id)347 Function* ValidationState_t::function(uint32_t id) {
348   auto it = id_to_function_.find(id);
349   if (it == id_to_function_.end()) return nullptr;
350   return it->second;
351 }
352 
in_function_body() const353 bool ValidationState_t::in_function_body() const { return in_function_; }
354 
in_block() const355 bool ValidationState_t::in_block() const {
356   return module_functions_.empty() == false &&
357          module_functions_.back().current_block() != nullptr;
358 }
359 
RegisterCapability(spv::Capability cap)360 void ValidationState_t::RegisterCapability(spv::Capability cap) {
361   // Avoid redundant work.  Otherwise the recursion could induce work
362   // quadrdatic in the capability dependency depth. (Ok, not much, but
363   // it's something.)
364   if (module_capabilities_.contains(cap)) return;
365 
366   module_capabilities_.insert(cap);
367   spv_operand_desc desc;
368   if (SPV_SUCCESS == grammar_.lookupOperand(SPV_OPERAND_TYPE_CAPABILITY,
369                                             uint32_t(cap), &desc)) {
370     for (auto capability :
371          CapabilitySet(desc->numCapabilities, desc->capabilities)) {
372       RegisterCapability(capability);
373     }
374   }
375 
376   switch (cap) {
377     case spv::Capability::Kernel:
378       features_.group_ops_reduce_and_scans = true;
379       break;
380     case spv::Capability::Int8:
381       features_.use_int8_type = true;
382       features_.declare_int8_type = true;
383       break;
384     case spv::Capability::StorageBuffer8BitAccess:
385     case spv::Capability::UniformAndStorageBuffer8BitAccess:
386     case spv::Capability::StoragePushConstant8:
387     case spv::Capability::WorkgroupMemoryExplicitLayout8BitAccessKHR:
388       features_.declare_int8_type = true;
389       break;
390     case spv::Capability::Int16:
391       features_.declare_int16_type = true;
392       break;
393     case spv::Capability::Float16:
394     case spv::Capability::Float16Buffer:
395       features_.declare_float16_type = true;
396       break;
397     case spv::Capability::StorageUniformBufferBlock16:
398     case spv::Capability::StorageUniform16:
399     case spv::Capability::StoragePushConstant16:
400     case spv::Capability::StorageInputOutput16:
401     case spv::Capability::WorkgroupMemoryExplicitLayout16BitAccessKHR:
402       features_.declare_int16_type = true;
403       features_.declare_float16_type = true;
404       features_.free_fp_rounding_mode = true;
405       break;
406     case spv::Capability::VariablePointers:
407     case spv::Capability::VariablePointersStorageBuffer:
408       features_.variable_pointers = true;
409       break;
410     default:
411       // TODO(dneto): For now don't validate SPV_NV_ray_tracing, which uses
412       // capability spv::Capability::RayTracingNV.
413       // spv::Capability::RayTracingProvisionalKHR would need the same
414       // treatment. One of the differences going from SPV_KHR_ray_tracing from
415       // provisional to final spec was the provisional spec uses Locations
416       // for variables in certain storage classes, just like the
417       // SPV_NV_ray_tracing extension.  So it mimics the NVIDIA extension.
418       // The final SPV_KHR_ray_tracing uses a different capability token
419       // number, so it doesn't fall into this case.
420       break;
421   }
422 }
423 
RegisterExtension(Extension ext)424 void ValidationState_t::RegisterExtension(Extension ext) {
425   if (module_extensions_.contains(ext)) return;
426 
427   module_extensions_.insert(ext);
428 
429   switch (ext) {
430     case kSPV_AMD_gpu_shader_half_float:
431     case kSPV_AMD_gpu_shader_half_float_fetch:
432       // SPV_AMD_gpu_shader_half_float enables float16 type.
433       // https://github.com/KhronosGroup/SPIRV-Tools/issues/1375
434       features_.declare_float16_type = true;
435       break;
436     case kSPV_AMD_gpu_shader_int16:
437       // This is not yet in the extension, but it's recommended for it.
438       // See https://github.com/KhronosGroup/glslang/issues/848
439       features_.uconvert_spec_constant_op = true;
440       break;
441     case kSPV_AMD_shader_ballot:
442       // The grammar doesn't encode the fact that SPV_AMD_shader_ballot
443       // enables the use of group operations Reduce, InclusiveScan,
444       // and ExclusiveScan.  Enable it manually.
445       // https://github.com/KhronosGroup/SPIRV-Tools/issues/991
446       features_.group_ops_reduce_and_scans = true;
447       break;
448     default:
449       break;
450   }
451 }
452 
HasAnyOfCapabilities(const CapabilitySet & capabilities) const453 bool ValidationState_t::HasAnyOfCapabilities(
454     const CapabilitySet& capabilities) const {
455   return module_capabilities_.HasAnyOf(capabilities);
456 }
457 
HasAnyOfExtensions(const ExtensionSet & extensions) const458 bool ValidationState_t::HasAnyOfExtensions(
459     const ExtensionSet& extensions) const {
460   return module_extensions_.HasAnyOf(extensions);
461 }
462 
set_addressing_model(spv::AddressingModel am)463 void ValidationState_t::set_addressing_model(spv::AddressingModel am) {
464   addressing_model_ = am;
465   switch (am) {
466     case spv::AddressingModel::Physical32:
467       pointer_size_and_alignment_ = 4;
468       break;
469     default:
470     // fall through
471     case spv::AddressingModel::Physical64:
472     case spv::AddressingModel::PhysicalStorageBuffer64:
473       pointer_size_and_alignment_ = 8;
474       break;
475   }
476 }
477 
addressing_model() const478 spv::AddressingModel ValidationState_t::addressing_model() const {
479   return addressing_model_;
480 }
481 
set_memory_model(spv::MemoryModel mm)482 void ValidationState_t::set_memory_model(spv::MemoryModel mm) {
483   memory_model_ = mm;
484 }
485 
memory_model() const486 spv::MemoryModel ValidationState_t::memory_model() const {
487   return memory_model_;
488 }
489 
set_samplerimage_variable_address_mode(uint32_t bit_width)490 void ValidationState_t::set_samplerimage_variable_address_mode(
491     uint32_t bit_width) {
492   sampler_image_addressing_mode_ = bit_width;
493 }
494 
samplerimage_variable_address_mode() const495 uint32_t ValidationState_t::samplerimage_variable_address_mode() const {
496   return sampler_image_addressing_mode_;
497 }
498 
RegisterFunction(uint32_t id,uint32_t ret_type_id,spv::FunctionControlMask function_control,uint32_t function_type_id)499 spv_result_t ValidationState_t::RegisterFunction(
500     uint32_t id, uint32_t ret_type_id,
501     spv::FunctionControlMask function_control, uint32_t function_type_id) {
502   assert(in_function_body() == false &&
503          "RegisterFunction can only be called when parsing the binary outside "
504          "of another function");
505   in_function_ = true;
506   module_functions_.emplace_back(id, ret_type_id, function_control,
507                                  function_type_id);
508   id_to_function_.emplace(id, &current_function());
509 
510   // TODO(umar): validate function type and type_id
511 
512   return SPV_SUCCESS;
513 }
514 
RegisterFunctionEnd()515 spv_result_t ValidationState_t::RegisterFunctionEnd() {
516   assert(in_function_body() == true &&
517          "RegisterFunctionEnd can only be called when parsing the binary "
518          "inside of another function");
519   assert(in_block() == false &&
520          "RegisterFunctionParameter can only be called when parsing the binary "
521          "outside of a block");
522   current_function().RegisterFunctionEnd();
523   in_function_ = false;
524   return SPV_SUCCESS;
525 }
526 
AddOrderedInstruction(const spv_parsed_instruction_t * inst)527 Instruction* ValidationState_t::AddOrderedInstruction(
528     const spv_parsed_instruction_t* inst) {
529   ordered_instructions_.emplace_back(inst);
530   ordered_instructions_.back().SetLineNum(ordered_instructions_.size());
531   return &ordered_instructions_.back();
532 }
533 
534 // Improves diagnostic messages by collecting names of IDs
RegisterDebugInstruction(const Instruction * inst)535 void ValidationState_t::RegisterDebugInstruction(const Instruction* inst) {
536   switch (inst->opcode()) {
537     case spv::Op::OpName: {
538       const auto target = inst->GetOperandAs<uint32_t>(0);
539       const std::string str = inst->GetOperandAs<std::string>(1);
540       AssignNameToId(target, str);
541       break;
542     }
543     case spv::Op::OpMemberName: {
544       const auto target = inst->GetOperandAs<uint32_t>(0);
545       const std::string str = inst->GetOperandAs<std::string>(2);
546       AssignNameToId(target, str);
547       break;
548     }
549     case spv::Op::OpSourceContinued:
550     case spv::Op::OpSource:
551     case spv::Op::OpSourceExtension:
552     case spv::Op::OpString:
553     case spv::Op::OpLine:
554     case spv::Op::OpNoLine:
555     default:
556       break;
557   }
558 }
559 
RegisterInstruction(Instruction * inst)560 void ValidationState_t::RegisterInstruction(Instruction* inst) {
561   if (inst->id()) all_definitions_.insert(std::make_pair(inst->id(), inst));
562 
563   // Some validation checks are easier by getting all the consumers
564   for (size_t i = 0; i < inst->operands().size(); ++i) {
565     const spv_parsed_operand_t& operand = inst->operand(i);
566     if ((SPV_OPERAND_TYPE_ID == operand.type) ||
567         (SPV_OPERAND_TYPE_TYPE_ID == operand.type)) {
568       const uint32_t operand_word = inst->word(operand.offset);
569       Instruction* operand_inst = FindDef(operand_word);
570       if (!operand_inst) {
571         continue;
572       }
573 
574       // If the instruction is using an OpTypeSampledImage as an operand, it
575       // should be recorded. The validator will ensure that all usages of an
576       // OpTypeSampledImage and its definition are in the same basic block.
577       if ((SPV_OPERAND_TYPE_ID == operand.type) &&
578           (spv::Op::OpSampledImage == operand_inst->opcode())) {
579         RegisterSampledImageConsumer(operand_word, inst);
580       }
581 
582       // In order to track storage classes (not Function) used per execution
583       // model we can't use RegisterExecutionModelLimitation on instructions
584       // like OpTypePointer which are going to be in the pre-function section.
585       // Instead just need to register storage class usage for consumers in a
586       // function block.
587       if (inst->function()) {
588         if (operand_inst->opcode() == spv::Op::OpTypePointer) {
589           RegisterStorageClassConsumer(
590               operand_inst->GetOperandAs<spv::StorageClass>(1), inst);
591         } else if (operand_inst->opcode() == spv::Op::OpVariable) {
592           RegisterStorageClassConsumer(
593               operand_inst->GetOperandAs<spv::StorageClass>(2), inst);
594         }
595       }
596     }
597   }
598 }
599 
getSampledImageConsumers(uint32_t sampled_image_id) const600 std::vector<Instruction*> ValidationState_t::getSampledImageConsumers(
601     uint32_t sampled_image_id) const {
602   std::vector<Instruction*> result;
603   auto iter = sampled_image_consumers_.find(sampled_image_id);
604   if (iter != sampled_image_consumers_.end()) {
605     result = iter->second;
606   }
607   return result;
608 }
609 
RegisterSampledImageConsumer(uint32_t sampled_image_id,Instruction * consumer)610 void ValidationState_t::RegisterSampledImageConsumer(uint32_t sampled_image_id,
611                                                      Instruction* consumer) {
612   sampled_image_consumers_[sampled_image_id].push_back(consumer);
613 }
614 
RegisterQCOMImageProcessingTextureConsumer(uint32_t texture_id,const Instruction * consumer0,const Instruction * consumer1)615 void ValidationState_t::RegisterQCOMImageProcessingTextureConsumer(
616     uint32_t texture_id, const Instruction* consumer0,
617     const Instruction* consumer1) {
618   if (HasDecoration(texture_id, spv::Decoration::WeightTextureQCOM) ||
619       HasDecoration(texture_id, spv::Decoration::BlockMatchTextureQCOM) ||
620       HasDecoration(texture_id, spv::Decoration::BlockMatchSamplerQCOM)) {
621     qcom_image_processing_consumers_.insert(consumer0->id());
622     if (consumer1) {
623       qcom_image_processing_consumers_.insert(consumer1->id());
624     }
625   }
626 }
627 
RegisterStorageClassConsumer(spv::StorageClass storage_class,Instruction * consumer)628 void ValidationState_t::RegisterStorageClassConsumer(
629     spv::StorageClass storage_class, Instruction* consumer) {
630   if (spvIsVulkanEnv(context()->target_env)) {
631     if (storage_class == spv::StorageClass::Output) {
632       std::string errorVUID = VkErrorID(4644);
633       function(consumer->function()->id())
634           ->RegisterExecutionModelLimitation([errorVUID](
635                                                  spv::ExecutionModel model,
636                                                  std::string* message) {
637             if (model == spv::ExecutionModel::GLCompute ||
638                 model == spv::ExecutionModel::RayGenerationKHR ||
639                 model == spv::ExecutionModel::IntersectionKHR ||
640                 model == spv::ExecutionModel::AnyHitKHR ||
641                 model == spv::ExecutionModel::ClosestHitKHR ||
642                 model == spv::ExecutionModel::MissKHR ||
643                 model == spv::ExecutionModel::CallableKHR) {
644               if (message) {
645                 *message =
646                     errorVUID +
647                     "in Vulkan environment, Output Storage Class must not be "
648                     "used in GLCompute, RayGenerationKHR, IntersectionKHR, "
649                     "AnyHitKHR, ClosestHitKHR, MissKHR, or CallableKHR "
650                     "execution models";
651               }
652               return false;
653             }
654             return true;
655           });
656     }
657 
658     if (storage_class == spv::StorageClass::Workgroup) {
659       std::string errorVUID = VkErrorID(4645);
660       function(consumer->function()->id())
661           ->RegisterExecutionModelLimitation([errorVUID](
662                                                  spv::ExecutionModel model,
663                                                  std::string* message) {
664             if (model != spv::ExecutionModel::GLCompute &&
665                 model != spv::ExecutionModel::TaskNV &&
666                 model != spv::ExecutionModel::MeshNV &&
667                 model != spv::ExecutionModel::TaskEXT &&
668                 model != spv::ExecutionModel::MeshEXT) {
669               if (message) {
670                 *message =
671                     errorVUID +
672                     "in Vulkan environment, Workgroup Storage Class is limited "
673                     "to MeshNV, TaskNV, and GLCompute execution model";
674               }
675               return false;
676             }
677             return true;
678           });
679     }
680   }
681 
682   if (storage_class == spv::StorageClass::CallableDataKHR) {
683     std::string errorVUID = VkErrorID(4704);
684     function(consumer->function()->id())
685         ->RegisterExecutionModelLimitation(
686             [errorVUID](spv::ExecutionModel model, std::string* message) {
687               if (model != spv::ExecutionModel::RayGenerationKHR &&
688                   model != spv::ExecutionModel::ClosestHitKHR &&
689                   model != spv::ExecutionModel::CallableKHR &&
690                   model != spv::ExecutionModel::MissKHR) {
691                 if (message) {
692                   *message =
693                       errorVUID +
694                       "CallableDataKHR Storage Class is limited to "
695                       "RayGenerationKHR, ClosestHitKHR, CallableKHR, and "
696                       "MissKHR execution model";
697                 }
698                 return false;
699               }
700               return true;
701             });
702   } else if (storage_class == spv::StorageClass::IncomingCallableDataKHR) {
703     std::string errorVUID = VkErrorID(4705);
704     function(consumer->function()->id())
705         ->RegisterExecutionModelLimitation(
706             [errorVUID](spv::ExecutionModel model, std::string* message) {
707               if (model != spv::ExecutionModel::CallableKHR) {
708                 if (message) {
709                   *message =
710                       errorVUID +
711                       "IncomingCallableDataKHR Storage Class is limited to "
712                       "CallableKHR execution model";
713                 }
714                 return false;
715               }
716               return true;
717             });
718   } else if (storage_class == spv::StorageClass::RayPayloadKHR) {
719     std::string errorVUID = VkErrorID(4698);
720     function(consumer->function()->id())
721         ->RegisterExecutionModelLimitation([errorVUID](
722                                                spv::ExecutionModel model,
723                                                std::string* message) {
724           if (model != spv::ExecutionModel::RayGenerationKHR &&
725               model != spv::ExecutionModel::ClosestHitKHR &&
726               model != spv::ExecutionModel::MissKHR) {
727             if (message) {
728               *message =
729                   errorVUID +
730                   "RayPayloadKHR Storage Class is limited to RayGenerationKHR, "
731                   "ClosestHitKHR, and MissKHR execution model";
732             }
733             return false;
734           }
735           return true;
736         });
737   } else if (storage_class == spv::StorageClass::HitAttributeKHR) {
738     std::string errorVUID = VkErrorID(4701);
739     function(consumer->function()->id())
740         ->RegisterExecutionModelLimitation(
741             [errorVUID](spv::ExecutionModel model, std::string* message) {
742               if (model != spv::ExecutionModel::IntersectionKHR &&
743                   model != spv::ExecutionModel::AnyHitKHR &&
744                   model != spv::ExecutionModel::ClosestHitKHR) {
745                 if (message) {
746                   *message = errorVUID +
747                              "HitAttributeKHR Storage Class is limited to "
748                              "IntersectionKHR, AnyHitKHR, sand ClosestHitKHR "
749                              "execution model";
750                 }
751                 return false;
752               }
753               return true;
754             });
755   } else if (storage_class == spv::StorageClass::IncomingRayPayloadKHR) {
756     std::string errorVUID = VkErrorID(4699);
757     function(consumer->function()->id())
758         ->RegisterExecutionModelLimitation(
759             [errorVUID](spv::ExecutionModel model, std::string* message) {
760               if (model != spv::ExecutionModel::AnyHitKHR &&
761                   model != spv::ExecutionModel::ClosestHitKHR &&
762                   model != spv::ExecutionModel::MissKHR) {
763                 if (message) {
764                   *message =
765                       errorVUID +
766                       "IncomingRayPayloadKHR Storage Class is limited to "
767                       "AnyHitKHR, ClosestHitKHR, and MissKHR execution model";
768                 }
769                 return false;
770               }
771               return true;
772             });
773   } else if (storage_class == spv::StorageClass::ShaderRecordBufferKHR) {
774     std::string errorVUID = VkErrorID(7119);
775     function(consumer->function()->id())
776         ->RegisterExecutionModelLimitation(
777             [errorVUID](spv::ExecutionModel model, std::string* message) {
778               if (model != spv::ExecutionModel::RayGenerationKHR &&
779                   model != spv::ExecutionModel::IntersectionKHR &&
780                   model != spv::ExecutionModel::AnyHitKHR &&
781                   model != spv::ExecutionModel::ClosestHitKHR &&
782                   model != spv::ExecutionModel::CallableKHR &&
783                   model != spv::ExecutionModel::MissKHR) {
784                 if (message) {
785                   *message =
786                       errorVUID +
787                       "ShaderRecordBufferKHR Storage Class is limited to "
788                       "RayGenerationKHR, IntersectionKHR, AnyHitKHR, "
789                       "ClosestHitKHR, CallableKHR, and MissKHR execution model";
790                 }
791                 return false;
792               }
793               return true;
794             });
795   } else if (storage_class == spv::StorageClass::TaskPayloadWorkgroupEXT) {
796     function(consumer->function()->id())
797         ->RegisterExecutionModelLimitation(
798             [](spv::ExecutionModel model, std::string* message) {
799               if (model != spv::ExecutionModel::TaskEXT &&
800                   model != spv::ExecutionModel::MeshEXT) {
801                 if (message) {
802                   *message =
803                       "TaskPayloadWorkgroupEXT Storage Class is limited to "
804                       "TaskEXT and MeshKHR execution model";
805                 }
806                 return false;
807               }
808               return true;
809             });
810   } else if (storage_class == spv::StorageClass::HitObjectAttributeNV) {
811     function(consumer->function()->id())
812         ->RegisterExecutionModelLimitation([](spv::ExecutionModel model,
813                                               std::string* message) {
814           if (model != spv::ExecutionModel::RayGenerationKHR &&
815               model != spv::ExecutionModel::ClosestHitKHR &&
816               model != spv::ExecutionModel::MissKHR) {
817             if (message) {
818               *message =
819                   "HitObjectAttributeNV Storage Class is limited to "
820                   "RayGenerationKHR, ClosestHitKHR or MissKHR execution model";
821             }
822             return false;
823           }
824           return true;
825         });
826   }
827 }
828 
getIdBound() const829 uint32_t ValidationState_t::getIdBound() const { return id_bound_; }
830 
setIdBound(const uint32_t bound)831 void ValidationState_t::setIdBound(const uint32_t bound) { id_bound_ = bound; }
832 
RegisterUniqueTypeDeclaration(const Instruction * inst)833 bool ValidationState_t::RegisterUniqueTypeDeclaration(const Instruction* inst) {
834   std::vector<uint32_t> key;
835   key.push_back(static_cast<uint32_t>(inst->opcode()));
836   for (size_t index = 0; index < inst->operands().size(); ++index) {
837     const spv_parsed_operand_t& operand = inst->operand(index);
838 
839     if (operand.type == SPV_OPERAND_TYPE_RESULT_ID) continue;
840 
841     const int words_begin = operand.offset;
842     const int words_end = words_begin + operand.num_words;
843     assert(words_end <= static_cast<int>(inst->words().size()));
844 
845     key.insert(key.end(), inst->words().begin() + words_begin,
846                inst->words().begin() + words_end);
847   }
848 
849   return unique_type_declarations_.insert(std::move(key)).second;
850 }
851 
GetTypeId(uint32_t id) const852 uint32_t ValidationState_t::GetTypeId(uint32_t id) const {
853   const Instruction* inst = FindDef(id);
854   return inst ? inst->type_id() : 0;
855 }
856 
GetIdOpcode(uint32_t id) const857 spv::Op ValidationState_t::GetIdOpcode(uint32_t id) const {
858   const Instruction* inst = FindDef(id);
859   return inst ? inst->opcode() : spv::Op::OpNop;
860 }
861 
GetComponentType(uint32_t id) const862 uint32_t ValidationState_t::GetComponentType(uint32_t id) const {
863   const Instruction* inst = FindDef(id);
864   assert(inst);
865 
866   switch (inst->opcode()) {
867     case spv::Op::OpTypeFloat:
868     case spv::Op::OpTypeInt:
869     case spv::Op::OpTypeBool:
870       return id;
871 
872     case spv::Op::OpTypeVector:
873       return inst->word(2);
874 
875     case spv::Op::OpTypeMatrix:
876       return GetComponentType(inst->word(2));
877 
878     case spv::Op::OpTypeCooperativeMatrixNV:
879     case spv::Op::OpTypeCooperativeMatrixKHR:
880       return inst->word(2);
881 
882     default:
883       break;
884   }
885 
886   if (inst->type_id()) return GetComponentType(inst->type_id());
887 
888   assert(0);
889   return 0;
890 }
891 
GetDimension(uint32_t id) const892 uint32_t ValidationState_t::GetDimension(uint32_t id) const {
893   const Instruction* inst = FindDef(id);
894   assert(inst);
895 
896   switch (inst->opcode()) {
897     case spv::Op::OpTypeFloat:
898     case spv::Op::OpTypeInt:
899     case spv::Op::OpTypeBool:
900       return 1;
901 
902     case spv::Op::OpTypeVector:
903     case spv::Op::OpTypeMatrix:
904       return inst->word(3);
905 
906     case spv::Op::OpTypeCooperativeMatrixNV:
907     case spv::Op::OpTypeCooperativeMatrixKHR:
908       // Actual dimension isn't known, return 0
909       return 0;
910 
911     default:
912       break;
913   }
914 
915   if (inst->type_id()) return GetDimension(inst->type_id());
916 
917   assert(0);
918   return 0;
919 }
920 
GetBitWidth(uint32_t id) const921 uint32_t ValidationState_t::GetBitWidth(uint32_t id) const {
922   const uint32_t component_type_id = GetComponentType(id);
923   const Instruction* inst = FindDef(component_type_id);
924   assert(inst);
925 
926   if (inst->opcode() == spv::Op::OpTypeFloat ||
927       inst->opcode() == spv::Op::OpTypeInt)
928     return inst->word(2);
929 
930   if (inst->opcode() == spv::Op::OpTypeBool) return 1;
931 
932   assert(0);
933   return 0;
934 }
935 
IsVoidType(uint32_t id) const936 bool ValidationState_t::IsVoidType(uint32_t id) const {
937   const Instruction* inst = FindDef(id);
938   return inst && inst->opcode() == spv::Op::OpTypeVoid;
939 }
940 
IsFloatScalarType(uint32_t id) const941 bool ValidationState_t::IsFloatScalarType(uint32_t id) const {
942   const Instruction* inst = FindDef(id);
943   return inst && inst->opcode() == spv::Op::OpTypeFloat;
944 }
945 
IsFloatVectorType(uint32_t id) const946 bool ValidationState_t::IsFloatVectorType(uint32_t id) const {
947   const Instruction* inst = FindDef(id);
948   if (!inst) {
949     return false;
950   }
951 
952   if (inst->opcode() == spv::Op::OpTypeVector) {
953     return IsFloatScalarType(GetComponentType(id));
954   }
955 
956   return false;
957 }
958 
IsFloat16Vector2Or4Type(uint32_t id) const959 bool ValidationState_t::IsFloat16Vector2Or4Type(uint32_t id) const {
960   const Instruction* inst = FindDef(id);
961   assert(inst);
962 
963   if (inst->opcode() == spv::Op::OpTypeVector) {
964     uint32_t vectorDim = GetDimension(id);
965     return IsFloatScalarType(GetComponentType(id)) &&
966            (vectorDim == 2 || vectorDim == 4) &&
967            (GetBitWidth(GetComponentType(id)) == 16);
968   }
969 
970   return false;
971 }
972 
IsFloatScalarOrVectorType(uint32_t id) const973 bool ValidationState_t::IsFloatScalarOrVectorType(uint32_t id) const {
974   const Instruction* inst = FindDef(id);
975   if (!inst) {
976     return false;
977   }
978 
979   if (inst->opcode() == spv::Op::OpTypeFloat) {
980     return true;
981   }
982 
983   if (inst->opcode() == spv::Op::OpTypeVector) {
984     return IsFloatScalarType(GetComponentType(id));
985   }
986 
987   return false;
988 }
989 
IsIntScalarType(uint32_t id) const990 bool ValidationState_t::IsIntScalarType(uint32_t id) const {
991   const Instruction* inst = FindDef(id);
992   return inst && inst->opcode() == spv::Op::OpTypeInt;
993 }
994 
IsIntVectorType(uint32_t id) const995 bool ValidationState_t::IsIntVectorType(uint32_t id) const {
996   const Instruction* inst = FindDef(id);
997   if (!inst) {
998     return false;
999   }
1000 
1001   if (inst->opcode() == spv::Op::OpTypeVector) {
1002     return IsIntScalarType(GetComponentType(id));
1003   }
1004 
1005   return false;
1006 }
1007 
IsIntScalarOrVectorType(uint32_t id) const1008 bool ValidationState_t::IsIntScalarOrVectorType(uint32_t id) const {
1009   const Instruction* inst = FindDef(id);
1010   if (!inst) {
1011     return false;
1012   }
1013 
1014   if (inst->opcode() == spv::Op::OpTypeInt) {
1015     return true;
1016   }
1017 
1018   if (inst->opcode() == spv::Op::OpTypeVector) {
1019     return IsIntScalarType(GetComponentType(id));
1020   }
1021 
1022   return false;
1023 }
1024 
IsUnsignedIntScalarType(uint32_t id) const1025 bool ValidationState_t::IsUnsignedIntScalarType(uint32_t id) const {
1026   const Instruction* inst = FindDef(id);
1027   return inst && inst->opcode() == spv::Op::OpTypeInt && inst->word(3) == 0;
1028 }
1029 
IsUnsignedIntVectorType(uint32_t id) const1030 bool ValidationState_t::IsUnsignedIntVectorType(uint32_t id) const {
1031   const Instruction* inst = FindDef(id);
1032   if (!inst) {
1033     return false;
1034   }
1035 
1036   if (inst->opcode() == spv::Op::OpTypeVector) {
1037     return IsUnsignedIntScalarType(GetComponentType(id));
1038   }
1039 
1040   return false;
1041 }
1042 
IsUnsignedIntScalarOrVectorType(uint32_t id) const1043 bool ValidationState_t::IsUnsignedIntScalarOrVectorType(uint32_t id) const {
1044   const Instruction* inst = FindDef(id);
1045   if (!inst) {
1046     return false;
1047   }
1048 
1049   if (inst->opcode() == spv::Op::OpTypeInt) {
1050     return inst->GetOperandAs<uint32_t>(2) == 0;
1051   }
1052 
1053   if (inst->opcode() == spv::Op::OpTypeVector) {
1054     return IsUnsignedIntScalarType(GetComponentType(id));
1055   }
1056 
1057   return false;
1058 }
1059 
IsSignedIntScalarType(uint32_t id) const1060 bool ValidationState_t::IsSignedIntScalarType(uint32_t id) const {
1061   const Instruction* inst = FindDef(id);
1062   return inst && inst->opcode() == spv::Op::OpTypeInt && inst->word(3) == 1;
1063 }
1064 
IsSignedIntVectorType(uint32_t id) const1065 bool ValidationState_t::IsSignedIntVectorType(uint32_t id) const {
1066   const Instruction* inst = FindDef(id);
1067   if (!inst) {
1068     return false;
1069   }
1070 
1071   if (inst->opcode() == spv::Op::OpTypeVector) {
1072     return IsSignedIntScalarType(GetComponentType(id));
1073   }
1074 
1075   return false;
1076 }
1077 
IsBoolScalarType(uint32_t id) const1078 bool ValidationState_t::IsBoolScalarType(uint32_t id) const {
1079   const Instruction* inst = FindDef(id);
1080   return inst && inst->opcode() == spv::Op::OpTypeBool;
1081 }
1082 
IsBoolVectorType(uint32_t id) const1083 bool ValidationState_t::IsBoolVectorType(uint32_t id) const {
1084   const Instruction* inst = FindDef(id);
1085   if (!inst) {
1086     return false;
1087   }
1088 
1089   if (inst->opcode() == spv::Op::OpTypeVector) {
1090     return IsBoolScalarType(GetComponentType(id));
1091   }
1092 
1093   return false;
1094 }
1095 
IsBoolScalarOrVectorType(uint32_t id) const1096 bool ValidationState_t::IsBoolScalarOrVectorType(uint32_t id) const {
1097   const Instruction* inst = FindDef(id);
1098   if (!inst) {
1099     return false;
1100   }
1101 
1102   if (inst->opcode() == spv::Op::OpTypeBool) {
1103     return true;
1104   }
1105 
1106   if (inst->opcode() == spv::Op::OpTypeVector) {
1107     return IsBoolScalarType(GetComponentType(id));
1108   }
1109 
1110   return false;
1111 }
1112 
IsFloatMatrixType(uint32_t id) const1113 bool ValidationState_t::IsFloatMatrixType(uint32_t id) const {
1114   const Instruction* inst = FindDef(id);
1115   if (!inst) {
1116     return false;
1117   }
1118 
1119   if (inst->opcode() == spv::Op::OpTypeMatrix) {
1120     return IsFloatScalarType(GetComponentType(id));
1121   }
1122 
1123   return false;
1124 }
1125 
GetMatrixTypeInfo(uint32_t id,uint32_t * num_rows,uint32_t * num_cols,uint32_t * column_type,uint32_t * component_type) const1126 bool ValidationState_t::GetMatrixTypeInfo(uint32_t id, uint32_t* num_rows,
1127                                           uint32_t* num_cols,
1128                                           uint32_t* column_type,
1129                                           uint32_t* component_type) const {
1130   if (!id) return false;
1131 
1132   const Instruction* mat_inst = FindDef(id);
1133   assert(mat_inst);
1134   if (mat_inst->opcode() != spv::Op::OpTypeMatrix) return false;
1135 
1136   const uint32_t vec_type = mat_inst->word(2);
1137   const Instruction* vec_inst = FindDef(vec_type);
1138   assert(vec_inst);
1139 
1140   if (vec_inst->opcode() != spv::Op::OpTypeVector) {
1141     assert(0);
1142     return false;
1143   }
1144 
1145   *num_cols = mat_inst->word(3);
1146   *num_rows = vec_inst->word(3);
1147   *column_type = mat_inst->word(2);
1148   *component_type = vec_inst->word(2);
1149 
1150   return true;
1151 }
1152 
GetStructMemberTypes(uint32_t struct_type_id,std::vector<uint32_t> * member_types) const1153 bool ValidationState_t::GetStructMemberTypes(
1154     uint32_t struct_type_id, std::vector<uint32_t>* member_types) const {
1155   member_types->clear();
1156   if (!struct_type_id) return false;
1157 
1158   const Instruction* inst = FindDef(struct_type_id);
1159   assert(inst);
1160   if (inst->opcode() != spv::Op::OpTypeStruct) return false;
1161 
1162   *member_types =
1163       std::vector<uint32_t>(inst->words().cbegin() + 2, inst->words().cend());
1164 
1165   if (member_types->empty()) return false;
1166 
1167   return true;
1168 }
1169 
IsPointerType(uint32_t id) const1170 bool ValidationState_t::IsPointerType(uint32_t id) const {
1171   const Instruction* inst = FindDef(id);
1172   return inst && inst->opcode() == spv::Op::OpTypePointer;
1173 }
1174 
GetPointerTypeInfo(uint32_t id,uint32_t * data_type,spv::StorageClass * storage_class) const1175 bool ValidationState_t::GetPointerTypeInfo(
1176     uint32_t id, uint32_t* data_type, spv::StorageClass* storage_class) const {
1177   *storage_class = spv::StorageClass::Max;
1178   if (!id) return false;
1179 
1180   const Instruction* inst = FindDef(id);
1181   assert(inst);
1182   if (inst->opcode() != spv::Op::OpTypePointer) return false;
1183 
1184   *storage_class = spv::StorageClass(inst->word(2));
1185   *data_type = inst->word(3);
1186   return true;
1187 }
1188 
IsAccelerationStructureType(uint32_t id) const1189 bool ValidationState_t::IsAccelerationStructureType(uint32_t id) const {
1190   const Instruction* inst = FindDef(id);
1191   return inst && inst->opcode() == spv::Op::OpTypeAccelerationStructureKHR;
1192 }
1193 
IsCooperativeMatrixType(uint32_t id) const1194 bool ValidationState_t::IsCooperativeMatrixType(uint32_t id) const {
1195   const Instruction* inst = FindDef(id);
1196   return inst && (inst->opcode() == spv::Op::OpTypeCooperativeMatrixNV ||
1197                   inst->opcode() == spv::Op::OpTypeCooperativeMatrixKHR);
1198 }
1199 
IsCooperativeMatrixNVType(uint32_t id) const1200 bool ValidationState_t::IsCooperativeMatrixNVType(uint32_t id) const {
1201   const Instruction* inst = FindDef(id);
1202   return inst && inst->opcode() == spv::Op::OpTypeCooperativeMatrixNV;
1203 }
1204 
IsCooperativeMatrixKHRType(uint32_t id) const1205 bool ValidationState_t::IsCooperativeMatrixKHRType(uint32_t id) const {
1206   const Instruction* inst = FindDef(id);
1207   return inst && inst->opcode() == spv::Op::OpTypeCooperativeMatrixKHR;
1208 }
1209 
IsCooperativeMatrixAType(uint32_t id) const1210 bool ValidationState_t::IsCooperativeMatrixAType(uint32_t id) const {
1211   if (!IsCooperativeMatrixKHRType(id)) return false;
1212   const Instruction* inst = FindDef(id);
1213   uint64_t matrixUse = 0;
1214   if (EvalConstantValUint64(inst->word(6), &matrixUse)) {
1215     return matrixUse ==
1216            static_cast<uint64_t>(spv::CooperativeMatrixUse::MatrixAKHR);
1217   }
1218   return false;
1219 }
1220 
IsCooperativeMatrixBType(uint32_t id) const1221 bool ValidationState_t::IsCooperativeMatrixBType(uint32_t id) const {
1222   if (!IsCooperativeMatrixKHRType(id)) return false;
1223   const Instruction* inst = FindDef(id);
1224   uint64_t matrixUse = 0;
1225   if (EvalConstantValUint64(inst->word(6), &matrixUse)) {
1226     return matrixUse ==
1227            static_cast<uint64_t>(spv::CooperativeMatrixUse::MatrixBKHR);
1228   }
1229   return false;
1230 }
IsCooperativeMatrixAccType(uint32_t id) const1231 bool ValidationState_t::IsCooperativeMatrixAccType(uint32_t id) const {
1232   if (!IsCooperativeMatrixKHRType(id)) return false;
1233   const Instruction* inst = FindDef(id);
1234   uint64_t matrixUse = 0;
1235   if (EvalConstantValUint64(inst->word(6), &matrixUse)) {
1236     return matrixUse == static_cast<uint64_t>(
1237                             spv::CooperativeMatrixUse::MatrixAccumulatorKHR);
1238   }
1239   return false;
1240 }
1241 
IsFloatCooperativeMatrixType(uint32_t id) const1242 bool ValidationState_t::IsFloatCooperativeMatrixType(uint32_t id) const {
1243   if (!IsCooperativeMatrixNVType(id) && !IsCooperativeMatrixKHRType(id))
1244     return false;
1245   return IsFloatScalarType(FindDef(id)->word(2));
1246 }
1247 
IsIntCooperativeMatrixType(uint32_t id) const1248 bool ValidationState_t::IsIntCooperativeMatrixType(uint32_t id) const {
1249   if (!IsCooperativeMatrixNVType(id) && !IsCooperativeMatrixKHRType(id))
1250     return false;
1251   return IsIntScalarType(FindDef(id)->word(2));
1252 }
1253 
IsUnsignedIntCooperativeMatrixType(uint32_t id) const1254 bool ValidationState_t::IsUnsignedIntCooperativeMatrixType(uint32_t id) const {
1255   if (!IsCooperativeMatrixNVType(id) && !IsCooperativeMatrixKHRType(id))
1256     return false;
1257   return IsUnsignedIntScalarType(FindDef(id)->word(2));
1258 }
1259 
1260 // Either a 32 bit 2-component uint vector or a 64 bit uint scalar
IsUnsigned64BitHandle(uint32_t id) const1261 bool ValidationState_t::IsUnsigned64BitHandle(uint32_t id) const {
1262   return ((IsUnsignedIntScalarType(id) && GetBitWidth(id) == 64) ||
1263           (IsUnsignedIntVectorType(id) && GetDimension(id) == 2 &&
1264            GetBitWidth(id) == 32));
1265 }
1266 
CooperativeMatrixShapesMatch(const Instruction * inst,uint32_t m1,uint32_t m2)1267 spv_result_t ValidationState_t::CooperativeMatrixShapesMatch(
1268     const Instruction* inst, uint32_t m1, uint32_t m2) {
1269   const auto m1_type = FindDef(m1);
1270   const auto m2_type = FindDef(m2);
1271 
1272   if (m1_type->opcode() != m2_type->opcode()) {
1273     return diag(SPV_ERROR_INVALID_DATA, inst)
1274            << "Expected cooperative matrix types";
1275   }
1276 
1277   uint32_t m1_scope_id = m1_type->GetOperandAs<uint32_t>(2);
1278   uint32_t m1_rows_id = m1_type->GetOperandAs<uint32_t>(3);
1279   uint32_t m1_cols_id = m1_type->GetOperandAs<uint32_t>(4);
1280 
1281   uint32_t m2_scope_id = m2_type->GetOperandAs<uint32_t>(2);
1282   uint32_t m2_rows_id = m2_type->GetOperandAs<uint32_t>(3);
1283   uint32_t m2_cols_id = m2_type->GetOperandAs<uint32_t>(4);
1284 
1285   bool m1_is_int32 = false, m1_is_const_int32 = false, m2_is_int32 = false,
1286        m2_is_const_int32 = false;
1287   uint32_t m1_value = 0, m2_value = 0;
1288 
1289   std::tie(m1_is_int32, m1_is_const_int32, m1_value) =
1290       EvalInt32IfConst(m1_scope_id);
1291   std::tie(m2_is_int32, m2_is_const_int32, m2_value) =
1292       EvalInt32IfConst(m2_scope_id);
1293 
1294   if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value) {
1295     return diag(SPV_ERROR_INVALID_DATA, inst)
1296            << "Expected scopes of Matrix and Result Type to be "
1297            << "identical";
1298   }
1299 
1300   std::tie(m1_is_int32, m1_is_const_int32, m1_value) =
1301       EvalInt32IfConst(m1_rows_id);
1302   std::tie(m2_is_int32, m2_is_const_int32, m2_value) =
1303       EvalInt32IfConst(m2_rows_id);
1304 
1305   if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value) {
1306     return diag(SPV_ERROR_INVALID_DATA, inst)
1307            << "Expected rows of Matrix type and Result Type to be "
1308            << "identical";
1309   }
1310 
1311   std::tie(m1_is_int32, m1_is_const_int32, m1_value) =
1312       EvalInt32IfConst(m1_cols_id);
1313   std::tie(m2_is_int32, m2_is_const_int32, m2_value) =
1314       EvalInt32IfConst(m2_cols_id);
1315 
1316   if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value) {
1317     return diag(SPV_ERROR_INVALID_DATA, inst)
1318            << "Expected columns of Matrix type and Result Type to be "
1319            << "identical";
1320   }
1321 
1322   if (m1_type->opcode() == spv::Op::OpTypeCooperativeMatrixKHR) {
1323     uint32_t m1_use_id = m1_type->GetOperandAs<uint32_t>(5);
1324     uint32_t m2_use_id = m2_type->GetOperandAs<uint32_t>(5);
1325     std::tie(m1_is_int32, m1_is_const_int32, m1_value) =
1326         EvalInt32IfConst(m1_use_id);
1327     std::tie(m2_is_int32, m2_is_const_int32, m2_value) =
1328         EvalInt32IfConst(m2_use_id);
1329 
1330     if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value) {
1331       return diag(SPV_ERROR_INVALID_DATA, inst)
1332              << "Expected Use of Matrix type and Result Type to be "
1333              << "identical";
1334     }
1335   }
1336 
1337   return SPV_SUCCESS;
1338 }
1339 
GetOperandTypeId(const Instruction * inst,size_t operand_index) const1340 uint32_t ValidationState_t::GetOperandTypeId(const Instruction* inst,
1341                                              size_t operand_index) const {
1342   return GetTypeId(inst->GetOperandAs<uint32_t>(operand_index));
1343 }
1344 
EvalConstantValUint64(uint32_t id,uint64_t * val) const1345 bool ValidationState_t::EvalConstantValUint64(uint32_t id,
1346                                               uint64_t* val) const {
1347   const Instruction* inst = FindDef(id);
1348   if (!inst) {
1349     assert(0 && "Instruction not found");
1350     return false;
1351   }
1352 
1353   if (!IsIntScalarType(inst->type_id())) return false;
1354 
1355   if (inst->opcode() == spv::Op::OpConstantNull) {
1356     *val = 0;
1357   } else if (inst->opcode() != spv::Op::OpConstant) {
1358     // Spec constant values cannot be evaluated so don't consider constant for
1359     // static validation
1360     return false;
1361   } else if (inst->words().size() == 4) {
1362     *val = inst->word(3);
1363   } else {
1364     assert(inst->words().size() == 5);
1365     *val = inst->word(3);
1366     *val |= uint64_t(inst->word(4)) << 32;
1367   }
1368   return true;
1369 }
1370 
EvalConstantValInt64(uint32_t id,int64_t * val) const1371 bool ValidationState_t::EvalConstantValInt64(uint32_t id, int64_t* val) const {
1372   const Instruction* inst = FindDef(id);
1373   if (!inst) {
1374     assert(0 && "Instruction not found");
1375     return false;
1376   }
1377 
1378   if (!IsIntScalarType(inst->type_id())) return false;
1379 
1380   if (inst->opcode() == spv::Op::OpConstantNull) {
1381     *val = 0;
1382   } else if (inst->opcode() != spv::Op::OpConstant) {
1383     // Spec constant values cannot be evaluated so don't consider constant for
1384     // static validation
1385     return false;
1386   } else if (inst->words().size() == 4) {
1387     *val = int32_t(inst->word(3));
1388   } else {
1389     assert(inst->words().size() == 5);
1390     const uint32_t lo_word = inst->word(3);
1391     const uint32_t hi_word = inst->word(4);
1392     *val = static_cast<int64_t>(uint64_t(lo_word) | uint64_t(hi_word) << 32);
1393   }
1394   return true;
1395 }
1396 
EvalInt32IfConst(uint32_t id) const1397 std::tuple<bool, bool, uint32_t> ValidationState_t::EvalInt32IfConst(
1398     uint32_t id) const {
1399   const Instruction* const inst = FindDef(id);
1400   assert(inst);
1401   const uint32_t type = inst->type_id();
1402 
1403   if (type == 0 || !IsIntScalarType(type) || GetBitWidth(type) != 32) {
1404     return std::make_tuple(false, false, 0);
1405   }
1406 
1407   // Spec constant values cannot be evaluated so don't consider constant for
1408   // the purpose of this method.
1409   if (!spvOpcodeIsConstant(inst->opcode()) ||
1410       spvOpcodeIsSpecConstant(inst->opcode())) {
1411     return std::make_tuple(true, false, 0);
1412   }
1413 
1414   if (inst->opcode() == spv::Op::OpConstantNull) {
1415     return std::make_tuple(true, true, 0);
1416   }
1417 
1418   assert(inst->words().size() == 4);
1419   return std::make_tuple(true, true, inst->word(3));
1420 }
1421 
ComputeFunctionToEntryPointMapping()1422 void ValidationState_t::ComputeFunctionToEntryPointMapping() {
1423   for (const uint32_t entry_point : entry_points()) {
1424     std::stack<uint32_t> call_stack;
1425     std::set<uint32_t> visited;
1426     call_stack.push(entry_point);
1427     while (!call_stack.empty()) {
1428       const uint32_t called_func_id = call_stack.top();
1429       call_stack.pop();
1430       if (!visited.insert(called_func_id).second) continue;
1431 
1432       function_to_entry_points_[called_func_id].push_back(entry_point);
1433 
1434       const Function* called_func = function(called_func_id);
1435       if (called_func) {
1436         // Other checks should error out on this invalid SPIR-V.
1437         for (const uint32_t new_call : called_func->function_call_targets()) {
1438           call_stack.push(new_call);
1439         }
1440       }
1441     }
1442   }
1443 }
1444 
ComputeRecursiveEntryPoints()1445 void ValidationState_t::ComputeRecursiveEntryPoints() {
1446   for (const Function& func : functions()) {
1447     std::stack<uint32_t> call_stack;
1448     std::set<uint32_t> visited;
1449 
1450     for (const uint32_t new_call : func.function_call_targets()) {
1451       call_stack.push(new_call);
1452     }
1453 
1454     while (!call_stack.empty()) {
1455       const uint32_t called_func_id = call_stack.top();
1456       call_stack.pop();
1457 
1458       if (!visited.insert(called_func_id).second) continue;
1459 
1460       if (called_func_id == func.id()) {
1461         for (const uint32_t entry_point :
1462              function_to_entry_points_[called_func_id])
1463           recursive_entry_points_.insert(entry_point);
1464         break;
1465       }
1466 
1467       const Function* called_func = function(called_func_id);
1468       if (called_func) {
1469         // Other checks should error out on this invalid SPIR-V.
1470         for (const uint32_t new_call : called_func->function_call_targets()) {
1471           call_stack.push(new_call);
1472         }
1473       }
1474     }
1475   }
1476 }
1477 
FunctionEntryPoints(uint32_t func) const1478 const std::vector<uint32_t>& ValidationState_t::FunctionEntryPoints(
1479     uint32_t func) const {
1480   auto iter = function_to_entry_points_.find(func);
1481   if (iter == function_to_entry_points_.end()) {
1482     return empty_ids_;
1483   } else {
1484     return iter->second;
1485   }
1486 }
1487 
EntryPointReferences(uint32_t id) const1488 std::set<uint32_t> ValidationState_t::EntryPointReferences(uint32_t id) const {
1489   std::set<uint32_t> referenced_entry_points;
1490   const auto inst = FindDef(id);
1491   if (!inst) return referenced_entry_points;
1492 
1493   std::vector<const Instruction*> stack;
1494   stack.push_back(inst);
1495   while (!stack.empty()) {
1496     const auto current_inst = stack.back();
1497     stack.pop_back();
1498 
1499     if (const auto func = current_inst->function()) {
1500       // Instruction lives in a function, we can stop searching.
1501       const auto function_entry_points = FunctionEntryPoints(func->id());
1502       referenced_entry_points.insert(function_entry_points.begin(),
1503                                      function_entry_points.end());
1504     } else {
1505       // Instruction is in the global scope, keep searching its uses.
1506       for (auto pair : current_inst->uses()) {
1507         const auto next_inst = pair.first;
1508         stack.push_back(next_inst);
1509       }
1510     }
1511   }
1512 
1513   return referenced_entry_points;
1514 }
1515 
Disassemble(const Instruction & inst) const1516 std::string ValidationState_t::Disassemble(const Instruction& inst) const {
1517   const spv_parsed_instruction_t& c_inst(inst.c_inst());
1518   return Disassemble(c_inst.words, c_inst.num_words);
1519 }
1520 
Disassemble(const uint32_t * words,uint16_t num_words) const1521 std::string ValidationState_t::Disassemble(const uint32_t* words,
1522                                            uint16_t num_words) const {
1523   uint32_t disassembly_options = SPV_BINARY_TO_TEXT_OPTION_NO_HEADER |
1524                                  SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
1525 
1526   return spvInstructionBinaryToText(context()->target_env, words, num_words,
1527                                     words_, num_words_, disassembly_options);
1528 }
1529 
LogicallyMatch(const Instruction * lhs,const Instruction * rhs,bool check_decorations)1530 bool ValidationState_t::LogicallyMatch(const Instruction* lhs,
1531                                        const Instruction* rhs,
1532                                        bool check_decorations) {
1533   if (lhs->opcode() != rhs->opcode()) {
1534     return false;
1535   }
1536 
1537   if (check_decorations) {
1538     const auto& dec_a = id_decorations(lhs->id());
1539     const auto& dec_b = id_decorations(rhs->id());
1540 
1541     for (const auto& dec : dec_b) {
1542       if (std::find(dec_a.begin(), dec_a.end(), dec) == dec_a.end()) {
1543         return false;
1544       }
1545     }
1546   }
1547 
1548   if (lhs->opcode() == spv::Op::OpTypeArray) {
1549     // Size operands must match.
1550     if (lhs->GetOperandAs<uint32_t>(2u) != rhs->GetOperandAs<uint32_t>(2u)) {
1551       return false;
1552     }
1553 
1554     // Elements must match or logically match.
1555     const auto lhs_ele_id = lhs->GetOperandAs<uint32_t>(1u);
1556     const auto rhs_ele_id = rhs->GetOperandAs<uint32_t>(1u);
1557     if (lhs_ele_id == rhs_ele_id) {
1558       return true;
1559     }
1560 
1561     const auto lhs_ele = FindDef(lhs_ele_id);
1562     const auto rhs_ele = FindDef(rhs_ele_id);
1563     if (!lhs_ele || !rhs_ele) {
1564       return false;
1565     }
1566     return LogicallyMatch(lhs_ele, rhs_ele, check_decorations);
1567   } else if (lhs->opcode() == spv::Op::OpTypeStruct) {
1568     // Number of elements must match.
1569     if (lhs->operands().size() != rhs->operands().size()) {
1570       return false;
1571     }
1572 
1573     for (size_t i = 1u; i < lhs->operands().size(); ++i) {
1574       const auto lhs_ele_id = lhs->GetOperandAs<uint32_t>(i);
1575       const auto rhs_ele_id = rhs->GetOperandAs<uint32_t>(i);
1576       // Elements must match or logically match.
1577       if (lhs_ele_id == rhs_ele_id) {
1578         continue;
1579       }
1580 
1581       const auto lhs_ele = FindDef(lhs_ele_id);
1582       const auto rhs_ele = FindDef(rhs_ele_id);
1583       if (!lhs_ele || !rhs_ele) {
1584         return false;
1585       }
1586 
1587       if (!LogicallyMatch(lhs_ele, rhs_ele, check_decorations)) {
1588         return false;
1589       }
1590     }
1591 
1592     // All checks passed.
1593     return true;
1594   }
1595 
1596   // No other opcodes are acceptable at this point. Arrays and structs are
1597   // caught above and if they're elements are not arrays or structs they are
1598   // required to match exactly.
1599   return false;
1600 }
1601 
TracePointer(const Instruction * inst) const1602 const Instruction* ValidationState_t::TracePointer(
1603     const Instruction* inst) const {
1604   auto base_ptr = inst;
1605   while (base_ptr->opcode() == spv::Op::OpAccessChain ||
1606          base_ptr->opcode() == spv::Op::OpInBoundsAccessChain ||
1607          base_ptr->opcode() == spv::Op::OpPtrAccessChain ||
1608          base_ptr->opcode() == spv::Op::OpInBoundsPtrAccessChain ||
1609          base_ptr->opcode() == spv::Op::OpCopyObject) {
1610     base_ptr = FindDef(base_ptr->GetOperandAs<uint32_t>(2u));
1611   }
1612   return base_ptr;
1613 }
1614 
ContainsType(uint32_t id,const std::function<bool (const Instruction *)> & f,bool traverse_all_types) const1615 bool ValidationState_t::ContainsType(
1616     uint32_t id, const std::function<bool(const Instruction*)>& f,
1617     bool traverse_all_types) const {
1618   const auto inst = FindDef(id);
1619   if (!inst) return false;
1620 
1621   if (f(inst)) return true;
1622 
1623   switch (inst->opcode()) {
1624     case spv::Op::OpTypeArray:
1625     case spv::Op::OpTypeRuntimeArray:
1626     case spv::Op::OpTypeVector:
1627     case spv::Op::OpTypeMatrix:
1628     case spv::Op::OpTypeImage:
1629     case spv::Op::OpTypeSampledImage:
1630     case spv::Op::OpTypeCooperativeMatrixNV:
1631     case spv::Op::OpTypeCooperativeMatrixKHR:
1632       return ContainsType(inst->GetOperandAs<uint32_t>(1u), f,
1633                           traverse_all_types);
1634     case spv::Op::OpTypePointer:
1635       if (IsForwardPointer(id)) return false;
1636       if (traverse_all_types) {
1637         return ContainsType(inst->GetOperandAs<uint32_t>(2u), f,
1638                             traverse_all_types);
1639       }
1640       break;
1641     case spv::Op::OpTypeFunction:
1642     case spv::Op::OpTypeStruct:
1643       if (inst->opcode() == spv::Op::OpTypeFunction && !traverse_all_types) {
1644         return false;
1645       }
1646       for (uint32_t i = 1; i < inst->operands().size(); ++i) {
1647         if (ContainsType(inst->GetOperandAs<uint32_t>(i), f,
1648                          traverse_all_types)) {
1649           return true;
1650         }
1651       }
1652       break;
1653     default:
1654       break;
1655   }
1656 
1657   return false;
1658 }
1659 
ContainsSizedIntOrFloatType(uint32_t id,spv::Op type,uint32_t width) const1660 bool ValidationState_t::ContainsSizedIntOrFloatType(uint32_t id, spv::Op type,
1661                                                     uint32_t width) const {
1662   if (type != spv::Op::OpTypeInt && type != spv::Op::OpTypeFloat) return false;
1663 
1664   const auto f = [type, width](const Instruction* inst) {
1665     if (inst->opcode() == type) {
1666       return inst->GetOperandAs<uint32_t>(1u) == width;
1667     }
1668     return false;
1669   };
1670   return ContainsType(id, f);
1671 }
1672 
ContainsLimitedUseIntOrFloatType(uint32_t id) const1673 bool ValidationState_t::ContainsLimitedUseIntOrFloatType(uint32_t id) const {
1674   if ((!HasCapability(spv::Capability::Int16) &&
1675        ContainsSizedIntOrFloatType(id, spv::Op::OpTypeInt, 16)) ||
1676       (!HasCapability(spv::Capability::Int8) &&
1677        ContainsSizedIntOrFloatType(id, spv::Op::OpTypeInt, 8)) ||
1678       (!HasCapability(spv::Capability::Float16) &&
1679        ContainsSizedIntOrFloatType(id, spv::Op::OpTypeFloat, 16))) {
1680     return true;
1681   }
1682   return false;
1683 }
1684 
ContainsRuntimeArray(uint32_t id) const1685 bool ValidationState_t::ContainsRuntimeArray(uint32_t id) const {
1686   const auto f = [](const Instruction* inst) {
1687     return inst->opcode() == spv::Op::OpTypeRuntimeArray;
1688   };
1689   return ContainsType(id, f, /* traverse_all_types = */ false);
1690 }
1691 
IsValidStorageClass(spv::StorageClass storage_class) const1692 bool ValidationState_t::IsValidStorageClass(
1693     spv::StorageClass storage_class) const {
1694   if (spvIsVulkanEnv(context()->target_env)) {
1695     switch (storage_class) {
1696       case spv::StorageClass::UniformConstant:
1697       case spv::StorageClass::Uniform:
1698       case spv::StorageClass::StorageBuffer:
1699       case spv::StorageClass::Input:
1700       case spv::StorageClass::Output:
1701       case spv::StorageClass::Image:
1702       case spv::StorageClass::Workgroup:
1703       case spv::StorageClass::Private:
1704       case spv::StorageClass::Function:
1705       case spv::StorageClass::PushConstant:
1706       case spv::StorageClass::PhysicalStorageBuffer:
1707       case spv::StorageClass::RayPayloadKHR:
1708       case spv::StorageClass::IncomingRayPayloadKHR:
1709       case spv::StorageClass::HitAttributeKHR:
1710       case spv::StorageClass::CallableDataKHR:
1711       case spv::StorageClass::IncomingCallableDataKHR:
1712       case spv::StorageClass::ShaderRecordBufferKHR:
1713       case spv::StorageClass::TaskPayloadWorkgroupEXT:
1714       case spv::StorageClass::HitObjectAttributeNV:
1715       case spv::StorageClass::TileImageEXT:
1716         return true;
1717       default:
1718         return false;
1719     }
1720   }
1721 
1722   return true;
1723 }
1724 
1725 #define VUID_WRAP(vuid) "[" #vuid "] "
1726 
1727 // Currently no 2 VUID share the same id, so no need for |reference|
VkErrorID(uint32_t id,const char *) const1728 std::string ValidationState_t::VkErrorID(uint32_t id,
1729                                          const char* /*reference*/) const {
1730   if (!spvIsVulkanEnv(context_->target_env)) {
1731     return "";
1732   }
1733 
1734   // This large switch case is only searched when an error has occurred.
1735   // If an id is changed, the old case must be modified or removed. Each string
1736   // here is interpreted as being "implemented"
1737 
1738   // Clang format adds spaces between hyphens
1739   // clang-format off
1740   switch (id) {
1741     case 4154:
1742       return VUID_WRAP(VUID-BaryCoordKHR-BaryCoordKHR-04154);
1743     case 4155:
1744       return VUID_WRAP(VUID-BaryCoordKHR-BaryCoordKHR-04155);
1745     case 4156:
1746       return VUID_WRAP(VUID-BaryCoordKHR-BaryCoordKHR-04156);
1747     case 4160:
1748       return VUID_WRAP(VUID-BaryCoordNoPerspKHR-BaryCoordNoPerspKHR-04160);
1749     case 4161:
1750       return VUID_WRAP(VUID-BaryCoordNoPerspKHR-BaryCoordNoPerspKHR-04161);
1751     case 4162:
1752       return VUID_WRAP(VUID-BaryCoordNoPerspKHR-BaryCoordNoPerspKHR-04162);
1753     case 4181:
1754       return VUID_WRAP(VUID-BaseInstance-BaseInstance-04181);
1755     case 4182:
1756       return VUID_WRAP(VUID-BaseInstance-BaseInstance-04182);
1757     case 4183:
1758       return VUID_WRAP(VUID-BaseInstance-BaseInstance-04183);
1759     case 4184:
1760       return VUID_WRAP(VUID-BaseVertex-BaseVertex-04184);
1761     case 4185:
1762       return VUID_WRAP(VUID-BaseVertex-BaseVertex-04185);
1763     case 4186:
1764       return VUID_WRAP(VUID-BaseVertex-BaseVertex-04186);
1765     case 4187:
1766       return VUID_WRAP(VUID-ClipDistance-ClipDistance-04187);
1767     case 4188:
1768       return VUID_WRAP(VUID-ClipDistance-ClipDistance-04188);
1769     case 4189:
1770       return VUID_WRAP(VUID-ClipDistance-ClipDistance-04189);
1771     case 4190:
1772       return VUID_WRAP(VUID-ClipDistance-ClipDistance-04190);
1773     case 4191:
1774       return VUID_WRAP(VUID-ClipDistance-ClipDistance-04191);
1775     case 4196:
1776       return VUID_WRAP(VUID-CullDistance-CullDistance-04196);
1777     case 4197:
1778       return VUID_WRAP(VUID-CullDistance-CullDistance-04197);
1779     case 4198:
1780       return VUID_WRAP(VUID-CullDistance-CullDistance-04198);
1781     case 4199:
1782       return VUID_WRAP(VUID-CullDistance-CullDistance-04199);
1783     case 4200:
1784       return VUID_WRAP(VUID-CullDistance-CullDistance-04200);
1785     case 6735:
1786       return VUID_WRAP(VUID-CullMaskKHR-CullMaskKHR-06735); // Execution Model
1787     case 6736:
1788       return VUID_WRAP(VUID-CullMaskKHR-CullMaskKHR-06736); // input storage
1789     case 6737:
1790       return VUID_WRAP(VUID-CullMaskKHR-CullMaskKHR-06737); // 32 int scalar
1791     case 4205:
1792       return VUID_WRAP(VUID-DeviceIndex-DeviceIndex-04205);
1793     case 4206:
1794       return VUID_WRAP(VUID-DeviceIndex-DeviceIndex-04206);
1795     case 4207:
1796       return VUID_WRAP(VUID-DrawIndex-DrawIndex-04207);
1797     case 4208:
1798       return VUID_WRAP(VUID-DrawIndex-DrawIndex-04208);
1799     case 4209:
1800       return VUID_WRAP(VUID-DrawIndex-DrawIndex-04209);
1801     case 4210:
1802       return VUID_WRAP(VUID-FragCoord-FragCoord-04210);
1803     case 4211:
1804       return VUID_WRAP(VUID-FragCoord-FragCoord-04211);
1805     case 4212:
1806       return VUID_WRAP(VUID-FragCoord-FragCoord-04212);
1807     case 4213:
1808       return VUID_WRAP(VUID-FragDepth-FragDepth-04213);
1809     case 4214:
1810       return VUID_WRAP(VUID-FragDepth-FragDepth-04214);
1811     case 4215:
1812       return VUID_WRAP(VUID-FragDepth-FragDepth-04215);
1813     case 4216:
1814       return VUID_WRAP(VUID-FragDepth-FragDepth-04216);
1815     case 4217:
1816       return VUID_WRAP(VUID-FragInvocationCountEXT-FragInvocationCountEXT-04217);
1817     case 4218:
1818       return VUID_WRAP(VUID-FragInvocationCountEXT-FragInvocationCountEXT-04218);
1819     case 4219:
1820       return VUID_WRAP(VUID-FragInvocationCountEXT-FragInvocationCountEXT-04219);
1821     case 4220:
1822       return VUID_WRAP(VUID-FragSizeEXT-FragSizeEXT-04220);
1823     case 4221:
1824       return VUID_WRAP(VUID-FragSizeEXT-FragSizeEXT-04221);
1825     case 4222:
1826       return VUID_WRAP(VUID-FragSizeEXT-FragSizeEXT-04222);
1827     case 4223:
1828       return VUID_WRAP(VUID-FragStencilRefEXT-FragStencilRefEXT-04223);
1829     case 4224:
1830       return VUID_WRAP(VUID-FragStencilRefEXT-FragStencilRefEXT-04224);
1831     case 4225:
1832       return VUID_WRAP(VUID-FragStencilRefEXT-FragStencilRefEXT-04225);
1833     case 4229:
1834       return VUID_WRAP(VUID-FrontFacing-FrontFacing-04229);
1835     case 4230:
1836       return VUID_WRAP(VUID-FrontFacing-FrontFacing-04230);
1837     case 4231:
1838       return VUID_WRAP(VUID-FrontFacing-FrontFacing-04231);
1839     case 4232:
1840       return VUID_WRAP(VUID-FullyCoveredEXT-FullyCoveredEXT-04232);
1841     case 4233:
1842       return VUID_WRAP(VUID-FullyCoveredEXT-FullyCoveredEXT-04233);
1843     case 4234:
1844       return VUID_WRAP(VUID-FullyCoveredEXT-FullyCoveredEXT-04234);
1845     case 4236:
1846       return VUID_WRAP(VUID-GlobalInvocationId-GlobalInvocationId-04236);
1847     case 4237:
1848       return VUID_WRAP(VUID-GlobalInvocationId-GlobalInvocationId-04237);
1849     case 4238:
1850       return VUID_WRAP(VUID-GlobalInvocationId-GlobalInvocationId-04238);
1851     case 4239:
1852       return VUID_WRAP(VUID-HelperInvocation-HelperInvocation-04239);
1853     case 4240:
1854       return VUID_WRAP(VUID-HelperInvocation-HelperInvocation-04240);
1855     case 4241:
1856       return VUID_WRAP(VUID-HelperInvocation-HelperInvocation-04241);
1857     case 4242:
1858       return VUID_WRAP(VUID-HitKindKHR-HitKindKHR-04242);
1859     case 4243:
1860       return VUID_WRAP(VUID-HitKindKHR-HitKindKHR-04243);
1861     case 4244:
1862       return VUID_WRAP(VUID-HitKindKHR-HitKindKHR-04244);
1863     case 4245:
1864       return VUID_WRAP(VUID-HitTNV-HitTNV-04245);
1865     case 4246:
1866       return VUID_WRAP(VUID-HitTNV-HitTNV-04246);
1867     case 4247:
1868       return VUID_WRAP(VUID-HitTNV-HitTNV-04247);
1869     case 4248:
1870       return VUID_WRAP(VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04248);
1871     case 4249:
1872       return VUID_WRAP(VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04249);
1873     case 4250:
1874       return VUID_WRAP(VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04250);
1875     case 4251:
1876       return VUID_WRAP(VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04251);
1877     case 4252:
1878       return VUID_WRAP(VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04252);
1879     case 4253:
1880       return VUID_WRAP(VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04253);
1881     case 4254:
1882       return VUID_WRAP(VUID-InstanceId-InstanceId-04254);
1883     case 4255:
1884       return VUID_WRAP(VUID-InstanceId-InstanceId-04255);
1885     case 4256:
1886       return VUID_WRAP(VUID-InstanceId-InstanceId-04256);
1887     case 4257:
1888       return VUID_WRAP(VUID-InvocationId-InvocationId-04257);
1889     case 4258:
1890       return VUID_WRAP(VUID-InvocationId-InvocationId-04258);
1891     case 4259:
1892       return VUID_WRAP(VUID-InvocationId-InvocationId-04259);
1893     case 4263:
1894       return VUID_WRAP(VUID-InstanceIndex-InstanceIndex-04263);
1895     case 4264:
1896       return VUID_WRAP(VUID-InstanceIndex-InstanceIndex-04264);
1897     case 4265:
1898       return VUID_WRAP(VUID-InstanceIndex-InstanceIndex-04265);
1899     case 4266:
1900       return VUID_WRAP(VUID-LaunchIdKHR-LaunchIdKHR-04266);
1901     case 4267:
1902       return VUID_WRAP(VUID-LaunchIdKHR-LaunchIdKHR-04267);
1903     case 4268:
1904       return VUID_WRAP(VUID-LaunchIdKHR-LaunchIdKHR-04268);
1905     case 4269:
1906       return VUID_WRAP(VUID-LaunchSizeKHR-LaunchSizeKHR-04269);
1907     case 4270:
1908       return VUID_WRAP(VUID-LaunchSizeKHR-LaunchSizeKHR-04270);
1909     case 4271:
1910       return VUID_WRAP(VUID-LaunchSizeKHR-LaunchSizeKHR-04271);
1911     case 4272:
1912       return VUID_WRAP(VUID-Layer-Layer-04272);
1913     case 4273:
1914       return VUID_WRAP(VUID-Layer-Layer-04273);
1915     case 4274:
1916       return VUID_WRAP(VUID-Layer-Layer-04274);
1917     case 4275:
1918       return VUID_WRAP(VUID-Layer-Layer-04275);
1919     case 4276:
1920       return VUID_WRAP(VUID-Layer-Layer-04276);
1921     case 4281:
1922       return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04281);
1923     case 4282:
1924       return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04282);
1925     case 4283:
1926       return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04283);
1927     case 4293:
1928       return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04293);
1929     case 4294:
1930       return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04294);
1931     case 4295:
1932       return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04295);
1933     case 4296:
1934       return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04296);
1935     case 4297:
1936       return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04297);
1937     case 4298:
1938       return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04298);
1939     case 4299:
1940       return VUID_WRAP(VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04299);
1941     case 4300:
1942       return VUID_WRAP(VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04300);
1943     case 4301:
1944       return VUID_WRAP(VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04301);
1945     case 4302:
1946       return VUID_WRAP(VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04302);
1947     case 4303:
1948       return VUID_WRAP(VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04303);
1949     case 4304:
1950       return VUID_WRAP(VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04304);
1951     case 4305:
1952       return VUID_WRAP(VUID-ObjectToWorldKHR-ObjectToWorldKHR-04305);
1953     case 4306:
1954       return VUID_WRAP(VUID-ObjectToWorldKHR-ObjectToWorldKHR-04306);
1955     case 4307:
1956       return VUID_WRAP(VUID-ObjectToWorldKHR-ObjectToWorldKHR-04307);
1957     case 4308:
1958       return VUID_WRAP(VUID-PatchVertices-PatchVertices-04308);
1959     case 4309:
1960       return VUID_WRAP(VUID-PatchVertices-PatchVertices-04309);
1961     case 4310:
1962       return VUID_WRAP(VUID-PatchVertices-PatchVertices-04310);
1963     case 4311:
1964       return VUID_WRAP(VUID-PointCoord-PointCoord-04311);
1965     case 4312:
1966       return VUID_WRAP(VUID-PointCoord-PointCoord-04312);
1967     case 4313:
1968       return VUID_WRAP(VUID-PointCoord-PointCoord-04313);
1969     case 4314:
1970       return VUID_WRAP(VUID-PointSize-PointSize-04314);
1971     case 4315:
1972       return VUID_WRAP(VUID-PointSize-PointSize-04315);
1973     case 4316:
1974       return VUID_WRAP(VUID-PointSize-PointSize-04316);
1975     case 4317:
1976       return VUID_WRAP(VUID-PointSize-PointSize-04317);
1977     case 4318:
1978       return VUID_WRAP(VUID-Position-Position-04318);
1979     case 4319:
1980       return VUID_WRAP(VUID-Position-Position-04319);
1981     case 4320:
1982       return VUID_WRAP(VUID-Position-Position-04320);
1983     case 4321:
1984       return VUID_WRAP(VUID-Position-Position-04321);
1985     case 4330:
1986       return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04330);
1987     case 4334:
1988       return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04334);
1989     case 4337:
1990       return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04337);
1991     case 4345:
1992       return VUID_WRAP(VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04345);
1993     case 4346:
1994       return VUID_WRAP(VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04346);
1995     case 4347:
1996       return VUID_WRAP(VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04347);
1997     case 4348:
1998       return VUID_WRAP(VUID-RayTmaxKHR-RayTmaxKHR-04348);
1999     case 4349:
2000       return VUID_WRAP(VUID-RayTmaxKHR-RayTmaxKHR-04349);
2001     case 4350:
2002       return VUID_WRAP(VUID-RayTmaxKHR-RayTmaxKHR-04350);
2003     case 4351:
2004       return VUID_WRAP(VUID-RayTminKHR-RayTminKHR-04351);
2005     case 4352:
2006       return VUID_WRAP(VUID-RayTminKHR-RayTminKHR-04352);
2007     case 4353:
2008       return VUID_WRAP(VUID-RayTminKHR-RayTminKHR-04353);
2009     case 4354:
2010       return VUID_WRAP(VUID-SampleId-SampleId-04354);
2011     case 4355:
2012       return VUID_WRAP(VUID-SampleId-SampleId-04355);
2013     case 4356:
2014       return VUID_WRAP(VUID-SampleId-SampleId-04356);
2015     case 4357:
2016       return VUID_WRAP(VUID-SampleMask-SampleMask-04357);
2017     case 4358:
2018       return VUID_WRAP(VUID-SampleMask-SampleMask-04358);
2019     case 4359:
2020       return VUID_WRAP(VUID-SampleMask-SampleMask-04359);
2021     case 4360:
2022       return VUID_WRAP(VUID-SamplePosition-SamplePosition-04360);
2023     case 4361:
2024       return VUID_WRAP(VUID-SamplePosition-SamplePosition-04361);
2025     case 4362:
2026       return VUID_WRAP(VUID-SamplePosition-SamplePosition-04362);
2027     case 4367:
2028       return VUID_WRAP(VUID-SubgroupId-SubgroupId-04367);
2029     case 4368:
2030       return VUID_WRAP(VUID-SubgroupId-SubgroupId-04368);
2031     case 4369:
2032       return VUID_WRAP(VUID-SubgroupId-SubgroupId-04369);
2033     case 4370:
2034       return VUID_WRAP(VUID-SubgroupEqMask-SubgroupEqMask-04370);
2035     case 4371:
2036       return VUID_WRAP(VUID-SubgroupEqMask-SubgroupEqMask-04371);
2037     case 4372:
2038       return VUID_WRAP(VUID-SubgroupGeMask-SubgroupGeMask-04372);
2039     case 4373:
2040       return VUID_WRAP(VUID-SubgroupGeMask-SubgroupGeMask-04373);
2041     case 4374:
2042       return VUID_WRAP(VUID-SubgroupGtMask-SubgroupGtMask-04374);
2043     case 4375:
2044       return VUID_WRAP(VUID-SubgroupGtMask-SubgroupGtMask-04375);
2045     case 4376:
2046       return VUID_WRAP(VUID-SubgroupLeMask-SubgroupLeMask-04376);
2047     case 4377:
2048       return VUID_WRAP(VUID-SubgroupLeMask-SubgroupLeMask-04377);
2049     case 4378:
2050       return VUID_WRAP(VUID-SubgroupLtMask-SubgroupLtMask-04378);
2051     case 4379:
2052       return VUID_WRAP(VUID-SubgroupLtMask-SubgroupLtMask-04379);
2053     case 4380:
2054       return VUID_WRAP(VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-04380);
2055     case 4381:
2056       return VUID_WRAP(VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-04381);
2057     case 4382:
2058       return VUID_WRAP(VUID-SubgroupSize-SubgroupSize-04382);
2059     case 4383:
2060       return VUID_WRAP(VUID-SubgroupSize-SubgroupSize-04383);
2061     case 4387:
2062       return VUID_WRAP(VUID-TessCoord-TessCoord-04387);
2063     case 4388:
2064       return VUID_WRAP(VUID-TessCoord-TessCoord-04388);
2065     case 4389:
2066       return VUID_WRAP(VUID-TessCoord-TessCoord-04389);
2067     case 4390:
2068       return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04390);
2069     case 4391:
2070       return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04391);
2071     case 4392:
2072       return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04392);
2073     case 4393:
2074       return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04393);
2075     case 4394:
2076       return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04394);
2077     case 4395:
2078       return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04395);
2079     case 4396:
2080       return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04396);
2081     case 4397:
2082       return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04397);
2083     case 4398:
2084       return VUID_WRAP(VUID-VertexIndex-VertexIndex-04398);
2085     case 4399:
2086       return VUID_WRAP(VUID-VertexIndex-VertexIndex-04399);
2087     case 4400:
2088       return VUID_WRAP(VUID-VertexIndex-VertexIndex-04400);
2089     case 4401:
2090       return VUID_WRAP(VUID-ViewIndex-ViewIndex-04401);
2091     case 4402:
2092       return VUID_WRAP(VUID-ViewIndex-ViewIndex-04402);
2093     case 4403:
2094       return VUID_WRAP(VUID-ViewIndex-ViewIndex-04403);
2095     case 4404:
2096       return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04404);
2097     case 4405:
2098       return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04405);
2099     case 4406:
2100       return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04406);
2101     case 4407:
2102       return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04407);
2103     case 4408:
2104       return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04408);
2105     case 4422:
2106       return VUID_WRAP(VUID-WorkgroupId-WorkgroupId-04422);
2107     case 4423:
2108       return VUID_WRAP(VUID-WorkgroupId-WorkgroupId-04423);
2109     case 4424:
2110       return VUID_WRAP(VUID-WorkgroupId-WorkgroupId-04424);
2111     case 4425:
2112       return VUID_WRAP(VUID-WorkgroupSize-WorkgroupSize-04425);
2113     case 4426:
2114       return VUID_WRAP(VUID-WorkgroupSize-WorkgroupSize-04426);
2115     case 4427:
2116       return VUID_WRAP(VUID-WorkgroupSize-WorkgroupSize-04427);
2117     case 4428:
2118       return VUID_WRAP(VUID-WorldRayDirectionKHR-WorldRayDirectionKHR-04428);
2119     case 4429:
2120       return VUID_WRAP(VUID-WorldRayDirectionKHR-WorldRayDirectionKHR-04429);
2121     case 4430:
2122       return VUID_WRAP(VUID-WorldRayDirectionKHR-WorldRayDirectionKHR-04430);
2123     case 4431:
2124       return VUID_WRAP(VUID-WorldRayOriginKHR-WorldRayOriginKHR-04431);
2125     case 4432:
2126       return VUID_WRAP(VUID-WorldRayOriginKHR-WorldRayOriginKHR-04432);
2127     case 4433:
2128       return VUID_WRAP(VUID-WorldRayOriginKHR-WorldRayOriginKHR-04433);
2129     case 4434:
2130       return VUID_WRAP(VUID-WorldToObjectKHR-WorldToObjectKHR-04434);
2131     case 4435:
2132       return VUID_WRAP(VUID-WorldToObjectKHR-WorldToObjectKHR-04435);
2133     case 4436:
2134       return VUID_WRAP(VUID-WorldToObjectKHR-WorldToObjectKHR-04436);
2135     case 4484:
2136       return VUID_WRAP(VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04484);
2137     case 4485:
2138       return VUID_WRAP(VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04485);
2139     case 4486:
2140       return VUID_WRAP(VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04486);
2141     case 4490:
2142       return VUID_WRAP(VUID-ShadingRateKHR-ShadingRateKHR-04490);
2143     case 4491:
2144       return VUID_WRAP(VUID-ShadingRateKHR-ShadingRateKHR-04491);
2145     case 4492:
2146       return VUID_WRAP(VUID-ShadingRateKHR-ShadingRateKHR-04492);
2147     case 4633:
2148       return VUID_WRAP(VUID-StandaloneSpirv-None-04633);
2149     case 4634:
2150       return VUID_WRAP(VUID-StandaloneSpirv-None-04634);
2151     case 4635:
2152       return VUID_WRAP(VUID-StandaloneSpirv-None-04635);
2153     case 4636:
2154       return VUID_WRAP(VUID-StandaloneSpirv-None-04636);
2155     case 4637:
2156       return VUID_WRAP(VUID-StandaloneSpirv-None-04637);
2157     case 4638:
2158       return VUID_WRAP(VUID-StandaloneSpirv-None-04638);
2159     case 7321:
2160       return VUID_WRAP(VUID-StandaloneSpirv-None-07321);
2161     case 4640:
2162       return VUID_WRAP(VUID-StandaloneSpirv-None-04640);
2163     case 4641:
2164       return VUID_WRAP(VUID-StandaloneSpirv-None-04641);
2165     case 4642:
2166       return VUID_WRAP(VUID-StandaloneSpirv-None-04642);
2167     case 4643:
2168       return VUID_WRAP(VUID-StandaloneSpirv-None-04643);
2169     case 4644:
2170       return VUID_WRAP(VUID-StandaloneSpirv-None-04644);
2171     case 4645:
2172       return VUID_WRAP(VUID-StandaloneSpirv-None-04645);
2173     case 4650:
2174       return VUID_WRAP(VUID-StandaloneSpirv-OpControlBarrier-04650);
2175     case 4651:
2176       return VUID_WRAP(VUID-StandaloneSpirv-OpVariable-04651);
2177     case 4652:
2178       return VUID_WRAP(VUID-StandaloneSpirv-OpReadClockKHR-04652);
2179     case 4653:
2180       return VUID_WRAP(VUID-StandaloneSpirv-OriginLowerLeft-04653);
2181     case 4654:
2182       return VUID_WRAP(VUID-StandaloneSpirv-PixelCenterInteger-04654);
2183     case 4655:
2184       return VUID_WRAP(VUID-StandaloneSpirv-UniformConstant-04655);
2185     case 4656:
2186       return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-04656);
2187     case 4657:
2188       return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-04657);
2189     case 4658:
2190       return VUID_WRAP(VUID-StandaloneSpirv-OpImageTexelPointer-04658);
2191     case 4659:
2192       return VUID_WRAP(VUID-StandaloneSpirv-OpImageQuerySizeLod-04659);
2193     case 4663:
2194       return VUID_WRAP(VUID-StandaloneSpirv-Offset-04663);
2195     case 4664:
2196       return VUID_WRAP(VUID-StandaloneSpirv-OpImageGather-04664);
2197     case 4667:
2198       return VUID_WRAP(VUID-StandaloneSpirv-None-04667);
2199     case 4669:
2200       return VUID_WRAP(VUID-StandaloneSpirv-GLSLShared-04669);
2201     case 4670:
2202       return VUID_WRAP(VUID-StandaloneSpirv-Flat-04670);
2203     case 4675:
2204       return VUID_WRAP(VUID-StandaloneSpirv-FPRoundingMode-04675);
2205     case 4677:
2206       return VUID_WRAP(VUID-StandaloneSpirv-Invariant-04677);
2207     case 4680:
2208       return VUID_WRAP(VUID-StandaloneSpirv-OpTypeRuntimeArray-04680);
2209     case 4682:
2210       return VUID_WRAP(VUID-StandaloneSpirv-OpControlBarrier-04682);
2211     case 6426:
2212       return VUID_WRAP(VUID-StandaloneSpirv-LocalSize-06426); // formally 04683
2213     case 4685:
2214       return VUID_WRAP(VUID-StandaloneSpirv-OpGroupNonUniformBallotBitCount-04685);
2215     case 4686:
2216       return VUID_WRAP(VUID-StandaloneSpirv-None-04686);
2217     case 4698:
2218       return VUID_WRAP(VUID-StandaloneSpirv-RayPayloadKHR-04698);
2219     case 4699:
2220       return VUID_WRAP(VUID-StandaloneSpirv-IncomingRayPayloadKHR-04699);
2221     case 4700:
2222       return VUID_WRAP(VUID-StandaloneSpirv-IncomingRayPayloadKHR-04700);
2223     case 4701:
2224       return VUID_WRAP(VUID-StandaloneSpirv-HitAttributeKHR-04701);
2225     case 4702:
2226       return VUID_WRAP(VUID-StandaloneSpirv-HitAttributeKHR-04702);
2227     case 4703:
2228       return VUID_WRAP(VUID-StandaloneSpirv-HitAttributeKHR-04703);
2229     case 4704:
2230       return VUID_WRAP(VUID-StandaloneSpirv-CallableDataKHR-04704);
2231     case 4705:
2232       return VUID_WRAP(VUID-StandaloneSpirv-IncomingCallableDataKHR-04705);
2233     case 4706:
2234       return VUID_WRAP(VUID-StandaloneSpirv-IncomingCallableDataKHR-04706);
2235     case 7119:
2236       return VUID_WRAP(VUID-StandaloneSpirv-ShaderRecordBufferKHR-07119);
2237     case 4708:
2238       return VUID_WRAP(VUID-StandaloneSpirv-PhysicalStorageBuffer64-04708);
2239     case 4710:
2240       return VUID_WRAP(VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710);
2241     case 4711:
2242       return VUID_WRAP(VUID-StandaloneSpirv-OpTypeForwardPointer-04711);
2243     case 4730:
2244       return VUID_WRAP(VUID-StandaloneSpirv-OpAtomicStore-04730);
2245     case 4731:
2246       return VUID_WRAP(VUID-StandaloneSpirv-OpAtomicLoad-04731);
2247     case 4732:
2248       return VUID_WRAP(VUID-StandaloneSpirv-OpMemoryBarrier-04732);
2249     case 4733:
2250       return VUID_WRAP(VUID-StandaloneSpirv-OpMemoryBarrier-04733);
2251     case 4734:
2252       return VUID_WRAP(VUID-StandaloneSpirv-OpVariable-04734);
2253     case 4744:
2254       return VUID_WRAP(VUID-StandaloneSpirv-Flat-04744);
2255     case 4777:
2256       return VUID_WRAP(VUID-StandaloneSpirv-OpImage-04777);
2257     case 4780:
2258       return VUID_WRAP(VUID-StandaloneSpirv-Result-04780);
2259     case 4781:
2260       return VUID_WRAP(VUID-StandaloneSpirv-Base-04781);
2261     case 4915:
2262       return VUID_WRAP(VUID-StandaloneSpirv-Location-04915);
2263     case 4916:
2264       return VUID_WRAP(VUID-StandaloneSpirv-Location-04916);
2265     case 4917:
2266       return VUID_WRAP(VUID-StandaloneSpirv-Location-04917);
2267     case 4918:
2268       return VUID_WRAP(VUID-StandaloneSpirv-Location-04918);
2269     case 4919:
2270       return VUID_WRAP(VUID-StandaloneSpirv-Location-04919);
2271     case 4920:
2272       return VUID_WRAP(VUID-StandaloneSpirv-Component-04920);
2273     case 4921:
2274       return VUID_WRAP(VUID-StandaloneSpirv-Component-04921);
2275     case 4922:
2276       return VUID_WRAP(VUID-StandaloneSpirv-Component-04922);
2277     case 4923:
2278       return VUID_WRAP(VUID-StandaloneSpirv-Component-04923);
2279     case 4924:
2280       return VUID_WRAP(VUID-StandaloneSpirv-Component-04924);
2281     case 6201:
2282       return VUID_WRAP(VUID-StandaloneSpirv-Flat-06201);
2283     case 6202:
2284       return VUID_WRAP(VUID-StandaloneSpirv-Flat-06202);
2285     case 6214:
2286       return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-06214);
2287     case 6491:
2288       return VUID_WRAP(VUID-StandaloneSpirv-DescriptorSet-06491);
2289     case 6671:
2290       return VUID_WRAP(VUID-StandaloneSpirv-OpTypeSampledImage-06671);
2291     case 6672:
2292       return VUID_WRAP(VUID-StandaloneSpirv-Location-06672);
2293     case 6673:
2294       return VUID_WRAP(VUID-StandaloneSpirv-OpVariable-06673);
2295     case 6674:
2296       return VUID_WRAP(VUID-StandaloneSpirv-OpEntryPoint-06674);
2297     case 6675:
2298       return VUID_WRAP(VUID-StandaloneSpirv-PushConstant-06675);
2299     case 6676:
2300       return VUID_WRAP(VUID-StandaloneSpirv-Uniform-06676);
2301     case 6677:
2302       return VUID_WRAP(VUID-StandaloneSpirv-UniformConstant-06677);
2303     case 6678:
2304       return VUID_WRAP(VUID-StandaloneSpirv-InputAttachmentIndex-06678);
2305     case 6777:
2306       return VUID_WRAP(VUID-StandaloneSpirv-PerVertexKHR-06777);
2307     case 6778:
2308       return VUID_WRAP(VUID-StandaloneSpirv-Input-06778);
2309     case 6807:
2310       return VUID_WRAP(VUID-StandaloneSpirv-Uniform-06807);
2311     case 6808:
2312       return VUID_WRAP(VUID-StandaloneSpirv-PushConstant-06808);
2313     case 6925:
2314       return VUID_WRAP(VUID-StandaloneSpirv-Uniform-06925);
2315     case 7041:
2316       return VUID_WRAP(VUID-PrimitivePointIndicesEXT-PrimitivePointIndicesEXT-07041);
2317     case 7043:
2318       return VUID_WRAP(VUID-PrimitivePointIndicesEXT-PrimitivePointIndicesEXT-07043);
2319     case 7044:
2320       return VUID_WRAP(VUID-PrimitivePointIndicesEXT-PrimitivePointIndicesEXT-07044);
2321     case 7047:
2322       return VUID_WRAP(VUID-PrimitiveLineIndicesEXT-PrimitiveLineIndicesEXT-07047);
2323     case 7049:
2324       return VUID_WRAP(VUID-PrimitiveLineIndicesEXT-PrimitiveLineIndicesEXT-07049);
2325     case 7050:
2326       return VUID_WRAP(VUID-PrimitiveLineIndicesEXT-PrimitiveLineIndicesEXT-07050);
2327     case 7053:
2328       return VUID_WRAP(VUID-PrimitiveTriangleIndicesEXT-PrimitiveTriangleIndicesEXT-07053);
2329     case 7055:
2330       return VUID_WRAP(VUID-PrimitiveTriangleIndicesEXT-PrimitiveTriangleIndicesEXT-07055);
2331     case 7056:
2332       return VUID_WRAP(VUID-PrimitiveTriangleIndicesEXT-PrimitiveTriangleIndicesEXT-07056);
2333     case 7102:
2334       return VUID_WRAP(VUID-StandaloneSpirv-MeshEXT-07102);
2335     case 7320:
2336       return VUID_WRAP(VUID-StandaloneSpirv-ExecutionModel-07320);
2337     case 7290:
2338       return VUID_WRAP(VUID-StandaloneSpirv-Input-07290);
2339     case 7650:
2340       return VUID_WRAP(VUID-StandaloneSpirv-Base-07650);
2341     case 7651:
2342       return VUID_WRAP(VUID-StandaloneSpirv-Base-07651);
2343     case 7652:
2344       return VUID_WRAP(VUID-StandaloneSpirv-Base-07652);
2345     case 7703:
2346       return VUID_WRAP(VUID-StandaloneSpirv-Component-07703);
2347     case 7951:
2348       return VUID_WRAP(VUID-StandaloneSpirv-SubgroupVoteKHR-07951);
2349     case 8721:
2350       return VUID_WRAP(VUID-StandaloneSpirv-OpEntryPoint-08721);
2351     case 8722:
2352       return VUID_WRAP(VUID-StandaloneSpirv-OpEntryPoint-08722);
2353     case 8973:
2354       return VUID_WRAP(VUID-StandaloneSpirv-Pointer-08973);
2355     case 9638:
2356       return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-09638);
2357     case 9658:
2358       return VUID_WRAP(VUID-StandaloneSpirv-OpEntryPoint-09658);
2359     case 9659:
2360       return VUID_WRAP(VUID-StandaloneSpirv-OpEntryPoint-09659);
2361     default:
2362       return "";  // unknown id
2363   }
2364   // clang-format on
2365 }
2366 
2367 }  // namespace val
2368 }  // namespace spvtools
2369