validation_state.cpp 64 KB

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