validation_state.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  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. #include "source/val/validation_state.h"
  15. #include <cassert>
  16. #include <stack>
  17. #include <utility>
  18. #include "source/opcode.h"
  19. #include "source/spirv_constant.h"
  20. #include "source/spirv_target_env.h"
  21. #include "source/val/basic_block.h"
  22. #include "source/val/construct.h"
  23. #include "source/val/function.h"
  24. #include "spirv-tools/libspirv.h"
  25. namespace spvtools {
  26. namespace val {
  27. namespace {
  28. ModuleLayoutSection InstructionLayoutSection(
  29. ModuleLayoutSection current_section, SpvOp op) {
  30. // See Section 2.4
  31. if (spvOpcodeGeneratesType(op) || spvOpcodeIsConstant(op))
  32. return kLayoutTypes;
  33. switch (op) {
  34. case SpvOpCapability:
  35. return kLayoutCapabilities;
  36. case SpvOpExtension:
  37. return kLayoutExtensions;
  38. case SpvOpExtInstImport:
  39. return kLayoutExtInstImport;
  40. case SpvOpMemoryModel:
  41. return kLayoutMemoryModel;
  42. case SpvOpEntryPoint:
  43. return kLayoutEntryPoint;
  44. case SpvOpExecutionMode:
  45. case SpvOpExecutionModeId:
  46. return kLayoutExecutionMode;
  47. case SpvOpSourceContinued:
  48. case SpvOpSource:
  49. case SpvOpSourceExtension:
  50. case SpvOpString:
  51. return kLayoutDebug1;
  52. case SpvOpName:
  53. case SpvOpMemberName:
  54. return kLayoutDebug2;
  55. case SpvOpModuleProcessed:
  56. return kLayoutDebug3;
  57. case SpvOpDecorate:
  58. case SpvOpMemberDecorate:
  59. case SpvOpGroupDecorate:
  60. case SpvOpGroupMemberDecorate:
  61. case SpvOpDecorationGroup:
  62. case SpvOpDecorateId:
  63. case SpvOpDecorateStringGOOGLE:
  64. case SpvOpMemberDecorateStringGOOGLE:
  65. return kLayoutAnnotations;
  66. case SpvOpTypeForwardPointer:
  67. return kLayoutTypes;
  68. case SpvOpVariable:
  69. if (current_section == kLayoutTypes) return kLayoutTypes;
  70. return kLayoutFunctionDefinitions;
  71. case SpvOpExtInst:
  72. // SpvOpExtInst is only allowed in types section for certain extended
  73. // instruction sets. This will be checked separately.
  74. if (current_section == kLayoutTypes) return kLayoutTypes;
  75. return kLayoutFunctionDefinitions;
  76. case SpvOpLine:
  77. case SpvOpNoLine:
  78. case SpvOpUndef:
  79. if (current_section == kLayoutTypes) return kLayoutTypes;
  80. return kLayoutFunctionDefinitions;
  81. case SpvOpFunction:
  82. case SpvOpFunctionParameter:
  83. case SpvOpFunctionEnd:
  84. if (current_section == kLayoutFunctionDeclarations)
  85. return kLayoutFunctionDeclarations;
  86. return kLayoutFunctionDefinitions;
  87. default:
  88. break;
  89. }
  90. return kLayoutFunctionDefinitions;
  91. }
  92. bool IsInstructionInLayoutSection(ModuleLayoutSection layout, SpvOp op) {
  93. return layout == InstructionLayoutSection(layout, op);
  94. }
  95. // Counts the number of instructions and functions in the file.
  96. spv_result_t CountInstructions(void* user_data,
  97. const spv_parsed_instruction_t* inst) {
  98. ValidationState_t& _ = *(reinterpret_cast<ValidationState_t*>(user_data));
  99. if (inst->opcode == SpvOpFunction) _.increment_total_functions();
  100. _.increment_total_instructions();
  101. return SPV_SUCCESS;
  102. }
  103. spv_result_t setHeader(void* user_data, spv_endianness_t, uint32_t,
  104. uint32_t version, uint32_t generator, uint32_t id_bound,
  105. uint32_t) {
  106. ValidationState_t& vstate =
  107. *(reinterpret_cast<ValidationState_t*>(user_data));
  108. vstate.setIdBound(id_bound);
  109. vstate.setGenerator(generator);
  110. vstate.setVersion(version);
  111. return SPV_SUCCESS;
  112. }
  113. // Add features based on SPIR-V core version number.
  114. void UpdateFeaturesBasedOnSpirvVersion(ValidationState_t::Feature* features,
  115. uint32_t version) {
  116. assert(features);
  117. if (version >= SPV_SPIRV_VERSION_WORD(1, 4)) {
  118. features->select_between_composites = true;
  119. features->copy_memory_permits_two_memory_accesses = true;
  120. features->uconvert_spec_constant_op = true;
  121. features->nonwritable_var_in_function_or_private = true;
  122. }
  123. }
  124. } // namespace
  125. ValidationState_t::ValidationState_t(const spv_const_context ctx,
  126. const spv_const_validator_options opt,
  127. const uint32_t* words,
  128. const size_t num_words,
  129. const uint32_t max_warnings)
  130. : context_(ctx),
  131. options_(opt),
  132. words_(words),
  133. num_words_(num_words),
  134. unresolved_forward_ids_{},
  135. operand_names_{},
  136. current_layout_section_(kLayoutCapabilities),
  137. module_functions_(),
  138. module_capabilities_(),
  139. module_extensions_(),
  140. ordered_instructions_(),
  141. all_definitions_(),
  142. global_vars_(),
  143. local_vars_(),
  144. struct_nesting_depth_(),
  145. struct_has_nested_blockorbufferblock_struct_(),
  146. grammar_(ctx),
  147. addressing_model_(SpvAddressingModelMax),
  148. memory_model_(SpvMemoryModelMax),
  149. pointer_size_and_alignment_(0),
  150. in_function_(false),
  151. num_of_warnings_(0),
  152. max_num_of_warnings_(max_warnings) {
  153. assert(opt && "Validator options may not be Null.");
  154. const auto env = context_->target_env;
  155. if (spvIsVulkanEnv(env)) {
  156. // Vulkan 1.1 includes VK_KHR_relaxed_block_layout in core.
  157. if (env != SPV_ENV_VULKAN_1_0) {
  158. features_.env_relaxed_block_layout = true;
  159. }
  160. }
  161. // Only attempt to count if we have words, otherwise let the other validation
  162. // fail and generate an error.
  163. if (num_words > 0) {
  164. // Count the number of instructions in the binary.
  165. // This parse should not produce any error messages. Hijack the context and
  166. // replace the message consumer so that we do not pollute any state in input
  167. // consumer.
  168. spv_context_t hijacked_context = *ctx;
  169. hijacked_context.consumer = [](spv_message_level_t, const char*,
  170. const spv_position_t&, const char*) {};
  171. spvBinaryParse(&hijacked_context, this, words, num_words, setHeader,
  172. CountInstructions,
  173. /* diagnostic = */ nullptr);
  174. preallocateStorage();
  175. }
  176. UpdateFeaturesBasedOnSpirvVersion(&features_, version_);
  177. friendly_mapper_ = spvtools::MakeUnique<spvtools::FriendlyNameMapper>(
  178. context_, words_, num_words_);
  179. name_mapper_ = friendly_mapper_->GetNameMapper();
  180. }
  181. void ValidationState_t::preallocateStorage() {
  182. ordered_instructions_.reserve(total_instructions_);
  183. module_functions_.reserve(total_functions_);
  184. }
  185. spv_result_t ValidationState_t::ForwardDeclareId(uint32_t id) {
  186. unresolved_forward_ids_.insert(id);
  187. return SPV_SUCCESS;
  188. }
  189. spv_result_t ValidationState_t::RemoveIfForwardDeclared(uint32_t id) {
  190. unresolved_forward_ids_.erase(id);
  191. return SPV_SUCCESS;
  192. }
  193. spv_result_t ValidationState_t::RegisterForwardPointer(uint32_t id) {
  194. forward_pointer_ids_.insert(id);
  195. return SPV_SUCCESS;
  196. }
  197. bool ValidationState_t::IsForwardPointer(uint32_t id) const {
  198. return (forward_pointer_ids_.find(id) != forward_pointer_ids_.end());
  199. }
  200. void ValidationState_t::AssignNameToId(uint32_t id, std::string name) {
  201. operand_names_[id] = name;
  202. }
  203. std::string ValidationState_t::getIdName(uint32_t id) const {
  204. const std::string id_name = name_mapper_(id);
  205. std::stringstream out;
  206. out << id << "[%" << id_name << "]";
  207. return out.str();
  208. }
  209. size_t ValidationState_t::unresolved_forward_id_count() const {
  210. return unresolved_forward_ids_.size();
  211. }
  212. std::vector<uint32_t> ValidationState_t::UnresolvedForwardIds() const {
  213. std::vector<uint32_t> out(std::begin(unresolved_forward_ids_),
  214. std::end(unresolved_forward_ids_));
  215. return out;
  216. }
  217. bool ValidationState_t::IsDefinedId(uint32_t id) const {
  218. return all_definitions_.find(id) != std::end(all_definitions_);
  219. }
  220. const Instruction* ValidationState_t::FindDef(uint32_t id) const {
  221. auto it = all_definitions_.find(id);
  222. if (it == all_definitions_.end()) return nullptr;
  223. return it->second;
  224. }
  225. Instruction* ValidationState_t::FindDef(uint32_t id) {
  226. auto it = all_definitions_.find(id);
  227. if (it == all_definitions_.end()) return nullptr;
  228. return it->second;
  229. }
  230. ModuleLayoutSection ValidationState_t::current_layout_section() const {
  231. return current_layout_section_;
  232. }
  233. void ValidationState_t::ProgressToNextLayoutSectionOrder() {
  234. // Guard against going past the last element(kLayoutFunctionDefinitions)
  235. if (current_layout_section_ <= kLayoutFunctionDefinitions) {
  236. current_layout_section_ =
  237. static_cast<ModuleLayoutSection>(current_layout_section_ + 1);
  238. }
  239. }
  240. bool ValidationState_t::IsOpcodeInPreviousLayoutSection(SpvOp op) {
  241. ModuleLayoutSection section =
  242. InstructionLayoutSection(current_layout_section_, op);
  243. return section < current_layout_section_;
  244. }
  245. bool ValidationState_t::IsOpcodeInCurrentLayoutSection(SpvOp op) {
  246. return IsInstructionInLayoutSection(current_layout_section_, op);
  247. }
  248. DiagnosticStream ValidationState_t::diag(spv_result_t error_code,
  249. const Instruction* inst) {
  250. if (error_code == SPV_WARNING) {
  251. if (num_of_warnings_ == max_num_of_warnings_) {
  252. DiagnosticStream({0, 0, 0}, context_->consumer, "", error_code)
  253. << "Other warnings have been suppressed.\n";
  254. }
  255. if (num_of_warnings_ >= max_num_of_warnings_) {
  256. return DiagnosticStream({0, 0, 0}, nullptr, "", error_code);
  257. }
  258. ++num_of_warnings_;
  259. }
  260. std::string disassembly;
  261. if (inst) disassembly = Disassemble(*inst);
  262. return DiagnosticStream({0, 0, inst ? inst->LineNum() : 0},
  263. context_->consumer, disassembly, error_code);
  264. }
  265. std::vector<Function>& ValidationState_t::functions() {
  266. return module_functions_;
  267. }
  268. Function& ValidationState_t::current_function() {
  269. assert(in_function_body());
  270. return module_functions_.back();
  271. }
  272. const Function& ValidationState_t::current_function() const {
  273. assert(in_function_body());
  274. return module_functions_.back();
  275. }
  276. const Function* ValidationState_t::function(uint32_t id) const {
  277. const auto it = id_to_function_.find(id);
  278. if (it == id_to_function_.end()) return nullptr;
  279. return it->second;
  280. }
  281. Function* ValidationState_t::function(uint32_t id) {
  282. auto it = id_to_function_.find(id);
  283. if (it == id_to_function_.end()) return nullptr;
  284. return it->second;
  285. }
  286. bool ValidationState_t::in_function_body() const { return in_function_; }
  287. bool ValidationState_t::in_block() const {
  288. return module_functions_.empty() == false &&
  289. module_functions_.back().current_block() != nullptr;
  290. }
  291. void ValidationState_t::RegisterCapability(SpvCapability cap) {
  292. // Avoid redundant work. Otherwise the recursion could induce work
  293. // quadrdatic in the capability dependency depth. (Ok, not much, but
  294. // it's something.)
  295. if (module_capabilities_.Contains(cap)) return;
  296. module_capabilities_.Add(cap);
  297. spv_operand_desc desc;
  298. if (SPV_SUCCESS ==
  299. grammar_.lookupOperand(SPV_OPERAND_TYPE_CAPABILITY, cap, &desc)) {
  300. CapabilitySet(desc->numCapabilities, desc->capabilities)
  301. .ForEach([this](SpvCapability c) { RegisterCapability(c); });
  302. }
  303. switch (cap) {
  304. case SpvCapabilityKernel:
  305. features_.group_ops_reduce_and_scans = true;
  306. break;
  307. case SpvCapabilityInt8:
  308. features_.use_int8_type = true;
  309. features_.declare_int8_type = true;
  310. break;
  311. case SpvCapabilityStorageBuffer8BitAccess:
  312. case SpvCapabilityUniformAndStorageBuffer8BitAccess:
  313. case SpvCapabilityStoragePushConstant8:
  314. case SpvCapabilityWorkgroupMemoryExplicitLayout8BitAccessKHR:
  315. features_.declare_int8_type = true;
  316. break;
  317. case SpvCapabilityInt16:
  318. features_.declare_int16_type = true;
  319. break;
  320. case SpvCapabilityFloat16:
  321. case SpvCapabilityFloat16Buffer:
  322. features_.declare_float16_type = true;
  323. break;
  324. case SpvCapabilityStorageUniformBufferBlock16:
  325. case SpvCapabilityStorageUniform16:
  326. case SpvCapabilityStoragePushConstant16:
  327. case SpvCapabilityStorageInputOutput16:
  328. case SpvCapabilityWorkgroupMemoryExplicitLayout16BitAccessKHR:
  329. features_.declare_int16_type = true;
  330. features_.declare_float16_type = true;
  331. features_.free_fp_rounding_mode = true;
  332. break;
  333. case SpvCapabilityVariablePointers:
  334. features_.variable_pointers = true;
  335. features_.variable_pointers_storage_buffer = true;
  336. break;
  337. case SpvCapabilityVariablePointersStorageBuffer:
  338. features_.variable_pointers_storage_buffer = true;
  339. break;
  340. default:
  341. break;
  342. }
  343. }
  344. void ValidationState_t::RegisterExtension(Extension ext) {
  345. if (module_extensions_.Contains(ext)) return;
  346. module_extensions_.Add(ext);
  347. switch (ext) {
  348. case kSPV_AMD_gpu_shader_half_float:
  349. case kSPV_AMD_gpu_shader_half_float_fetch:
  350. // SPV_AMD_gpu_shader_half_float enables float16 type.
  351. // https://github.com/KhronosGroup/SPIRV-Tools/issues/1375
  352. features_.declare_float16_type = true;
  353. break;
  354. case kSPV_AMD_gpu_shader_int16:
  355. // This is not yet in the extension, but it's recommended for it.
  356. // See https://github.com/KhronosGroup/glslang/issues/848
  357. features_.uconvert_spec_constant_op = true;
  358. break;
  359. case kSPV_AMD_shader_ballot:
  360. // The grammar doesn't encode the fact that SPV_AMD_shader_ballot
  361. // enables the use of group operations Reduce, InclusiveScan,
  362. // and ExclusiveScan. Enable it manually.
  363. // https://github.com/KhronosGroup/SPIRV-Tools/issues/991
  364. features_.group_ops_reduce_and_scans = true;
  365. break;
  366. default:
  367. break;
  368. }
  369. }
  370. bool ValidationState_t::HasAnyOfCapabilities(
  371. const CapabilitySet& capabilities) const {
  372. return module_capabilities_.HasAnyOf(capabilities);
  373. }
  374. bool ValidationState_t::HasAnyOfExtensions(
  375. const ExtensionSet& extensions) const {
  376. return module_extensions_.HasAnyOf(extensions);
  377. }
  378. void ValidationState_t::set_addressing_model(SpvAddressingModel am) {
  379. addressing_model_ = am;
  380. switch (am) {
  381. case SpvAddressingModelPhysical32:
  382. pointer_size_and_alignment_ = 4;
  383. break;
  384. default:
  385. // fall through
  386. case SpvAddressingModelPhysical64:
  387. case SpvAddressingModelPhysicalStorageBuffer64EXT:
  388. pointer_size_and_alignment_ = 8;
  389. break;
  390. }
  391. }
  392. SpvAddressingModel ValidationState_t::addressing_model() const {
  393. return addressing_model_;
  394. }
  395. void ValidationState_t::set_memory_model(SpvMemoryModel mm) {
  396. memory_model_ = mm;
  397. }
  398. SpvMemoryModel ValidationState_t::memory_model() const { return memory_model_; }
  399. spv_result_t ValidationState_t::RegisterFunction(
  400. uint32_t id, uint32_t ret_type_id, SpvFunctionControlMask function_control,
  401. uint32_t function_type_id) {
  402. assert(in_function_body() == false &&
  403. "RegisterFunction can only be called when parsing the binary outside "
  404. "of another function");
  405. in_function_ = true;
  406. module_functions_.emplace_back(id, ret_type_id, function_control,
  407. function_type_id);
  408. id_to_function_.emplace(id, &current_function());
  409. // TODO(umar): validate function type and type_id
  410. return SPV_SUCCESS;
  411. }
  412. spv_result_t ValidationState_t::RegisterFunctionEnd() {
  413. assert(in_function_body() == true &&
  414. "RegisterFunctionEnd can only be called when parsing the binary "
  415. "inside of another function");
  416. assert(in_block() == false &&
  417. "RegisterFunctionParameter can only be called when parsing the binary "
  418. "ouside of a block");
  419. current_function().RegisterFunctionEnd();
  420. in_function_ = false;
  421. return SPV_SUCCESS;
  422. }
  423. Instruction* ValidationState_t::AddOrderedInstruction(
  424. const spv_parsed_instruction_t* inst) {
  425. ordered_instructions_.emplace_back(inst);
  426. ordered_instructions_.back().SetLineNum(ordered_instructions_.size());
  427. return &ordered_instructions_.back();
  428. }
  429. // Improves diagnostic messages by collecting names of IDs
  430. void ValidationState_t::RegisterDebugInstruction(const Instruction* inst) {
  431. switch (inst->opcode()) {
  432. case SpvOpName: {
  433. const auto target = inst->GetOperandAs<uint32_t>(0);
  434. const auto* str = reinterpret_cast<const char*>(inst->words().data() +
  435. inst->operand(1).offset);
  436. AssignNameToId(target, str);
  437. break;
  438. }
  439. case SpvOpMemberName: {
  440. const auto target = inst->GetOperandAs<uint32_t>(0);
  441. const auto* str = reinterpret_cast<const char*>(inst->words().data() +
  442. inst->operand(2).offset);
  443. AssignNameToId(target, str);
  444. break;
  445. }
  446. case SpvOpSourceContinued:
  447. case SpvOpSource:
  448. case SpvOpSourceExtension:
  449. case SpvOpString:
  450. case SpvOpLine:
  451. case SpvOpNoLine:
  452. default:
  453. break;
  454. }
  455. }
  456. void ValidationState_t::RegisterInstruction(Instruction* inst) {
  457. if (inst->id()) all_definitions_.insert(std::make_pair(inst->id(), inst));
  458. // Some validation checks are easier by getting all the consumers
  459. for (uint16_t i = 0; i < inst->operands().size(); ++i) {
  460. const spv_parsed_operand_t& operand = inst->operand(i);
  461. if ((SPV_OPERAND_TYPE_ID == operand.type) ||
  462. (SPV_OPERAND_TYPE_TYPE_ID == operand.type)) {
  463. const uint32_t operand_word = inst->word(operand.offset);
  464. Instruction* operand_inst = FindDef(operand_word);
  465. if (!operand_inst) {
  466. continue;
  467. }
  468. // If the instruction is using an OpTypeSampledImage as an operand, it
  469. // should be recorded. The validator will ensure that all usages of an
  470. // OpTypeSampledImage and its definition are in the same basic block.
  471. if ((SPV_OPERAND_TYPE_ID == operand.type) &&
  472. (SpvOpSampledImage == operand_inst->opcode())) {
  473. RegisterSampledImageConsumer(operand_word, inst);
  474. }
  475. // In order to track storage classes (not Function) used per execution
  476. // model we can't use RegisterExecutionModelLimitation on instructions
  477. // like OpTypePointer which are going to be in the pre-function section.
  478. // Instead just need to register storage class usage for consumers in a
  479. // function block.
  480. if (inst->function()) {
  481. if (operand_inst->opcode() == SpvOpTypePointer) {
  482. RegisterStorageClassConsumer(
  483. operand_inst->GetOperandAs<SpvStorageClass>(1), inst);
  484. } else if (operand_inst->opcode() == SpvOpVariable) {
  485. RegisterStorageClassConsumer(
  486. operand_inst->GetOperandAs<SpvStorageClass>(2), inst);
  487. }
  488. }
  489. }
  490. }
  491. }
  492. std::vector<Instruction*> ValidationState_t::getSampledImageConsumers(
  493. uint32_t sampled_image_id) const {
  494. std::vector<Instruction*> result;
  495. auto iter = sampled_image_consumers_.find(sampled_image_id);
  496. if (iter != sampled_image_consumers_.end()) {
  497. result = iter->second;
  498. }
  499. return result;
  500. }
  501. void ValidationState_t::RegisterSampledImageConsumer(uint32_t sampled_image_id,
  502. Instruction* consumer) {
  503. sampled_image_consumers_[sampled_image_id].push_back(consumer);
  504. }
  505. void ValidationState_t::RegisterStorageClassConsumer(
  506. SpvStorageClass storage_class, Instruction* consumer) {
  507. if (spvIsVulkanEnv(context()->target_env)) {
  508. if (storage_class == SpvStorageClassOutput) {
  509. std::string errorVUID = VkErrorID(4644);
  510. function(consumer->function()->id())
  511. ->RegisterExecutionModelLimitation([errorVUID](
  512. SpvExecutionModel model, std::string* message) {
  513. if (model == SpvExecutionModelGLCompute ||
  514. model == SpvExecutionModelRayGenerationKHR ||
  515. model == SpvExecutionModelIntersectionKHR ||
  516. model == SpvExecutionModelAnyHitKHR ||
  517. model == SpvExecutionModelClosestHitKHR ||
  518. model == SpvExecutionModelMissKHR ||
  519. model == SpvExecutionModelCallableKHR) {
  520. if (message) {
  521. *message =
  522. errorVUID +
  523. "in Vulkan evironment, Output Storage Class must not be "
  524. "used in GLCompute, RayGenerationKHR, IntersectionKHR, "
  525. "AnyHitKHR, ClosestHitKHR, MissKHR, or CallableKHR "
  526. "execution models";
  527. }
  528. return false;
  529. }
  530. return true;
  531. });
  532. }
  533. if (storage_class == SpvStorageClassWorkgroup) {
  534. std::string errorVUID = VkErrorID(4645);
  535. function(consumer->function()->id())
  536. ->RegisterExecutionModelLimitation([errorVUID](
  537. SpvExecutionModel model, std::string* message) {
  538. if (model != SpvExecutionModelGLCompute &&
  539. model != SpvExecutionModelTaskNV &&
  540. model != SpvExecutionModelMeshNV) {
  541. if (message) {
  542. *message =
  543. errorVUID +
  544. "in Vulkan evironment, Workgroup Storage Class is limited "
  545. "to MeshNV, TaskNV, and GLCompute execution model";
  546. }
  547. return false;
  548. }
  549. return true;
  550. });
  551. }
  552. }
  553. }
  554. uint32_t ValidationState_t::getIdBound() const { return id_bound_; }
  555. void ValidationState_t::setIdBound(const uint32_t bound) { id_bound_ = bound; }
  556. bool ValidationState_t::RegisterUniqueTypeDeclaration(const Instruction* inst) {
  557. std::vector<uint32_t> key;
  558. key.push_back(static_cast<uint32_t>(inst->opcode()));
  559. for (size_t index = 0; index < inst->operands().size(); ++index) {
  560. const spv_parsed_operand_t& operand = inst->operand(index);
  561. if (operand.type == SPV_OPERAND_TYPE_RESULT_ID) continue;
  562. const int words_begin = operand.offset;
  563. const int words_end = words_begin + operand.num_words;
  564. assert(words_end <= static_cast<int>(inst->words().size()));
  565. key.insert(key.end(), inst->words().begin() + words_begin,
  566. inst->words().begin() + words_end);
  567. }
  568. return unique_type_declarations_.insert(std::move(key)).second;
  569. }
  570. uint32_t ValidationState_t::GetTypeId(uint32_t id) const {
  571. const Instruction* inst = FindDef(id);
  572. return inst ? inst->type_id() : 0;
  573. }
  574. SpvOp ValidationState_t::GetIdOpcode(uint32_t id) const {
  575. const Instruction* inst = FindDef(id);
  576. return inst ? inst->opcode() : SpvOpNop;
  577. }
  578. uint32_t ValidationState_t::GetComponentType(uint32_t id) const {
  579. const Instruction* inst = FindDef(id);
  580. assert(inst);
  581. switch (inst->opcode()) {
  582. case SpvOpTypeFloat:
  583. case SpvOpTypeInt:
  584. case SpvOpTypeBool:
  585. return id;
  586. case SpvOpTypeVector:
  587. return inst->word(2);
  588. case SpvOpTypeMatrix:
  589. return GetComponentType(inst->word(2));
  590. case SpvOpTypeCooperativeMatrixNV:
  591. return inst->word(2);
  592. default:
  593. break;
  594. }
  595. if (inst->type_id()) return GetComponentType(inst->type_id());
  596. assert(0);
  597. return 0;
  598. }
  599. uint32_t ValidationState_t::GetDimension(uint32_t id) const {
  600. const Instruction* inst = FindDef(id);
  601. assert(inst);
  602. switch (inst->opcode()) {
  603. case SpvOpTypeFloat:
  604. case SpvOpTypeInt:
  605. case SpvOpTypeBool:
  606. return 1;
  607. case SpvOpTypeVector:
  608. case SpvOpTypeMatrix:
  609. return inst->word(3);
  610. case SpvOpTypeCooperativeMatrixNV:
  611. // Actual dimension isn't known, return 0
  612. return 0;
  613. default:
  614. break;
  615. }
  616. if (inst->type_id()) return GetDimension(inst->type_id());
  617. assert(0);
  618. return 0;
  619. }
  620. uint32_t ValidationState_t::GetBitWidth(uint32_t id) const {
  621. const uint32_t component_type_id = GetComponentType(id);
  622. const Instruction* inst = FindDef(component_type_id);
  623. assert(inst);
  624. if (inst->opcode() == SpvOpTypeFloat || inst->opcode() == SpvOpTypeInt)
  625. return inst->word(2);
  626. if (inst->opcode() == SpvOpTypeBool) return 1;
  627. assert(0);
  628. return 0;
  629. }
  630. bool ValidationState_t::IsVoidType(uint32_t id) const {
  631. const Instruction* inst = FindDef(id);
  632. assert(inst);
  633. return inst->opcode() == SpvOpTypeVoid;
  634. }
  635. bool ValidationState_t::IsFloatScalarType(uint32_t id) const {
  636. const Instruction* inst = FindDef(id);
  637. assert(inst);
  638. return inst->opcode() == SpvOpTypeFloat;
  639. }
  640. bool ValidationState_t::IsFloatVectorType(uint32_t id) const {
  641. const Instruction* inst = FindDef(id);
  642. assert(inst);
  643. if (inst->opcode() == SpvOpTypeVector) {
  644. return IsFloatScalarType(GetComponentType(id));
  645. }
  646. return false;
  647. }
  648. bool ValidationState_t::IsFloatScalarOrVectorType(uint32_t id) const {
  649. const Instruction* inst = FindDef(id);
  650. assert(inst);
  651. if (inst->opcode() == SpvOpTypeFloat) {
  652. return true;
  653. }
  654. if (inst->opcode() == SpvOpTypeVector) {
  655. return IsFloatScalarType(GetComponentType(id));
  656. }
  657. return false;
  658. }
  659. bool ValidationState_t::IsIntScalarType(uint32_t id) const {
  660. const Instruction* inst = FindDef(id);
  661. assert(inst);
  662. return inst->opcode() == SpvOpTypeInt;
  663. }
  664. bool ValidationState_t::IsIntVectorType(uint32_t id) const {
  665. const Instruction* inst = FindDef(id);
  666. assert(inst);
  667. if (inst->opcode() == SpvOpTypeVector) {
  668. return IsIntScalarType(GetComponentType(id));
  669. }
  670. return false;
  671. }
  672. bool ValidationState_t::IsIntScalarOrVectorType(uint32_t id) const {
  673. const Instruction* inst = FindDef(id);
  674. assert(inst);
  675. if (inst->opcode() == SpvOpTypeInt) {
  676. return true;
  677. }
  678. if (inst->opcode() == SpvOpTypeVector) {
  679. return IsIntScalarType(GetComponentType(id));
  680. }
  681. return false;
  682. }
  683. bool ValidationState_t::IsUnsignedIntScalarType(uint32_t id) const {
  684. const Instruction* inst = FindDef(id);
  685. assert(inst);
  686. return inst->opcode() == SpvOpTypeInt && inst->word(3) == 0;
  687. }
  688. bool ValidationState_t::IsUnsignedIntVectorType(uint32_t id) const {
  689. const Instruction* inst = FindDef(id);
  690. assert(inst);
  691. if (inst->opcode() == SpvOpTypeVector) {
  692. return IsUnsignedIntScalarType(GetComponentType(id));
  693. }
  694. return false;
  695. }
  696. bool ValidationState_t::IsSignedIntScalarType(uint32_t id) const {
  697. const Instruction* inst = FindDef(id);
  698. assert(inst);
  699. return inst->opcode() == SpvOpTypeInt && inst->word(3) == 1;
  700. }
  701. bool ValidationState_t::IsSignedIntVectorType(uint32_t id) const {
  702. const Instruction* inst = FindDef(id);
  703. assert(inst);
  704. if (inst->opcode() == SpvOpTypeVector) {
  705. return IsSignedIntScalarType(GetComponentType(id));
  706. }
  707. return false;
  708. }
  709. bool ValidationState_t::IsBoolScalarType(uint32_t id) const {
  710. const Instruction* inst = FindDef(id);
  711. assert(inst);
  712. return inst->opcode() == SpvOpTypeBool;
  713. }
  714. bool ValidationState_t::IsBoolVectorType(uint32_t id) const {
  715. const Instruction* inst = FindDef(id);
  716. assert(inst);
  717. if (inst->opcode() == SpvOpTypeVector) {
  718. return IsBoolScalarType(GetComponentType(id));
  719. }
  720. return false;
  721. }
  722. bool ValidationState_t::IsBoolScalarOrVectorType(uint32_t id) const {
  723. const Instruction* inst = FindDef(id);
  724. assert(inst);
  725. if (inst->opcode() == SpvOpTypeBool) {
  726. return true;
  727. }
  728. if (inst->opcode() == SpvOpTypeVector) {
  729. return IsBoolScalarType(GetComponentType(id));
  730. }
  731. return false;
  732. }
  733. bool ValidationState_t::IsFloatMatrixType(uint32_t id) const {
  734. const Instruction* inst = FindDef(id);
  735. assert(inst);
  736. if (inst->opcode() == SpvOpTypeMatrix) {
  737. return IsFloatScalarType(GetComponentType(id));
  738. }
  739. return false;
  740. }
  741. bool ValidationState_t::GetMatrixTypeInfo(uint32_t id, uint32_t* num_rows,
  742. uint32_t* num_cols,
  743. uint32_t* column_type,
  744. uint32_t* component_type) const {
  745. if (!id) return false;
  746. const Instruction* mat_inst = FindDef(id);
  747. assert(mat_inst);
  748. if (mat_inst->opcode() != SpvOpTypeMatrix) return false;
  749. const uint32_t vec_type = mat_inst->word(2);
  750. const Instruction* vec_inst = FindDef(vec_type);
  751. assert(vec_inst);
  752. if (vec_inst->opcode() != SpvOpTypeVector) {
  753. assert(0);
  754. return false;
  755. }
  756. *num_cols = mat_inst->word(3);
  757. *num_rows = vec_inst->word(3);
  758. *column_type = mat_inst->word(2);
  759. *component_type = vec_inst->word(2);
  760. return true;
  761. }
  762. bool ValidationState_t::GetStructMemberTypes(
  763. uint32_t struct_type_id, std::vector<uint32_t>* member_types) const {
  764. member_types->clear();
  765. if (!struct_type_id) return false;
  766. const Instruction* inst = FindDef(struct_type_id);
  767. assert(inst);
  768. if (inst->opcode() != SpvOpTypeStruct) return false;
  769. *member_types =
  770. std::vector<uint32_t>(inst->words().cbegin() + 2, inst->words().cend());
  771. if (member_types->empty()) return false;
  772. return true;
  773. }
  774. bool ValidationState_t::IsPointerType(uint32_t id) const {
  775. const Instruction* inst = FindDef(id);
  776. assert(inst);
  777. return inst->opcode() == SpvOpTypePointer;
  778. }
  779. bool ValidationState_t::GetPointerTypeInfo(uint32_t id, uint32_t* data_type,
  780. uint32_t* storage_class) const {
  781. if (!id) return false;
  782. const Instruction* inst = FindDef(id);
  783. assert(inst);
  784. if (inst->opcode() != SpvOpTypePointer) return false;
  785. *storage_class = inst->word(2);
  786. *data_type = inst->word(3);
  787. return true;
  788. }
  789. bool ValidationState_t::IsCooperativeMatrixType(uint32_t id) const {
  790. const Instruction* inst = FindDef(id);
  791. assert(inst);
  792. return inst->opcode() == SpvOpTypeCooperativeMatrixNV;
  793. }
  794. bool ValidationState_t::IsFloatCooperativeMatrixType(uint32_t id) const {
  795. if (!IsCooperativeMatrixType(id)) return false;
  796. return IsFloatScalarType(FindDef(id)->word(2));
  797. }
  798. bool ValidationState_t::IsIntCooperativeMatrixType(uint32_t id) const {
  799. if (!IsCooperativeMatrixType(id)) return false;
  800. return IsIntScalarType(FindDef(id)->word(2));
  801. }
  802. bool ValidationState_t::IsUnsignedIntCooperativeMatrixType(uint32_t id) const {
  803. if (!IsCooperativeMatrixType(id)) return false;
  804. return IsUnsignedIntScalarType(FindDef(id)->word(2));
  805. }
  806. spv_result_t ValidationState_t::CooperativeMatrixShapesMatch(
  807. const Instruction* inst, uint32_t m1, uint32_t m2) {
  808. const auto m1_type = FindDef(m1);
  809. const auto m2_type = FindDef(m2);
  810. if (m1_type->opcode() != SpvOpTypeCooperativeMatrixNV ||
  811. m2_type->opcode() != SpvOpTypeCooperativeMatrixNV) {
  812. return diag(SPV_ERROR_INVALID_DATA, inst)
  813. << "Expected cooperative matrix types";
  814. }
  815. uint32_t m1_scope_id = m1_type->GetOperandAs<uint32_t>(2);
  816. uint32_t m1_rows_id = m1_type->GetOperandAs<uint32_t>(3);
  817. uint32_t m1_cols_id = m1_type->GetOperandAs<uint32_t>(4);
  818. uint32_t m2_scope_id = m2_type->GetOperandAs<uint32_t>(2);
  819. uint32_t m2_rows_id = m2_type->GetOperandAs<uint32_t>(3);
  820. uint32_t m2_cols_id = m2_type->GetOperandAs<uint32_t>(4);
  821. bool m1_is_int32 = false, m1_is_const_int32 = false, m2_is_int32 = false,
  822. m2_is_const_int32 = false;
  823. uint32_t m1_value = 0, m2_value = 0;
  824. std::tie(m1_is_int32, m1_is_const_int32, m1_value) =
  825. EvalInt32IfConst(m1_scope_id);
  826. std::tie(m2_is_int32, m2_is_const_int32, m2_value) =
  827. EvalInt32IfConst(m2_scope_id);
  828. if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value) {
  829. return diag(SPV_ERROR_INVALID_DATA, inst)
  830. << "Expected scopes of Matrix and Result Type to be "
  831. << "identical";
  832. }
  833. std::tie(m1_is_int32, m1_is_const_int32, m1_value) =
  834. EvalInt32IfConst(m1_rows_id);
  835. std::tie(m2_is_int32, m2_is_const_int32, m2_value) =
  836. EvalInt32IfConst(m2_rows_id);
  837. if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value) {
  838. return diag(SPV_ERROR_INVALID_DATA, inst)
  839. << "Expected rows of Matrix type and Result Type to be "
  840. << "identical";
  841. }
  842. std::tie(m1_is_int32, m1_is_const_int32, m1_value) =
  843. EvalInt32IfConst(m1_cols_id);
  844. std::tie(m2_is_int32, m2_is_const_int32, m2_value) =
  845. EvalInt32IfConst(m2_cols_id);
  846. if (m1_is_const_int32 && m2_is_const_int32 && m1_value != m2_value) {
  847. return diag(SPV_ERROR_INVALID_DATA, inst)
  848. << "Expected columns of Matrix type and Result Type to be "
  849. << "identical";
  850. }
  851. return SPV_SUCCESS;
  852. }
  853. uint32_t ValidationState_t::GetOperandTypeId(const Instruction* inst,
  854. size_t operand_index) const {
  855. return GetTypeId(inst->GetOperandAs<uint32_t>(operand_index));
  856. }
  857. bool ValidationState_t::GetConstantValUint64(uint32_t id, uint64_t* val) const {
  858. const Instruction* inst = FindDef(id);
  859. if (!inst) {
  860. assert(0 && "Instruction not found");
  861. return false;
  862. }
  863. if (inst->opcode() != SpvOpConstant && inst->opcode() != SpvOpSpecConstant)
  864. return false;
  865. if (!IsIntScalarType(inst->type_id())) return false;
  866. if (inst->words().size() == 4) {
  867. *val = inst->word(3);
  868. } else {
  869. assert(inst->words().size() == 5);
  870. *val = inst->word(3);
  871. *val |= uint64_t(inst->word(4)) << 32;
  872. }
  873. return true;
  874. }
  875. std::tuple<bool, bool, uint32_t> ValidationState_t::EvalInt32IfConst(
  876. uint32_t id) const {
  877. const Instruction* const inst = FindDef(id);
  878. assert(inst);
  879. const uint32_t type = inst->type_id();
  880. if (type == 0 || !IsIntScalarType(type) || GetBitWidth(type) != 32) {
  881. return std::make_tuple(false, false, 0);
  882. }
  883. // Spec constant values cannot be evaluated so don't consider constant for
  884. // the purpose of this method.
  885. if (!spvOpcodeIsConstant(inst->opcode()) ||
  886. spvOpcodeIsSpecConstant(inst->opcode())) {
  887. return std::make_tuple(true, false, 0);
  888. }
  889. if (inst->opcode() == SpvOpConstantNull) {
  890. return std::make_tuple(true, true, 0);
  891. }
  892. assert(inst->words().size() == 4);
  893. return std::make_tuple(true, true, inst->word(3));
  894. }
  895. void ValidationState_t::ComputeFunctionToEntryPointMapping() {
  896. for (const uint32_t entry_point : entry_points()) {
  897. std::stack<uint32_t> call_stack;
  898. std::set<uint32_t> visited;
  899. call_stack.push(entry_point);
  900. while (!call_stack.empty()) {
  901. const uint32_t called_func_id = call_stack.top();
  902. call_stack.pop();
  903. if (!visited.insert(called_func_id).second) continue;
  904. function_to_entry_points_[called_func_id].push_back(entry_point);
  905. const Function* called_func = function(called_func_id);
  906. if (called_func) {
  907. // Other checks should error out on this invalid SPIR-V.
  908. for (const uint32_t new_call : called_func->function_call_targets()) {
  909. call_stack.push(new_call);
  910. }
  911. }
  912. }
  913. }
  914. }
  915. void ValidationState_t::ComputeRecursiveEntryPoints() {
  916. for (const Function& func : functions()) {
  917. std::stack<uint32_t> call_stack;
  918. std::set<uint32_t> visited;
  919. for (const uint32_t new_call : func.function_call_targets()) {
  920. call_stack.push(new_call);
  921. }
  922. while (!call_stack.empty()) {
  923. const uint32_t called_func_id = call_stack.top();
  924. call_stack.pop();
  925. if (!visited.insert(called_func_id).second) continue;
  926. if (called_func_id == func.id()) {
  927. for (const uint32_t entry_point :
  928. function_to_entry_points_[called_func_id])
  929. recursive_entry_points_.insert(entry_point);
  930. break;
  931. }
  932. const Function* called_func = function(called_func_id);
  933. if (called_func) {
  934. // Other checks should error out on this invalid SPIR-V.
  935. for (const uint32_t new_call : called_func->function_call_targets()) {
  936. call_stack.push(new_call);
  937. }
  938. }
  939. }
  940. }
  941. }
  942. const std::vector<uint32_t>& ValidationState_t::FunctionEntryPoints(
  943. uint32_t func) const {
  944. auto iter = function_to_entry_points_.find(func);
  945. if (iter == function_to_entry_points_.end()) {
  946. return empty_ids_;
  947. } else {
  948. return iter->second;
  949. }
  950. }
  951. std::set<uint32_t> ValidationState_t::EntryPointReferences(uint32_t id) const {
  952. std::set<uint32_t> referenced_entry_points;
  953. const auto inst = FindDef(id);
  954. if (!inst) return referenced_entry_points;
  955. std::vector<const Instruction*> stack;
  956. stack.push_back(inst);
  957. while (!stack.empty()) {
  958. const auto current_inst = stack.back();
  959. stack.pop_back();
  960. if (const auto func = current_inst->function()) {
  961. // Instruction lives in a function, we can stop searching.
  962. const auto function_entry_points = FunctionEntryPoints(func->id());
  963. referenced_entry_points.insert(function_entry_points.begin(),
  964. function_entry_points.end());
  965. } else {
  966. // Instruction is in the global scope, keep searching its uses.
  967. for (auto pair : current_inst->uses()) {
  968. const auto next_inst = pair.first;
  969. stack.push_back(next_inst);
  970. }
  971. }
  972. }
  973. return referenced_entry_points;
  974. }
  975. std::string ValidationState_t::Disassemble(const Instruction& inst) const {
  976. const spv_parsed_instruction_t& c_inst(inst.c_inst());
  977. return Disassemble(c_inst.words, c_inst.num_words);
  978. }
  979. std::string ValidationState_t::Disassemble(const uint32_t* words,
  980. uint16_t num_words) const {
  981. uint32_t disassembly_options = SPV_BINARY_TO_TEXT_OPTION_NO_HEADER |
  982. SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
  983. return spvInstructionBinaryToText(context()->target_env, words, num_words,
  984. words_, num_words_, disassembly_options);
  985. }
  986. bool ValidationState_t::LogicallyMatch(const Instruction* lhs,
  987. const Instruction* rhs,
  988. bool check_decorations) {
  989. if (lhs->opcode() != rhs->opcode()) {
  990. return false;
  991. }
  992. if (check_decorations) {
  993. const auto& dec_a = id_decorations(lhs->id());
  994. const auto& dec_b = id_decorations(rhs->id());
  995. for (const auto& dec : dec_b) {
  996. if (std::find(dec_a.begin(), dec_a.end(), dec) == dec_a.end()) {
  997. return false;
  998. }
  999. }
  1000. }
  1001. if (lhs->opcode() == SpvOpTypeArray) {
  1002. // Size operands must match.
  1003. if (lhs->GetOperandAs<uint32_t>(2u) != rhs->GetOperandAs<uint32_t>(2u)) {
  1004. return false;
  1005. }
  1006. // Elements must match or logically match.
  1007. const auto lhs_ele_id = lhs->GetOperandAs<uint32_t>(1u);
  1008. const auto rhs_ele_id = rhs->GetOperandAs<uint32_t>(1u);
  1009. if (lhs_ele_id == rhs_ele_id) {
  1010. return true;
  1011. }
  1012. const auto lhs_ele = FindDef(lhs_ele_id);
  1013. const auto rhs_ele = FindDef(rhs_ele_id);
  1014. if (!lhs_ele || !rhs_ele) {
  1015. return false;
  1016. }
  1017. return LogicallyMatch(lhs_ele, rhs_ele, check_decorations);
  1018. } else if (lhs->opcode() == SpvOpTypeStruct) {
  1019. // Number of elements must match.
  1020. if (lhs->operands().size() != rhs->operands().size()) {
  1021. return false;
  1022. }
  1023. for (size_t i = 1u; i < lhs->operands().size(); ++i) {
  1024. const auto lhs_ele_id = lhs->GetOperandAs<uint32_t>(i);
  1025. const auto rhs_ele_id = rhs->GetOperandAs<uint32_t>(i);
  1026. // Elements must match or logically match.
  1027. if (lhs_ele_id == rhs_ele_id) {
  1028. continue;
  1029. }
  1030. const auto lhs_ele = FindDef(lhs_ele_id);
  1031. const auto rhs_ele = FindDef(rhs_ele_id);
  1032. if (!lhs_ele || !rhs_ele) {
  1033. return false;
  1034. }
  1035. if (!LogicallyMatch(lhs_ele, rhs_ele, check_decorations)) {
  1036. return false;
  1037. }
  1038. }
  1039. // All checks passed.
  1040. return true;
  1041. }
  1042. // No other opcodes are acceptable at this point. Arrays and structs are
  1043. // caught above and if they're elements are not arrays or structs they are
  1044. // required to match exactly.
  1045. return false;
  1046. }
  1047. const Instruction* ValidationState_t::TracePointer(
  1048. const Instruction* inst) const {
  1049. auto base_ptr = inst;
  1050. while (base_ptr->opcode() == SpvOpAccessChain ||
  1051. base_ptr->opcode() == SpvOpInBoundsAccessChain ||
  1052. base_ptr->opcode() == SpvOpPtrAccessChain ||
  1053. base_ptr->opcode() == SpvOpInBoundsPtrAccessChain ||
  1054. base_ptr->opcode() == SpvOpCopyObject) {
  1055. base_ptr = FindDef(base_ptr->GetOperandAs<uint32_t>(2u));
  1056. }
  1057. return base_ptr;
  1058. }
  1059. bool ValidationState_t::ContainsSizedIntOrFloatType(uint32_t id, SpvOp type,
  1060. uint32_t width) const {
  1061. if (type != SpvOpTypeInt && type != SpvOpTypeFloat) return false;
  1062. const auto inst = FindDef(id);
  1063. if (!inst) return false;
  1064. if (inst->opcode() == type) {
  1065. return inst->GetOperandAs<uint32_t>(1u) == width;
  1066. }
  1067. switch (inst->opcode()) {
  1068. case SpvOpTypeArray:
  1069. case SpvOpTypeRuntimeArray:
  1070. case SpvOpTypeVector:
  1071. case SpvOpTypeMatrix:
  1072. case SpvOpTypeImage:
  1073. case SpvOpTypeSampledImage:
  1074. case SpvOpTypeCooperativeMatrixNV:
  1075. return ContainsSizedIntOrFloatType(inst->GetOperandAs<uint32_t>(1u), type,
  1076. width);
  1077. case SpvOpTypePointer:
  1078. if (IsForwardPointer(id)) return false;
  1079. return ContainsSizedIntOrFloatType(inst->GetOperandAs<uint32_t>(2u), type,
  1080. width);
  1081. case SpvOpTypeFunction:
  1082. case SpvOpTypeStruct: {
  1083. for (uint32_t i = 1; i < inst->operands().size(); ++i) {
  1084. if (ContainsSizedIntOrFloatType(inst->GetOperandAs<uint32_t>(i), type,
  1085. width))
  1086. return true;
  1087. }
  1088. return false;
  1089. }
  1090. default:
  1091. return false;
  1092. }
  1093. }
  1094. bool ValidationState_t::ContainsLimitedUseIntOrFloatType(uint32_t id) const {
  1095. if ((!HasCapability(SpvCapabilityInt16) &&
  1096. ContainsSizedIntOrFloatType(id, SpvOpTypeInt, 16)) ||
  1097. (!HasCapability(SpvCapabilityInt8) &&
  1098. ContainsSizedIntOrFloatType(id, SpvOpTypeInt, 8)) ||
  1099. (!HasCapability(SpvCapabilityFloat16) &&
  1100. ContainsSizedIntOrFloatType(id, SpvOpTypeFloat, 16))) {
  1101. return true;
  1102. }
  1103. return false;
  1104. }
  1105. bool ValidationState_t::IsValidStorageClass(
  1106. SpvStorageClass storage_class) const {
  1107. if (spvIsVulkanEnv(context()->target_env)) {
  1108. switch (storage_class) {
  1109. case SpvStorageClassUniformConstant:
  1110. case SpvStorageClassUniform:
  1111. case SpvStorageClassStorageBuffer:
  1112. case SpvStorageClassInput:
  1113. case SpvStorageClassOutput:
  1114. case SpvStorageClassImage:
  1115. case SpvStorageClassWorkgroup:
  1116. case SpvStorageClassPrivate:
  1117. case SpvStorageClassFunction:
  1118. case SpvStorageClassPushConstant:
  1119. case SpvStorageClassPhysicalStorageBuffer:
  1120. case SpvStorageClassRayPayloadKHR:
  1121. case SpvStorageClassIncomingRayPayloadKHR:
  1122. case SpvStorageClassHitAttributeKHR:
  1123. case SpvStorageClassCallableDataKHR:
  1124. case SpvStorageClassIncomingCallableDataKHR:
  1125. case SpvStorageClassShaderRecordBufferKHR:
  1126. return true;
  1127. default:
  1128. return false;
  1129. }
  1130. }
  1131. return true;
  1132. }
  1133. #define VUID_WRAP(vuid) "[" #vuid "] "
  1134. // Currently no 2 VUID share the same id, so no need for |reference|
  1135. std::string ValidationState_t::VkErrorID(uint32_t id,
  1136. const char* /*reference*/) const {
  1137. if (!spvIsVulkanEnv(context_->target_env)) {
  1138. return "";
  1139. }
  1140. // This large switch case is only searched when an error has occured.
  1141. // If an id is changed, the old case must be modified or removed. Each string
  1142. // here is interpreted as being "implemented"
  1143. // Clang format adds spaces between hyphens
  1144. // clang-format off
  1145. switch (id) {
  1146. case 4181:
  1147. return VUID_WRAP(VUID-BaseInstance-BaseInstance-04181);
  1148. case 4182:
  1149. return VUID_WRAP(VUID-BaseInstance-BaseInstance-04182);
  1150. case 4183:
  1151. return VUID_WRAP(VUID-BaseInstance-BaseInstance-04183);
  1152. case 4184:
  1153. return VUID_WRAP(VUID-BaseVertex-BaseVertex-04184);
  1154. case 4185:
  1155. return VUID_WRAP(VUID-BaseVertex-BaseVertex-04185);
  1156. case 4186:
  1157. return VUID_WRAP(VUID-BaseVertex-BaseVertex-04186);
  1158. case 4187:
  1159. return VUID_WRAP(VUID-ClipDistance-ClipDistance-04187);
  1160. case 4188:
  1161. return VUID_WRAP(VUID-ClipDistance-ClipDistance-04188);
  1162. case 4189:
  1163. return VUID_WRAP(VUID-ClipDistance-ClipDistance-04189);
  1164. case 4190:
  1165. return VUID_WRAP(VUID-ClipDistance-ClipDistance-04190);
  1166. case 4191:
  1167. return VUID_WRAP(VUID-ClipDistance-ClipDistance-04191);
  1168. case 4196:
  1169. return VUID_WRAP(VUID-CullDistance-CullDistance-04196);
  1170. case 4197:
  1171. return VUID_WRAP(VUID-CullDistance-CullDistance-04197);
  1172. case 4198:
  1173. return VUID_WRAP(VUID-CullDistance-CullDistance-04198);
  1174. case 4199:
  1175. return VUID_WRAP(VUID-CullDistance-CullDistance-04199);
  1176. case 4200:
  1177. return VUID_WRAP(VUID-CullDistance-CullDistance-04200);
  1178. case 4205:
  1179. return VUID_WRAP(VUID-DeviceIndex-DeviceIndex-04205);
  1180. case 4206:
  1181. return VUID_WRAP(VUID-DeviceIndex-DeviceIndex-04206);
  1182. case 4207:
  1183. return VUID_WRAP(VUID-DrawIndex-DrawIndex-04207);
  1184. case 4208:
  1185. return VUID_WRAP(VUID-DrawIndex-DrawIndex-04208);
  1186. case 4209:
  1187. return VUID_WRAP(VUID-DrawIndex-DrawIndex-04209);
  1188. case 4210:
  1189. return VUID_WRAP(VUID-FragCoord-FragCoord-04210);
  1190. case 4211:
  1191. return VUID_WRAP(VUID-FragCoord-FragCoord-04211);
  1192. case 4212:
  1193. return VUID_WRAP(VUID-FragCoord-FragCoord-04212);
  1194. case 4213:
  1195. return VUID_WRAP(VUID-FragDepth-FragDepth-04213);
  1196. case 4214:
  1197. return VUID_WRAP(VUID-FragDepth-FragDepth-04214);
  1198. case 4215:
  1199. return VUID_WRAP(VUID-FragDepth-FragDepth-04215);
  1200. case 4216:
  1201. return VUID_WRAP(VUID-FragDepth-FragDepth-04216);
  1202. case 4217:
  1203. return VUID_WRAP(VUID-FragInvocationCountEXT-FragInvocationCountEXT-04217);
  1204. case 4218:
  1205. return VUID_WRAP(VUID-FragInvocationCountEXT-FragInvocationCountEXT-04218);
  1206. case 4219:
  1207. return VUID_WRAP(VUID-FragInvocationCountEXT-FragInvocationCountEXT-04219);
  1208. case 4220:
  1209. return VUID_WRAP(VUID-FragSizeEXT-FragSizeEXT-04220);
  1210. case 4221:
  1211. return VUID_WRAP(VUID-FragSizeEXT-FragSizeEXT-04221);
  1212. case 4222:
  1213. return VUID_WRAP(VUID-FragSizeEXT-FragSizeEXT-04222);
  1214. case 4223:
  1215. return VUID_WRAP(VUID-FragStencilRefEXT-FragStencilRefEXT-04223);
  1216. case 4224:
  1217. return VUID_WRAP(VUID-FragStencilRefEXT-FragStencilRefEXT-04224);
  1218. case 4225:
  1219. return VUID_WRAP(VUID-FragStencilRefEXT-FragStencilRefEXT-04225);
  1220. case 4229:
  1221. return VUID_WRAP(VUID-FrontFacing-FrontFacing-04229);
  1222. case 4230:
  1223. return VUID_WRAP(VUID-FrontFacing-FrontFacing-04230);
  1224. case 4231:
  1225. return VUID_WRAP(VUID-FrontFacing-FrontFacing-04231);
  1226. case 4232:
  1227. return VUID_WRAP(VUID-FullyCoveredEXT-FullyCoveredEXT-04232);
  1228. case 4233:
  1229. return VUID_WRAP(VUID-FullyCoveredEXT-FullyCoveredEXT-04233);
  1230. case 4234:
  1231. return VUID_WRAP(VUID-FullyCoveredEXT-FullyCoveredEXT-04234);
  1232. case 4236:
  1233. return VUID_WRAP(VUID-GlobalInvocationId-GlobalInvocationId-04236);
  1234. case 4237:
  1235. return VUID_WRAP(VUID-GlobalInvocationId-GlobalInvocationId-04237);
  1236. case 4238:
  1237. return VUID_WRAP(VUID-GlobalInvocationId-GlobalInvocationId-04238);
  1238. case 4239:
  1239. return VUID_WRAP(VUID-HelperInvocation-HelperInvocation-04239);
  1240. case 4240:
  1241. return VUID_WRAP(VUID-HelperInvocation-HelperInvocation-04240);
  1242. case 4241:
  1243. return VUID_WRAP(VUID-HelperInvocation-HelperInvocation-04241);
  1244. case 4242:
  1245. return VUID_WRAP(VUID-HitKindKHR-HitKindKHR-04242);
  1246. case 4243:
  1247. return VUID_WRAP(VUID-HitKindKHR-HitKindKHR-04243);
  1248. case 4244:
  1249. return VUID_WRAP(VUID-HitKindKHR-HitKindKHR-04244);
  1250. case 4245:
  1251. return VUID_WRAP(VUID-HitTNV-HitTNV-04245);
  1252. case 4246:
  1253. return VUID_WRAP(VUID-HitTNV-HitTNV-04246);
  1254. case 4247:
  1255. return VUID_WRAP(VUID-HitTNV-HitTNV-04247);
  1256. case 4248:
  1257. return VUID_WRAP(VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04248);
  1258. case 4249:
  1259. return VUID_WRAP(VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04249);
  1260. case 4250:
  1261. return VUID_WRAP(VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04250);
  1262. case 4251:
  1263. return VUID_WRAP(VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04251);
  1264. case 4252:
  1265. return VUID_WRAP(VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04252);
  1266. case 4253:
  1267. return VUID_WRAP(VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04253);
  1268. case 4254:
  1269. return VUID_WRAP(VUID-InstanceId-InstanceId-04254);
  1270. case 4255:
  1271. return VUID_WRAP(VUID-InstanceId-InstanceId-04255);
  1272. case 4256:
  1273. return VUID_WRAP(VUID-InstanceId-InstanceId-04256);
  1274. case 4257:
  1275. return VUID_WRAP(VUID-InvocationId-InvocationId-04257);
  1276. case 4258:
  1277. return VUID_WRAP(VUID-InvocationId-InvocationId-04258);
  1278. case 4259:
  1279. return VUID_WRAP(VUID-InvocationId-InvocationId-04259);
  1280. case 4263:
  1281. return VUID_WRAP(VUID-InstanceIndex-InstanceIndex-04263);
  1282. case 4264:
  1283. return VUID_WRAP(VUID-InstanceIndex-InstanceIndex-04264);
  1284. case 4265:
  1285. return VUID_WRAP(VUID-InstanceIndex-InstanceIndex-04265);
  1286. case 4266:
  1287. return VUID_WRAP(VUID-LaunchIdKHR-LaunchIdKHR-04266);
  1288. case 4267:
  1289. return VUID_WRAP(VUID-LaunchIdKHR-LaunchIdKHR-04267);
  1290. case 4268:
  1291. return VUID_WRAP(VUID-LaunchIdKHR-LaunchIdKHR-04268);
  1292. case 4269:
  1293. return VUID_WRAP(VUID-LaunchSizeKHR-LaunchSizeKHR-04269);
  1294. case 4270:
  1295. return VUID_WRAP(VUID-LaunchSizeKHR-LaunchSizeKHR-04270);
  1296. case 4271:
  1297. return VUID_WRAP(VUID-LaunchSizeKHR-LaunchSizeKHR-04271);
  1298. case 4272:
  1299. return VUID_WRAP(VUID-Layer-Layer-04272);
  1300. case 4273:
  1301. return VUID_WRAP(VUID-Layer-Layer-04273);
  1302. case 4274:
  1303. return VUID_WRAP(VUID-Layer-Layer-04274);
  1304. case 4275:
  1305. return VUID_WRAP(VUID-Layer-Layer-04275);
  1306. case 4276:
  1307. return VUID_WRAP(VUID-Layer-Layer-04276);
  1308. case 4281:
  1309. return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04281);
  1310. case 4282:
  1311. return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04282);
  1312. case 4283:
  1313. return VUID_WRAP(VUID-LocalInvocationId-LocalInvocationId-04283);
  1314. case 4293:
  1315. return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04293);
  1316. case 4294:
  1317. return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04294);
  1318. case 4295:
  1319. return VUID_WRAP(VUID-NumSubgroups-NumSubgroups-04295);
  1320. case 4296:
  1321. return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04296);
  1322. case 4297:
  1323. return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04297);
  1324. case 4298:
  1325. return VUID_WRAP(VUID-NumWorkgroups-NumWorkgroups-04298);
  1326. case 4299:
  1327. return VUID_WRAP(VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04299);
  1328. case 4300:
  1329. return VUID_WRAP(VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04300);
  1330. case 4301:
  1331. return VUID_WRAP(VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04301);
  1332. case 4302:
  1333. return VUID_WRAP(VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04302);
  1334. case 4303:
  1335. return VUID_WRAP(VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04303);
  1336. case 4304:
  1337. return VUID_WRAP(VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04304);
  1338. case 4305:
  1339. return VUID_WRAP(VUID-ObjectToWorldKHR-ObjectToWorldKHR-04305);
  1340. case 4306:
  1341. return VUID_WRAP(VUID-ObjectToWorldKHR-ObjectToWorldKHR-04306);
  1342. case 4307:
  1343. return VUID_WRAP(VUID-ObjectToWorldKHR-ObjectToWorldKHR-04307);
  1344. case 4308:
  1345. return VUID_WRAP(VUID-PatchVertices-PatchVertices-04308);
  1346. case 4309:
  1347. return VUID_WRAP(VUID-PatchVertices-PatchVertices-04309);
  1348. case 4310:
  1349. return VUID_WRAP(VUID-PatchVertices-PatchVertices-04310);
  1350. case 4311:
  1351. return VUID_WRAP(VUID-PointCoord-PointCoord-04311);
  1352. case 4312:
  1353. return VUID_WRAP(VUID-PointCoord-PointCoord-04312);
  1354. case 4313:
  1355. return VUID_WRAP(VUID-PointCoord-PointCoord-04313);
  1356. case 4314:
  1357. return VUID_WRAP(VUID-PointSize-PointSize-04314);
  1358. case 4315:
  1359. return VUID_WRAP(VUID-PointSize-PointSize-04315);
  1360. case 4316:
  1361. return VUID_WRAP(VUID-PointSize-PointSize-04316);
  1362. case 4317:
  1363. return VUID_WRAP(VUID-PointSize-PointSize-04317);
  1364. case 4318:
  1365. return VUID_WRAP(VUID-Position-Position-04318);
  1366. case 4319:
  1367. return VUID_WRAP(VUID-Position-Position-04319);
  1368. case 4320:
  1369. return VUID_WRAP(VUID-Position-Position-04320);
  1370. case 4321:
  1371. return VUID_WRAP(VUID-Position-Position-04321);
  1372. case 4330:
  1373. return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04330);
  1374. case 4334:
  1375. return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04334);
  1376. case 4337:
  1377. return VUID_WRAP(VUID-PrimitiveId-PrimitiveId-04337);
  1378. case 4345:
  1379. return VUID_WRAP(VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04345);
  1380. case 4346:
  1381. return VUID_WRAP(VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04346);
  1382. case 4347:
  1383. return VUID_WRAP(VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04347);
  1384. case 4348:
  1385. return VUID_WRAP(VUID-RayTmaxKHR-RayTmaxKHR-04348);
  1386. case 4349:
  1387. return VUID_WRAP(VUID-RayTmaxKHR-RayTmaxKHR-04349);
  1388. case 4350:
  1389. return VUID_WRAP(VUID-RayTmaxKHR-RayTmaxKHR-04350);
  1390. case 4351:
  1391. return VUID_WRAP(VUID-RayTminKHR-RayTminKHR-04351);
  1392. case 4352:
  1393. return VUID_WRAP(VUID-RayTminKHR-RayTminKHR-04352);
  1394. case 4353:
  1395. return VUID_WRAP(VUID-RayTminKHR-RayTminKHR-04353);
  1396. case 4354:
  1397. return VUID_WRAP(VUID-SampleId-SampleId-04354);
  1398. case 4355:
  1399. return VUID_WRAP(VUID-SampleId-SampleId-04355);
  1400. case 4356:
  1401. return VUID_WRAP(VUID-SampleId-SampleId-04356);
  1402. case 4357:
  1403. return VUID_WRAP(VUID-SampleMask-SampleMask-04357);
  1404. case 4358:
  1405. return VUID_WRAP(VUID-SampleMask-SampleMask-04358);
  1406. case 4359:
  1407. return VUID_WRAP(VUID-SampleMask-SampleMask-04359);
  1408. case 4360:
  1409. return VUID_WRAP(VUID-SamplePosition-SamplePosition-04360);
  1410. case 4361:
  1411. return VUID_WRAP(VUID-SamplePosition-SamplePosition-04361);
  1412. case 4362:
  1413. return VUID_WRAP(VUID-SamplePosition-SamplePosition-04362);
  1414. case 4367:
  1415. return VUID_WRAP(VUID-SubgroupId-SubgroupId-04367);
  1416. case 4368:
  1417. return VUID_WRAP(VUID-SubgroupId-SubgroupId-04368);
  1418. case 4369:
  1419. return VUID_WRAP(VUID-SubgroupId-SubgroupId-04369);
  1420. case 4370:
  1421. return VUID_WRAP(VUID-SubgroupEqMask-SubgroupEqMask-04370);
  1422. case 4371:
  1423. return VUID_WRAP(VUID-SubgroupEqMask-SubgroupEqMask-04371);
  1424. case 4372:
  1425. return VUID_WRAP(VUID-SubgroupGeMask-SubgroupGeMask-04372);
  1426. case 4373:
  1427. return VUID_WRAP(VUID-SubgroupGeMask-SubgroupGeMask-04373);
  1428. case 4374:
  1429. return VUID_WRAP(VUID-SubgroupGtMask-SubgroupGtMask-04374);
  1430. case 4375:
  1431. return VUID_WRAP(VUID-SubgroupGtMask-SubgroupGtMask-04375);
  1432. case 4376:
  1433. return VUID_WRAP(VUID-SubgroupLeMask-SubgroupLeMask-04376);
  1434. case 4377:
  1435. return VUID_WRAP(VUID-SubgroupLeMask-SubgroupLeMask-04377);
  1436. case 4378:
  1437. return VUID_WRAP(VUID-SubgroupLtMask-SubgroupLtMask-04378);
  1438. case 4379:
  1439. return VUID_WRAP(VUID-SubgroupLtMask-SubgroupLtMask-04379);
  1440. case 4380:
  1441. return VUID_WRAP(VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-04380);
  1442. case 4381:
  1443. return VUID_WRAP(VUID-SubgroupLocalInvocationId-SubgroupLocalInvocationId-04381);
  1444. case 4382:
  1445. return VUID_WRAP(VUID-SubgroupSize-SubgroupSize-04382);
  1446. case 4383:
  1447. return VUID_WRAP(VUID-SubgroupSize-SubgroupSize-04383);
  1448. case 4387:
  1449. return VUID_WRAP(VUID-TessCoord-TessCoord-04387);
  1450. case 4388:
  1451. return VUID_WRAP(VUID-TessCoord-TessCoord-04388);
  1452. case 4389:
  1453. return VUID_WRAP(VUID-TessCoord-TessCoord-04389);
  1454. case 4390:
  1455. return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04390);
  1456. case 4391:
  1457. return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04391);
  1458. case 4392:
  1459. return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04392);
  1460. case 4393:
  1461. return VUID_WRAP(VUID-TessLevelOuter-TessLevelOuter-04393);
  1462. case 4394:
  1463. return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04394);
  1464. case 4395:
  1465. return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04395);
  1466. case 4396:
  1467. return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04396);
  1468. case 4397:
  1469. return VUID_WRAP(VUID-TessLevelInner-TessLevelInner-04397);
  1470. case 4398:
  1471. return VUID_WRAP(VUID-VertexIndex-VertexIndex-04398);
  1472. case 4399:
  1473. return VUID_WRAP(VUID-VertexIndex-VertexIndex-04399);
  1474. case 4400:
  1475. return VUID_WRAP(VUID-VertexIndex-VertexIndex-04400);
  1476. case 4401:
  1477. return VUID_WRAP(VUID-ViewIndex-ViewIndex-04401);
  1478. case 4402:
  1479. return VUID_WRAP(VUID-ViewIndex-ViewIndex-04402);
  1480. case 4403:
  1481. return VUID_WRAP(VUID-ViewIndex-ViewIndex-04403);
  1482. case 4404:
  1483. return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04404);
  1484. case 4405:
  1485. return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04405);
  1486. case 4406:
  1487. return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04406);
  1488. case 4407:
  1489. return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04407);
  1490. case 4408:
  1491. return VUID_WRAP(VUID-ViewportIndex-ViewportIndex-04408);
  1492. case 4422:
  1493. return VUID_WRAP(VUID-WorkgroupId-WorkgroupId-04422);
  1494. case 4423:
  1495. return VUID_WRAP(VUID-WorkgroupId-WorkgroupId-04423);
  1496. case 4424:
  1497. return VUID_WRAP(VUID-WorkgroupId-WorkgroupId-04424);
  1498. case 4425:
  1499. return VUID_WRAP(VUID-WorkgroupSize-WorkgroupSize-04425);
  1500. case 4426:
  1501. return VUID_WRAP(VUID-WorkgroupSize-WorkgroupSize-04426);
  1502. case 4427:
  1503. return VUID_WRAP(VUID-WorkgroupSize-WorkgroupSize-04427);
  1504. case 4428:
  1505. return VUID_WRAP(VUID-WorldRayDirectionKHR-WorldRayDirectionKHR-04428);
  1506. case 4429:
  1507. return VUID_WRAP(VUID-WorldRayDirectionKHR-WorldRayDirectionKHR-04429);
  1508. case 4430:
  1509. return VUID_WRAP(VUID-WorldRayDirectionKHR-WorldRayDirectionKHR-04430);
  1510. case 4431:
  1511. return VUID_WRAP(VUID-WorldRayOriginKHR-WorldRayOriginKHR-04431);
  1512. case 4432:
  1513. return VUID_WRAP(VUID-WorldRayOriginKHR-WorldRayOriginKHR-04432);
  1514. case 4433:
  1515. return VUID_WRAP(VUID-WorldRayOriginKHR-WorldRayOriginKHR-04433);
  1516. case 4434:
  1517. return VUID_WRAP(VUID-WorldToObjectKHR-WorldToObjectKHR-04434);
  1518. case 4435:
  1519. return VUID_WRAP(VUID-WorldToObjectKHR-WorldToObjectKHR-04435);
  1520. case 4436:
  1521. return VUID_WRAP(VUID-WorldToObjectKHR-WorldToObjectKHR-04436);
  1522. case 4484:
  1523. return VUID_WRAP(VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04484);
  1524. case 4485:
  1525. return VUID_WRAP(VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04485);
  1526. case 4486:
  1527. return VUID_WRAP(VUID-PrimitiveShadingRateKHR-PrimitiveShadingRateKHR-04486);
  1528. case 4490:
  1529. return VUID_WRAP(VUID-ShadingRateKHR-ShadingRateKHR-04490);
  1530. case 4491:
  1531. return VUID_WRAP(VUID-ShadingRateKHR-ShadingRateKHR-04491);
  1532. case 4492:
  1533. return VUID_WRAP(VUID-ShadingRateKHR-ShadingRateKHR-04492);
  1534. case 4633:
  1535. return VUID_WRAP(VUID-StandaloneSpirv-None-04633);
  1536. case 4634:
  1537. return VUID_WRAP(VUID-StandaloneSpirv-None-04634);
  1538. case 4635:
  1539. return VUID_WRAP(VUID-StandaloneSpirv-None-04635);
  1540. case 4636:
  1541. return VUID_WRAP(VUID-StandaloneSpirv-None-04636);
  1542. case 4637:
  1543. return VUID_WRAP(VUID-StandaloneSpirv-None-04637);
  1544. case 4638:
  1545. return VUID_WRAP(VUID-StandaloneSpirv-None-04638);
  1546. case 4639:
  1547. return VUID_WRAP(VUID-StandaloneSpirv-None-04639);
  1548. case 4640:
  1549. return VUID_WRAP(VUID-StandaloneSpirv-None-04640);
  1550. case 4641:
  1551. return VUID_WRAP(VUID-StandaloneSpirv-None-04641);
  1552. case 4642:
  1553. return VUID_WRAP(VUID-StandaloneSpirv-None-04642);
  1554. case 4643:
  1555. return VUID_WRAP(VUID-StandaloneSpirv-None-04643);
  1556. case 4644:
  1557. return VUID_WRAP(VUID-StandaloneSpirv-None-04644);
  1558. case 4645:
  1559. return VUID_WRAP(VUID-StandaloneSpirv-None-04645);
  1560. case 4651:
  1561. return VUID_WRAP(VUID-StandaloneSpirv-OpVariable-04651);
  1562. case 4652:
  1563. return VUID_WRAP(VUID-StandaloneSpirv-OpReadClockKHR-04652);
  1564. case 4653:
  1565. return VUID_WRAP(VUID-StandaloneSpirv-OriginLowerLeft-04653);
  1566. case 4654:
  1567. return VUID_WRAP(VUID-StandaloneSpirv-PixelCenterInteger-04654);
  1568. case 4655:
  1569. return VUID_WRAP(VUID-StandaloneSpirv-UniformConstant-04655);
  1570. case 4656:
  1571. return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-04656);
  1572. case 4657:
  1573. return VUID_WRAP(VUID-StandaloneSpirv-OpTypeImage-04657);
  1574. case 4658:
  1575. return VUID_WRAP(VUID-StandaloneSpirv-OpImageTexelPointer-04658);
  1576. case 4659:
  1577. return VUID_WRAP(VUID-StandaloneSpirv-OpImageQuerySizeLod-04659);
  1578. case 4662:
  1579. return VUID_WRAP(VUID-StandaloneSpirv-Offset-04662);
  1580. case 4663:
  1581. return VUID_WRAP(VUID-StandaloneSpirv-Offset-04663);
  1582. case 4664:
  1583. return VUID_WRAP(VUID-StandaloneSpirv-OpImageGather-04664);
  1584. case 4667:
  1585. return VUID_WRAP(VUID-StandaloneSpirv-None-04667);
  1586. case 4669:
  1587. return VUID_WRAP(VUID-StandaloneSpirv-GLSLShared-04669);
  1588. case 4675:
  1589. return VUID_WRAP(VUID-StandaloneSpirv-FPRoundingMode-04675);
  1590. case 4677:
  1591. return VUID_WRAP(VUID-StandaloneSpirv-Invariant-04677);
  1592. case 4682:
  1593. return VUID_WRAP(VUID-StandaloneSpirv-OpControlBarrier-04682);
  1594. case 4683:
  1595. return VUID_WRAP(VUID-StandaloneSpirv-LocalSize-04683);
  1596. case 4685:
  1597. return VUID_WRAP(VUID-StandaloneSpirv-OpGroupNonUniformBallotBitCount-04685);
  1598. case 4686:
  1599. return VUID_WRAP(VUID-StandaloneSpirv-None-04686);
  1600. case 4710:
  1601. return VUID_WRAP(VUID-StandaloneSpirv-PhysicalStorageBuffer64-04710);
  1602. case 4711:
  1603. return VUID_WRAP(VUID-StandaloneSpirv-OpTypeForwardPointer-04711);
  1604. case 4730:
  1605. return VUID_WRAP(VUID-StandaloneSpirv-OpAtomicStore-04730);
  1606. case 4731:
  1607. return VUID_WRAP(VUID-StandaloneSpirv-OpAtomicLoad-04731);
  1608. case 4732:
  1609. return VUID_WRAP(VUID-StandaloneSpirv-OpMemoryBarrier-04732);
  1610. case 4733:
  1611. return VUID_WRAP(VUID-StandaloneSpirv-OpMemoryBarrier-04733);
  1612. case 4780:
  1613. return VUID_WRAP(VUID-StandaloneSpirv-Result-04780);
  1614. default:
  1615. return ""; // unknown id
  1616. }
  1617. // clang-format on
  1618. }
  1619. } // namespace val
  1620. } // namespace spvtools