validate_extensions.cpp 152 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875
  1. // Copyright (c) 2018 Google 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. // Validates correctness of extension SPIR-V instructions.
  15. #include <cstdlib>
  16. #include <sstream>
  17. #include <string>
  18. #include <vector>
  19. #include "NonSemanticShaderDebugInfo100.h"
  20. #include "OpenCLDebugInfo100.h"
  21. #include "source/common_debug_info.h"
  22. #include "source/extensions.h"
  23. #include "source/latest_version_glsl_std_450_header.h"
  24. #include "source/latest_version_opencl_std_header.h"
  25. #include "source/spirv_constant.h"
  26. #include "source/table2.h"
  27. #include "source/val/instruction.h"
  28. #include "source/val/validate.h"
  29. #include "source/val/validation_state.h"
  30. #include "spirv/unified1/NonSemanticClspvReflection.h"
  31. namespace spvtools {
  32. namespace val {
  33. namespace {
  34. std::string ReflectionInstructionName(const Instruction* inst) {
  35. const ExtInstDesc* desc = nullptr;
  36. if (LookupExtInst(SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
  37. inst->word(4), &desc) != SPV_SUCCESS ||
  38. !desc) {
  39. return std::string("Unknown ExtInst");
  40. }
  41. std::ostringstream ss;
  42. ss << desc->name().data();
  43. return ss.str();
  44. }
  45. uint32_t GetSizeTBitWidth(const ValidationState_t& _) {
  46. if (_.addressing_model() == spv::AddressingModel::Physical32) return 32;
  47. if (_.addressing_model() == spv::AddressingModel::Physical64) return 64;
  48. return 0;
  49. }
  50. bool IsIntScalar(ValidationState_t& _, uint32_t id, bool must_len32,
  51. bool must_unsigned) {
  52. auto type = _.FindDef(id);
  53. if (!type || type->opcode() != spv::Op::OpTypeInt) {
  54. return false;
  55. }
  56. if (must_len32 && type->GetOperandAs<uint32_t>(1) != 32) {
  57. return false;
  58. }
  59. return !must_unsigned || type->GetOperandAs<uint32_t>(2) == 0;
  60. }
  61. bool IsUint32Constant(ValidationState_t& _, uint32_t id) {
  62. auto inst = _.FindDef(id);
  63. if (!inst || inst->opcode() != spv::Op::OpConstant) {
  64. return false;
  65. }
  66. return IsIntScalar(_, inst->type_id(), true, true);
  67. }
  68. uint32_t GetUint32Constant(ValidationState_t& _, uint32_t id) {
  69. auto inst = _.FindDef(id);
  70. return inst->word(3);
  71. }
  72. std::string GetExtInstName(const ValidationState_t& _,
  73. const Instruction* inst) {
  74. const uint32_t ext_inst_set = inst->word(3);
  75. const uint32_t ext_inst_index = inst->word(4);
  76. const spv_ext_inst_type_t ext_inst_type =
  77. spv_ext_inst_type_t(inst->ext_inst_type());
  78. const ExtInstDesc* desc = nullptr;
  79. if (LookupExtInst(ext_inst_type, ext_inst_index, &desc) != SPV_SUCCESS ||
  80. !desc) {
  81. return std::string("Unknown ExtInst");
  82. }
  83. auto* import_inst = _.FindDef(ext_inst_set);
  84. assert(import_inst);
  85. std::ostringstream ss;
  86. ss << import_inst->GetOperandAs<std::string>(1);
  87. ss << " ";
  88. ss << desc->name().data();
  89. return ss.str();
  90. }
  91. // Check that the operand of a debug info instruction |inst| at |word_index|
  92. // is a result id of an instruction with |expected_opcode|.
  93. spv_result_t ValidateOperandForDebugInfo(ValidationState_t& _,
  94. const std::string& operand_name,
  95. spv::Op expected_opcode,
  96. const Instruction* inst,
  97. uint32_t word_index) {
  98. auto* operand = _.FindDef(inst->word(word_index));
  99. if (operand->opcode() != expected_opcode) {
  100. const spvtools::InstructionDesc* desc = nullptr;
  101. if (spvtools::LookupOpcodeForEnv(_.context()->target_env, expected_opcode,
  102. &desc) != SPV_SUCCESS ||
  103. !desc) {
  104. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  105. << GetExtInstName(_, inst) << ": " << "expected operand "
  106. << operand_name << " is invalid";
  107. }
  108. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  109. << GetExtInstName(_, inst) << ": " << "expected operand "
  110. << operand_name << " must be a result id of " << "Op"
  111. << desc->name().data();
  112. }
  113. return SPV_SUCCESS;
  114. }
  115. // For NonSemantic.Shader.DebugInfo.100 check that the operand of a debug info
  116. // instruction |inst| at |word_index| is a result id of a 32-bit integer
  117. // OpConstant instruction. For OpenCL.DebugInfo.100 the parameter is a literal
  118. // word so cannot be validated.
  119. spv_result_t ValidateUint32ConstantOperandForDebugInfo(
  120. ValidationState_t& _, const std::string& operand_name,
  121. const Instruction* inst, uint32_t word_index) {
  122. if (!IsUint32Constant(_, inst->word(word_index))) {
  123. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  124. << GetExtInstName(_, inst) << ": expected operand " << operand_name
  125. << " must be a result id of 32-bit unsigned OpConstant";
  126. }
  127. return SPV_SUCCESS;
  128. }
  129. #define CHECK_OPERAND(NAME, opcode, index) \
  130. do { \
  131. auto result = ValidateOperandForDebugInfo(_, NAME, opcode, inst, index); \
  132. if (result != SPV_SUCCESS) return result; \
  133. } while (0)
  134. #define CHECK_CONST_UINT_OPERAND(NAME, index) \
  135. if (vulkanDebugInfo) { \
  136. auto result = \
  137. ValidateUint32ConstantOperandForDebugInfo(_, NAME, inst, index); \
  138. if (result != SPV_SUCCESS) return result; \
  139. }
  140. // True if the operand of a debug info instruction |inst| at |word_index|
  141. // satisfies |expectation| that is given as a function. Otherwise,
  142. // returns false.
  143. bool DoesDebugInfoOperandMatchExpectation(
  144. const ValidationState_t& _,
  145. const std::function<bool(CommonDebugInfoInstructions)>& expectation,
  146. const Instruction* inst, uint32_t word_index) {
  147. if (inst->words().size() <= word_index) return false;
  148. auto* debug_inst = _.FindDef(inst->word(word_index));
  149. if (!spvIsExtendedInstruction(debug_inst->opcode()) ||
  150. (debug_inst->ext_inst_type() != SPV_EXT_INST_TYPE_OPENCL_DEBUGINFO_100 &&
  151. debug_inst->ext_inst_type() !=
  152. SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100) ||
  153. !expectation(CommonDebugInfoInstructions(debug_inst->word(4)))) {
  154. return false;
  155. }
  156. return true;
  157. }
  158. // Overload for NonSemanticShaderDebugInfo100Instructions.
  159. bool DoesDebugInfoOperandMatchExpectation(
  160. const ValidationState_t& _,
  161. const std::function<bool(NonSemanticShaderDebugInfo100Instructions)>&
  162. expectation,
  163. const Instruction* inst, uint32_t word_index) {
  164. if (inst->words().size() <= word_index) return false;
  165. auto* debug_inst = _.FindDef(inst->word(word_index));
  166. if (!spvIsExtendedInstruction(debug_inst->opcode()) ||
  167. (debug_inst->ext_inst_type() !=
  168. SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100) ||
  169. !expectation(
  170. NonSemanticShaderDebugInfo100Instructions(debug_inst->word(4)))) {
  171. return false;
  172. }
  173. return true;
  174. }
  175. // Check that the operand of a debug info instruction |inst| at |word_index|
  176. // is a result id of an debug info instruction whose debug instruction type
  177. // is |expected_debug_inst|.
  178. spv_result_t ValidateDebugInfoOperand(
  179. ValidationState_t& _, const std::string& debug_inst_name,
  180. CommonDebugInfoInstructions expected_debug_inst, const Instruction* inst,
  181. uint32_t word_index) {
  182. std::function<bool(CommonDebugInfoInstructions)> expectation =
  183. [expected_debug_inst](CommonDebugInfoInstructions dbg_inst) {
  184. return dbg_inst == expected_debug_inst;
  185. };
  186. if (DoesDebugInfoOperandMatchExpectation(_, expectation, inst, word_index))
  187. return SPV_SUCCESS;
  188. const ExtInstDesc* desc = nullptr;
  189. if (LookupExtInst(inst->ext_inst_type(), expected_debug_inst, &desc) !=
  190. SPV_SUCCESS ||
  191. !desc) {
  192. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  193. << GetExtInstName(_, inst) << ": " << "expected operand "
  194. << debug_inst_name << " is invalid";
  195. }
  196. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  197. << GetExtInstName(_, inst) << ": " << "expected operand "
  198. << debug_inst_name << " must be a result id of "
  199. << desc->name().data();
  200. }
  201. #define CHECK_DEBUG_OPERAND(NAME, debug_opcode, index) \
  202. do { \
  203. auto result = \
  204. ValidateDebugInfoOperand(_, NAME, debug_opcode, inst, index); \
  205. if (result != SPV_SUCCESS) return result; \
  206. } while (0)
  207. // Check that the operand of a debug info instruction |inst| at |word_index|
  208. // is a result id of an debug info instruction with DebugTypeBasic.
  209. spv_result_t ValidateOperandBaseType(ValidationState_t& _,
  210. const Instruction* inst,
  211. uint32_t word_index) {
  212. return ValidateDebugInfoOperand(_, "Base Type", CommonDebugInfoDebugTypeBasic,
  213. inst, word_index);
  214. }
  215. // Check that the operand of a debug info instruction |inst| at |word_index|
  216. // is a result id of a debug lexical scope instruction which is one of
  217. // DebugCompilationUnit, DebugFunction, DebugLexicalBlock, or
  218. // DebugTypeComposite.
  219. spv_result_t ValidateOperandLexicalScope(ValidationState_t& _,
  220. const std::string& debug_inst_name,
  221. const Instruction* inst,
  222. uint32_t word_index) {
  223. std::function<bool(CommonDebugInfoInstructions)> expectation =
  224. [](CommonDebugInfoInstructions dbg_inst) {
  225. return dbg_inst == CommonDebugInfoDebugCompilationUnit ||
  226. dbg_inst == CommonDebugInfoDebugFunction ||
  227. dbg_inst == CommonDebugInfoDebugLexicalBlock ||
  228. dbg_inst == CommonDebugInfoDebugTypeComposite;
  229. };
  230. if (DoesDebugInfoOperandMatchExpectation(_, expectation, inst, word_index))
  231. return SPV_SUCCESS;
  232. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  233. << GetExtInstName(_, inst) << ": " << "expected operand "
  234. << debug_inst_name << " must be a result id of a lexical scope";
  235. }
  236. // Check that the operand of a debug info instruction |inst| at |word_index|
  237. // is a result id of a debug type instruction (See DebugTypeXXX in
  238. // "4.3. Type instructions" section of OpenCL.DebugInfo.100 spec.
  239. spv_result_t ValidateOperandDebugType(ValidationState_t& _,
  240. const std::string& debug_inst_name,
  241. const Instruction* inst,
  242. uint32_t word_index,
  243. bool allow_template_param) {
  244. // Check for NonSemanticShaderDebugInfo100 specific types.
  245. if (inst->ext_inst_type() ==
  246. SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100) {
  247. std::function<bool(NonSemanticShaderDebugInfo100Instructions)> expectation =
  248. [](NonSemanticShaderDebugInfo100Instructions dbg_inst) {
  249. return dbg_inst == NonSemanticShaderDebugInfo100DebugTypeMatrix;
  250. };
  251. if (DoesDebugInfoOperandMatchExpectation(_, expectation, inst, word_index))
  252. return SPV_SUCCESS;
  253. }
  254. // Check for common types.
  255. std::function<bool(CommonDebugInfoInstructions)> expectation =
  256. [&allow_template_param](CommonDebugInfoInstructions dbg_inst) {
  257. if (allow_template_param &&
  258. (dbg_inst == CommonDebugInfoDebugTypeTemplateParameter ||
  259. dbg_inst == CommonDebugInfoDebugTypeTemplateTemplateParameter)) {
  260. return true;
  261. }
  262. return CommonDebugInfoDebugTypeBasic <= dbg_inst &&
  263. dbg_inst <= CommonDebugInfoDebugTypeTemplate;
  264. };
  265. if (DoesDebugInfoOperandMatchExpectation(_, expectation, inst, word_index))
  266. return SPV_SUCCESS;
  267. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  268. << GetExtInstName(_, inst) << ": " << "expected operand "
  269. << debug_inst_name << " is not a valid debug type";
  270. }
  271. spv_result_t ValidateClspvReflectionKernel(ValidationState_t& _,
  272. const Instruction* inst,
  273. uint32_t version) {
  274. const auto inst_name = ReflectionInstructionName(inst);
  275. const auto kernel_id = inst->GetOperandAs<uint32_t>(4);
  276. const auto kernel = _.FindDef(kernel_id);
  277. if (kernel->opcode() != spv::Op::OpFunction) {
  278. return _.diag(SPV_ERROR_INVALID_ID, inst)
  279. << inst_name << " does not reference a function";
  280. }
  281. bool found_kernel = false;
  282. for (auto entry_point : _.entry_points()) {
  283. if (entry_point == kernel_id) {
  284. found_kernel = true;
  285. break;
  286. }
  287. }
  288. if (!found_kernel) {
  289. return _.diag(SPV_ERROR_INVALID_ID, inst)
  290. << inst_name << " does not reference an entry-point";
  291. }
  292. const auto* exec_models = _.GetExecutionModels(kernel_id);
  293. if (!exec_models || exec_models->empty()) {
  294. return _.diag(SPV_ERROR_INVALID_ID, inst)
  295. << inst_name << " does not reference an entry-point";
  296. }
  297. for (auto exec_model : *exec_models) {
  298. if (exec_model != spv::ExecutionModel::GLCompute) {
  299. return _.diag(SPV_ERROR_INVALID_ID, inst)
  300. << inst_name << " must refer only to GLCompute entry-points";
  301. }
  302. }
  303. auto name = _.FindDef(inst->GetOperandAs<uint32_t>(5));
  304. if (!name || name->opcode() != spv::Op::OpString) {
  305. return _.diag(SPV_ERROR_INVALID_ID, inst) << "Name must be an OpString";
  306. }
  307. const std::string name_str = name->GetOperandAs<std::string>(1);
  308. bool found = false;
  309. for (auto& desc : _.entry_point_descriptions(kernel_id)) {
  310. if (name_str == desc.name) {
  311. found = true;
  312. break;
  313. }
  314. }
  315. if (!found) {
  316. return _.diag(SPV_ERROR_INVALID_ID, inst)
  317. << "Name must match an entry-point for Kernel";
  318. }
  319. const auto num_operands = inst->operands().size();
  320. if (version < 5 && num_operands > 6) {
  321. return _.diag(SPV_ERROR_INVALID_ID, inst)
  322. << "Version " << version << " of the " << inst_name
  323. << " instruction can only have 2 additional operands";
  324. }
  325. if (num_operands > 6) {
  326. const auto num_args_id = inst->GetOperandAs<uint32_t>(6);
  327. if (!IsUint32Constant(_, num_args_id)) {
  328. return _.diag(SPV_ERROR_INVALID_ID, inst)
  329. << "NumArguments must be a 32-bit unsigned integer OpConstant";
  330. }
  331. }
  332. if (num_operands > 7) {
  333. const auto flags_id = inst->GetOperandAs<uint32_t>(7);
  334. if (!IsUint32Constant(_, flags_id)) {
  335. return _.diag(SPV_ERROR_INVALID_ID, inst)
  336. << "Flags must be a 32-bit unsigned integer OpConstant";
  337. }
  338. }
  339. if (num_operands > 8) {
  340. const auto atts_id = inst->GetOperandAs<uint32_t>(8);
  341. if (_.GetIdOpcode(atts_id) != spv::Op::OpString) {
  342. return _.diag(SPV_ERROR_INVALID_ID, inst)
  343. << "Attributes must be an OpString";
  344. }
  345. }
  346. return SPV_SUCCESS;
  347. }
  348. spv_result_t ValidateClspvReflectionArgumentInfo(ValidationState_t& _,
  349. const Instruction* inst) {
  350. const auto num_operands = inst->operands().size();
  351. if (_.GetIdOpcode(inst->GetOperandAs<uint32_t>(4)) != spv::Op::OpString) {
  352. return _.diag(SPV_ERROR_INVALID_ID, inst) << "Name must be an OpString";
  353. }
  354. if (num_operands > 5) {
  355. if (_.GetIdOpcode(inst->GetOperandAs<uint32_t>(5)) != spv::Op::OpString) {
  356. return _.diag(SPV_ERROR_INVALID_ID, inst)
  357. << "TypeName must be an OpString";
  358. }
  359. }
  360. if (num_operands > 6) {
  361. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  362. return _.diag(SPV_ERROR_INVALID_ID, inst)
  363. << "AddressQualifier must be a 32-bit unsigned integer "
  364. "OpConstant";
  365. }
  366. }
  367. if (num_operands > 7) {
  368. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  369. return _.diag(SPV_ERROR_INVALID_ID, inst)
  370. << "AccessQualifier must be a 32-bit unsigned integer "
  371. "OpConstant";
  372. }
  373. }
  374. if (num_operands > 8) {
  375. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(8))) {
  376. return _.diag(SPV_ERROR_INVALID_ID, inst)
  377. << "TypeQualifier must be a 32-bit unsigned integer "
  378. "OpConstant";
  379. }
  380. }
  381. return SPV_SUCCESS;
  382. }
  383. spv_result_t ValidateKernelDecl(ValidationState_t& _, const Instruction* inst) {
  384. const auto decl_id = inst->GetOperandAs<uint32_t>(4);
  385. const auto decl = _.FindDef(decl_id);
  386. if (!decl || !spvIsExtendedInstruction(decl->opcode())) {
  387. return _.diag(SPV_ERROR_INVALID_ID, inst)
  388. << "Kernel must be a Kernel extended instruction";
  389. }
  390. if (decl->GetOperandAs<uint32_t>(2) != inst->GetOperandAs<uint32_t>(2)) {
  391. return _.diag(SPV_ERROR_INVALID_ID, inst)
  392. << "Kernel must be from the same extended instruction import";
  393. }
  394. const auto ext_inst =
  395. decl->GetOperandAs<NonSemanticClspvReflectionInstructions>(3);
  396. if (ext_inst != NonSemanticClspvReflectionKernel) {
  397. return _.diag(SPV_ERROR_INVALID_ID, inst)
  398. << "Kernel must be a Kernel extended instruction";
  399. }
  400. return SPV_SUCCESS;
  401. }
  402. spv_result_t ValidateArgInfo(ValidationState_t& _, const Instruction* inst,
  403. uint32_t info_index) {
  404. auto info = _.FindDef(inst->GetOperandAs<uint32_t>(info_index));
  405. if (!info || !spvIsExtendedInstruction(info->opcode())) {
  406. return _.diag(SPV_ERROR_INVALID_ID, inst)
  407. << "ArgInfo must be an ArgumentInfo extended instruction";
  408. }
  409. if (info->GetOperandAs<uint32_t>(2) != inst->GetOperandAs<uint32_t>(2)) {
  410. return _.diag(SPV_ERROR_INVALID_ID, inst)
  411. << "ArgInfo must be from the same extended instruction import";
  412. }
  413. auto ext_inst = info->GetOperandAs<NonSemanticClspvReflectionInstructions>(3);
  414. if (ext_inst != NonSemanticClspvReflectionArgumentInfo) {
  415. return _.diag(SPV_ERROR_INVALID_ID, inst)
  416. << "ArgInfo must be an ArgumentInfo extended instruction";
  417. }
  418. return SPV_SUCCESS;
  419. }
  420. spv_result_t ValidateClspvReflectionArgumentBuffer(ValidationState_t& _,
  421. const Instruction* inst) {
  422. const auto num_operands = inst->operands().size();
  423. if (auto error = ValidateKernelDecl(_, inst)) {
  424. return error;
  425. }
  426. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  427. return _.diag(SPV_ERROR_INVALID_ID, inst)
  428. << "Ordinal must be a 32-bit unsigned integer OpConstant";
  429. }
  430. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  431. return _.diag(SPV_ERROR_INVALID_ID, inst)
  432. << "DescriptorSet must be a 32-bit unsigned integer OpConstant";
  433. }
  434. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  435. return _.diag(SPV_ERROR_INVALID_ID, inst)
  436. << "Binding must be a 32-bit unsigned integer OpConstant";
  437. }
  438. if (num_operands == 9) {
  439. if (auto error = ValidateArgInfo(_, inst, 8)) {
  440. return error;
  441. }
  442. }
  443. return SPV_SUCCESS;
  444. }
  445. spv_result_t ValidateClspvReflectionArgumentOffsetBuffer(
  446. ValidationState_t& _, const Instruction* inst) {
  447. const auto num_operands = inst->operands().size();
  448. if (auto error = ValidateKernelDecl(_, inst)) {
  449. return error;
  450. }
  451. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  452. return _.diag(SPV_ERROR_INVALID_ID, inst)
  453. << "Ordinal must be a 32-bit unsigned integer OpConstant";
  454. }
  455. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  456. return _.diag(SPV_ERROR_INVALID_ID, inst)
  457. << "DescriptorSet must be a 32-bit unsigned integer OpConstant";
  458. }
  459. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  460. return _.diag(SPV_ERROR_INVALID_ID, inst)
  461. << "Binding must be a 32-bit unsigned integer OpConstant";
  462. }
  463. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(8))) {
  464. return _.diag(SPV_ERROR_INVALID_ID, inst)
  465. << "Offset must be a 32-bit unsigned integer OpConstant";
  466. }
  467. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(9))) {
  468. return _.diag(SPV_ERROR_INVALID_ID, inst)
  469. << "Size must be a 32-bit unsigned integer OpConstant";
  470. }
  471. if (num_operands == 11) {
  472. if (auto error = ValidateArgInfo(_, inst, 10)) {
  473. return error;
  474. }
  475. }
  476. return SPV_SUCCESS;
  477. }
  478. spv_result_t ValidateClspvReflectionArgumentPushConstant(
  479. ValidationState_t& _, const Instruction* inst) {
  480. const auto num_operands = inst->operands().size();
  481. if (auto error = ValidateKernelDecl(_, inst)) {
  482. return error;
  483. }
  484. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  485. return _.diag(SPV_ERROR_INVALID_ID, inst)
  486. << "Ordinal must be a 32-bit unsigned integer OpConstant";
  487. }
  488. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  489. return _.diag(SPV_ERROR_INVALID_ID, inst)
  490. << "Offset must be a 32-bit unsigned integer OpConstant";
  491. }
  492. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  493. return _.diag(SPV_ERROR_INVALID_ID, inst)
  494. << "Size must be a 32-bit unsigned integer OpConstant";
  495. }
  496. if (num_operands == 9) {
  497. if (auto error = ValidateArgInfo(_, inst, 8)) {
  498. return error;
  499. }
  500. }
  501. return SPV_SUCCESS;
  502. }
  503. spv_result_t ValidateClspvReflectionArgumentWorkgroup(ValidationState_t& _,
  504. const Instruction* inst) {
  505. const auto num_operands = inst->operands().size();
  506. if (auto error = ValidateKernelDecl(_, inst)) {
  507. return error;
  508. }
  509. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  510. return _.diag(SPV_ERROR_INVALID_ID, inst)
  511. << "Ordinal must be a 32-bit unsigned integer OpConstant";
  512. }
  513. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  514. return _.diag(SPV_ERROR_INVALID_ID, inst)
  515. << "SpecId must be a 32-bit unsigned integer OpConstant";
  516. }
  517. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  518. return _.diag(SPV_ERROR_INVALID_ID, inst)
  519. << "ElemSize must be a 32-bit unsigned integer OpConstant";
  520. }
  521. if (num_operands == 9) {
  522. if (auto error = ValidateArgInfo(_, inst, 8)) {
  523. return error;
  524. }
  525. }
  526. return SPV_SUCCESS;
  527. }
  528. spv_result_t ValidateClspvReflectionSpecConstantTriple(
  529. ValidationState_t& _, const Instruction* inst) {
  530. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  531. return _.diag(SPV_ERROR_INVALID_ID, inst)
  532. << "X must be a 32-bit unsigned integer OpConstant";
  533. }
  534. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  535. return _.diag(SPV_ERROR_INVALID_ID, inst)
  536. << "Y must be a 32-bit unsigned integer OpConstant";
  537. }
  538. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  539. return _.diag(SPV_ERROR_INVALID_ID, inst)
  540. << "Z must be a 32-bit unsigned integer OpConstant";
  541. }
  542. return SPV_SUCCESS;
  543. }
  544. spv_result_t ValidateClspvReflectionSpecConstantWorkDim(
  545. ValidationState_t& _, const Instruction* inst) {
  546. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  547. return _.diag(SPV_ERROR_INVALID_ID, inst)
  548. << "Dim must be a 32-bit unsigned integer OpConstant";
  549. }
  550. return SPV_SUCCESS;
  551. }
  552. spv_result_t ValidateClspvReflectionPushConstant(ValidationState_t& _,
  553. const Instruction* inst) {
  554. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  555. return _.diag(SPV_ERROR_INVALID_ID, inst)
  556. << "Offset must be a 32-bit unsigned integer OpConstant";
  557. }
  558. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  559. return _.diag(SPV_ERROR_INVALID_ID, inst)
  560. << "Size must be a 32-bit unsigned integer OpConstant";
  561. }
  562. return SPV_SUCCESS;
  563. }
  564. spv_result_t ValidateClspvReflectionInitializedData(ValidationState_t& _,
  565. const Instruction* inst) {
  566. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  567. return _.diag(SPV_ERROR_INVALID_ID, inst)
  568. << "DescriptorSet must be a 32-bit unsigned integer OpConstant";
  569. }
  570. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  571. return _.diag(SPV_ERROR_INVALID_ID, inst)
  572. << "Binding must be a 32-bit unsigned integer OpConstant";
  573. }
  574. if (_.GetIdOpcode(inst->GetOperandAs<uint32_t>(6)) != spv::Op::OpString) {
  575. return _.diag(SPV_ERROR_INVALID_ID, inst) << "Data must be an OpString";
  576. }
  577. return SPV_SUCCESS;
  578. }
  579. spv_result_t ValidateClspvReflectionSampler(ValidationState_t& _,
  580. const Instruction* inst) {
  581. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  582. return _.diag(SPV_ERROR_INVALID_ID, inst)
  583. << "DescriptorSet must be a 32-bit unsigned integer OpConstant";
  584. }
  585. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  586. return _.diag(SPV_ERROR_INVALID_ID, inst)
  587. << "Binding must be a 32-bit unsigned integer OpConstant";
  588. }
  589. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  590. return _.diag(SPV_ERROR_INVALID_ID, inst)
  591. << "Mask must be a 32-bit unsigned integer OpConstant";
  592. }
  593. return SPV_SUCCESS;
  594. }
  595. spv_result_t ValidateClspvReflectionPropertyRequiredWorkgroupSize(
  596. ValidationState_t& _, const Instruction* inst) {
  597. if (auto error = ValidateKernelDecl(_, inst)) {
  598. return error;
  599. }
  600. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  601. return _.diag(SPV_ERROR_INVALID_ID, inst)
  602. << "X must be a 32-bit unsigned integer OpConstant";
  603. }
  604. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  605. return _.diag(SPV_ERROR_INVALID_ID, inst)
  606. << "Y must be a 32-bit unsigned integer OpConstant";
  607. }
  608. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  609. return _.diag(SPV_ERROR_INVALID_ID, inst)
  610. << "Z must be a 32-bit unsigned integer OpConstant";
  611. }
  612. return SPV_SUCCESS;
  613. }
  614. spv_result_t ValidateClspvReflectionSubgroupMaxSize(ValidationState_t& _,
  615. const Instruction* inst) {
  616. const auto size_id = inst->GetOperandAs<uint32_t>(4);
  617. if (!IsUint32Constant(_, size_id)) {
  618. return _.diag(SPV_ERROR_INVALID_ID, inst)
  619. << "Size must be a 32-bit unsigned integer OpConstant";
  620. }
  621. return SPV_SUCCESS;
  622. }
  623. spv_result_t ValidateClspvReflectionPointerRelocation(ValidationState_t& _,
  624. const Instruction* inst) {
  625. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  626. return _.diag(SPV_ERROR_INVALID_ID, inst)
  627. << "ObjectOffset must be a 32-bit unsigned integer OpConstant";
  628. }
  629. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  630. return _.diag(SPV_ERROR_INVALID_ID, inst)
  631. << "PointerOffset must be a 32-bit unsigned integer OpConstant";
  632. }
  633. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  634. return _.diag(SPV_ERROR_INVALID_ID, inst)
  635. << "PointerSize must be a 32-bit unsigned integer OpConstant";
  636. }
  637. return SPV_SUCCESS;
  638. }
  639. spv_result_t ValidateClspvReflectionImageMetadataPushConstant(
  640. ValidationState_t& _, const Instruction* inst) {
  641. if (auto error = ValidateKernelDecl(_, inst)) {
  642. return error;
  643. }
  644. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  645. return _.diag(SPV_ERROR_INVALID_ID, inst)
  646. << "Ordinal must be a 32-bit unsigned integer OpConstant";
  647. }
  648. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  649. return _.diag(SPV_ERROR_INVALID_ID, inst)
  650. << "Offset must be a 32-bit unsigned integer OpConstant";
  651. }
  652. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  653. return _.diag(SPV_ERROR_INVALID_ID, inst)
  654. << "Size must be a 32-bit unsigned integer OpConstant";
  655. }
  656. return SPV_SUCCESS;
  657. }
  658. spv_result_t ValidateClspvReflectionImageMetadataUniform(
  659. ValidationState_t& _, const Instruction* inst) {
  660. if (auto error = ValidateKernelDecl(_, inst)) {
  661. return error;
  662. }
  663. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  664. return _.diag(SPV_ERROR_INVALID_ID, inst)
  665. << "Ordinal must be a 32-bit unsigned integer OpConstant";
  666. }
  667. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  668. return _.diag(SPV_ERROR_INVALID_ID, inst)
  669. << "DescriptorSet must be a 32-bit unsigned integer OpConstant";
  670. }
  671. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(7))) {
  672. return _.diag(SPV_ERROR_INVALID_ID, inst)
  673. << "Binding must be a 32-bit unsigned integer OpConstant";
  674. }
  675. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(8))) {
  676. return _.diag(SPV_ERROR_INVALID_ID, inst)
  677. << "Offset must be a 32-bit unsigned integer OpConstant";
  678. }
  679. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(9))) {
  680. return _.diag(SPV_ERROR_INVALID_ID, inst)
  681. << "Size must be a 32-bit unsigned integer OpConstant";
  682. }
  683. return SPV_SUCCESS;
  684. }
  685. spv_result_t ValidateClspvReflectionPushConstantData(ValidationState_t& _,
  686. const Instruction* inst) {
  687. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  688. return _.diag(SPV_ERROR_INVALID_ID, inst)
  689. << "Offset must be a 32-bit unsigned integer OpConstant";
  690. }
  691. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  692. return _.diag(SPV_ERROR_INVALID_ID, inst)
  693. << "Size must be a 32-bit unsigned integer OpConstant";
  694. }
  695. if (_.GetIdOpcode(inst->GetOperandAs<uint32_t>(6)) != spv::Op::OpString) {
  696. return _.diag(SPV_ERROR_INVALID_ID, inst) << "Data must be an OpString";
  697. }
  698. return SPV_SUCCESS;
  699. }
  700. spv_result_t ValidateClspvReflectionPrintfInfo(ValidationState_t& _,
  701. const Instruction* inst) {
  702. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  703. return _.diag(SPV_ERROR_INVALID_ID, inst)
  704. << "PrintfID must be a 32-bit unsigned integer OpConstant";
  705. }
  706. if (_.GetIdOpcode(inst->GetOperandAs<uint32_t>(5)) != spv::Op::OpString) {
  707. return _.diag(SPV_ERROR_INVALID_ID, inst)
  708. << "FormatString must be an OpString";
  709. }
  710. for (size_t i = 6; i < inst->operands().size(); ++i) {
  711. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(i))) {
  712. return _.diag(SPV_ERROR_INVALID_ID, inst)
  713. << "ArgumentSizes must be a 32-bit unsigned integer OpConstant";
  714. }
  715. }
  716. return SPV_SUCCESS;
  717. }
  718. spv_result_t ValidateClspvReflectionPrintfStorageBuffer(
  719. ValidationState_t& _, const Instruction* inst) {
  720. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  721. return _.diag(SPV_ERROR_INVALID_ID, inst)
  722. << "DescriptorSet must be a 32-bit unsigned integer OpConstant";
  723. }
  724. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  725. return _.diag(SPV_ERROR_INVALID_ID, inst)
  726. << "Binding must be a 32-bit unsigned integer OpConstant";
  727. }
  728. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  729. return _.diag(SPV_ERROR_INVALID_ID, inst)
  730. << "Size must be a 32-bit unsigned integer OpConstant";
  731. }
  732. return SPV_SUCCESS;
  733. }
  734. spv_result_t ValidateClspvReflectionPrintfPushConstant(
  735. ValidationState_t& _, const Instruction* inst) {
  736. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(4))) {
  737. return _.diag(SPV_ERROR_INVALID_ID, inst)
  738. << "Offset must be a 32-bit unsigned integer OpConstant";
  739. }
  740. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(5))) {
  741. return _.diag(SPV_ERROR_INVALID_ID, inst)
  742. << "Size must be a 32-bit unsigned integer OpConstant";
  743. }
  744. if (!IsUint32Constant(_, inst->GetOperandAs<uint32_t>(6))) {
  745. return _.diag(SPV_ERROR_INVALID_ID, inst)
  746. << "BufferSize must be a 32-bit unsigned integer OpConstant";
  747. }
  748. return SPV_SUCCESS;
  749. }
  750. spv_result_t ValidateClspvReflectionInstruction(ValidationState_t& _,
  751. const Instruction* inst,
  752. uint32_t version) {
  753. if (!_.IsVoidType(inst->type_id())) {
  754. return _.diag(SPV_ERROR_INVALID_ID, inst)
  755. << "Return Type must be OpTypeVoid";
  756. }
  757. uint32_t required_version = 0;
  758. const auto ext_inst =
  759. inst->GetOperandAs<NonSemanticClspvReflectionInstructions>(3);
  760. switch (ext_inst) {
  761. case NonSemanticClspvReflectionKernel:
  762. case NonSemanticClspvReflectionArgumentInfo:
  763. case NonSemanticClspvReflectionArgumentStorageBuffer:
  764. case NonSemanticClspvReflectionArgumentUniform:
  765. case NonSemanticClspvReflectionArgumentPodStorageBuffer:
  766. case NonSemanticClspvReflectionArgumentPodUniform:
  767. case NonSemanticClspvReflectionArgumentPodPushConstant:
  768. case NonSemanticClspvReflectionArgumentSampledImage:
  769. case NonSemanticClspvReflectionArgumentStorageImage:
  770. case NonSemanticClspvReflectionArgumentSampler:
  771. case NonSemanticClspvReflectionArgumentWorkgroup:
  772. case NonSemanticClspvReflectionSpecConstantWorkgroupSize:
  773. case NonSemanticClspvReflectionSpecConstantGlobalOffset:
  774. case NonSemanticClspvReflectionSpecConstantWorkDim:
  775. case NonSemanticClspvReflectionPushConstantGlobalOffset:
  776. case NonSemanticClspvReflectionPushConstantEnqueuedLocalSize:
  777. case NonSemanticClspvReflectionPushConstantGlobalSize:
  778. case NonSemanticClspvReflectionPushConstantRegionOffset:
  779. case NonSemanticClspvReflectionPushConstantNumWorkgroups:
  780. case NonSemanticClspvReflectionPushConstantRegionGroupOffset:
  781. case NonSemanticClspvReflectionConstantDataStorageBuffer:
  782. case NonSemanticClspvReflectionConstantDataUniform:
  783. case NonSemanticClspvReflectionLiteralSampler:
  784. case NonSemanticClspvReflectionPropertyRequiredWorkgroupSize:
  785. required_version = 1;
  786. break;
  787. case NonSemanticClspvReflectionSpecConstantSubgroupMaxSize:
  788. required_version = 2;
  789. break;
  790. case NonSemanticClspvReflectionArgumentPointerPushConstant:
  791. case NonSemanticClspvReflectionArgumentPointerUniform:
  792. case NonSemanticClspvReflectionProgramScopeVariablesStorageBuffer:
  793. case NonSemanticClspvReflectionProgramScopeVariablePointerRelocation:
  794. case NonSemanticClspvReflectionImageArgumentInfoChannelOrderPushConstant:
  795. case NonSemanticClspvReflectionImageArgumentInfoChannelDataTypePushConstant:
  796. case NonSemanticClspvReflectionImageArgumentInfoChannelOrderUniform:
  797. case NonSemanticClspvReflectionImageArgumentInfoChannelDataTypeUniform:
  798. required_version = 3;
  799. break;
  800. case NonSemanticClspvReflectionArgumentStorageTexelBuffer:
  801. case NonSemanticClspvReflectionArgumentUniformTexelBuffer:
  802. required_version = 4;
  803. break;
  804. case NonSemanticClspvReflectionConstantDataPointerPushConstant:
  805. case NonSemanticClspvReflectionProgramScopeVariablePointerPushConstant:
  806. case NonSemanticClspvReflectionPrintfInfo:
  807. case NonSemanticClspvReflectionPrintfBufferStorageBuffer:
  808. case NonSemanticClspvReflectionPrintfBufferPointerPushConstant:
  809. required_version = 5;
  810. break;
  811. default:
  812. break;
  813. }
  814. if (version < required_version) {
  815. return _.diag(SPV_ERROR_INVALID_ID, inst)
  816. << ReflectionInstructionName(inst) << " requires version "
  817. << required_version << ", but parsed version is " << version;
  818. }
  819. switch (ext_inst) {
  820. case NonSemanticClspvReflectionKernel:
  821. return ValidateClspvReflectionKernel(_, inst, version);
  822. case NonSemanticClspvReflectionArgumentInfo:
  823. return ValidateClspvReflectionArgumentInfo(_, inst);
  824. case NonSemanticClspvReflectionArgumentStorageBuffer:
  825. case NonSemanticClspvReflectionArgumentUniform:
  826. case NonSemanticClspvReflectionArgumentSampledImage:
  827. case NonSemanticClspvReflectionArgumentStorageImage:
  828. case NonSemanticClspvReflectionArgumentSampler:
  829. case NonSemanticClspvReflectionArgumentStorageTexelBuffer:
  830. case NonSemanticClspvReflectionArgumentUniformTexelBuffer:
  831. return ValidateClspvReflectionArgumentBuffer(_, inst);
  832. case NonSemanticClspvReflectionArgumentPodStorageBuffer:
  833. case NonSemanticClspvReflectionArgumentPodUniform:
  834. case NonSemanticClspvReflectionArgumentPointerUniform:
  835. return ValidateClspvReflectionArgumentOffsetBuffer(_, inst);
  836. case NonSemanticClspvReflectionArgumentPodPushConstant:
  837. case NonSemanticClspvReflectionArgumentPointerPushConstant:
  838. return ValidateClspvReflectionArgumentPushConstant(_, inst);
  839. case NonSemanticClspvReflectionArgumentWorkgroup:
  840. return ValidateClspvReflectionArgumentWorkgroup(_, inst);
  841. case NonSemanticClspvReflectionSpecConstantWorkgroupSize:
  842. case NonSemanticClspvReflectionSpecConstantGlobalOffset:
  843. return ValidateClspvReflectionSpecConstantTriple(_, inst);
  844. case NonSemanticClspvReflectionSpecConstantWorkDim:
  845. return ValidateClspvReflectionSpecConstantWorkDim(_, inst);
  846. case NonSemanticClspvReflectionPushConstantGlobalOffset:
  847. case NonSemanticClspvReflectionPushConstantEnqueuedLocalSize:
  848. case NonSemanticClspvReflectionPushConstantGlobalSize:
  849. case NonSemanticClspvReflectionPushConstantRegionOffset:
  850. case NonSemanticClspvReflectionPushConstantNumWorkgroups:
  851. case NonSemanticClspvReflectionPushConstantRegionGroupOffset:
  852. return ValidateClspvReflectionPushConstant(_, inst);
  853. case NonSemanticClspvReflectionConstantDataStorageBuffer:
  854. case NonSemanticClspvReflectionConstantDataUniform:
  855. case NonSemanticClspvReflectionProgramScopeVariablesStorageBuffer:
  856. return ValidateClspvReflectionInitializedData(_, inst);
  857. case NonSemanticClspvReflectionLiteralSampler:
  858. return ValidateClspvReflectionSampler(_, inst);
  859. case NonSemanticClspvReflectionPropertyRequiredWorkgroupSize:
  860. return ValidateClspvReflectionPropertyRequiredWorkgroupSize(_, inst);
  861. case NonSemanticClspvReflectionSpecConstantSubgroupMaxSize:
  862. return ValidateClspvReflectionSubgroupMaxSize(_, inst);
  863. case NonSemanticClspvReflectionProgramScopeVariablePointerRelocation:
  864. return ValidateClspvReflectionPointerRelocation(_, inst);
  865. case NonSemanticClspvReflectionImageArgumentInfoChannelOrderPushConstant:
  866. case NonSemanticClspvReflectionImageArgumentInfoChannelDataTypePushConstant:
  867. return ValidateClspvReflectionImageMetadataPushConstant(_, inst);
  868. case NonSemanticClspvReflectionImageArgumentInfoChannelOrderUniform:
  869. case NonSemanticClspvReflectionImageArgumentInfoChannelDataTypeUniform:
  870. return ValidateClspvReflectionImageMetadataUniform(_, inst);
  871. case NonSemanticClspvReflectionConstantDataPointerPushConstant:
  872. case NonSemanticClspvReflectionProgramScopeVariablePointerPushConstant:
  873. return ValidateClspvReflectionPushConstantData(_, inst);
  874. case NonSemanticClspvReflectionPrintfInfo:
  875. return ValidateClspvReflectionPrintfInfo(_, inst);
  876. case NonSemanticClspvReflectionPrintfBufferStorageBuffer:
  877. return ValidateClspvReflectionPrintfStorageBuffer(_, inst);
  878. case NonSemanticClspvReflectionPrintfBufferPointerPushConstant:
  879. return ValidateClspvReflectionPrintfPushConstant(_, inst);
  880. default:
  881. break;
  882. }
  883. return SPV_SUCCESS;
  884. }
  885. bool IsConstIntScalarTypeWith32Or64Bits(ValidationState_t& _,
  886. Instruction* instr) {
  887. if (instr->opcode() != spv::Op::OpConstant) return false;
  888. if (!_.IsIntScalarType(instr->type_id())) return false;
  889. uint32_t size_in_bits = _.GetBitWidth(instr->type_id());
  890. return size_in_bits == 32 || size_in_bits == 64;
  891. }
  892. bool IsConstWithIntScalarType(ValidationState_t& _, const Instruction* inst,
  893. uint32_t word_index) {
  894. auto* int_scalar_const = _.FindDef(inst->word(word_index));
  895. if (int_scalar_const->opcode() == spv::Op::OpConstant &&
  896. _.IsIntScalarType(int_scalar_const->type_id())) {
  897. return true;
  898. }
  899. return false;
  900. }
  901. bool IsDebugVariableWithIntScalarType(ValidationState_t& _,
  902. const Instruction* inst,
  903. uint32_t word_index) {
  904. auto* dbg_int_scalar_var = _.FindDef(inst->word(word_index));
  905. if (CommonDebugInfoInstructions(dbg_int_scalar_var->word(4)) ==
  906. CommonDebugInfoDebugLocalVariable ||
  907. CommonDebugInfoInstructions(dbg_int_scalar_var->word(4)) ==
  908. CommonDebugInfoDebugGlobalVariable) {
  909. auto* dbg_type = _.FindDef(dbg_int_scalar_var->word(6));
  910. if (CommonDebugInfoInstructions(dbg_type->word(4)) ==
  911. CommonDebugInfoDebugTypeBasic) {
  912. const spv_ext_inst_type_t ext_inst_type =
  913. spv_ext_inst_type_t(inst->ext_inst_type());
  914. const bool vulkanDebugInfo =
  915. ext_inst_type == SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100;
  916. uint32_t encoding = dbg_type->word(7);
  917. if (!vulkanDebugInfo || IsUint32Constant(_, encoding)) {
  918. auto ocl_encoding = OpenCLDebugInfo100DebugBaseTypeAttributeEncoding(
  919. vulkanDebugInfo ? GetUint32Constant(_, encoding) : encoding);
  920. if (ocl_encoding == OpenCLDebugInfo100Signed ||
  921. ocl_encoding == OpenCLDebugInfo100Unsigned) {
  922. return true;
  923. }
  924. }
  925. }
  926. }
  927. return false;
  928. }
  929. } // anonymous namespace
  930. spv_result_t ValidateExtension(ValidationState_t& _, const Instruction* inst) {
  931. std::string extension = GetExtensionString(&(inst->c_inst()));
  932. if (_.version() < SPV_SPIRV_VERSION_WORD(1, 3)) {
  933. if (extension == ExtensionToString(kSPV_KHR_vulkan_memory_model) ||
  934. extension ==
  935. ExtensionToString(kSPV_QCOM_cooperative_matrix_conversion)) {
  936. return _.diag(SPV_ERROR_WRONG_VERSION, inst)
  937. << extension << " extension requires SPIR-V version 1.3 or later.";
  938. }
  939. }
  940. if (_.version() < SPV_SPIRV_VERSION_WORD(1, 4)) {
  941. if (extension ==
  942. ExtensionToString(kSPV_KHR_workgroup_memory_explicit_layout) ||
  943. extension == ExtensionToString(kSPV_EXT_mesh_shader) ||
  944. extension == ExtensionToString(kSPV_NV_shader_invocation_reorder) ||
  945. extension ==
  946. ExtensionToString(kSPV_NV_cluster_acceleration_structure) ||
  947. extension == ExtensionToString(kSPV_NV_linear_swept_spheres) ||
  948. extension == ExtensionToString(kSPV_QCOM_image_processing) ||
  949. extension == ExtensionToString(kSPV_QCOM_image_processing2)) {
  950. return _.diag(SPV_ERROR_WRONG_VERSION, inst)
  951. << extension << " extension requires SPIR-V version 1.4 or later.";
  952. }
  953. }
  954. return SPV_SUCCESS;
  955. }
  956. spv_result_t ValidateExtInstImport(ValidationState_t& _,
  957. const Instruction* inst) {
  958. const auto name_id = 1;
  959. if (_.version() <= SPV_SPIRV_VERSION_WORD(1, 5) &&
  960. !_.HasExtension(kSPV_KHR_non_semantic_info)) {
  961. const std::string name = inst->GetOperandAs<std::string>(name_id);
  962. if (name.find("NonSemantic.") == 0) {
  963. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  964. << "NonSemantic extended instruction "
  965. "sets cannot be declared "
  966. "without SPV_KHR_non_semantic_info. (This can also be fixed "
  967. "having SPIR-V 1.6 or later)";
  968. }
  969. }
  970. return SPV_SUCCESS;
  971. }
  972. spv_result_t ValidateExtInstGlslStd450(ValidationState_t& _,
  973. const Instruction* inst) {
  974. const uint32_t result_type = inst->type_id();
  975. const uint32_t num_operands = static_cast<uint32_t>(inst->operands().size());
  976. const uint32_t ext_inst_index = inst->word(4);
  977. const GLSLstd450 ext_inst_key = GLSLstd450(ext_inst_index);
  978. switch (ext_inst_key) {
  979. case GLSLstd450Round:
  980. case GLSLstd450RoundEven:
  981. case GLSLstd450FAbs:
  982. case GLSLstd450Trunc:
  983. case GLSLstd450FSign:
  984. case GLSLstd450Floor:
  985. case GLSLstd450Ceil:
  986. case GLSLstd450Fract:
  987. case GLSLstd450Sqrt:
  988. case GLSLstd450InverseSqrt:
  989. case GLSLstd450FMin:
  990. case GLSLstd450FMax:
  991. case GLSLstd450FClamp:
  992. case GLSLstd450FMix:
  993. case GLSLstd450Step:
  994. case GLSLstd450SmoothStep:
  995. case GLSLstd450Fma:
  996. case GLSLstd450Normalize:
  997. case GLSLstd450FaceForward:
  998. case GLSLstd450Reflect:
  999. case GLSLstd450NMin:
  1000. case GLSLstd450NMax:
  1001. case GLSLstd450NClamp: {
  1002. bool supportsCoopVec =
  1003. (ext_inst_key == GLSLstd450FMin || ext_inst_key == GLSLstd450FMax ||
  1004. ext_inst_key == GLSLstd450FClamp || ext_inst_key == GLSLstd450NMin ||
  1005. ext_inst_key == GLSLstd450NMax || ext_inst_key == GLSLstd450NClamp ||
  1006. ext_inst_key == GLSLstd450Step || ext_inst_key == GLSLstd450Fma);
  1007. if (!_.IsFloatScalarOrVectorType(result_type) &&
  1008. !(supportsCoopVec && _.IsFloatCooperativeVectorNVType(result_type))) {
  1009. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1010. << GetExtInstName(_, inst) << ": "
  1011. << "expected Result Type to be a float scalar or vector type";
  1012. }
  1013. for (uint32_t operand_index = 4; operand_index < num_operands;
  1014. ++operand_index) {
  1015. const uint32_t operand_type = _.GetOperandTypeId(inst, operand_index);
  1016. if (result_type != operand_type) {
  1017. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1018. << GetExtInstName(_, inst) << ": "
  1019. << "expected types of all operands to be equal to Result "
  1020. "Type";
  1021. }
  1022. }
  1023. break;
  1024. }
  1025. case GLSLstd450SAbs:
  1026. case GLSLstd450SSign:
  1027. case GLSLstd450UMin:
  1028. case GLSLstd450SMin:
  1029. case GLSLstd450UMax:
  1030. case GLSLstd450SMax:
  1031. case GLSLstd450UClamp:
  1032. case GLSLstd450SClamp:
  1033. case GLSLstd450FindILsb:
  1034. case GLSLstd450FindUMsb:
  1035. case GLSLstd450FindSMsb: {
  1036. bool supportsCoopVec =
  1037. (ext_inst_key == GLSLstd450UMin || ext_inst_key == GLSLstd450UMax ||
  1038. ext_inst_key == GLSLstd450UClamp || ext_inst_key == GLSLstd450SMin ||
  1039. ext_inst_key == GLSLstd450SMax || ext_inst_key == GLSLstd450SClamp);
  1040. if (!_.IsIntScalarOrVectorType(result_type) &&
  1041. !(supportsCoopVec && _.IsIntCooperativeVectorNVType(result_type))) {
  1042. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1043. << GetExtInstName(_, inst) << ": "
  1044. << "expected Result Type to be an int scalar or vector type";
  1045. }
  1046. const uint32_t result_type_bit_width = _.GetBitWidth(result_type);
  1047. const uint32_t result_type_dimension = _.GetDimension(result_type);
  1048. for (uint32_t operand_index = 4; operand_index < num_operands;
  1049. ++operand_index) {
  1050. const uint32_t operand_type = _.GetOperandTypeId(inst, operand_index);
  1051. if (!operand_type ||
  1052. (!_.IsIntScalarOrVectorType(operand_type) &&
  1053. !(supportsCoopVec &&
  1054. _.IsIntCooperativeVectorNVType(operand_type)))) {
  1055. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1056. << GetExtInstName(_, inst) << ": "
  1057. << "expected all operands to be int scalars or vectors";
  1058. }
  1059. if (result_type_dimension != _.GetDimension(operand_type)) {
  1060. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1061. << GetExtInstName(_, inst) << ": "
  1062. << "expected all operands to have the same dimension as "
  1063. << "Result Type";
  1064. }
  1065. if (result_type_bit_width != _.GetBitWidth(operand_type)) {
  1066. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1067. << GetExtInstName(_, inst) << ": "
  1068. << "expected all operands to have the same bit width as "
  1069. << "Result Type";
  1070. }
  1071. if (ext_inst_key == GLSLstd450FindUMsb ||
  1072. ext_inst_key == GLSLstd450FindSMsb) {
  1073. if (result_type_bit_width != 32) {
  1074. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1075. << GetExtInstName(_, inst) << ": "
  1076. << "this instruction is currently limited to 32-bit width "
  1077. << "components";
  1078. }
  1079. }
  1080. }
  1081. break;
  1082. }
  1083. case GLSLstd450Radians:
  1084. case GLSLstd450Degrees:
  1085. case GLSLstd450Sin:
  1086. case GLSLstd450Cos:
  1087. case GLSLstd450Tan:
  1088. case GLSLstd450Asin:
  1089. case GLSLstd450Acos:
  1090. case GLSLstd450Atan:
  1091. case GLSLstd450Sinh:
  1092. case GLSLstd450Cosh:
  1093. case GLSLstd450Tanh:
  1094. case GLSLstd450Asinh:
  1095. case GLSLstd450Acosh:
  1096. case GLSLstd450Atanh:
  1097. case GLSLstd450Exp:
  1098. case GLSLstd450Exp2:
  1099. case GLSLstd450Log:
  1100. case GLSLstd450Log2:
  1101. case GLSLstd450Atan2:
  1102. case GLSLstd450Pow: {
  1103. bool supportsCoopVec =
  1104. (ext_inst_key == GLSLstd450Atan || ext_inst_key == GLSLstd450Tanh ||
  1105. ext_inst_key == GLSLstd450Exp || ext_inst_key == GLSLstd450Log);
  1106. if (!_.IsFloatScalarOrVectorType(result_type) &&
  1107. !(supportsCoopVec && _.IsFloatCooperativeVectorNVType(result_type))) {
  1108. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1109. << GetExtInstName(_, inst) << ": "
  1110. << "expected Result Type to be a 16 or 32-bit scalar or "
  1111. "vector float type";
  1112. }
  1113. const uint32_t result_type_bit_width = _.GetBitWidth(result_type);
  1114. if (result_type_bit_width != 16 && result_type_bit_width != 32) {
  1115. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1116. << GetExtInstName(_, inst) << ": "
  1117. << "expected Result Type to be a 16 or 32-bit scalar or "
  1118. "vector float type";
  1119. }
  1120. for (uint32_t operand_index = 4; operand_index < num_operands;
  1121. ++operand_index) {
  1122. const uint32_t operand_type = _.GetOperandTypeId(inst, operand_index);
  1123. if (result_type != operand_type) {
  1124. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1125. << GetExtInstName(_, inst) << ": "
  1126. << "expected types of all operands to be equal to Result "
  1127. "Type";
  1128. }
  1129. }
  1130. break;
  1131. }
  1132. case GLSLstd450Determinant: {
  1133. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1134. uint32_t num_rows = 0;
  1135. uint32_t num_cols = 0;
  1136. uint32_t col_type = 0;
  1137. uint32_t component_type = 0;
  1138. if (!_.GetMatrixTypeInfo(x_type, &num_rows, &num_cols, &col_type,
  1139. &component_type) ||
  1140. num_rows != num_cols) {
  1141. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1142. << GetExtInstName(_, inst) << ": "
  1143. << "expected operand X to be a square matrix";
  1144. }
  1145. if (result_type != component_type) {
  1146. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1147. << GetExtInstName(_, inst) << ": "
  1148. << "expected operand X component type to be equal to "
  1149. << "Result Type";
  1150. }
  1151. break;
  1152. }
  1153. case GLSLstd450MatrixInverse: {
  1154. uint32_t num_rows = 0;
  1155. uint32_t num_cols = 0;
  1156. uint32_t col_type = 0;
  1157. uint32_t component_type = 0;
  1158. if (!_.GetMatrixTypeInfo(result_type, &num_rows, &num_cols, &col_type,
  1159. &component_type) ||
  1160. num_rows != num_cols) {
  1161. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1162. << GetExtInstName(_, inst) << ": "
  1163. << "expected Result Type to be a square matrix";
  1164. }
  1165. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1166. if (result_type != x_type) {
  1167. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1168. << GetExtInstName(_, inst) << ": "
  1169. << "expected operand X type to be equal to Result Type";
  1170. }
  1171. break;
  1172. }
  1173. case GLSLstd450Modf: {
  1174. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1175. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1176. << GetExtInstName(_, inst) << ": "
  1177. << "expected Result Type to be a scalar or vector float type";
  1178. }
  1179. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1180. const uint32_t i_type = _.GetOperandTypeId(inst, 5);
  1181. if (x_type != result_type) {
  1182. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1183. << GetExtInstName(_, inst) << ": "
  1184. << "expected operand X type to be equal to Result Type";
  1185. }
  1186. spv::StorageClass i_storage_class;
  1187. uint32_t i_data_type = 0;
  1188. if (!_.GetPointerTypeInfo(i_type, &i_data_type, &i_storage_class)) {
  1189. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1190. << GetExtInstName(_, inst) << ": "
  1191. << "expected operand I to be a pointer";
  1192. }
  1193. if (i_data_type != result_type) {
  1194. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1195. << GetExtInstName(_, inst) << ": "
  1196. << "expected operand I data type to be equal to Result Type";
  1197. }
  1198. break;
  1199. }
  1200. case GLSLstd450ModfStruct: {
  1201. std::vector<uint32_t> result_types;
  1202. if (!_.GetStructMemberTypes(result_type, &result_types) ||
  1203. result_types.size() != 2 ||
  1204. !_.IsFloatScalarOrVectorType(result_types[0]) ||
  1205. result_types[1] != result_types[0]) {
  1206. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1207. << GetExtInstName(_, inst) << ": "
  1208. << "expected Result Type to be a struct with two identical "
  1209. << "scalar or vector float type members";
  1210. }
  1211. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1212. if (x_type != result_types[0]) {
  1213. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1214. << GetExtInstName(_, inst) << ": "
  1215. << "expected operand X type to be equal to members of "
  1216. << "Result Type struct";
  1217. }
  1218. break;
  1219. }
  1220. case GLSLstd450Frexp: {
  1221. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1222. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1223. << GetExtInstName(_, inst) << ": "
  1224. << "expected Result Type to be a scalar or vector float type";
  1225. }
  1226. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1227. const uint32_t exp_type = _.GetOperandTypeId(inst, 5);
  1228. if (x_type != result_type) {
  1229. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1230. << GetExtInstName(_, inst) << ": "
  1231. << "expected operand X type to be equal to Result Type";
  1232. }
  1233. spv::StorageClass exp_storage_class;
  1234. uint32_t exp_data_type = 0;
  1235. if (!_.GetPointerTypeInfo(exp_type, &exp_data_type, &exp_storage_class)) {
  1236. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1237. << GetExtInstName(_, inst) << ": "
  1238. << "expected operand Exp to be a pointer";
  1239. }
  1240. if (!_.IsIntScalarOrVectorType(exp_data_type) ||
  1241. (!_.HasExtension(kSPV_AMD_gpu_shader_int16) &&
  1242. _.GetBitWidth(exp_data_type) != 32) ||
  1243. (_.HasExtension(kSPV_AMD_gpu_shader_int16) &&
  1244. _.GetBitWidth(exp_data_type) != 16 &&
  1245. _.GetBitWidth(exp_data_type) != 32)) {
  1246. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1247. << GetExtInstName(_, inst) << ": "
  1248. << "expected operand Exp data type to be a "
  1249. << (_.HasExtension(kSPV_AMD_gpu_shader_int16)
  1250. ? "16-bit or 32-bit "
  1251. : "32-bit ")
  1252. << "int scalar or vector type";
  1253. }
  1254. if (_.GetDimension(result_type) != _.GetDimension(exp_data_type)) {
  1255. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1256. << GetExtInstName(_, inst) << ": "
  1257. << "expected operand Exp data type to have the same component "
  1258. << "number as Result Type";
  1259. }
  1260. break;
  1261. }
  1262. case GLSLstd450Ldexp: {
  1263. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1264. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1265. << GetExtInstName(_, inst) << ": "
  1266. << "expected Result Type to be a scalar or vector float type";
  1267. }
  1268. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1269. const uint32_t exp_type = _.GetOperandTypeId(inst, 5);
  1270. if (x_type != result_type) {
  1271. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1272. << GetExtInstName(_, inst) << ": "
  1273. << "expected operand X type to be equal to Result Type";
  1274. }
  1275. if (!_.IsIntScalarOrVectorType(exp_type)) {
  1276. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1277. << GetExtInstName(_, inst) << ": "
  1278. << "expected operand Exp to be a 32-bit int scalar "
  1279. << "or vector type";
  1280. }
  1281. if (_.GetDimension(result_type) != _.GetDimension(exp_type)) {
  1282. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1283. << GetExtInstName(_, inst) << ": "
  1284. << "expected operand Exp to have the same component "
  1285. << "number as Result Type";
  1286. }
  1287. break;
  1288. }
  1289. case GLSLstd450FrexpStruct: {
  1290. std::vector<uint32_t> result_types;
  1291. if (!_.GetStructMemberTypes(result_type, &result_types) ||
  1292. result_types.size() != 2 ||
  1293. !_.IsFloatScalarOrVectorType(result_types[0]) ||
  1294. !_.IsIntScalarOrVectorType(result_types[1]) ||
  1295. (!_.HasExtension(kSPV_AMD_gpu_shader_int16) &&
  1296. _.GetBitWidth(result_types[1]) != 32) ||
  1297. (_.HasExtension(kSPV_AMD_gpu_shader_int16) &&
  1298. _.GetBitWidth(result_types[1]) != 16 &&
  1299. _.GetBitWidth(result_types[1]) != 32) ||
  1300. _.GetDimension(result_types[0]) != _.GetDimension(result_types[1])) {
  1301. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1302. << GetExtInstName(_, inst) << ": "
  1303. << "expected Result Type to be a struct with two members, "
  1304. << "first member a float scalar or vector, second member a "
  1305. << (_.HasExtension(kSPV_AMD_gpu_shader_int16)
  1306. ? "16-bit or 32-bit "
  1307. : "32-bit ")
  1308. << "int scalar or vector with the same number of "
  1309. << "components as the first member";
  1310. }
  1311. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1312. if (x_type != result_types[0]) {
  1313. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1314. << GetExtInstName(_, inst) << ": "
  1315. << "expected operand X type to be equal to the first member "
  1316. << "of Result Type struct";
  1317. }
  1318. break;
  1319. }
  1320. case GLSLstd450PackSnorm4x8:
  1321. case GLSLstd450PackUnorm4x8: {
  1322. if (!_.IsIntScalarType(result_type) || _.GetBitWidth(result_type) != 32) {
  1323. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1324. << GetExtInstName(_, inst) << ": "
  1325. << "expected Result Type to be 32-bit int scalar type";
  1326. }
  1327. const uint32_t v_type = _.GetOperandTypeId(inst, 4);
  1328. if (!_.IsFloatVectorType(v_type) || _.GetDimension(v_type) != 4 ||
  1329. _.GetBitWidth(v_type) != 32) {
  1330. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1331. << GetExtInstName(_, inst) << ": "
  1332. << "expected operand V to be a 32-bit float vector of size 4";
  1333. }
  1334. break;
  1335. }
  1336. case GLSLstd450PackSnorm2x16:
  1337. case GLSLstd450PackUnorm2x16:
  1338. case GLSLstd450PackHalf2x16: {
  1339. if (!_.IsIntScalarType(result_type) || _.GetBitWidth(result_type) != 32) {
  1340. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1341. << GetExtInstName(_, inst) << ": "
  1342. << "expected Result Type to be 32-bit int scalar type";
  1343. }
  1344. const uint32_t v_type = _.GetOperandTypeId(inst, 4);
  1345. if (!_.IsFloatVectorType(v_type) || _.GetDimension(v_type) != 2 ||
  1346. _.GetBitWidth(v_type) != 32) {
  1347. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1348. << GetExtInstName(_, inst) << ": "
  1349. << "expected operand V to be a 32-bit float vector of size 2";
  1350. }
  1351. break;
  1352. }
  1353. case GLSLstd450PackDouble2x32: {
  1354. if (!_.IsFloatScalarType(result_type) ||
  1355. _.GetBitWidth(result_type) != 64) {
  1356. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1357. << GetExtInstName(_, inst) << ": "
  1358. << "expected Result Type to be 64-bit float scalar type";
  1359. }
  1360. const uint32_t v_type = _.GetOperandTypeId(inst, 4);
  1361. if (!_.IsIntVectorType(v_type) || _.GetDimension(v_type) != 2 ||
  1362. _.GetBitWidth(v_type) != 32) {
  1363. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1364. << GetExtInstName(_, inst) << ": "
  1365. << "expected operand V to be a 32-bit int vector of size 2";
  1366. }
  1367. break;
  1368. }
  1369. case GLSLstd450UnpackSnorm4x8:
  1370. case GLSLstd450UnpackUnorm4x8: {
  1371. if (!_.IsFloatVectorType(result_type) ||
  1372. _.GetDimension(result_type) != 4 ||
  1373. _.GetBitWidth(result_type) != 32) {
  1374. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1375. << GetExtInstName(_, inst) << ": "
  1376. << "expected Result Type to be a 32-bit float vector of size "
  1377. "4";
  1378. }
  1379. const uint32_t v_type = _.GetOperandTypeId(inst, 4);
  1380. if (!_.IsIntScalarType(v_type) || _.GetBitWidth(v_type) != 32) {
  1381. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1382. << GetExtInstName(_, inst) << ": "
  1383. << "expected operand P to be a 32-bit int scalar";
  1384. }
  1385. break;
  1386. }
  1387. case GLSLstd450UnpackSnorm2x16:
  1388. case GLSLstd450UnpackUnorm2x16:
  1389. case GLSLstd450UnpackHalf2x16: {
  1390. if (!_.IsFloatVectorType(result_type) ||
  1391. _.GetDimension(result_type) != 2 ||
  1392. _.GetBitWidth(result_type) != 32) {
  1393. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1394. << GetExtInstName(_, inst) << ": "
  1395. << "expected Result Type to be a 32-bit float vector of size "
  1396. "2";
  1397. }
  1398. const uint32_t v_type = _.GetOperandTypeId(inst, 4);
  1399. if (!_.IsIntScalarType(v_type) || _.GetBitWidth(v_type) != 32) {
  1400. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1401. << GetExtInstName(_, inst) << ": "
  1402. << "expected operand P to be a 32-bit int scalar";
  1403. }
  1404. break;
  1405. }
  1406. case GLSLstd450UnpackDouble2x32: {
  1407. if (!_.IsIntVectorType(result_type) || _.GetDimension(result_type) != 2 ||
  1408. _.GetBitWidth(result_type) != 32) {
  1409. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1410. << GetExtInstName(_, inst) << ": "
  1411. << "expected Result Type to be a 32-bit int vector of size "
  1412. "2";
  1413. }
  1414. const uint32_t v_type = _.GetOperandTypeId(inst, 4);
  1415. if (!_.IsFloatScalarType(v_type) || _.GetBitWidth(v_type) != 64) {
  1416. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1417. << GetExtInstName(_, inst) << ": "
  1418. << "expected operand V to be a 64-bit float scalar";
  1419. }
  1420. break;
  1421. }
  1422. case GLSLstd450Length: {
  1423. if (!_.IsFloatScalarType(result_type)) {
  1424. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1425. << GetExtInstName(_, inst) << ": "
  1426. << "expected Result Type to be a float scalar type";
  1427. }
  1428. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1429. if (!_.IsFloatScalarOrVectorType(x_type)) {
  1430. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1431. << GetExtInstName(_, inst) << ": "
  1432. << "expected operand X to be of float scalar or vector type";
  1433. }
  1434. if (result_type != _.GetComponentType(x_type)) {
  1435. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1436. << GetExtInstName(_, inst) << ": "
  1437. << "expected operand X component type to be equal to Result "
  1438. "Type";
  1439. }
  1440. break;
  1441. }
  1442. case GLSLstd450Distance: {
  1443. if (!_.IsFloatScalarType(result_type)) {
  1444. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1445. << GetExtInstName(_, inst) << ": "
  1446. << "expected Result Type to be a float scalar type";
  1447. }
  1448. const uint32_t p0_type = _.GetOperandTypeId(inst, 4);
  1449. if (!_.IsFloatScalarOrVectorType(p0_type)) {
  1450. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1451. << GetExtInstName(_, inst) << ": "
  1452. << "expected operand P0 to be of float scalar or vector type";
  1453. }
  1454. if (result_type != _.GetComponentType(p0_type)) {
  1455. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1456. << GetExtInstName(_, inst) << ": "
  1457. << "expected operand P0 component type to be equal to "
  1458. << "Result Type";
  1459. }
  1460. const uint32_t p1_type = _.GetOperandTypeId(inst, 5);
  1461. if (!_.IsFloatScalarOrVectorType(p1_type)) {
  1462. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1463. << GetExtInstName(_, inst) << ": "
  1464. << "expected operand P1 to be of float scalar or vector type";
  1465. }
  1466. if (result_type != _.GetComponentType(p1_type)) {
  1467. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1468. << GetExtInstName(_, inst) << ": "
  1469. << "expected operand P1 component type to be equal to "
  1470. << "Result Type";
  1471. }
  1472. if (_.GetDimension(p0_type) != _.GetDimension(p1_type)) {
  1473. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1474. << GetExtInstName(_, inst) << ": "
  1475. << "expected operands P0 and P1 to have the same number of "
  1476. << "components";
  1477. }
  1478. break;
  1479. }
  1480. case GLSLstd450Cross: {
  1481. if (!_.IsFloatVectorType(result_type)) {
  1482. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1483. << GetExtInstName(_, inst) << ": "
  1484. << "expected Result Type to be a float vector type";
  1485. }
  1486. if (_.GetDimension(result_type) != 3) {
  1487. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1488. << GetExtInstName(_, inst) << ": "
  1489. << "expected Result Type to have 3 components";
  1490. }
  1491. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1492. const uint32_t y_type = _.GetOperandTypeId(inst, 5);
  1493. if (x_type != result_type) {
  1494. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1495. << GetExtInstName(_, inst) << ": "
  1496. << "expected operand X type to be equal to Result Type";
  1497. }
  1498. if (y_type != result_type) {
  1499. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1500. << GetExtInstName(_, inst) << ": "
  1501. << "expected operand Y type to be equal to Result Type";
  1502. }
  1503. break;
  1504. }
  1505. case GLSLstd450Refract: {
  1506. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1507. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1508. << GetExtInstName(_, inst) << ": "
  1509. << "expected Result Type to be a float scalar or vector type";
  1510. }
  1511. const uint32_t i_type = _.GetOperandTypeId(inst, 4);
  1512. const uint32_t n_type = _.GetOperandTypeId(inst, 5);
  1513. const uint32_t eta_type = _.GetOperandTypeId(inst, 6);
  1514. if (result_type != i_type) {
  1515. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1516. << GetExtInstName(_, inst) << ": "
  1517. << "expected operand I to be of type equal to Result Type";
  1518. }
  1519. if (result_type != n_type) {
  1520. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1521. << GetExtInstName(_, inst) << ": "
  1522. << "expected operand N to be of type equal to Result Type";
  1523. }
  1524. if (!_.IsFloatScalarType(eta_type)) {
  1525. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1526. << GetExtInstName(_, inst) << ": "
  1527. << "expected operand Eta to be a float scalar";
  1528. }
  1529. break;
  1530. }
  1531. case GLSLstd450InterpolateAtCentroid:
  1532. case GLSLstd450InterpolateAtSample:
  1533. case GLSLstd450InterpolateAtOffset: {
  1534. if (!_.HasCapability(spv::Capability::InterpolationFunction)) {
  1535. return _.diag(SPV_ERROR_INVALID_CAPABILITY, inst)
  1536. << GetExtInstName(_, inst)
  1537. << " requires capability InterpolationFunction";
  1538. }
  1539. if (!_.IsFloatScalarOrVectorType(result_type) ||
  1540. _.GetBitWidth(result_type) != 32) {
  1541. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1542. << GetExtInstName(_, inst) << ": "
  1543. << "expected Result Type to be a 32-bit float scalar "
  1544. << "or vector type";
  1545. }
  1546. // If HLSL legalization and first operand is an OpLoad, use load
  1547. // pointer as the interpolant lvalue. Else use interpolate first
  1548. // operand.
  1549. uint32_t interp_id = inst->GetOperandAs<uint32_t>(4);
  1550. auto* interp_inst = _.FindDef(interp_id);
  1551. uint32_t interpolant_type = (_.options()->before_hlsl_legalization &&
  1552. interp_inst->opcode() == spv::Op::OpLoad)
  1553. ? _.GetOperandTypeId(interp_inst, 2)
  1554. : _.GetOperandTypeId(inst, 4);
  1555. spv::StorageClass interpolant_storage_class;
  1556. uint32_t interpolant_data_type = 0;
  1557. if (!_.GetPointerTypeInfo(interpolant_type, &interpolant_data_type,
  1558. &interpolant_storage_class)) {
  1559. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1560. << GetExtInstName(_, inst) << ": "
  1561. << "expected Interpolant to be a pointer";
  1562. }
  1563. if (result_type != interpolant_data_type) {
  1564. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1565. << GetExtInstName(_, inst) << ": "
  1566. << "expected Interpolant data type to be equal to Result Type";
  1567. }
  1568. if (interpolant_storage_class != spv::StorageClass::Input) {
  1569. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1570. << GetExtInstName(_, inst) << ": "
  1571. << "expected Interpolant storage class to be Input";
  1572. }
  1573. if (ext_inst_key == GLSLstd450InterpolateAtSample) {
  1574. const uint32_t sample_type = _.GetOperandTypeId(inst, 5);
  1575. if (!_.IsIntScalarType(sample_type) ||
  1576. _.GetBitWidth(sample_type) != 32) {
  1577. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1578. << GetExtInstName(_, inst) << ": "
  1579. << "expected Sample to be 32-bit integer";
  1580. }
  1581. }
  1582. if (ext_inst_key == GLSLstd450InterpolateAtOffset) {
  1583. const uint32_t offset_type = _.GetOperandTypeId(inst, 5);
  1584. if (!_.IsFloatVectorType(offset_type) ||
  1585. _.GetDimension(offset_type) != 2 ||
  1586. _.GetBitWidth(offset_type) != 32) {
  1587. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1588. << GetExtInstName(_, inst) << ": "
  1589. << "expected Offset to be a vector of 2 32-bit floats";
  1590. }
  1591. }
  1592. _.function(inst->function()->id())
  1593. ->RegisterExecutionModelLimitation(
  1594. spv::ExecutionModel::Fragment,
  1595. GetExtInstName(_, inst) +
  1596. std::string(" requires Fragment execution model"));
  1597. break;
  1598. }
  1599. case GLSLstd450IMix: {
  1600. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1601. << "Extended instruction GLSLstd450IMix is not supported";
  1602. }
  1603. case GLSLstd450Bad: {
  1604. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1605. << "Encountered extended instruction GLSLstd450Bad";
  1606. }
  1607. case GLSLstd450Count: {
  1608. assert(0);
  1609. break;
  1610. }
  1611. }
  1612. return SPV_SUCCESS;
  1613. }
  1614. spv_result_t ValidateExtInstOpenClStd(ValidationState_t& _,
  1615. const Instruction* inst) {
  1616. const uint32_t result_type = inst->type_id();
  1617. const uint32_t num_operands = static_cast<uint32_t>(inst->operands().size());
  1618. const uint32_t ext_inst_index = inst->word(4);
  1619. const OpenCLLIB::Entrypoints ext_inst_key =
  1620. OpenCLLIB::Entrypoints(ext_inst_index);
  1621. switch (ext_inst_key) {
  1622. case OpenCLLIB::Acos:
  1623. case OpenCLLIB::Acosh:
  1624. case OpenCLLIB::Acospi:
  1625. case OpenCLLIB::Asin:
  1626. case OpenCLLIB::Asinh:
  1627. case OpenCLLIB::Asinpi:
  1628. case OpenCLLIB::Atan:
  1629. case OpenCLLIB::Atan2:
  1630. case OpenCLLIB::Atanh:
  1631. case OpenCLLIB::Atanpi:
  1632. case OpenCLLIB::Atan2pi:
  1633. case OpenCLLIB::Cbrt:
  1634. case OpenCLLIB::Ceil:
  1635. case OpenCLLIB::Copysign:
  1636. case OpenCLLIB::Cos:
  1637. case OpenCLLIB::Cosh:
  1638. case OpenCLLIB::Cospi:
  1639. case OpenCLLIB::Erfc:
  1640. case OpenCLLIB::Erf:
  1641. case OpenCLLIB::Exp:
  1642. case OpenCLLIB::Exp2:
  1643. case OpenCLLIB::Exp10:
  1644. case OpenCLLIB::Expm1:
  1645. case OpenCLLIB::Fabs:
  1646. case OpenCLLIB::Fdim:
  1647. case OpenCLLIB::Floor:
  1648. case OpenCLLIB::Fma:
  1649. case OpenCLLIB::Fmax:
  1650. case OpenCLLIB::Fmin:
  1651. case OpenCLLIB::Fmod:
  1652. case OpenCLLIB::Hypot:
  1653. case OpenCLLIB::Lgamma:
  1654. case OpenCLLIB::Log:
  1655. case OpenCLLIB::Log2:
  1656. case OpenCLLIB::Log10:
  1657. case OpenCLLIB::Log1p:
  1658. case OpenCLLIB::Logb:
  1659. case OpenCLLIB::Mad:
  1660. case OpenCLLIB::Maxmag:
  1661. case OpenCLLIB::Minmag:
  1662. case OpenCLLIB::Nextafter:
  1663. case OpenCLLIB::Pow:
  1664. case OpenCLLIB::Powr:
  1665. case OpenCLLIB::Remainder:
  1666. case OpenCLLIB::Rint:
  1667. case OpenCLLIB::Round:
  1668. case OpenCLLIB::Rsqrt:
  1669. case OpenCLLIB::Sin:
  1670. case OpenCLLIB::Sinh:
  1671. case OpenCLLIB::Sinpi:
  1672. case OpenCLLIB::Sqrt:
  1673. case OpenCLLIB::Tan:
  1674. case OpenCLLIB::Tanh:
  1675. case OpenCLLIB::Tanpi:
  1676. case OpenCLLIB::Tgamma:
  1677. case OpenCLLIB::Trunc:
  1678. case OpenCLLIB::Half_cos:
  1679. case OpenCLLIB::Half_divide:
  1680. case OpenCLLIB::Half_exp:
  1681. case OpenCLLIB::Half_exp2:
  1682. case OpenCLLIB::Half_exp10:
  1683. case OpenCLLIB::Half_log:
  1684. case OpenCLLIB::Half_log2:
  1685. case OpenCLLIB::Half_log10:
  1686. case OpenCLLIB::Half_powr:
  1687. case OpenCLLIB::Half_recip:
  1688. case OpenCLLIB::Half_rsqrt:
  1689. case OpenCLLIB::Half_sin:
  1690. case OpenCLLIB::Half_sqrt:
  1691. case OpenCLLIB::Half_tan:
  1692. case OpenCLLIB::Native_cos:
  1693. case OpenCLLIB::Native_divide:
  1694. case OpenCLLIB::Native_exp:
  1695. case OpenCLLIB::Native_exp2:
  1696. case OpenCLLIB::Native_exp10:
  1697. case OpenCLLIB::Native_log:
  1698. case OpenCLLIB::Native_log2:
  1699. case OpenCLLIB::Native_log10:
  1700. case OpenCLLIB::Native_powr:
  1701. case OpenCLLIB::Native_recip:
  1702. case OpenCLLIB::Native_rsqrt:
  1703. case OpenCLLIB::Native_sin:
  1704. case OpenCLLIB::Native_sqrt:
  1705. case OpenCLLIB::Native_tan:
  1706. case OpenCLLIB::FClamp:
  1707. case OpenCLLIB::Degrees:
  1708. case OpenCLLIB::FMax_common:
  1709. case OpenCLLIB::FMin_common:
  1710. case OpenCLLIB::Mix:
  1711. case OpenCLLIB::Radians:
  1712. case OpenCLLIB::Step:
  1713. case OpenCLLIB::Smoothstep:
  1714. case OpenCLLIB::Sign: {
  1715. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1716. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1717. << GetExtInstName(_, inst) << ": "
  1718. << "expected Result Type to be a float scalar or vector type";
  1719. }
  1720. const uint32_t num_components = _.GetDimension(result_type);
  1721. if (num_components > 4 && num_components != 8 && num_components != 16) {
  1722. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1723. << GetExtInstName(_, inst) << ": "
  1724. << "expected Result Type to be a scalar or a vector with 2, "
  1725. "3, 4, 8 or 16 components";
  1726. }
  1727. for (uint32_t operand_index = 4; operand_index < num_operands;
  1728. ++operand_index) {
  1729. const uint32_t operand_type = _.GetOperandTypeId(inst, operand_index);
  1730. if (result_type != operand_type) {
  1731. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1732. << GetExtInstName(_, inst) << ": "
  1733. << "expected types of all operands to be equal to Result "
  1734. "Type";
  1735. }
  1736. }
  1737. break;
  1738. }
  1739. case OpenCLLIB::Fract:
  1740. case OpenCLLIB::Modf:
  1741. case OpenCLLIB::Sincos: {
  1742. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1743. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1744. << GetExtInstName(_, inst) << ": "
  1745. << "expected Result Type to be a float scalar or vector type";
  1746. }
  1747. const uint32_t num_components = _.GetDimension(result_type);
  1748. if (num_components > 4 && num_components != 8 && num_components != 16) {
  1749. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1750. << GetExtInstName(_, inst) << ": "
  1751. << "expected Result Type to be a scalar or a vector with 2, "
  1752. "3, 4, 8 or 16 components";
  1753. }
  1754. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1755. if (result_type != x_type) {
  1756. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1757. << GetExtInstName(_, inst) << ": "
  1758. << "expected type of operand X to be equal to Result Type";
  1759. }
  1760. const uint32_t p_type = _.GetOperandTypeId(inst, 5);
  1761. spv::StorageClass p_storage_class;
  1762. uint32_t p_data_type = 0;
  1763. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  1764. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1765. << GetExtInstName(_, inst) << ": "
  1766. << "expected the last operand to be a pointer";
  1767. }
  1768. if (p_storage_class != spv::StorageClass::Generic &&
  1769. p_storage_class != spv::StorageClass::CrossWorkgroup &&
  1770. p_storage_class != spv::StorageClass::Workgroup &&
  1771. p_storage_class != spv::StorageClass::Function) {
  1772. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1773. << GetExtInstName(_, inst) << ": "
  1774. << "expected storage class of the pointer to be Generic, "
  1775. "CrossWorkgroup, Workgroup or Function";
  1776. }
  1777. if (!_.ContainsUntypedPointer(p_type) && result_type != p_data_type) {
  1778. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1779. << GetExtInstName(_, inst) << ": "
  1780. << "expected data type of the pointer to be equal to Result "
  1781. "Type";
  1782. }
  1783. break;
  1784. }
  1785. case OpenCLLIB::Frexp:
  1786. case OpenCLLIB::Lgamma_r:
  1787. case OpenCLLIB::Remquo: {
  1788. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1789. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1790. << GetExtInstName(_, inst) << ": "
  1791. << "expected Result Type to be a float scalar or vector type";
  1792. }
  1793. const uint32_t num_components = _.GetDimension(result_type);
  1794. if (num_components > 4 && num_components != 8 && num_components != 16) {
  1795. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1796. << GetExtInstName(_, inst) << ": "
  1797. << "expected Result Type to be a scalar or a vector with 2, "
  1798. "3, 4, 8 or 16 components";
  1799. }
  1800. uint32_t operand_index = 4;
  1801. const uint32_t x_type = _.GetOperandTypeId(inst, operand_index++);
  1802. if (result_type != x_type) {
  1803. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1804. << GetExtInstName(_, inst) << ": "
  1805. << "expected type of operand X to be equal to Result Type";
  1806. }
  1807. if (ext_inst_key == OpenCLLIB::Remquo) {
  1808. const uint32_t y_type = _.GetOperandTypeId(inst, operand_index++);
  1809. if (result_type != y_type) {
  1810. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1811. << GetExtInstName(_, inst) << ": "
  1812. << "expected type of operand Y to be equal to Result Type";
  1813. }
  1814. }
  1815. const uint32_t p_type = _.GetOperandTypeId(inst, operand_index++);
  1816. spv::StorageClass p_storage_class;
  1817. uint32_t p_data_type = 0;
  1818. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  1819. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1820. << GetExtInstName(_, inst) << ": "
  1821. << "expected the last operand to be a pointer";
  1822. }
  1823. if (p_storage_class != spv::StorageClass::Generic &&
  1824. p_storage_class != spv::StorageClass::CrossWorkgroup &&
  1825. p_storage_class != spv::StorageClass::Workgroup &&
  1826. p_storage_class != spv::StorageClass::Function) {
  1827. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1828. << GetExtInstName(_, inst) << ": "
  1829. << "expected storage class of the pointer to be Generic, "
  1830. "CrossWorkgroup, Workgroup or Function";
  1831. }
  1832. if ((!_.IsIntScalarOrVectorType(p_data_type) ||
  1833. _.GetBitWidth(p_data_type) != 32) &&
  1834. !_.ContainsUntypedPointer(p_type)) {
  1835. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1836. << GetExtInstName(_, inst) << ": "
  1837. << "expected data type of the pointer to be a 32-bit int "
  1838. "scalar or vector type";
  1839. }
  1840. if (!_.ContainsUntypedPointer(p_type) &&
  1841. _.GetDimension(p_data_type) != num_components) {
  1842. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1843. << GetExtInstName(_, inst) << ": "
  1844. << "expected data type of the pointer to have the same number "
  1845. "of components as Result Type";
  1846. }
  1847. break;
  1848. }
  1849. case OpenCLLIB::Ilogb: {
  1850. if (!_.IsIntScalarOrVectorType(result_type) ||
  1851. _.GetBitWidth(result_type) != 32) {
  1852. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1853. << GetExtInstName(_, inst) << ": "
  1854. << "expected Result Type to be a 32-bit int scalar or vector "
  1855. "type";
  1856. }
  1857. const uint32_t num_components = _.GetDimension(result_type);
  1858. if (num_components > 4 && num_components != 8 && num_components != 16) {
  1859. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1860. << GetExtInstName(_, inst) << ": "
  1861. << "expected Result Type to be a scalar or a vector with 2, "
  1862. "3, 4, 8 or 16 components";
  1863. }
  1864. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1865. if (!_.IsFloatScalarOrVectorType(x_type)) {
  1866. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1867. << GetExtInstName(_, inst) << ": "
  1868. << "expected operand X to be a float scalar or vector";
  1869. }
  1870. if (_.GetDimension(x_type) != num_components) {
  1871. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1872. << GetExtInstName(_, inst) << ": "
  1873. << "expected operand X to have the same number of components "
  1874. "as Result Type";
  1875. }
  1876. break;
  1877. }
  1878. case OpenCLLIB::Ldexp:
  1879. case OpenCLLIB::Pown:
  1880. case OpenCLLIB::Rootn: {
  1881. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1882. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1883. << GetExtInstName(_, inst) << ": "
  1884. << "expected Result Type to be a float scalar or vector type";
  1885. }
  1886. const uint32_t num_components = _.GetDimension(result_type);
  1887. if (num_components > 4 && num_components != 8 && num_components != 16) {
  1888. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1889. << GetExtInstName(_, inst) << ": "
  1890. << "expected Result Type to be a scalar or a vector with 2, "
  1891. "3, 4, 8 or 16 components";
  1892. }
  1893. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  1894. if (result_type != x_type) {
  1895. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1896. << GetExtInstName(_, inst) << ": "
  1897. << "expected type of operand X to be equal to Result Type";
  1898. }
  1899. const uint32_t exp_type = _.GetOperandTypeId(inst, 5);
  1900. if (!_.IsIntScalarOrVectorType(exp_type) ||
  1901. _.GetBitWidth(exp_type) != 32) {
  1902. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1903. << GetExtInstName(_, inst) << ": "
  1904. << "expected the exponent to be a 32-bit int scalar or vector";
  1905. }
  1906. if (_.GetDimension(exp_type) != num_components) {
  1907. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1908. << GetExtInstName(_, inst) << ": "
  1909. << "expected the exponent to have the same number of "
  1910. "components as Result Type";
  1911. }
  1912. break;
  1913. }
  1914. case OpenCLLIB::Nan: {
  1915. if (!_.IsFloatScalarOrVectorType(result_type)) {
  1916. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1917. << GetExtInstName(_, inst) << ": "
  1918. << "expected Result Type to be a float scalar or vector type";
  1919. }
  1920. const uint32_t num_components = _.GetDimension(result_type);
  1921. if (num_components > 4 && num_components != 8 && num_components != 16) {
  1922. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1923. << GetExtInstName(_, inst) << ": "
  1924. << "expected Result Type to be a scalar or a vector with 2, "
  1925. "3, 4, 8 or 16 components";
  1926. }
  1927. const uint32_t nancode_type = _.GetOperandTypeId(inst, 4);
  1928. if (!_.IsIntScalarOrVectorType(nancode_type)) {
  1929. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1930. << GetExtInstName(_, inst) << ": "
  1931. << "expected Nancode to be an int scalar or vector type";
  1932. }
  1933. if (_.GetDimension(nancode_type) != num_components) {
  1934. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1935. << GetExtInstName(_, inst) << ": "
  1936. << "expected Nancode to have the same number of components as "
  1937. "Result Type";
  1938. }
  1939. if (_.GetBitWidth(result_type) != _.GetBitWidth(nancode_type)) {
  1940. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1941. << GetExtInstName(_, inst) << ": "
  1942. << "expected Nancode to have the same bit width as Result "
  1943. "Type";
  1944. }
  1945. break;
  1946. }
  1947. case OpenCLLIB::SAbs:
  1948. case OpenCLLIB::SAbs_diff:
  1949. case OpenCLLIB::SAdd_sat:
  1950. case OpenCLLIB::UAdd_sat:
  1951. case OpenCLLIB::SHadd:
  1952. case OpenCLLIB::UHadd:
  1953. case OpenCLLIB::SRhadd:
  1954. case OpenCLLIB::URhadd:
  1955. case OpenCLLIB::SClamp:
  1956. case OpenCLLIB::UClamp:
  1957. case OpenCLLIB::Clz:
  1958. case OpenCLLIB::Ctz:
  1959. case OpenCLLIB::SMad_hi:
  1960. case OpenCLLIB::UMad_sat:
  1961. case OpenCLLIB::SMad_sat:
  1962. case OpenCLLIB::SMax:
  1963. case OpenCLLIB::UMax:
  1964. case OpenCLLIB::SMin:
  1965. case OpenCLLIB::UMin:
  1966. case OpenCLLIB::SMul_hi:
  1967. case OpenCLLIB::Rotate:
  1968. case OpenCLLIB::SSub_sat:
  1969. case OpenCLLIB::USub_sat:
  1970. case OpenCLLIB::Popcount:
  1971. case OpenCLLIB::UAbs:
  1972. case OpenCLLIB::UAbs_diff:
  1973. case OpenCLLIB::UMul_hi:
  1974. case OpenCLLIB::UMad_hi: {
  1975. if (!_.IsIntScalarOrVectorType(result_type)) {
  1976. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1977. << GetExtInstName(_, inst) << ": "
  1978. << "expected Result Type to be an int scalar or vector type";
  1979. }
  1980. const uint32_t num_components = _.GetDimension(result_type);
  1981. if (num_components > 4 && num_components != 8 && num_components != 16) {
  1982. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1983. << GetExtInstName(_, inst) << ": "
  1984. << "expected Result Type to be a scalar or a vector with 2, "
  1985. "3, 4, 8 or 16 components";
  1986. }
  1987. for (uint32_t operand_index = 4; operand_index < num_operands;
  1988. ++operand_index) {
  1989. const uint32_t operand_type = _.GetOperandTypeId(inst, operand_index);
  1990. if (result_type != operand_type) {
  1991. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  1992. << GetExtInstName(_, inst) << ": "
  1993. << "expected types of all operands to be equal to Result "
  1994. "Type";
  1995. }
  1996. }
  1997. break;
  1998. }
  1999. case OpenCLLIB::U_Upsample:
  2000. case OpenCLLIB::S_Upsample: {
  2001. if (!_.IsIntScalarOrVectorType(result_type)) {
  2002. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2003. << GetExtInstName(_, inst) << ": "
  2004. << "expected Result Type to be an int scalar or vector "
  2005. "type";
  2006. }
  2007. const uint32_t result_num_components = _.GetDimension(result_type);
  2008. if (result_num_components > 4 && result_num_components != 8 &&
  2009. result_num_components != 16) {
  2010. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2011. << GetExtInstName(_, inst) << ": "
  2012. << "expected Result Type to be a scalar or a vector with 2, "
  2013. "3, 4, 8 or 16 components";
  2014. }
  2015. const uint32_t result_bit_width = _.GetBitWidth(result_type);
  2016. if (result_bit_width != 16 && result_bit_width != 32 &&
  2017. result_bit_width != 64) {
  2018. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2019. << GetExtInstName(_, inst) << ": "
  2020. << "expected bit width of Result Type components to be 16, 32 "
  2021. "or 64";
  2022. }
  2023. const uint32_t hi_type = _.GetOperandTypeId(inst, 4);
  2024. const uint32_t lo_type = _.GetOperandTypeId(inst, 5);
  2025. if (hi_type != lo_type) {
  2026. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2027. << GetExtInstName(_, inst) << ": "
  2028. << "expected Hi and Lo operands to have the same type";
  2029. }
  2030. if (result_num_components != _.GetDimension(hi_type)) {
  2031. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2032. << GetExtInstName(_, inst) << ": "
  2033. << "expected Hi and Lo operands to have the same number of "
  2034. "components as Result Type";
  2035. }
  2036. if (result_bit_width != 2 * _.GetBitWidth(hi_type)) {
  2037. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2038. << GetExtInstName(_, inst) << ": "
  2039. << "expected bit width of components of Hi and Lo operands to "
  2040. "be half of the bit width of components of Result Type";
  2041. }
  2042. break;
  2043. }
  2044. case OpenCLLIB::SMad24:
  2045. case OpenCLLIB::UMad24:
  2046. case OpenCLLIB::SMul24:
  2047. case OpenCLLIB::UMul24: {
  2048. if (!_.IsIntScalarOrVectorType(result_type) ||
  2049. _.GetBitWidth(result_type) != 32) {
  2050. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2051. << GetExtInstName(_, inst) << ": "
  2052. << "expected Result Type to be a 32-bit int scalar or vector "
  2053. "type";
  2054. }
  2055. const uint32_t num_components = _.GetDimension(result_type);
  2056. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2057. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2058. << GetExtInstName(_, inst) << ": "
  2059. << "expected Result Type to be a scalar or a vector with 2, "
  2060. "3, 4, 8 or 16 components";
  2061. }
  2062. for (uint32_t operand_index = 4; operand_index < num_operands;
  2063. ++operand_index) {
  2064. const uint32_t operand_type = _.GetOperandTypeId(inst, operand_index);
  2065. if (result_type != operand_type) {
  2066. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2067. << GetExtInstName(_, inst) << ": "
  2068. << "expected types of all operands to be equal to Result "
  2069. "Type";
  2070. }
  2071. }
  2072. break;
  2073. }
  2074. case OpenCLLIB::Cross: {
  2075. if (!_.IsFloatVectorType(result_type)) {
  2076. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2077. << GetExtInstName(_, inst) << ": "
  2078. << "expected Result Type to be a float vector type";
  2079. }
  2080. const uint32_t num_components = _.GetDimension(result_type);
  2081. if (num_components != 3 && num_components != 4) {
  2082. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2083. << GetExtInstName(_, inst) << ": "
  2084. << "expected Result Type to have 3 or 4 components";
  2085. }
  2086. const uint32_t x_type = _.GetOperandTypeId(inst, 4);
  2087. const uint32_t y_type = _.GetOperandTypeId(inst, 5);
  2088. if (x_type != result_type) {
  2089. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2090. << GetExtInstName(_, inst) << ": "
  2091. << "expected operand X type to be equal to Result Type";
  2092. }
  2093. if (y_type != result_type) {
  2094. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2095. << GetExtInstName(_, inst) << ": "
  2096. << "expected operand Y type to be equal to Result Type";
  2097. }
  2098. break;
  2099. }
  2100. case OpenCLLIB::Distance:
  2101. case OpenCLLIB::Fast_distance: {
  2102. if (!_.IsFloatScalarType(result_type)) {
  2103. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2104. << GetExtInstName(_, inst) << ": "
  2105. << "expected Result Type to be a float scalar type";
  2106. }
  2107. const uint32_t p0_type = _.GetOperandTypeId(inst, 4);
  2108. if (!_.IsFloatScalarOrVectorType(p0_type)) {
  2109. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2110. << GetExtInstName(_, inst) << ": "
  2111. << "expected operand P0 to be of float scalar or vector type";
  2112. }
  2113. const uint32_t num_components = _.GetDimension(p0_type);
  2114. if (num_components > 4) {
  2115. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2116. << GetExtInstName(_, inst) << ": "
  2117. << "expected operand P0 to have no more than 4 components";
  2118. }
  2119. if (result_type != _.GetComponentType(p0_type)) {
  2120. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2121. << GetExtInstName(_, inst) << ": "
  2122. << "expected operand P0 component type to be equal to "
  2123. << "Result Type";
  2124. }
  2125. const uint32_t p1_type = _.GetOperandTypeId(inst, 5);
  2126. if (p0_type != p1_type) {
  2127. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2128. << GetExtInstName(_, inst) << ": "
  2129. << "expected operands P0 and P1 to be of the same type";
  2130. }
  2131. break;
  2132. }
  2133. case OpenCLLIB::Length:
  2134. case OpenCLLIB::Fast_length: {
  2135. if (!_.IsFloatScalarType(result_type)) {
  2136. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2137. << GetExtInstName(_, inst) << ": "
  2138. << "expected Result Type to be a float scalar type";
  2139. }
  2140. const uint32_t p_type = _.GetOperandTypeId(inst, 4);
  2141. if (!_.IsFloatScalarOrVectorType(p_type)) {
  2142. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2143. << GetExtInstName(_, inst) << ": "
  2144. << "expected operand P to be a float scalar or vector";
  2145. }
  2146. const uint32_t num_components = _.GetDimension(p_type);
  2147. if (num_components > 4) {
  2148. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2149. << GetExtInstName(_, inst) << ": "
  2150. << "expected operand P to have no more than 4 components";
  2151. }
  2152. if (result_type != _.GetComponentType(p_type)) {
  2153. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2154. << GetExtInstName(_, inst) << ": "
  2155. << "expected operand P component type to be equal to Result "
  2156. "Type";
  2157. }
  2158. break;
  2159. }
  2160. case OpenCLLIB::Normalize:
  2161. case OpenCLLIB::Fast_normalize: {
  2162. if (!_.IsFloatScalarOrVectorType(result_type)) {
  2163. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2164. << GetExtInstName(_, inst) << ": "
  2165. << "expected Result Type to be a float scalar or vector type";
  2166. }
  2167. const uint32_t num_components = _.GetDimension(result_type);
  2168. if (num_components > 4) {
  2169. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2170. << GetExtInstName(_, inst) << ": "
  2171. << "expected Result Type to have no more than 4 components";
  2172. }
  2173. const uint32_t p_type = _.GetOperandTypeId(inst, 4);
  2174. if (p_type != result_type) {
  2175. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2176. << GetExtInstName(_, inst) << ": "
  2177. << "expected operand P type to be equal to Result Type";
  2178. }
  2179. break;
  2180. }
  2181. case OpenCLLIB::Bitselect: {
  2182. if (!_.IsFloatScalarOrVectorType(result_type) &&
  2183. !_.IsIntScalarOrVectorType(result_type)) {
  2184. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2185. << GetExtInstName(_, inst) << ": "
  2186. << "expected Result Type to be an int or float scalar or "
  2187. "vector type";
  2188. }
  2189. const uint32_t num_components = _.GetDimension(result_type);
  2190. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2191. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2192. << GetExtInstName(_, inst) << ": "
  2193. << "expected Result Type to be a scalar or a vector with 2, "
  2194. "3, 4, 8 or 16 components";
  2195. }
  2196. for (uint32_t operand_index = 4; operand_index < num_operands;
  2197. ++operand_index) {
  2198. const uint32_t operand_type = _.GetOperandTypeId(inst, operand_index);
  2199. if (result_type != operand_type) {
  2200. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2201. << GetExtInstName(_, inst) << ": "
  2202. << "expected types of all operands to be equal to Result "
  2203. "Type";
  2204. }
  2205. }
  2206. break;
  2207. }
  2208. case OpenCLLIB::Select: {
  2209. if (!_.IsFloatScalarOrVectorType(result_type) &&
  2210. !_.IsIntScalarOrVectorType(result_type)) {
  2211. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2212. << GetExtInstName(_, inst) << ": "
  2213. << "expected Result Type to be an int or float scalar or "
  2214. "vector type";
  2215. }
  2216. const uint32_t num_components = _.GetDimension(result_type);
  2217. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2218. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2219. << GetExtInstName(_, inst) << ": "
  2220. << "expected Result Type to be a scalar or a vector with 2, "
  2221. "3, 4, 8 or 16 components";
  2222. }
  2223. const uint32_t a_type = _.GetOperandTypeId(inst, 4);
  2224. const uint32_t b_type = _.GetOperandTypeId(inst, 5);
  2225. const uint32_t c_type = _.GetOperandTypeId(inst, 6);
  2226. if (result_type != a_type) {
  2227. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2228. << GetExtInstName(_, inst) << ": "
  2229. << "expected operand A type to be equal to Result Type";
  2230. }
  2231. if (result_type != b_type) {
  2232. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2233. << GetExtInstName(_, inst) << ": "
  2234. << "expected operand B type to be equal to Result Type";
  2235. }
  2236. if (!_.IsIntScalarOrVectorType(c_type)) {
  2237. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2238. << GetExtInstName(_, inst) << ": "
  2239. << "expected operand C to be an int scalar or vector";
  2240. }
  2241. if (num_components != _.GetDimension(c_type)) {
  2242. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2243. << GetExtInstName(_, inst) << ": "
  2244. << "expected operand C to have the same number of components "
  2245. "as Result Type";
  2246. }
  2247. if (_.GetBitWidth(result_type) != _.GetBitWidth(c_type)) {
  2248. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2249. << GetExtInstName(_, inst) << ": "
  2250. << "expected operand C to have the same bit width as Result "
  2251. "Type";
  2252. }
  2253. break;
  2254. }
  2255. case OpenCLLIB::Vloadn: {
  2256. if (!_.IsFloatVectorType(result_type) &&
  2257. !_.IsIntVectorType(result_type)) {
  2258. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2259. << GetExtInstName(_, inst) << ": "
  2260. << "expected Result Type to be an int or float vector type";
  2261. }
  2262. const uint32_t num_components = _.GetDimension(result_type);
  2263. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2264. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2265. << GetExtInstName(_, inst) << ": "
  2266. << "expected Result Type to have 2, 3, 4, 8 or 16 components";
  2267. }
  2268. const uint32_t offset_type = _.GetOperandTypeId(inst, 4);
  2269. const uint32_t p_type = _.GetOperandTypeId(inst, 5);
  2270. const uint32_t size_t_bit_width = GetSizeTBitWidth(_);
  2271. if (!size_t_bit_width) {
  2272. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2273. << GetExtInstName(_, inst)
  2274. << " can only be used with physical addressing models";
  2275. }
  2276. if (!_.IsIntScalarType(offset_type) ||
  2277. _.GetBitWidth(offset_type) != size_t_bit_width) {
  2278. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2279. << GetExtInstName(_, inst) << ": "
  2280. << "expected operand Offset to be of type size_t ("
  2281. << size_t_bit_width
  2282. << "-bit integer for the addressing model used in the module)";
  2283. }
  2284. spv::StorageClass p_storage_class;
  2285. uint32_t p_data_type = 0;
  2286. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  2287. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2288. << GetExtInstName(_, inst) << ": "
  2289. << "expected operand P to be a pointer";
  2290. }
  2291. if (p_storage_class != spv::StorageClass::UniformConstant &&
  2292. p_storage_class != spv::StorageClass::Generic &&
  2293. p_storage_class != spv::StorageClass::CrossWorkgroup &&
  2294. p_storage_class != spv::StorageClass::Workgroup &&
  2295. p_storage_class != spv::StorageClass::Function) {
  2296. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2297. << GetExtInstName(_, inst) << ": "
  2298. << "expected operand P storage class to be UniformConstant, "
  2299. "Generic, CrossWorkgroup, Workgroup or Function";
  2300. }
  2301. if (_.GetComponentType(result_type) != p_data_type) {
  2302. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2303. << GetExtInstName(_, inst) << ": "
  2304. << "expected operand P data type to be equal to component "
  2305. "type of Result Type";
  2306. }
  2307. const uint32_t n_value = inst->word(7);
  2308. if (num_components != n_value) {
  2309. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2310. << GetExtInstName(_, inst) << ": "
  2311. << "expected literal N to be equal to the number of "
  2312. "components of Result Type";
  2313. }
  2314. break;
  2315. }
  2316. case OpenCLLIB::Vstoren: {
  2317. if (_.GetIdOpcode(result_type) != spv::Op::OpTypeVoid) {
  2318. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2319. << GetExtInstName(_, inst)
  2320. << ": expected Result Type to be void";
  2321. }
  2322. const uint32_t data_type = _.GetOperandTypeId(inst, 4);
  2323. const uint32_t offset_type = _.GetOperandTypeId(inst, 5);
  2324. const uint32_t p_type = _.GetOperandTypeId(inst, 6);
  2325. if (!_.IsFloatVectorType(data_type) && !_.IsIntVectorType(data_type)) {
  2326. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2327. << GetExtInstName(_, inst) << ": "
  2328. << "expected Data to be an int or float vector";
  2329. }
  2330. const uint32_t num_components = _.GetDimension(data_type);
  2331. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2332. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2333. << GetExtInstName(_, inst) << ": "
  2334. << "expected Data to have 2, 3, 4, 8 or 16 components";
  2335. }
  2336. const uint32_t size_t_bit_width = GetSizeTBitWidth(_);
  2337. if (!size_t_bit_width) {
  2338. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2339. << GetExtInstName(_, inst)
  2340. << " can only be used with physical addressing models";
  2341. }
  2342. if (!_.IsIntScalarType(offset_type) ||
  2343. _.GetBitWidth(offset_type) != size_t_bit_width) {
  2344. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2345. << GetExtInstName(_, inst) << ": "
  2346. << "expected operand Offset to be of type size_t ("
  2347. << size_t_bit_width
  2348. << "-bit integer for the addressing model used in the module)";
  2349. }
  2350. spv::StorageClass p_storage_class;
  2351. uint32_t p_data_type = 0;
  2352. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  2353. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2354. << GetExtInstName(_, inst) << ": "
  2355. << "expected operand P to be a pointer";
  2356. }
  2357. if (p_storage_class != spv::StorageClass::Generic &&
  2358. p_storage_class != spv::StorageClass::CrossWorkgroup &&
  2359. p_storage_class != spv::StorageClass::Workgroup &&
  2360. p_storage_class != spv::StorageClass::Function) {
  2361. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2362. << GetExtInstName(_, inst) << ": "
  2363. << "expected operand P storage class to be Generic, "
  2364. "CrossWorkgroup, Workgroup or Function";
  2365. }
  2366. if (_.GetComponentType(data_type) != p_data_type) {
  2367. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2368. << GetExtInstName(_, inst) << ": "
  2369. << "expected operand P data type to be equal to the type of "
  2370. "operand Data components";
  2371. }
  2372. break;
  2373. }
  2374. case OpenCLLIB::Vload_half: {
  2375. if (!_.IsFloatScalarType(result_type)) {
  2376. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2377. << GetExtInstName(_, inst) << ": "
  2378. << "expected Result Type to be a float scalar type";
  2379. }
  2380. const uint32_t offset_type = _.GetOperandTypeId(inst, 4);
  2381. const uint32_t p_type = _.GetOperandTypeId(inst, 5);
  2382. const uint32_t size_t_bit_width = GetSizeTBitWidth(_);
  2383. if (!size_t_bit_width) {
  2384. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2385. << GetExtInstName(_, inst)
  2386. << " can only be used with physical addressing models";
  2387. }
  2388. if (!_.IsIntScalarType(offset_type) ||
  2389. _.GetBitWidth(offset_type) != size_t_bit_width) {
  2390. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2391. << GetExtInstName(_, inst) << ": "
  2392. << "expected operand Offset to be of type size_t ("
  2393. << size_t_bit_width
  2394. << "-bit integer for the addressing model used in the module)";
  2395. }
  2396. spv::StorageClass p_storage_class;
  2397. uint32_t p_data_type = 0;
  2398. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  2399. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2400. << GetExtInstName(_, inst) << ": "
  2401. << "expected operand P to be a pointer";
  2402. }
  2403. if (p_storage_class != spv::StorageClass::UniformConstant &&
  2404. p_storage_class != spv::StorageClass::Generic &&
  2405. p_storage_class != spv::StorageClass::CrossWorkgroup &&
  2406. p_storage_class != spv::StorageClass::Workgroup &&
  2407. p_storage_class != spv::StorageClass::Function) {
  2408. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2409. << GetExtInstName(_, inst) << ": "
  2410. << "expected operand P storage class to be UniformConstant, "
  2411. "Generic, CrossWorkgroup, Workgroup or Function";
  2412. }
  2413. if ((!_.IsFloatScalarType(p_data_type) ||
  2414. _.GetBitWidth(p_data_type) != 16) &&
  2415. !_.ContainsUntypedPointer(p_type)) {
  2416. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2417. << GetExtInstName(_, inst) << ": "
  2418. << "expected operand P data type to be 16-bit float scalar";
  2419. }
  2420. break;
  2421. }
  2422. case OpenCLLIB::Vload_halfn:
  2423. case OpenCLLIB::Vloada_halfn: {
  2424. if (!_.IsFloatVectorType(result_type)) {
  2425. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2426. << GetExtInstName(_, inst) << ": "
  2427. << "expected Result Type to be a float vector type";
  2428. }
  2429. const uint32_t num_components = _.GetDimension(result_type);
  2430. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2431. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2432. << GetExtInstName(_, inst) << ": "
  2433. << "expected Result Type to have 2, 3, 4, 8 or 16 components";
  2434. }
  2435. const uint32_t offset_type = _.GetOperandTypeId(inst, 4);
  2436. const uint32_t p_type = _.GetOperandTypeId(inst, 5);
  2437. const uint32_t size_t_bit_width = GetSizeTBitWidth(_);
  2438. if (!size_t_bit_width) {
  2439. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2440. << GetExtInstName(_, inst)
  2441. << " can only be used with physical addressing models";
  2442. }
  2443. if (!_.IsIntScalarType(offset_type) ||
  2444. _.GetBitWidth(offset_type) != size_t_bit_width) {
  2445. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2446. << GetExtInstName(_, inst) << ": "
  2447. << "expected operand Offset to be of type size_t ("
  2448. << size_t_bit_width
  2449. << "-bit integer for the addressing model used in the module)";
  2450. }
  2451. spv::StorageClass p_storage_class;
  2452. uint32_t p_data_type = 0;
  2453. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  2454. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2455. << GetExtInstName(_, inst) << ": "
  2456. << "expected operand P to be a pointer";
  2457. }
  2458. if (p_storage_class != spv::StorageClass::UniformConstant &&
  2459. p_storage_class != spv::StorageClass::Generic &&
  2460. p_storage_class != spv::StorageClass::CrossWorkgroup &&
  2461. p_storage_class != spv::StorageClass::Workgroup &&
  2462. p_storage_class != spv::StorageClass::Function) {
  2463. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2464. << GetExtInstName(_, inst) << ": "
  2465. << "expected operand P storage class to be UniformConstant, "
  2466. "Generic, CrossWorkgroup, Workgroup or Function";
  2467. }
  2468. if ((!_.IsFloatScalarType(p_data_type) ||
  2469. _.GetBitWidth(p_data_type) != 16) &&
  2470. !_.ContainsUntypedPointer(p_type)) {
  2471. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2472. << GetExtInstName(_, inst) << ": "
  2473. << "expected operand P data type to be 16-bit float scalar";
  2474. }
  2475. const uint32_t n_value = inst->word(7);
  2476. if (num_components != n_value) {
  2477. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2478. << GetExtInstName(_, inst) << ": "
  2479. << "expected literal N to be equal to the number of "
  2480. "components of Result Type";
  2481. }
  2482. break;
  2483. }
  2484. case OpenCLLIB::Vstore_half:
  2485. case OpenCLLIB::Vstore_half_r:
  2486. case OpenCLLIB::Vstore_halfn:
  2487. case OpenCLLIB::Vstore_halfn_r:
  2488. case OpenCLLIB::Vstorea_halfn:
  2489. case OpenCLLIB::Vstorea_halfn_r: {
  2490. if (_.GetIdOpcode(result_type) != spv::Op::OpTypeVoid) {
  2491. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2492. << GetExtInstName(_, inst)
  2493. << ": expected Result Type to be void";
  2494. }
  2495. const uint32_t data_type = _.GetOperandTypeId(inst, 4);
  2496. const uint32_t offset_type = _.GetOperandTypeId(inst, 5);
  2497. const uint32_t p_type = _.GetOperandTypeId(inst, 6);
  2498. const uint32_t data_type_bit_width = _.GetBitWidth(data_type);
  2499. if (ext_inst_key == OpenCLLIB::Vstore_half ||
  2500. ext_inst_key == OpenCLLIB::Vstore_half_r) {
  2501. if (!_.IsFloatScalarType(data_type) ||
  2502. (data_type_bit_width != 32 && data_type_bit_width != 64)) {
  2503. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2504. << GetExtInstName(_, inst) << ": "
  2505. << "expected Data to be a 32 or 64-bit float scalar";
  2506. }
  2507. } else {
  2508. if (!_.IsFloatVectorType(data_type) ||
  2509. (data_type_bit_width != 32 && data_type_bit_width != 64)) {
  2510. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2511. << GetExtInstName(_, inst) << ": "
  2512. << "expected Data to be a 32 or 64-bit float vector";
  2513. }
  2514. const uint32_t num_components = _.GetDimension(data_type);
  2515. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2516. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2517. << GetExtInstName(_, inst) << ": "
  2518. << "expected Data to have 2, 3, 4, 8 or 16 components";
  2519. }
  2520. }
  2521. const uint32_t size_t_bit_width = GetSizeTBitWidth(_);
  2522. if (!size_t_bit_width) {
  2523. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2524. << GetExtInstName(_, inst)
  2525. << " can only be used with physical addressing models";
  2526. }
  2527. if (!_.IsIntScalarType(offset_type) ||
  2528. _.GetBitWidth(offset_type) != size_t_bit_width) {
  2529. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2530. << GetExtInstName(_, inst) << ": "
  2531. << "expected operand Offset to be of type size_t ("
  2532. << size_t_bit_width
  2533. << "-bit integer for the addressing model used in the module)";
  2534. }
  2535. spv::StorageClass p_storage_class;
  2536. uint32_t p_data_type = 0;
  2537. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  2538. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2539. << GetExtInstName(_, inst) << ": "
  2540. << "expected operand P to be a pointer";
  2541. }
  2542. if (p_storage_class != spv::StorageClass::Generic &&
  2543. p_storage_class != spv::StorageClass::CrossWorkgroup &&
  2544. p_storage_class != spv::StorageClass::Workgroup &&
  2545. p_storage_class != spv::StorageClass::Function) {
  2546. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2547. << GetExtInstName(_, inst) << ": "
  2548. << "expected operand P storage class to be Generic, "
  2549. "CrossWorkgroup, Workgroup or Function";
  2550. }
  2551. if ((!_.IsFloatScalarType(p_data_type) ||
  2552. _.GetBitWidth(p_data_type) != 16) &&
  2553. !_.ContainsUntypedPointer(p_type)) {
  2554. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2555. << GetExtInstName(_, inst) << ": "
  2556. << "expected operand P data type to be 16-bit float scalar";
  2557. }
  2558. // Rounding mode enum is checked by assembler.
  2559. break;
  2560. }
  2561. case OpenCLLIB::Shuffle:
  2562. case OpenCLLIB::Shuffle2: {
  2563. if (!_.IsFloatVectorType(result_type) &&
  2564. !_.IsIntVectorType(result_type)) {
  2565. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2566. << GetExtInstName(_, inst) << ": "
  2567. << "expected Result Type to be an int or float vector type";
  2568. }
  2569. const uint32_t result_num_components = _.GetDimension(result_type);
  2570. if (result_num_components != 2 && result_num_components != 4 &&
  2571. result_num_components != 8 && result_num_components != 16) {
  2572. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2573. << GetExtInstName(_, inst) << ": "
  2574. << "expected Result Type to have 2, 4, 8 or 16 components";
  2575. }
  2576. uint32_t operand_index = 4;
  2577. const uint32_t x_type = _.GetOperandTypeId(inst, operand_index++);
  2578. if (ext_inst_key == OpenCLLIB::Shuffle2) {
  2579. const uint32_t y_type = _.GetOperandTypeId(inst, operand_index++);
  2580. if (x_type != y_type) {
  2581. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2582. << GetExtInstName(_, inst) << ": "
  2583. << "expected operands X and Y to be of the same type";
  2584. }
  2585. }
  2586. const uint32_t shuffle_mask_type =
  2587. _.GetOperandTypeId(inst, operand_index++);
  2588. if (!_.IsFloatVectorType(x_type) && !_.IsIntVectorType(x_type)) {
  2589. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2590. << GetExtInstName(_, inst) << ": "
  2591. << "expected operand X to be an int or float vector";
  2592. }
  2593. const uint32_t x_num_components = _.GetDimension(x_type);
  2594. if (x_num_components != 2 && x_num_components != 4 &&
  2595. x_num_components != 8 && x_num_components != 16) {
  2596. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2597. << GetExtInstName(_, inst) << ": "
  2598. << "expected operand X to have 2, 4, 8 or 16 components";
  2599. }
  2600. const uint32_t result_component_type = _.GetComponentType(result_type);
  2601. if (result_component_type != _.GetComponentType(x_type)) {
  2602. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2603. << GetExtInstName(_, inst) << ": "
  2604. << "expected operand X and Result Type to have equal "
  2605. "component types";
  2606. }
  2607. if (!_.IsIntVectorType(shuffle_mask_type)) {
  2608. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2609. << GetExtInstName(_, inst) << ": "
  2610. << "expected operand Shuffle Mask to be an int vector";
  2611. }
  2612. if (result_num_components != _.GetDimension(shuffle_mask_type)) {
  2613. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2614. << GetExtInstName(_, inst) << ": "
  2615. << "expected operand Shuffle Mask to have the same number of "
  2616. "components as Result Type";
  2617. }
  2618. if (_.GetBitWidth(result_component_type) !=
  2619. _.GetBitWidth(shuffle_mask_type)) {
  2620. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2621. << GetExtInstName(_, inst) << ": "
  2622. << "expected operand Shuffle Mask components to have the same "
  2623. "bit width as Result Type components";
  2624. }
  2625. break;
  2626. }
  2627. case OpenCLLIB::Printf: {
  2628. if (!_.IsIntScalarType(result_type) || _.GetBitWidth(result_type) != 32) {
  2629. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2630. << GetExtInstName(_, inst) << ": "
  2631. << "expected Result Type to be a 32-bit int type";
  2632. }
  2633. const uint32_t format_type = _.GetOperandTypeId(inst, 4);
  2634. spv::StorageClass format_storage_class;
  2635. uint32_t format_data_type = 0;
  2636. if (!_.GetPointerTypeInfo(format_type, &format_data_type,
  2637. &format_storage_class)) {
  2638. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2639. << GetExtInstName(_, inst) << ": "
  2640. << "expected operand Format to be a pointer";
  2641. }
  2642. if (_.HasExtension(
  2643. Extension::kSPV_EXT_relaxed_printf_string_address_space)) {
  2644. if (format_storage_class != spv::StorageClass::UniformConstant &&
  2645. // Extension SPV_EXT_relaxed_printf_string_address_space allows
  2646. // format strings in Global, Local, Private and Generic address
  2647. // spaces
  2648. // Global
  2649. format_storage_class != spv::StorageClass::CrossWorkgroup &&
  2650. // Local
  2651. format_storage_class != spv::StorageClass::Workgroup &&
  2652. // Private
  2653. format_storage_class != spv::StorageClass::Function &&
  2654. // Generic
  2655. format_storage_class != spv::StorageClass::Generic) {
  2656. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2657. << GetExtInstName(_, inst) << ": "
  2658. << "expected Format storage class to be UniformConstant, "
  2659. "Crossworkgroup, Workgroup, Function, or Generic";
  2660. }
  2661. } else {
  2662. if (format_storage_class != spv::StorageClass::UniformConstant) {
  2663. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2664. << GetExtInstName(_, inst) << ": "
  2665. << "expected Format storage class to be UniformConstant";
  2666. }
  2667. }
  2668. // If pointer points to an array, get the type of an element
  2669. if (_.IsIntArrayType(format_data_type))
  2670. format_data_type = _.GetComponentType(format_data_type);
  2671. if ((!_.IsIntScalarType(format_data_type) ||
  2672. _.GetBitWidth(format_data_type) != 8) &&
  2673. !_.ContainsUntypedPointer(format_type)) {
  2674. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2675. << GetExtInstName(_, inst) << ": "
  2676. << "expected Format data type to be 8-bit int";
  2677. }
  2678. break;
  2679. }
  2680. case OpenCLLIB::Prefetch: {
  2681. if (_.GetIdOpcode(result_type) != spv::Op::OpTypeVoid) {
  2682. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2683. << GetExtInstName(_, inst)
  2684. << ": expected Result Type to be void";
  2685. }
  2686. const uint32_t p_type = _.GetOperandTypeId(inst, 4);
  2687. const uint32_t num_elements_type = _.GetOperandTypeId(inst, 5);
  2688. spv::StorageClass p_storage_class;
  2689. uint32_t p_data_type = 0;
  2690. if (!_.GetPointerTypeInfo(p_type, &p_data_type, &p_storage_class)) {
  2691. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2692. << GetExtInstName(_, inst) << ": "
  2693. << "expected operand Ptr to be a pointer";
  2694. }
  2695. if (p_storage_class != spv::StorageClass::CrossWorkgroup) {
  2696. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2697. << GetExtInstName(_, inst) << ": "
  2698. << "expected operand Ptr storage class to be CrossWorkgroup";
  2699. }
  2700. if (!_.IsFloatScalarOrVectorType(p_data_type) &&
  2701. !_.IsIntScalarOrVectorType(p_data_type)) {
  2702. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2703. << GetExtInstName(_, inst) << ": "
  2704. << "expected Ptr data type to be int or float scalar or "
  2705. "vector";
  2706. }
  2707. const uint32_t num_components = _.GetDimension(p_data_type);
  2708. if (num_components > 4 && num_components != 8 && num_components != 16) {
  2709. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2710. << GetExtInstName(_, inst) << ": "
  2711. << "expected Result Type to be a scalar or a vector with 2, "
  2712. "3, 4, 8 or 16 components";
  2713. }
  2714. const uint32_t size_t_bit_width = GetSizeTBitWidth(_);
  2715. if (!size_t_bit_width) {
  2716. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2717. << GetExtInstName(_, inst)
  2718. << " can only be used with physical addressing models";
  2719. }
  2720. if (!_.IsIntScalarType(num_elements_type) ||
  2721. _.GetBitWidth(num_elements_type) != size_t_bit_width) {
  2722. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2723. << GetExtInstName(_, inst) << ": "
  2724. << "expected operand Num Elements to be of type size_t ("
  2725. << size_t_bit_width
  2726. << "-bit integer for the addressing model used in the module)";
  2727. }
  2728. break;
  2729. }
  2730. }
  2731. return SPV_SUCCESS;
  2732. }
  2733. spv_result_t ValidateExtInstDebugInfo100(ValidationState_t& _,
  2734. const Instruction* inst) {
  2735. const uint32_t result_type = inst->type_id();
  2736. const uint32_t ext_inst_index = inst->word(4);
  2737. if (!_.IsVoidType(result_type)) {
  2738. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2739. << GetExtInstName(_, inst) << ": "
  2740. << "expected result type must be a result id of " << "OpTypeVoid";
  2741. }
  2742. const spv_ext_inst_type_t ext_inst_type =
  2743. spv_ext_inst_type_t(inst->ext_inst_type());
  2744. const bool vulkanDebugInfo =
  2745. ext_inst_type == SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100;
  2746. auto num_words = inst->words().size();
  2747. // Handle any non-common NonSemanticShaderDebugInfo instructions.
  2748. if (vulkanDebugInfo) {
  2749. const NonSemanticShaderDebugInfo100Instructions ext_inst_key =
  2750. NonSemanticShaderDebugInfo100Instructions(ext_inst_index);
  2751. switch (ext_inst_key) {
  2752. // The following block of instructions will be handled by the common
  2753. // validation.
  2754. case NonSemanticShaderDebugInfo100DebugInfoNone:
  2755. case NonSemanticShaderDebugInfo100DebugCompilationUnit:
  2756. case NonSemanticShaderDebugInfo100DebugTypePointer:
  2757. case NonSemanticShaderDebugInfo100DebugTypeQualifier:
  2758. case NonSemanticShaderDebugInfo100DebugTypeArray:
  2759. case NonSemanticShaderDebugInfo100DebugTypeVector:
  2760. case NonSemanticShaderDebugInfo100DebugTypedef:
  2761. case NonSemanticShaderDebugInfo100DebugTypeFunction:
  2762. case NonSemanticShaderDebugInfo100DebugTypeEnum:
  2763. case NonSemanticShaderDebugInfo100DebugTypeComposite:
  2764. case NonSemanticShaderDebugInfo100DebugTypeMember:
  2765. case NonSemanticShaderDebugInfo100DebugTypeInheritance:
  2766. case NonSemanticShaderDebugInfo100DebugTypePtrToMember:
  2767. case NonSemanticShaderDebugInfo100DebugTypeTemplate:
  2768. case NonSemanticShaderDebugInfo100DebugTypeTemplateParameter:
  2769. case NonSemanticShaderDebugInfo100DebugTypeTemplateTemplateParameter:
  2770. case NonSemanticShaderDebugInfo100DebugTypeTemplateParameterPack:
  2771. case NonSemanticShaderDebugInfo100DebugGlobalVariable:
  2772. case NonSemanticShaderDebugInfo100DebugFunctionDeclaration:
  2773. case NonSemanticShaderDebugInfo100DebugFunction:
  2774. case NonSemanticShaderDebugInfo100DebugLexicalBlock:
  2775. case NonSemanticShaderDebugInfo100DebugLexicalBlockDiscriminator:
  2776. case NonSemanticShaderDebugInfo100DebugScope:
  2777. case NonSemanticShaderDebugInfo100DebugNoScope:
  2778. case NonSemanticShaderDebugInfo100DebugInlinedAt:
  2779. case NonSemanticShaderDebugInfo100DebugLocalVariable:
  2780. case NonSemanticShaderDebugInfo100DebugInlinedVariable:
  2781. case NonSemanticShaderDebugInfo100DebugValue:
  2782. case NonSemanticShaderDebugInfo100DebugOperation:
  2783. case NonSemanticShaderDebugInfo100DebugExpression:
  2784. case NonSemanticShaderDebugInfo100DebugMacroDef:
  2785. case NonSemanticShaderDebugInfo100DebugMacroUndef:
  2786. case NonSemanticShaderDebugInfo100DebugImportedEntity:
  2787. case NonSemanticShaderDebugInfo100DebugSource:
  2788. break;
  2789. // These checks are for operands that are differnet in
  2790. // ShaderDebugInfo100
  2791. case NonSemanticShaderDebugInfo100DebugTypeBasic: {
  2792. CHECK_CONST_UINT_OPERAND("Flags", 8);
  2793. break;
  2794. }
  2795. case NonSemanticShaderDebugInfo100DebugDeclare: {
  2796. for (uint32_t word_index = 8; word_index < num_words; ++word_index) {
  2797. auto index_inst = _.FindDef(inst->word(word_index));
  2798. auto type_id = index_inst != nullptr ? index_inst->type_id() : 0;
  2799. if (type_id == 0 || !IsIntScalar(_, type_id, false, false))
  2800. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2801. << GetExtInstName(_, inst) << ": "
  2802. << "expected index must be scalar integer";
  2803. }
  2804. break;
  2805. }
  2806. case NonSemanticShaderDebugInfo100DebugTypeMatrix: {
  2807. CHECK_DEBUG_OPERAND("Vector Type", CommonDebugInfoDebugTypeVector, 5);
  2808. CHECK_CONST_UINT_OPERAND("Vector Count", 6);
  2809. uint32_t vector_count = inst->word(6);
  2810. uint64_t const_val;
  2811. if (!_.EvalConstantValUint64(vector_count, &const_val)) {
  2812. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2813. << GetExtInstName(_, inst)
  2814. << ": Vector Count must be 32-bit integer OpConstant";
  2815. }
  2816. vector_count = const_val & 0xffffffff;
  2817. if (!vector_count || vector_count > 4) {
  2818. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2819. << GetExtInstName(_, inst)
  2820. << ": Vector Count must be positive "
  2821. << "integer less than or equal to 4";
  2822. }
  2823. break;
  2824. }
  2825. case NonSemanticShaderDebugInfo100DebugFunctionDefinition: {
  2826. CHECK_DEBUG_OPERAND("Function", CommonDebugInfoDebugFunction, 5);
  2827. CHECK_OPERAND("Definition", spv::Op::OpFunction, 6);
  2828. const auto* current_function = inst->function();
  2829. if (current_function->first_block()->id() != inst->block()->id()) {
  2830. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2831. << GetExtInstName(_, inst)
  2832. << ": must be in the entry basic block of the function";
  2833. }
  2834. const uint32_t definition_id = inst->word(6);
  2835. if (definition_id != current_function->id()) {
  2836. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2837. << GetExtInstName(_, inst)
  2838. << ": operand Definition must point to the OpFunction it is "
  2839. "inside";
  2840. }
  2841. break;
  2842. }
  2843. case NonSemanticShaderDebugInfo100DebugLine: {
  2844. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 5);
  2845. CHECK_CONST_UINT_OPERAND("Line Start", 6);
  2846. CHECK_CONST_UINT_OPERAND("Line End", 7);
  2847. CHECK_CONST_UINT_OPERAND("Column Start", 8);
  2848. CHECK_CONST_UINT_OPERAND("Column End", 9);
  2849. // above already validates if 32-bit and non-spec constant
  2850. // but want to use EvalInt32IfConst to be consistent with other Eval
  2851. // locations
  2852. bool is_int32 = false, is_const_int32 = false;
  2853. uint32_t line_start = 0;
  2854. uint32_t line_end = 0;
  2855. uint32_t column_start = 0;
  2856. uint32_t column_end = 0;
  2857. std::tie(is_int32, is_const_int32, line_start) =
  2858. _.EvalInt32IfConst(inst->word(6));
  2859. std::tie(is_int32, is_const_int32, line_end) =
  2860. _.EvalInt32IfConst(inst->word(7));
  2861. std::tie(is_int32, is_const_int32, column_start) =
  2862. _.EvalInt32IfConst(inst->word(8));
  2863. std::tie(is_int32, is_const_int32, column_end) =
  2864. _.EvalInt32IfConst(inst->word(9));
  2865. if (line_end < line_start) {
  2866. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2867. << GetExtInstName(_, inst) << ": operand Line End ("
  2868. << line_end << ") is less than Line Start (" << line_start
  2869. << ")";
  2870. } else if (line_start == line_end && column_end < column_start) {
  2871. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2872. << GetExtInstName(_, inst) << ": operand Column End ("
  2873. << column_end << ") is less than Column Start ("
  2874. << column_start << ") when Line Start equals Line End";
  2875. }
  2876. break;
  2877. }
  2878. case NonSemanticShaderDebugInfo100DebugSourceContinued: {
  2879. CHECK_OPERAND("Text", spv::Op::OpString, 5);
  2880. break;
  2881. }
  2882. case NonSemanticShaderDebugInfo100DebugBuildIdentifier: {
  2883. CHECK_OPERAND("Identifier", spv::Op::OpString, 5);
  2884. CHECK_CONST_UINT_OPERAND("Flags", 6);
  2885. break;
  2886. }
  2887. case NonSemanticShaderDebugInfo100DebugStoragePath: {
  2888. CHECK_OPERAND("Path", spv::Op::OpString, 5);
  2889. break;
  2890. }
  2891. case NonSemanticShaderDebugInfo100DebugEntryPoint: {
  2892. CHECK_DEBUG_OPERAND("Entry Point", CommonDebugInfoDebugFunction, 5);
  2893. CHECK_DEBUG_OPERAND("Compilation Unit",
  2894. CommonDebugInfoDebugCompilationUnit, 6);
  2895. CHECK_OPERAND("Compiler Signature", spv::Op::OpString, 7);
  2896. CHECK_OPERAND("Command-line Arguments", spv::Op::OpString, 8);
  2897. break;
  2898. }
  2899. // Has no additional checks
  2900. case NonSemanticShaderDebugInfo100DebugNoLine:
  2901. break;
  2902. case NonSemanticShaderDebugInfo100InstructionsMax:
  2903. assert(0);
  2904. break;
  2905. }
  2906. }
  2907. // Handle any non-common OpenCL insts, then common
  2908. if (ext_inst_type != SPV_EXT_INST_TYPE_OPENCL_DEBUGINFO_100 ||
  2909. OpenCLDebugInfo100Instructions(ext_inst_index) !=
  2910. OpenCLDebugInfo100DebugModuleINTEL) {
  2911. const CommonDebugInfoInstructions ext_inst_key =
  2912. CommonDebugInfoInstructions(ext_inst_index);
  2913. switch (ext_inst_key) {
  2914. case CommonDebugInfoDebugInfoNone:
  2915. case CommonDebugInfoDebugNoScope:
  2916. break;
  2917. // The binary parser validates the opcode for DebugInfoNone,
  2918. // DebugNoScope, DebugOperation. We just check the parameters to
  2919. // DebugOperation are properly constants for vulkan debug info.
  2920. case CommonDebugInfoDebugOperation: {
  2921. CHECK_CONST_UINT_OPERAND("Operation", 5);
  2922. for (uint32_t i = 6; i < num_words; ++i) {
  2923. CHECK_CONST_UINT_OPERAND("Operand", i);
  2924. }
  2925. break;
  2926. }
  2927. case CommonDebugInfoDebugCompilationUnit: {
  2928. CHECK_CONST_UINT_OPERAND("Version", 5);
  2929. CHECK_CONST_UINT_OPERAND("DWARF Version", 6);
  2930. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  2931. CHECK_CONST_UINT_OPERAND("Language", 8);
  2932. break;
  2933. }
  2934. case CommonDebugInfoDebugSource: {
  2935. CHECK_OPERAND("File", spv::Op::OpString, 5);
  2936. if (num_words == 7) CHECK_OPERAND("Text", spv::Op::OpString, 6);
  2937. break;
  2938. }
  2939. case CommonDebugInfoDebugTypeBasic: {
  2940. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  2941. CHECK_OPERAND("Size", spv::Op::OpConstant, 6);
  2942. CHECK_CONST_UINT_OPERAND("Encoding", 7);
  2943. break;
  2944. }
  2945. case CommonDebugInfoDebugTypePointer: {
  2946. auto validate_base_type =
  2947. ValidateOperandDebugType(_, "Base Type", inst, 5, false);
  2948. if (validate_base_type != SPV_SUCCESS) return validate_base_type;
  2949. CHECK_CONST_UINT_OPERAND("Storage Class", 6);
  2950. CHECK_CONST_UINT_OPERAND("Flags", 7);
  2951. break;
  2952. }
  2953. case CommonDebugInfoDebugTypeQualifier: {
  2954. auto validate_base_type =
  2955. ValidateOperandDebugType(_, "Base Type", inst, 5, false);
  2956. if (validate_base_type != SPV_SUCCESS) return validate_base_type;
  2957. CHECK_CONST_UINT_OPERAND("Type Qualifier", 6);
  2958. break;
  2959. }
  2960. case CommonDebugInfoDebugTypeVector: {
  2961. auto validate_base_type = ValidateOperandBaseType(_, inst, 5);
  2962. if (validate_base_type != SPV_SUCCESS) return validate_base_type;
  2963. CHECK_CONST_UINT_OPERAND("Component Count", 6);
  2964. uint32_t component_count = inst->word(6);
  2965. if (vulkanDebugInfo) {
  2966. uint64_t const_val;
  2967. if (!_.EvalConstantValUint64(component_count, &const_val)) {
  2968. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2969. << GetExtInstName(_, inst)
  2970. << ": Component Count must be 32-bit integer OpConstant";
  2971. }
  2972. component_count = const_val & 0xffffffff;
  2973. }
  2974. if (!component_count || component_count > 4) {
  2975. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  2976. << GetExtInstName(_, inst)
  2977. << ": Component Count must be positive "
  2978. << "integer less than or equal to 4";
  2979. }
  2980. break;
  2981. }
  2982. case CommonDebugInfoDebugTypeArray: {
  2983. auto validate_base_type =
  2984. ValidateOperandDebugType(_, "Base Type", inst, 5, false);
  2985. if (validate_base_type != SPV_SUCCESS) return validate_base_type;
  2986. for (uint32_t i = 6; i < num_words; ++i) {
  2987. bool invalid = false;
  2988. auto* component_count = _.FindDef(inst->word(i));
  2989. if (IsConstIntScalarTypeWith32Or64Bits(_, component_count)) {
  2990. // TODO: We need a spec discussion for the runtime array for
  2991. // OpenCL.
  2992. if (!vulkanDebugInfo && !component_count->word(3)) {
  2993. invalid = true;
  2994. }
  2995. } else if (component_count->words().size() > 6 &&
  2996. (CommonDebugInfoInstructions(component_count->word(4)) ==
  2997. CommonDebugInfoDebugLocalVariable ||
  2998. CommonDebugInfoInstructions(component_count->word(4)) ==
  2999. CommonDebugInfoDebugGlobalVariable)) {
  3000. auto* component_count_type = _.FindDef(component_count->word(6));
  3001. if (component_count_type->words().size() > 7) {
  3002. uint32_t encoding = component_count_type->word(7);
  3003. if (CommonDebugInfoInstructions(component_count_type->word(4)) !=
  3004. CommonDebugInfoDebugTypeBasic ||
  3005. (vulkanDebugInfo && !IsUint32Constant(_, encoding)) ||
  3006. OpenCLDebugInfo100DebugBaseTypeAttributeEncoding(
  3007. vulkanDebugInfo
  3008. ? GetUint32Constant(_, encoding)
  3009. : encoding) != OpenCLDebugInfo100Unsigned) {
  3010. invalid = true;
  3011. } else {
  3012. // DebugTypeBasic for DebugLocalVariable/DebugGlobalVariable
  3013. // must have Unsigned encoding and 32 or 64 as its size in
  3014. // bits.
  3015. Instruction* size_in_bits =
  3016. _.FindDef(component_count_type->word(6));
  3017. if (!_.IsIntScalarType(size_in_bits->type_id()) ||
  3018. (size_in_bits->word(3) != 32 &&
  3019. size_in_bits->word(3) != 64)) {
  3020. invalid = true;
  3021. }
  3022. }
  3023. } else {
  3024. invalid = true;
  3025. }
  3026. } else {
  3027. invalid = true;
  3028. }
  3029. if (invalid) {
  3030. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3031. << GetExtInstName(_, inst) << ": Component Count must be "
  3032. << "OpConstant with a 32- or 64-bits integer scalar type "
  3033. "or "
  3034. << "DebugGlobalVariable or DebugLocalVariable with a 32- "
  3035. "or "
  3036. << "64-bits unsigned integer scalar type";
  3037. }
  3038. }
  3039. break;
  3040. }
  3041. case CommonDebugInfoDebugTypedef: {
  3042. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3043. auto validate_base_type = ValidateOperandBaseType(_, inst, 6);
  3044. if (validate_base_type != SPV_SUCCESS) return validate_base_type;
  3045. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3046. CHECK_CONST_UINT_OPERAND("Line", 8);
  3047. CHECK_CONST_UINT_OPERAND("Column", 9);
  3048. auto validate_parent =
  3049. ValidateOperandLexicalScope(_, "Parent", inst, 10);
  3050. if (validate_parent != SPV_SUCCESS) return validate_parent;
  3051. break;
  3052. }
  3053. case CommonDebugInfoDebugTypeFunction: {
  3054. CHECK_CONST_UINT_OPERAND("Flags", 5);
  3055. auto* return_type = _.FindDef(inst->word(6));
  3056. // TODO: We need a spec discussion that we have to allow return and
  3057. // parameter types of a DebugTypeFunction to have template parameter.
  3058. if (return_type->opcode() != spv::Op::OpTypeVoid) {
  3059. auto validate_return =
  3060. ValidateOperandDebugType(_, "Return Type", inst, 6, true);
  3061. if (validate_return != SPV_SUCCESS) return validate_return;
  3062. }
  3063. for (uint32_t word_index = 7; word_index < num_words; ++word_index) {
  3064. auto validate_param = ValidateOperandDebugType(
  3065. _, "Parameter Types", inst, word_index, true);
  3066. if (validate_param != SPV_SUCCESS) return validate_param;
  3067. }
  3068. break;
  3069. }
  3070. case CommonDebugInfoDebugTypeEnum: {
  3071. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3072. if (!DoesDebugInfoOperandMatchExpectation(
  3073. _,
  3074. [](CommonDebugInfoInstructions dbg_inst) {
  3075. return dbg_inst == CommonDebugInfoDebugInfoNone;
  3076. },
  3077. inst, 6)) {
  3078. auto validate_underlying_type =
  3079. ValidateOperandDebugType(_, "Underlying Types", inst, 6, false);
  3080. if (validate_underlying_type != SPV_SUCCESS)
  3081. return validate_underlying_type;
  3082. }
  3083. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3084. CHECK_CONST_UINT_OPERAND("Line", 8);
  3085. CHECK_CONST_UINT_OPERAND("Column", 9);
  3086. auto validate_parent =
  3087. ValidateOperandLexicalScope(_, "Parent", inst, 10);
  3088. if (validate_parent != SPV_SUCCESS) return validate_parent;
  3089. CHECK_OPERAND("Size", spv::Op::OpConstant, 11);
  3090. auto* size = _.FindDef(inst->word(11));
  3091. if (!_.IsIntScalarType(size->type_id()) || !size->word(3)) {
  3092. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3093. << GetExtInstName(_, inst) << ": expected operand Size is a "
  3094. << "positive integer";
  3095. }
  3096. CHECK_CONST_UINT_OPERAND("Flags", 12);
  3097. for (uint32_t word_index = 13; word_index + 1 < num_words;
  3098. word_index += 2) {
  3099. CHECK_OPERAND("Value", spv::Op::OpConstant, word_index);
  3100. CHECK_OPERAND("Name", spv::Op::OpString, word_index + 1);
  3101. }
  3102. break;
  3103. }
  3104. case CommonDebugInfoDebugTypeComposite: {
  3105. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3106. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3107. CHECK_CONST_UINT_OPERAND("Line", 8);
  3108. CHECK_CONST_UINT_OPERAND("Column", 9);
  3109. auto validate_parent =
  3110. ValidateOperandLexicalScope(_, "Parent", inst, 10);
  3111. if (validate_parent != SPV_SUCCESS) return validate_parent;
  3112. CHECK_OPERAND("Linkage Name", spv::Op::OpString, 11);
  3113. if (!DoesDebugInfoOperandMatchExpectation(
  3114. _,
  3115. [](CommonDebugInfoInstructions dbg_inst) {
  3116. return dbg_inst == CommonDebugInfoDebugInfoNone;
  3117. },
  3118. inst, 12)) {
  3119. CHECK_OPERAND("Size", spv::Op::OpConstant, 12);
  3120. }
  3121. CHECK_CONST_UINT_OPERAND("Flags", 13);
  3122. for (uint32_t word_index = 14; word_index < num_words; ++word_index) {
  3123. if (!DoesDebugInfoOperandMatchExpectation(
  3124. _,
  3125. [](CommonDebugInfoInstructions dbg_inst) {
  3126. return dbg_inst == CommonDebugInfoDebugTypeMember ||
  3127. dbg_inst == CommonDebugInfoDebugFunction ||
  3128. dbg_inst == CommonDebugInfoDebugTypeInheritance;
  3129. },
  3130. inst, word_index)) {
  3131. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3132. << GetExtInstName(_, inst) << ": "
  3133. << "expected operand Members "
  3134. << "must be DebugTypeMember, DebugFunction, or "
  3135. "DebugTypeInheritance";
  3136. }
  3137. }
  3138. break;
  3139. }
  3140. case CommonDebugInfoDebugTypeMember: {
  3141. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3142. // TODO: We need a spec discussion that we have to allow member types
  3143. // to have template parameter.
  3144. auto validate_type = ValidateOperandDebugType(_, "Type", inst, 6, true);
  3145. if (validate_type != SPV_SUCCESS) return validate_type;
  3146. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3147. CHECK_CONST_UINT_OPERAND("Line", 8);
  3148. CHECK_CONST_UINT_OPERAND("Column", 9);
  3149. // NonSemantic.Shader.DebugInfo doesn't have the Parent operand
  3150. if (vulkanDebugInfo) {
  3151. CHECK_OPERAND("Offset", spv::Op::OpConstant, 10);
  3152. CHECK_OPERAND("Size", spv::Op::OpConstant, 11);
  3153. CHECK_CONST_UINT_OPERAND("Flags", 12);
  3154. if (num_words == 14) CHECK_OPERAND("Value", spv::Op::OpConstant, 13);
  3155. } else {
  3156. CHECK_DEBUG_OPERAND("Parent", CommonDebugInfoDebugTypeComposite, 10);
  3157. CHECK_OPERAND("Offset", spv::Op::OpConstant, 11);
  3158. CHECK_OPERAND("Size", spv::Op::OpConstant, 12);
  3159. CHECK_CONST_UINT_OPERAND("Flags", 13);
  3160. if (num_words == 15) CHECK_OPERAND("Value", spv::Op::OpConstant, 14);
  3161. }
  3162. break;
  3163. }
  3164. case CommonDebugInfoDebugTypeInheritance: {
  3165. CHECK_DEBUG_OPERAND("Child", CommonDebugInfoDebugTypeComposite, 5);
  3166. auto* debug_inst = _.FindDef(inst->word(5));
  3167. auto composite_type =
  3168. OpenCLDebugInfo100DebugCompositeType(debug_inst->word(6));
  3169. if (composite_type != OpenCLDebugInfo100Class &&
  3170. composite_type != OpenCLDebugInfo100Structure) {
  3171. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3172. << GetExtInstName(_, inst) << ": "
  3173. << "expected operand Child must be class or struct debug "
  3174. "type";
  3175. }
  3176. CHECK_DEBUG_OPERAND("Parent", CommonDebugInfoDebugTypeComposite, 6);
  3177. debug_inst = _.FindDef(inst->word(6));
  3178. composite_type =
  3179. OpenCLDebugInfo100DebugCompositeType(debug_inst->word(6));
  3180. if (composite_type != OpenCLDebugInfo100Class &&
  3181. composite_type != OpenCLDebugInfo100Structure) {
  3182. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3183. << GetExtInstName(_, inst) << ": "
  3184. << "expected operand Parent must be class or struct debug "
  3185. "type";
  3186. }
  3187. CHECK_OPERAND("Offset", spv::Op::OpConstant, 7);
  3188. CHECK_OPERAND("Size", spv::Op::OpConstant, 8);
  3189. CHECK_CONST_UINT_OPERAND("Flags", 9);
  3190. break;
  3191. }
  3192. case CommonDebugInfoDebugFunction: {
  3193. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3194. CHECK_DEBUG_OPERAND("Type", CommonDebugInfoDebugTypeFunction, 6);
  3195. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3196. CHECK_CONST_UINT_OPERAND("Line", 8);
  3197. CHECK_CONST_UINT_OPERAND("Column", 9);
  3198. auto validate_parent =
  3199. ValidateOperandLexicalScope(_, "Parent", inst, 10);
  3200. if (validate_parent != SPV_SUCCESS) return validate_parent;
  3201. CHECK_OPERAND("Linkage Name", spv::Op::OpString, 11);
  3202. CHECK_CONST_UINT_OPERAND("Flags", 12);
  3203. CHECK_CONST_UINT_OPERAND("Scope Line", 13);
  3204. // NonSemantic.Shader.DebugInfo.100 doesn't include a reference to the
  3205. // OpFunction
  3206. if (vulkanDebugInfo) {
  3207. if (num_words == 15) {
  3208. CHECK_DEBUG_OPERAND("Declaration",
  3209. CommonDebugInfoDebugFunctionDeclaration, 14);
  3210. }
  3211. } else {
  3212. if (!DoesDebugInfoOperandMatchExpectation(
  3213. _,
  3214. [](CommonDebugInfoInstructions dbg_inst) {
  3215. return dbg_inst == CommonDebugInfoDebugInfoNone;
  3216. },
  3217. inst, 14)) {
  3218. CHECK_OPERAND("Function", spv::Op::OpFunction, 14);
  3219. }
  3220. if (num_words == 16) {
  3221. CHECK_DEBUG_OPERAND("Declaration",
  3222. CommonDebugInfoDebugFunctionDeclaration, 15);
  3223. }
  3224. }
  3225. break;
  3226. }
  3227. case CommonDebugInfoDebugFunctionDeclaration: {
  3228. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3229. CHECK_DEBUG_OPERAND("Type", CommonDebugInfoDebugTypeFunction, 6);
  3230. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3231. CHECK_CONST_UINT_OPERAND("Line", 8);
  3232. CHECK_CONST_UINT_OPERAND("Column", 9);
  3233. auto validate_parent =
  3234. ValidateOperandLexicalScope(_, "Parent", inst, 10);
  3235. if (validate_parent != SPV_SUCCESS) return validate_parent;
  3236. CHECK_OPERAND("Linkage Name", spv::Op::OpString, 11);
  3237. CHECK_CONST_UINT_OPERAND("Flags", 12);
  3238. break;
  3239. }
  3240. case CommonDebugInfoDebugLexicalBlock: {
  3241. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 5);
  3242. CHECK_CONST_UINT_OPERAND("Line", 6);
  3243. CHECK_CONST_UINT_OPERAND("Column", 7);
  3244. auto validate_parent =
  3245. ValidateOperandLexicalScope(_, "Parent", inst, 8);
  3246. if (validate_parent != SPV_SUCCESS) return validate_parent;
  3247. if (num_words == 10) CHECK_OPERAND("Name", spv::Op::OpString, 9);
  3248. break;
  3249. }
  3250. case CommonDebugInfoDebugScope: {
  3251. auto validate_scope = ValidateOperandLexicalScope(_, "Scope", inst, 5);
  3252. if (validate_scope != SPV_SUCCESS) return validate_scope;
  3253. if (num_words == 7) {
  3254. CHECK_DEBUG_OPERAND("Inlined At", CommonDebugInfoDebugInlinedAt, 6);
  3255. }
  3256. break;
  3257. }
  3258. case CommonDebugInfoDebugLocalVariable: {
  3259. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3260. // TODO: We need a spec discussion that we have to allow local
  3261. // variable types to have template parameter.
  3262. auto validate_type = ValidateOperandDebugType(_, "Type", inst, 6, true);
  3263. if (validate_type != SPV_SUCCESS) return validate_type;
  3264. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3265. CHECK_CONST_UINT_OPERAND("Line", 8);
  3266. CHECK_CONST_UINT_OPERAND("Column", 9);
  3267. auto validate_parent =
  3268. ValidateOperandLexicalScope(_, "Parent", inst, 10);
  3269. if (validate_parent != SPV_SUCCESS) return validate_parent;
  3270. CHECK_CONST_UINT_OPERAND("Flags", 11);
  3271. if (num_words == 13) {
  3272. CHECK_CONST_UINT_OPERAND("ArgNumber", 12);
  3273. }
  3274. break;
  3275. }
  3276. case CommonDebugInfoDebugDeclare: {
  3277. CHECK_DEBUG_OPERAND("Local Variable", CommonDebugInfoDebugLocalVariable,
  3278. 5);
  3279. auto* operand = _.FindDef(inst->word(6));
  3280. if (operand->opcode() != spv::Op::OpVariable &&
  3281. operand->opcode() != spv::Op::OpFunctionParameter) {
  3282. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3283. << GetExtInstName(_, inst) << ": "
  3284. << "expected operand Variable must be a result id of "
  3285. "OpVariable or OpFunctionParameter";
  3286. }
  3287. CHECK_DEBUG_OPERAND("Expression", CommonDebugInfoDebugExpression, 7);
  3288. break;
  3289. }
  3290. case CommonDebugInfoDebugExpression: {
  3291. for (uint32_t word_index = 5; word_index < num_words; ++word_index) {
  3292. CHECK_DEBUG_OPERAND("Operation", CommonDebugInfoDebugOperation,
  3293. word_index);
  3294. }
  3295. break;
  3296. }
  3297. case CommonDebugInfoDebugTypeTemplate: {
  3298. if (!DoesDebugInfoOperandMatchExpectation(
  3299. _,
  3300. [](CommonDebugInfoInstructions dbg_inst) {
  3301. return dbg_inst == CommonDebugInfoDebugTypeComposite ||
  3302. dbg_inst == CommonDebugInfoDebugFunction;
  3303. },
  3304. inst, 5)) {
  3305. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3306. << GetExtInstName(_, inst) << ": "
  3307. << "expected operand Target must be DebugTypeComposite "
  3308. << "or DebugFunction";
  3309. }
  3310. for (uint32_t word_index = 6; word_index < num_words; ++word_index) {
  3311. if (!DoesDebugInfoOperandMatchExpectation(
  3312. _,
  3313. [](CommonDebugInfoInstructions dbg_inst) {
  3314. return dbg_inst ==
  3315. CommonDebugInfoDebugTypeTemplateParameter ||
  3316. dbg_inst ==
  3317. CommonDebugInfoDebugTypeTemplateTemplateParameter;
  3318. },
  3319. inst, word_index)) {
  3320. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3321. << GetExtInstName(_, inst) << ": "
  3322. << "expected operand Parameters must be "
  3323. << "DebugTypeTemplateParameter or "
  3324. << "DebugTypeTemplateTemplateParameter";
  3325. }
  3326. }
  3327. break;
  3328. }
  3329. case CommonDebugInfoDebugTypeTemplateParameter: {
  3330. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3331. auto validate_actual_type =
  3332. ValidateOperandDebugType(_, "Actual Type", inst, 6, false);
  3333. if (validate_actual_type != SPV_SUCCESS) return validate_actual_type;
  3334. if (!DoesDebugInfoOperandMatchExpectation(
  3335. _,
  3336. [](CommonDebugInfoInstructions dbg_inst) {
  3337. return dbg_inst == CommonDebugInfoDebugInfoNone;
  3338. },
  3339. inst, 7)) {
  3340. CHECK_OPERAND("Value", spv::Op::OpConstant, 7);
  3341. }
  3342. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 8);
  3343. CHECK_CONST_UINT_OPERAND("Line", 9);
  3344. CHECK_CONST_UINT_OPERAND("Column", 10);
  3345. break;
  3346. }
  3347. case CommonDebugInfoDebugGlobalVariable: {
  3348. CHECK_OPERAND("Name", spv::Op::OpString, 5);
  3349. auto validate_type =
  3350. ValidateOperandDebugType(_, "Type", inst, 6, false);
  3351. if (validate_type != SPV_SUCCESS) return validate_type;
  3352. CHECK_DEBUG_OPERAND("Source", CommonDebugInfoDebugSource, 7);
  3353. CHECK_CONST_UINT_OPERAND("Line", 8);
  3354. CHECK_CONST_UINT_OPERAND("Column", 9);
  3355. auto validate_scope = ValidateOperandLexicalScope(_, "Scope", inst, 10);
  3356. if (validate_scope != SPV_SUCCESS) return validate_scope;
  3357. CHECK_OPERAND("Linkage Name", spv::Op::OpString, 11);
  3358. if (!DoesDebugInfoOperandMatchExpectation(
  3359. _,
  3360. [](CommonDebugInfoInstructions dbg_inst) {
  3361. return dbg_inst == CommonDebugInfoDebugInfoNone;
  3362. },
  3363. inst, 12)) {
  3364. auto* operand = _.FindDef(inst->word(12));
  3365. if (operand->opcode() != spv::Op::OpVariable &&
  3366. operand->opcode() != spv::Op::OpConstant) {
  3367. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3368. << GetExtInstName(_, inst) << ": "
  3369. << "expected operand Variable must be a result id of "
  3370. "OpVariable or OpConstant or DebugInfoNone";
  3371. }
  3372. }
  3373. if (num_words == 15) {
  3374. CHECK_DEBUG_OPERAND("Static Member Declaration",
  3375. CommonDebugInfoDebugTypeMember, 14);
  3376. }
  3377. break;
  3378. }
  3379. case CommonDebugInfoDebugInlinedAt: {
  3380. CHECK_CONST_UINT_OPERAND("Line", 5);
  3381. auto validate_scope = ValidateOperandLexicalScope(_, "Scope", inst, 6);
  3382. if (validate_scope != SPV_SUCCESS) return validate_scope;
  3383. if (num_words == 8) {
  3384. CHECK_DEBUG_OPERAND("Inlined", CommonDebugInfoDebugInlinedAt, 7);
  3385. }
  3386. break;
  3387. }
  3388. case CommonDebugInfoDebugValue: {
  3389. CHECK_DEBUG_OPERAND("Local Variable", CommonDebugInfoDebugLocalVariable,
  3390. 5);
  3391. CHECK_DEBUG_OPERAND("Expression", CommonDebugInfoDebugExpression, 7);
  3392. for (uint32_t word_index = 8; word_index < num_words; ++word_index) {
  3393. // TODO: The following code simply checks if it is a const int
  3394. // scalar or a DebugLocalVariable or DebugGlobalVariable, but we
  3395. // have to check it using the same validation for Indexes of
  3396. // OpAccessChain.
  3397. if (!IsConstWithIntScalarType(_, inst, word_index) &&
  3398. !IsDebugVariableWithIntScalarType(_, inst, word_index)) {
  3399. return _.diag(SPV_ERROR_INVALID_DATA, inst)
  3400. << GetExtInstName(_, inst)
  3401. << ": expected operand Indexes is "
  3402. << "OpConstant, DebugGlobalVariable, or "
  3403. << "type is OpConstant with an integer scalar type";
  3404. }
  3405. }
  3406. break;
  3407. }
  3408. // TODO: Add validation rules for remaining cases as well.
  3409. case CommonDebugInfoDebugTypePtrToMember:
  3410. case CommonDebugInfoDebugTypeTemplateTemplateParameter:
  3411. case CommonDebugInfoDebugTypeTemplateParameterPack:
  3412. case CommonDebugInfoDebugLexicalBlockDiscriminator:
  3413. case CommonDebugInfoDebugInlinedVariable:
  3414. case CommonDebugInfoDebugMacroDef:
  3415. case CommonDebugInfoDebugMacroUndef:
  3416. case CommonDebugInfoDebugImportedEntity:
  3417. break;
  3418. case CommonDebugInfoInstructionsMax:
  3419. assert(0);
  3420. break;
  3421. }
  3422. }
  3423. return SPV_SUCCESS;
  3424. }
  3425. spv_result_t ValidateExtInstNonsemanticClspvReflection(
  3426. ValidationState_t& _, const Instruction* inst) {
  3427. auto import_inst = _.FindDef(inst->GetOperandAs<uint32_t>(2));
  3428. const std::string name = import_inst->GetOperandAs<std::string>(1);
  3429. const std::string reflection = "NonSemantic.ClspvReflection.";
  3430. char* end_ptr;
  3431. auto version_string = name.substr(reflection.size());
  3432. if (version_string.empty()) {
  3433. return _.diag(SPV_ERROR_INVALID_DATA, import_inst)
  3434. << "Missing NonSemantic.ClspvReflection import version";
  3435. }
  3436. uint32_t version =
  3437. static_cast<uint32_t>(std::strtoul(version_string.c_str(), &end_ptr, 10));
  3438. if (end_ptr && *end_ptr != '\0') {
  3439. return _.diag(SPV_ERROR_INVALID_DATA, import_inst)
  3440. << "NonSemantic.ClspvReflection import does not encode the "
  3441. "version correctly";
  3442. }
  3443. if (version == 0 || version > NonSemanticClspvReflectionRevision) {
  3444. return _.diag(SPV_ERROR_INVALID_DATA, import_inst)
  3445. << "Unknown NonSemantic.ClspvReflection import version";
  3446. }
  3447. return ValidateClspvReflectionInstruction(_, inst, version);
  3448. }
  3449. spv_result_t ValidateExtInst(ValidationState_t& _, const Instruction* inst) {
  3450. const spv_ext_inst_type_t ext_inst_type =
  3451. spv_ext_inst_type_t(inst->ext_inst_type());
  3452. if (ext_inst_type == SPV_EXT_INST_TYPE_GLSL_STD_450) {
  3453. return ValidateExtInstGlslStd450(_, inst);
  3454. } else if (ext_inst_type == SPV_EXT_INST_TYPE_OPENCL_STD) {
  3455. return ValidateExtInstOpenClStd(_, inst);
  3456. } else if (ext_inst_type == SPV_EXT_INST_TYPE_OPENCL_DEBUGINFO_100 ||
  3457. ext_inst_type ==
  3458. SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100) {
  3459. return ValidateExtInstDebugInfo100(_, inst);
  3460. } else if (ext_inst_type == SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION) {
  3461. return ValidateExtInstNonsemanticClspvReflection(_, inst);
  3462. }
  3463. return SPV_SUCCESS;
  3464. }
  3465. spv_result_t ExtensionPass(ValidationState_t& _, const Instruction* inst) {
  3466. const spv::Op opcode = inst->opcode();
  3467. if (opcode == spv::Op::OpExtension) return ValidateExtension(_, inst);
  3468. if (opcode == spv::Op::OpExtInstImport) return ValidateExtInstImport(_, inst);
  3469. if (spvIsExtendedInstruction(opcode)) return ValidateExtInst(_, inst);
  3470. return SPV_SUCCESS;
  3471. }
  3472. } // namespace val
  3473. } // namespace spvtools