val_ext_inst_debug_test.cpp 193 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052
  1. // Copyright (c) 2017 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. // Tests validation rules of GLSL.450.std and OpenCL.std extended instructions.
  15. // Doesn't test OpenCL.std vector size 2, 3, 4, 8 or 16 rules (not supported
  16. // by standard SPIR-V).
  17. #include <sstream>
  18. #include <string>
  19. #include <vector>
  20. #include "gmock/gmock.h"
  21. #include "spirv-tools/libspirv.h"
  22. #include "test/unit_spirv.h"
  23. #include "test/val/val_fixtures.h"
  24. namespace spvtools {
  25. namespace val {
  26. namespace {
  27. using ::testing::Eq;
  28. using ::testing::HasSubstr;
  29. using ::testing::Not;
  30. using ValidateOldDebugInfo = spvtest::ValidateBase<std::string>;
  31. using ValidateOpenCL100DebugInfo = spvtest::ValidateBase<std::string>;
  32. using ValidateXDebugInfo = spvtest::ValidateBase<std::string>;
  33. using ValidateLocalDebugInfoOutOfFunction = spvtest::ValidateBase<std::string>;
  34. using ValidateOpenCL100DebugInfoDebugTypedef =
  35. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  36. using ValidateVulkan100DebugInfoDebugTypedef =
  37. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  38. using ValidateOpenCL100DebugInfoDebugTypeEnum =
  39. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  40. using ValidateVulkan100DebugInfoDebugTypeEnum =
  41. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  42. using ValidateOpenCL100DebugInfoDebugTypeComposite =
  43. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  44. using ValidateVulkan100DebugInfoDebugTypeComposite =
  45. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  46. using ValidateOpenCL100DebugInfoDebugTypeMember =
  47. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  48. using ValidateVulkan100DebugInfoDebugTypeMember =
  49. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  50. using ValidateOpenCL100DebugInfoDebugTypeInheritance =
  51. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  52. using ValidateOpenCL100DebugInfoDebugFunction =
  53. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  54. using ValidateVulkan100DebugInfoDebugFunction =
  55. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  56. using ValidateOpenCL100DebugInfoDebugFunctionDeclaration =
  57. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  58. using ValidateVulkan100DebugInfoDebugFunctionDeclaration =
  59. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  60. using ValidateOpenCL100DebugInfoDebugLexicalBlock =
  61. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  62. using ValidateVulkan100DebugInfoDebugLexicalBlock =
  63. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  64. using ValidateOpenCL100DebugInfoDebugLocalVariable =
  65. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  66. using ValidateVulkan100DebugInfoDebugLocalVariable =
  67. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  68. using ValidateOpenCL100DebugInfoDebugGlobalVariable =
  69. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  70. using ValidateVulkan100DebugInfoDebugGlobalVariable =
  71. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  72. using ValidateOpenCL100DebugInfoDebugDeclare =
  73. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  74. using ValidateVulkan100DebugInfoDebugDeclare =
  75. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  76. using ValidateOpenCL100DebugInfoDebugValue =
  77. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  78. using ValidateVulkan100DebugInfoDebugValue =
  79. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  80. using ValidateVulkan100DebugInfo = spvtest::ValidateBase<std::string>;
  81. const static std::string shader_extension = R"(
  82. OpExtension "SPV_KHR_non_semantic_info"
  83. %DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
  84. )";
  85. const static std::string opencl_extension = R"(
  86. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  87. )";
  88. std::string GenerateShaderCodeForDebugInfo(
  89. const std::string& op_string_instructions,
  90. const std::string& op_const_instructions,
  91. const std::string& debug_instructions_before_main, const std::string& body,
  92. const std::string& capabilities_and_extensions = "",
  93. const std::string& execution_model = "Fragment") {
  94. std::ostringstream ss;
  95. ss << R"(
  96. OpCapability Shader
  97. OpCapability Float16
  98. OpCapability Float64
  99. OpCapability Int16
  100. OpCapability Int64
  101. )";
  102. ss << capabilities_and_extensions;
  103. ss << "%extinst = OpExtInstImport \"GLSL.std.450\"\n";
  104. ss << "OpMemoryModel Logical GLSL450\n";
  105. ss << "OpEntryPoint " << execution_model << " %main \"main\""
  106. << " %f32_output"
  107. << " %f32vec2_output"
  108. << " %u32_output"
  109. << " %u32vec2_output"
  110. << " %u64_output"
  111. << " %f32_input"
  112. << " %f32vec2_input"
  113. << " %u32_input"
  114. << " %u32vec2_input"
  115. << " %u64_input"
  116. << "\n";
  117. if (execution_model == "Fragment") {
  118. ss << "OpExecutionMode %main OriginUpperLeft\n";
  119. }
  120. ss << "%main_name = OpString \"main\"\n";
  121. ss << op_string_instructions;
  122. ss << R"(
  123. %void = OpTypeVoid
  124. %func = OpTypeFunction %void
  125. %bool = OpTypeBool
  126. %f16 = OpTypeFloat 16
  127. %f32 = OpTypeFloat 32
  128. %f64 = OpTypeFloat 64
  129. %u32 = OpTypeInt 32 0
  130. %s32 = OpTypeInt 32 1
  131. %u64 = OpTypeInt 64 0
  132. %s64 = OpTypeInt 64 1
  133. %u16 = OpTypeInt 16 0
  134. %s16 = OpTypeInt 16 1
  135. %f32vec2 = OpTypeVector %f32 2
  136. %f32vec3 = OpTypeVector %f32 3
  137. %f32vec4 = OpTypeVector %f32 4
  138. %f64vec2 = OpTypeVector %f64 2
  139. %f64vec3 = OpTypeVector %f64 3
  140. %f64vec4 = OpTypeVector %f64 4
  141. %u32vec2 = OpTypeVector %u32 2
  142. %u32vec3 = OpTypeVector %u32 3
  143. %s32vec2 = OpTypeVector %s32 2
  144. %u32vec4 = OpTypeVector %u32 4
  145. %s32vec4 = OpTypeVector %s32 4
  146. %u64vec2 = OpTypeVector %u64 2
  147. %s64vec2 = OpTypeVector %s64 2
  148. %f64mat22 = OpTypeMatrix %f64vec2 2
  149. %f32mat22 = OpTypeMatrix %f32vec2 2
  150. %f32mat23 = OpTypeMatrix %f32vec2 3
  151. %f32mat32 = OpTypeMatrix %f32vec3 2
  152. %f32mat33 = OpTypeMatrix %f32vec3 3
  153. %f32_0 = OpConstant %f32 0
  154. %f32_1 = OpConstant %f32 1
  155. %f32_2 = OpConstant %f32 2
  156. %f32_3 = OpConstant %f32 3
  157. %f32_4 = OpConstant %f32 4
  158. %f32_h = OpConstant %f32 0.5
  159. %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
  160. %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
  161. %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
  162. %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
  163. %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
  164. %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
  165. %f64_0 = OpConstant %f64 0
  166. %f64_1 = OpConstant %f64 1
  167. %f64_2 = OpConstant %f64 2
  168. %f64_3 = OpConstant %f64 3
  169. %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
  170. %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
  171. %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
  172. %f16_0 = OpConstant %f16 0
  173. %f16_1 = OpConstant %f16 1
  174. %f16_h = OpConstant %f16 0.5
  175. %u32_0 = OpConstant %u32 0
  176. %u32_1 = OpConstant %u32 1
  177. %u32_2 = OpConstant %u32 2
  178. %u32_3 = OpConstant %u32 3
  179. %u32_4 = OpConstant %u32 4
  180. %u32_5 = OpConstant %u32 5
  181. %u32_32 = OpConstant %u32 32
  182. %s32_0 = OpConstant %s32 0
  183. %s32_1 = OpConstant %s32 1
  184. %s32_2 = OpConstant %s32 2
  185. %s32_3 = OpConstant %s32 3
  186. %u64_0 = OpConstant %u64 0
  187. %u64_1 = OpConstant %u64 1
  188. %u64_2 = OpConstant %u64 2
  189. %u64_3 = OpConstant %u64 3
  190. %s64_0 = OpConstant %s64 0
  191. %s64_1 = OpConstant %s64 1
  192. %s64_2 = OpConstant %s64 2
  193. %s64_3 = OpConstant %s64 3
  194. )";
  195. ss << op_const_instructions;
  196. ss << R"(
  197. %s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
  198. %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
  199. %s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
  200. %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
  201. %s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
  202. %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
  203. %s64vec2_01 = OpConstantComposite %s64vec2 %s64_0 %s64_1
  204. %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
  205. %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
  206. %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
  207. %f32_ptr_output = OpTypePointer Output %f32
  208. %f32vec2_ptr_output = OpTypePointer Output %f32vec2
  209. %u32_ptr_output = OpTypePointer Output %u32
  210. %u32vec2_ptr_output = OpTypePointer Output %u32vec2
  211. %u64_ptr_output = OpTypePointer Output %u64
  212. %f32_output = OpVariable %f32_ptr_output Output
  213. %f32vec2_output = OpVariable %f32vec2_ptr_output Output
  214. %u32_output = OpVariable %u32_ptr_output Output
  215. %u32vec2_output = OpVariable %u32vec2_ptr_output Output
  216. %u64_output = OpVariable %u64_ptr_output Output
  217. %f32_ptr_input = OpTypePointer Input %f32
  218. %f32vec2_ptr_input = OpTypePointer Input %f32vec2
  219. %u32_ptr_input = OpTypePointer Input %u32
  220. %u32vec2_ptr_input = OpTypePointer Input %u32vec2
  221. %u64_ptr_input = OpTypePointer Input %u64
  222. %f32_ptr_function = OpTypePointer Function %f32
  223. %f32_input = OpVariable %f32_ptr_input Input
  224. %f32vec2_input = OpVariable %f32vec2_ptr_input Input
  225. %u32_input = OpVariable %u32_ptr_input Input
  226. %u32vec2_input = OpVariable %u32vec2_ptr_input Input
  227. %u64_input = OpVariable %u64_ptr_input Input
  228. %u32_ptr_function = OpTypePointer Function %u32
  229. %struct_f16_u16 = OpTypeStruct %f16 %u16
  230. %struct_f32_f32 = OpTypeStruct %f32 %f32
  231. %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
  232. %struct_f32_u32 = OpTypeStruct %f32 %u32
  233. %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
  234. %struct_u32_f32 = OpTypeStruct %u32 %f32
  235. %struct_u32_u32 = OpTypeStruct %u32 %u32
  236. %struct_f32_f64 = OpTypeStruct %f32 %f64
  237. %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
  238. %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
  239. )";
  240. ss << debug_instructions_before_main;
  241. ss << R"(
  242. %main = OpFunction %void None %func
  243. %main_entry = OpLabel
  244. )";
  245. ss << body;
  246. ss << R"(
  247. OpReturn
  248. OpFunctionEnd)";
  249. return ss.str();
  250. }
  251. TEST_F(ValidateOldDebugInfo, UseDebugInstructionOutOfFunction) {
  252. const std::string src = R"(
  253. %code = OpString "main() {}"
  254. )";
  255. const std::string dbg_inst = R"(
  256. %cu = OpExtInst %void %DbgExt DebugCompilationUnit %code 1 1
  257. )";
  258. const std::string extension = R"(
  259. %DbgExt = OpExtInstImport "DebugInfo"
  260. )";
  261. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  262. extension, "Vertex"));
  263. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  264. }
  265. TEST_F(ValidateOpenCL100DebugInfo, UseDebugInstructionOutOfFunction) {
  266. const std::string src = R"(
  267. %src = OpString "simple.hlsl"
  268. %code = OpString "main() {}"
  269. )";
  270. const std::string dbg_inst = R"(
  271. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  272. )";
  273. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  274. src, "", dbg_inst, "", opencl_extension, "Vertex"));
  275. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  276. }
  277. TEST_F(ValidateOpenCL100DebugInfo, DebugSourceInFunction) {
  278. const std::string src = R"(
  279. %src = OpString "simple.hlsl"
  280. %code = OpString "main() {}"
  281. )";
  282. const std::string dbg_inst = R"(
  283. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  284. )";
  285. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  286. src, "", "", dbg_inst, opencl_extension, "Vertex"));
  287. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  288. EXPECT_THAT(
  289. getDiagnosticString(),
  290. HasSubstr("Debug info extension instructions other than DebugScope, "
  291. "DebugNoScope, DebugDeclare, DebugValue must appear between "
  292. "section 9 (types, constants, global variables) and section 10 "
  293. "(function declarations)"));
  294. }
  295. TEST_F(ValidateVulkan100DebugInfo, DebugSourceInFunction) {
  296. const std::string src = R"(
  297. %src = OpString "simple.hlsl"
  298. %code = OpString "main() {}"
  299. )";
  300. const std::string dbg_inst = R"(
  301. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  302. )";
  303. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  304. src, "", "", dbg_inst, shader_extension, "Vertex"));
  305. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  306. EXPECT_THAT(
  307. getDiagnosticString(),
  308. HasSubstr("Debug info extension instructions other than DebugScope, "
  309. "DebugNoScope, DebugDeclare, DebugValue must appear between "
  310. "section 9 (types, constants, global variables) and section 10 "
  311. "(function declarations)"));
  312. }
  313. TEST_P(ValidateLocalDebugInfoOutOfFunction, OpenCLDebugInfo100DebugScope) {
  314. const std::string src = R"(
  315. %src = OpString "simple.hlsl"
  316. %code = OpString "void main() {}"
  317. %void_name = OpString "void"
  318. %int_name = OpString "int"
  319. %foo_name = OpString "foo"
  320. )";
  321. const std::string dbg_inst_header = R"(
  322. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  323. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  324. %int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_0 Signed
  325. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  326. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  327. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %int_info %dbg_src 1 1 %main_info FlagIsLocal
  328. %expr = OpExtInst %void %DbgExt DebugExpression
  329. )";
  330. const std::string body = R"(
  331. %foo = OpVariable %u32_ptr_function Function
  332. %foo_val = OpLoad %u32 %foo
  333. )";
  334. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  335. src, "", dbg_inst_header + GetParam(), body, opencl_extension, "Vertex"));
  336. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  337. EXPECT_THAT(getDiagnosticString(),
  338. HasSubstr("DebugScope, DebugNoScope, DebugDeclare, DebugValue "
  339. "of debug info extension must appear in a function "
  340. "body"));
  341. }
  342. TEST_P(ValidateLocalDebugInfoOutOfFunction, VulkanDebugInfo100DebugScope) {
  343. const std::string src = R"(
  344. %src = OpString "simple.hlsl"
  345. %code = OpString "void main() {}"
  346. %void_name = OpString "void"
  347. %int_name = OpString "int"
  348. %foo_name = OpString "foo"
  349. )";
  350. const std::string dbg_inst_header = R"(
  351. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  352. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  353. %int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_0 %u32_1 %u32_0
  354. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  355. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  356. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %int_info %dbg_src %u32_1 %u32_1 %main_info %u32_4
  357. %expr = OpExtInst %void %DbgExt DebugExpression
  358. )";
  359. const std::string body = R"(
  360. %foo = OpVariable %u32_ptr_function Function
  361. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main
  362. %foo_val = OpLoad %u32 %foo
  363. )";
  364. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  365. src, "", dbg_inst_header + GetParam(), body, shader_extension, "Vertex"));
  366. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  367. EXPECT_THAT(getDiagnosticString(),
  368. HasSubstr("DebugScope, DebugNoScope, DebugDeclare, DebugValue "
  369. "of debug info extension must appear in a function "
  370. "body"));
  371. }
  372. INSTANTIATE_TEST_SUITE_P(
  373. AllLocalDebugInfo, ValidateLocalDebugInfoOutOfFunction,
  374. ::testing::ValuesIn(std::vector<std::string>{
  375. "%main_scope = OpExtInst %void %DbgExt DebugScope %main_info",
  376. "%no_scope = OpExtInst %void %DbgExt DebugNoScope",
  377. }));
  378. TEST_F(ValidateOpenCL100DebugInfo, DebugFunctionForwardReference) {
  379. const std::string src = R"(
  380. %src = OpString "simple.hlsl"
  381. %code = OpString "void main() {}"
  382. %void_name = OpString "void"
  383. )";
  384. const std::string dbg_inst_header = R"(
  385. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  386. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  387. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  388. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  389. )";
  390. const std::string body = R"(
  391. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info
  392. )";
  393. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  394. src, "", dbg_inst_header, body, opencl_extension, "Vertex"));
  395. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  396. }
  397. TEST_F(ValidateOpenCL100DebugInfo, DebugFunctionMissingOpFunction) {
  398. const std::string src = R"(
  399. %src = OpString "simple.hlsl"
  400. %code = OpString "void main() {}"
  401. %void_name = OpString "void"
  402. )";
  403. const std::string dbg_inst_header = R"(
  404. %dbgNone = OpExtInst %void %DbgExt DebugInfoNone
  405. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  406. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  407. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  408. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %dbgNone
  409. )";
  410. const std::string body = R"(
  411. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info
  412. )";
  413. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  414. src, "", dbg_inst_header, body, opencl_extension, "Vertex"));
  415. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  416. }
  417. TEST_F(ValidateOpenCL100DebugInfo, DebugScopeBeforeOpVariableInFunction) {
  418. const std::string src = R"(
  419. %src = OpString "simple.hlsl"
  420. %code = OpString "float4 main(float arg) {
  421. float foo;
  422. return float4(0, 0, 0, 0);
  423. }
  424. "
  425. %float_name = OpString "float"
  426. )";
  427. const std::string size_const = R"(
  428. %int_32 = OpConstant %u32 32
  429. )";
  430. const std::string dbg_inst_header = R"(
  431. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  432. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  433. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  434. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  435. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
  436. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %main
  437. )";
  438. const std::string body = R"(
  439. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info
  440. %foo = OpVariable %f32_ptr_function Function
  441. )";
  442. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  443. src, size_const, dbg_inst_header, body, opencl_extension, "Vertex"));
  444. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  445. }
  446. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeSizeDebugInfoNone) {
  447. const std::string src = R"(
  448. %src = OpString "simple.hlsl"
  449. %code = OpString "OpaqueType foo;
  450. main() {}
  451. "
  452. %ty_name = OpString "struct VS_OUTPUT"
  453. )";
  454. const std::string dbg_inst_header = R"(
  455. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  456. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  457. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  458. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
  459. )";
  460. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  461. src, "", dbg_inst_header, "", opencl_extension, "Vertex"));
  462. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  463. }
  464. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeForwardReference) {
  465. const std::string src = R"(
  466. %src = OpString "simple.hlsl"
  467. %code = OpString "struct VS_OUTPUT {
  468. float4 pos : SV_POSITION;
  469. float4 color : COLOR;
  470. };
  471. main() {}
  472. "
  473. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  474. %float_name = OpString "float"
  475. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  476. %VS_OUTPUT_color_name = OpString "color : COLOR"
  477. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  478. )";
  479. const std::string size_const = R"(
  480. %int_32 = OpConstant %u32 32
  481. %int_128 = OpConstant %u32 128
  482. )";
  483. const std::string dbg_inst_header = R"(
  484. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  485. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  486. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %VS_OUTPUT_color_info
  487. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  488. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  489. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  490. %VS_OUTPUT_color_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_color_name %v4float_info %dbg_src 3 3 %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
  491. )";
  492. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  493. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  494. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  495. }
  496. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeMissingReference) {
  497. const std::string src = R"(
  498. %src = OpString "simple.hlsl"
  499. %code = OpString "struct VS_OUTPUT {
  500. float4 pos : SV_POSITION;
  501. float4 color : COLOR;
  502. };
  503. main() {}
  504. "
  505. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  506. %float_name = OpString "float"
  507. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  508. %VS_OUTPUT_color_name = OpString "color : COLOR"
  509. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  510. )";
  511. const std::string size_const = R"(
  512. %int_32 = OpConstant %u32 32
  513. %int_128 = OpConstant %u32 128
  514. )";
  515. const std::string dbg_inst_header = R"(
  516. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  517. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  518. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %VS_OUTPUT_color_info
  519. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  520. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  521. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  522. )";
  523. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  524. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  525. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  526. EXPECT_THAT(getDiagnosticString(),
  527. HasSubstr("forward referenced IDs have not been defined"));
  528. }
  529. TEST_P(ValidateXDebugInfo, DebugSourceWrongResultType) {
  530. const std::string src = R"(
  531. %src = OpString "simple.hlsl"
  532. %code = OpString "main() {}"
  533. )";
  534. const std::string dbg_inst = R"(
  535. %dbg_src = OpExtInst %bool %DbgExt DebugSource %src %code
  536. )";
  537. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  538. GetParam(), "Vertex"));
  539. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  540. EXPECT_THAT(getDiagnosticString(),
  541. HasSubstr("expected result type must be a result id of "
  542. "OpTypeVoid"));
  543. }
  544. TEST_P(ValidateXDebugInfo, DebugSourceFailFile) {
  545. const std::string src = R"(
  546. %code = OpString "main() {}"
  547. )";
  548. const std::string dbg_inst = R"(
  549. %dbg_src = OpExtInst %void %DbgExt DebugSource %DbgExt %code
  550. )";
  551. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  552. GetParam(), "Vertex"));
  553. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  554. EXPECT_THAT(getDiagnosticString(),
  555. HasSubstr("expected operand File must be a result id of "
  556. "OpString"));
  557. }
  558. TEST_P(ValidateXDebugInfo, DebugSourceFailSource) {
  559. const std::string src = R"(
  560. %src = OpString "simple.hlsl"
  561. )";
  562. const std::string dbg_inst = R"(
  563. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %DbgExt
  564. )";
  565. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  566. GetParam(), "Vertex"));
  567. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  568. EXPECT_THAT(getDiagnosticString(),
  569. HasSubstr("expected operand Text must be a result id of "
  570. "OpString"));
  571. }
  572. TEST_P(ValidateXDebugInfo, DebugSourceNoText) {
  573. const std::string src = R"(
  574. %src = OpString "simple.hlsl"
  575. )";
  576. const std::string dbg_inst = R"(
  577. %dbg_src = OpExtInst %void %DbgExt DebugSource %src
  578. )";
  579. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  580. GetParam(), "Vertex"));
  581. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  582. }
  583. INSTANTIATE_TEST_SUITE_P(OpenCLAndVkDebugInfo100, ValidateXDebugInfo,
  584. ::testing::ValuesIn(std::vector<std::string>{
  585. R"(
  586. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  587. )",
  588. R"(
  589. OpExtension "SPV_KHR_non_semantic_info"
  590. %DbgExt = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
  591. )",
  592. }));
  593. TEST_F(ValidateOpenCL100DebugInfo, DebugCompilationUnit) {
  594. const std::string src = R"(
  595. %src = OpString "simple.hlsl"
  596. %code = OpString "main() {}"
  597. )";
  598. const std::string dbg_inst = R"(
  599. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  600. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  601. )";
  602. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  603. src, "", dbg_inst, "", opencl_extension, "Vertex"));
  604. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  605. }
  606. TEST_F(ValidateOpenCL100DebugInfo, DebugCompilationUnitFail) {
  607. const std::string src = R"(
  608. %src = OpString "simple.hlsl"
  609. %code = OpString "main() {}"
  610. )";
  611. const std::string dbg_inst = R"(
  612. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  613. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %src HLSL
  614. )";
  615. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  616. src, "", dbg_inst, "", opencl_extension, "Vertex"));
  617. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  618. EXPECT_THAT(getDiagnosticString(),
  619. HasSubstr("expected operand Source must be a result id of "
  620. "DebugSource"));
  621. }
  622. TEST_F(ValidateVulkan100DebugInfo, DebugCompilationUnitFail) {
  623. const std::string src = R"(
  624. %src = OpString "simple.hlsl"
  625. %code = OpString "main() {}"
  626. )";
  627. const std::string dbg_inst = R"(
  628. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  629. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %src %u32_5
  630. )";
  631. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  632. src, "", dbg_inst, "", shader_extension, "Vertex"));
  633. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  634. EXPECT_THAT(getDiagnosticString(),
  635. HasSubstr("expected operand Source must be a result id of "
  636. "DebugSource"));
  637. }
  638. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeBasicFailName) {
  639. const std::string src = R"(
  640. %src = OpString "simple.hlsl"
  641. %code = OpString "float4 main(float arg) {
  642. float foo;
  643. return float4(0, 0, 0, 0);
  644. }
  645. "
  646. %float_name = OpString "float"
  647. )";
  648. const std::string size_const = R"(
  649. %int_32 = OpConstant %u32 32
  650. )";
  651. const std::string dbg_inst_header = R"(
  652. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  653. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  654. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %int_32 %int_32 Float
  655. )";
  656. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  657. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  658. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  659. EXPECT_THAT(getDiagnosticString(),
  660. HasSubstr("expected operand Name must be a result id of "
  661. "OpString"));
  662. }
  663. TEST_F(ValidateVulkan100DebugInfo, DebugTypeBasicFailName) {
  664. const std::string src = R"(
  665. %src = OpString "simple.hlsl"
  666. %code = OpString "float4 main(float arg) {
  667. float foo;
  668. return float4(0, 0, 0, 0);
  669. }
  670. "
  671. %float_name = OpString "float"
  672. )";
  673. const std::string dbg_inst_header = R"(
  674. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  675. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  676. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %u32_32 %u32_32 %u32_3 %u32_0
  677. )";
  678. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  679. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  680. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  681. EXPECT_THAT(getDiagnosticString(),
  682. HasSubstr("expected operand Name must be a result id of "
  683. "OpString"));
  684. }
  685. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeBasicFailSize) {
  686. const std::string src = R"(
  687. %src = OpString "simple.hlsl"
  688. %code = OpString "float4 main(float arg) {
  689. float foo;
  690. return float4(0, 0, 0, 0);
  691. }
  692. "
  693. %float_name = OpString "float"
  694. )";
  695. const std::string size_const = R"(
  696. %int_32 = OpConstant %u32 32
  697. )";
  698. const std::string dbg_inst_header = R"(
  699. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  700. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  701. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %float_name Float
  702. )";
  703. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  704. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  705. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  706. EXPECT_THAT(getDiagnosticString(),
  707. HasSubstr("expected operand Size must be a result id of "
  708. "OpConstant"));
  709. }
  710. TEST_F(ValidateVulkan100DebugInfo, DebugTypeBasicFailSize) {
  711. const std::string src = R"(
  712. %src = OpString "simple.hlsl"
  713. %code = OpString "float4 main(float arg) {
  714. float foo;
  715. return float4(0, 0, 0, 0);
  716. }
  717. "
  718. %float_name = OpString "float"
  719. )";
  720. const std::string dbg_inst_header = R"(
  721. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  722. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  723. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %float_name %u32_3 %u32_0
  724. )";
  725. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  726. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  727. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  728. EXPECT_THAT(getDiagnosticString(),
  729. HasSubstr("expected operand Size must be a result id of "
  730. "OpConstant"));
  731. }
  732. TEST_F(ValidateVulkan100DebugInfo, DebugTypeBasicFailFlags) {
  733. const std::string src = R"(
  734. %src = OpString "simple.hlsl"
  735. %code = OpString "int main() {}"
  736. %float_name = OpString "float"
  737. )";
  738. const std::string constants = R"(
  739. %f32_32 = OpConstant %f32 32
  740. )";
  741. const std::string dbg_inst_header = R"(
  742. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  743. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  744. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_3 %u32_3 %f32_32
  745. )";
  746. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  747. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  748. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  749. EXPECT_THAT(getDiagnosticString(),
  750. HasSubstr("expected operand Flags must be a result id of 32-bit "
  751. "unsigned OpConstant"));
  752. }
  753. TEST_F(ValidateOpenCL100DebugInfo, DebugTypePointer) {
  754. const std::string src = R"(
  755. %src = OpString "simple.hlsl"
  756. %code = OpString "float4 main(float arg) {
  757. float foo;
  758. return float4(0, 0, 0, 0);
  759. }
  760. "
  761. %float_name = OpString "float"
  762. )";
  763. const std::string size_const = R"(
  764. %int_32 = OpConstant %u32 32
  765. )";
  766. const std::string dbg_inst_header = R"(
  767. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  768. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  769. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  770. %pfloat_info = OpExtInst %void %DbgExt DebugTypePointer %float_info Function FlagIsLocal
  771. )";
  772. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  773. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  774. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  775. }
  776. TEST_F(ValidateOpenCL100DebugInfo, DebugTypePointerFail) {
  777. const std::string src = R"(
  778. %src = OpString "simple.hlsl"
  779. %code = OpString "float4 main(float arg) {
  780. float foo;
  781. return float4(0, 0, 0, 0);
  782. }
  783. "
  784. %float_name = OpString "float"
  785. )";
  786. const std::string size_const = R"(
  787. %int_32 = OpConstant %u32 32
  788. )";
  789. const std::string dbg_inst_header = R"(
  790. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  791. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  792. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  793. %pfloat_info = OpExtInst %void %DbgExt DebugTypePointer %dbg_src Function FlagIsLocal
  794. )";
  795. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  796. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  797. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  798. EXPECT_THAT(
  799. getDiagnosticString(),
  800. HasSubstr("expected operand Base Type is not a valid debug type"));
  801. }
  802. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeQualifier) {
  803. const std::string src = R"(
  804. %src = OpString "simple.hlsl"
  805. %code = OpString "float4 main(float arg) {
  806. float foo;
  807. return float4(0, 0, 0, 0);
  808. }
  809. "
  810. %float_name = OpString "float"
  811. )";
  812. const std::string size_const = R"(
  813. %int_32 = OpConstant %u32 32
  814. )";
  815. const std::string dbg_inst_header = R"(
  816. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  817. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  818. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  819. %cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %float_info ConstType
  820. )";
  821. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  822. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  823. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  824. }
  825. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeQualifierFail) {
  826. const std::string src = R"(
  827. %src = OpString "simple.hlsl"
  828. %code = OpString "float4 main(float arg) {
  829. float foo;
  830. return float4(0, 0, 0, 0);
  831. }
  832. "
  833. %float_name = OpString "float"
  834. )";
  835. const std::string size_const = R"(
  836. %int_32 = OpConstant %u32 32
  837. )";
  838. const std::string dbg_inst_header = R"(
  839. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  840. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  841. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  842. %cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %comp_unit ConstType
  843. )";
  844. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  845. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  846. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  847. EXPECT_THAT(
  848. getDiagnosticString(),
  849. HasSubstr("expected operand Base Type is not a valid debug type"));
  850. }
  851. TEST_F(ValidateVulkan100DebugInfo, DebugTypeQualifier) {
  852. const std::string src = R"(
  853. %src = OpString "simple.hlsl"
  854. %code = OpString "float4 main(float arg) {
  855. float foo;
  856. return float4(0, 0, 0, 0);
  857. }
  858. "
  859. %float_name = OpString "float"
  860. )";
  861. const std::string dbg_inst_header = R"(
  862. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  863. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  864. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  865. %cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %float_info %u32_0
  866. )";
  867. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  868. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  869. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  870. }
  871. TEST_F(ValidateVulkan100DebugInfo, DebugTypeQualifierFail) {
  872. const std::string src = R"(
  873. %src = OpString "simple.hlsl"
  874. %code = OpString "float4 main(float arg) {
  875. float foo;
  876. return float4(0, 0, 0, 0);
  877. }
  878. "
  879. %float_name = OpString "float"
  880. )";
  881. const std::string dbg_inst_header = R"(
  882. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  883. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  884. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  885. %cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %comp_unit %u32_0
  886. )";
  887. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  888. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  889. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  890. EXPECT_THAT(
  891. getDiagnosticString(),
  892. HasSubstr("expected operand Base Type is not a valid debug type"));
  893. }
  894. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArray) {
  895. const std::string src = R"(
  896. %src = OpString "simple.hlsl"
  897. %code = OpString "main() {}"
  898. %float_name = OpString "float"
  899. )";
  900. const std::string size_const = R"(
  901. %int_32 = OpConstant %u32 32
  902. )";
  903. const std::string dbg_inst_header = R"(
  904. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  905. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  906. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  907. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %int_32
  908. )";
  909. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  910. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  911. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  912. }
  913. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayWithVariableSize) {
  914. const std::string src = R"(
  915. %src = OpString "simple.hlsl"
  916. %code = OpString "main() {}"
  917. %float_name = OpString "float"
  918. %int_name = OpString "int"
  919. %foo_name = OpString "foo"
  920. )";
  921. const std::string size_const = R"(
  922. %int_32 = OpConstant %u32 32
  923. )";
  924. const std::string dbg_inst_header = R"(
  925. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  926. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  927. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  928. %uint_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %int_32 Unsigned
  929. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  930. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  931. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %uint_info %dbg_src 1 1 %main_info FlagIsLocal
  932. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
  933. )";
  934. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  935. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  936. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  937. }
  938. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailBaseType) {
  939. const std::string src = R"(
  940. %src = OpString "simple.hlsl"
  941. %code = OpString "main() {}"
  942. %float_name = OpString "float"
  943. )";
  944. const std::string size_const = R"(
  945. %int_32 = OpConstant %u32 32
  946. )";
  947. const std::string dbg_inst_header = R"(
  948. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  949. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  950. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  951. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %comp_unit %int_32
  952. )";
  953. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  954. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  955. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  956. EXPECT_THAT(getDiagnosticString(),
  957. HasSubstr("expected operand Base Type is not a valid debug "
  958. "type"));
  959. }
  960. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCount) {
  961. const std::string src = R"(
  962. %src = OpString "simple.hlsl"
  963. %code = OpString "main() {}"
  964. %float_name = OpString "float"
  965. )";
  966. const std::string size_const = R"(
  967. %int_32 = OpConstant %u32 32
  968. )";
  969. const std::string dbg_inst_header = R"(
  970. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  971. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  972. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  973. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %float_info
  974. )";
  975. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  976. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  977. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  978. EXPECT_THAT(getDiagnosticString(),
  979. HasSubstr("Component Count must be OpConstant with a 32- or "
  980. "64-bits integer scalar type or DebugGlobalVariable or "
  981. "DebugLocalVariable with a 32- or 64-bits unsigned "
  982. "integer scalar type"));
  983. }
  984. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCountFloat) {
  985. const std::string src = R"(
  986. %src = OpString "simple.hlsl"
  987. %code = OpString "main() {}"
  988. %float_name = OpString "float"
  989. )";
  990. const std::string size_const = R"(
  991. %int_32 = OpConstant %u32 32
  992. )";
  993. const std::string dbg_inst_header = R"(
  994. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  995. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  996. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  997. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %f32_4
  998. )";
  999. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1000. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1001. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1002. EXPECT_THAT(getDiagnosticString(),
  1003. HasSubstr("Component Count must be OpConstant with a 32- or "
  1004. "64-bits integer scalar type or DebugGlobalVariable or "
  1005. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1006. "integer scalar type"));
  1007. }
  1008. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCountZero) {
  1009. const std::string src = R"(
  1010. %src = OpString "simple.hlsl"
  1011. %code = OpString "main() {}"
  1012. %float_name = OpString "float"
  1013. )";
  1014. const std::string size_const = R"(
  1015. %int_32 = OpConstant %u32 32
  1016. )";
  1017. const std::string dbg_inst_header = R"(
  1018. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1019. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1020. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1021. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %u32_0
  1022. )";
  1023. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1024. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1025. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1026. EXPECT_THAT(getDiagnosticString(),
  1027. HasSubstr("Component Count must be OpConstant with a 32- or "
  1028. "64-bits integer scalar type or DebugGlobalVariable or "
  1029. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1030. "integer scalar type"));
  1031. }
  1032. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailVariableSizeTypeFloat) {
  1033. const std::string src = R"(
  1034. %src = OpString "simple.hlsl"
  1035. %code = OpString "main() {}"
  1036. %float_name = OpString "float"
  1037. %foo_name = OpString "foo"
  1038. )";
  1039. const std::string size_const = R"(
  1040. %int_32 = OpConstant %u32 32
  1041. )";
  1042. const std::string dbg_inst_header = R"(
  1043. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1044. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1045. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1046. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1047. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  1048. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 1 %main_info FlagIsLocal
  1049. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
  1050. )";
  1051. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1052. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1053. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1054. EXPECT_THAT(getDiagnosticString(),
  1055. HasSubstr("Component Count must be OpConstant with a 32- or "
  1056. "64-bits integer scalar type or DebugGlobalVariable or "
  1057. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1058. "integer scalar type"));
  1059. }
  1060. TEST_F(ValidateVulkan100DebugInfo, DebugTypeArray) {
  1061. const std::string src = R"(
  1062. %src = OpString "simple.hlsl"
  1063. %code = OpString "main() {}"
  1064. %float_name = OpString "float"
  1065. )";
  1066. const std::string dbg_inst_header = R"(
  1067. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1068. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1069. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1070. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %u32_32
  1071. )";
  1072. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1073. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1074. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1075. }
  1076. TEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayWithVariableSize) {
  1077. const std::string src = R"(
  1078. %src = OpString "simple.hlsl"
  1079. %code = OpString "main() {}"
  1080. %float_name = OpString "float"
  1081. %uint_name = OpString "uint"
  1082. %foo_name = OpString "foo"
  1083. )";
  1084. const std::string constants = R"(
  1085. %u32_6 = OpConstant %u32 6
  1086. )";
  1087. const std::string dbg_inst_header = R"(
  1088. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1089. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1090. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1091. %uint_info = OpExtInst %void %DbgExt DebugTypeBasic %uint_name %u32_32 %u32_6 %u32_0
  1092. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  1093. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  1094. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %uint_info %dbg_src %u32_1 %u32_1 %main_info %u32_4
  1095. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
  1096. )";
  1097. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1098. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  1099. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1100. }
  1101. TEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailBaseType) {
  1102. const std::string src = R"(
  1103. %src = OpString "simple.hlsl"
  1104. %code = OpString "main() {}"
  1105. %float_name = OpString "float"
  1106. )";
  1107. const std::string dbg_inst_header = R"(
  1108. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1109. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1110. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1111. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %comp_unit %u32_32
  1112. )";
  1113. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1114. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1115. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1116. EXPECT_THAT(getDiagnosticString(),
  1117. HasSubstr("expected operand Base Type is not a valid debug "
  1118. "type"));
  1119. }
  1120. TEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailComponentCount) {
  1121. const std::string src = R"(
  1122. %src = OpString "simple.hlsl"
  1123. %code = OpString "main() {}"
  1124. %float_name = OpString "float"
  1125. )";
  1126. const std::string dbg_inst_header = R"(
  1127. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1128. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1129. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1130. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %float_info
  1131. )";
  1132. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1133. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1134. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1135. EXPECT_THAT(getDiagnosticString(),
  1136. HasSubstr("Component Count must be OpConstant with a 32- or "
  1137. "64-bits integer scalar type or DebugGlobalVariable or "
  1138. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1139. "integer scalar type"));
  1140. }
  1141. TEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailComponentCountFloat) {
  1142. const std::string src = R"(
  1143. %src = OpString "simple.hlsl"
  1144. %code = OpString "main() {}"
  1145. %float_name = OpString "float"
  1146. )";
  1147. const std::string dbg_inst_header = R"(
  1148. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1149. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1150. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1151. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %f32_4
  1152. )";
  1153. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1154. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1155. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1156. EXPECT_THAT(getDiagnosticString(),
  1157. HasSubstr("Component Count must be OpConstant with a 32- or "
  1158. "64-bits integer scalar type or DebugGlobalVariable or "
  1159. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1160. "integer scalar type"));
  1161. }
  1162. TEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayComponentCountZero) {
  1163. const std::string src = R"(
  1164. %src = OpString "simple.hlsl"
  1165. %code = OpString "main() {}"
  1166. %float_name = OpString "float"
  1167. )";
  1168. const std::string dbg_inst_header = R"(
  1169. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1170. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1171. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1172. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %u32_0
  1173. )";
  1174. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1175. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1176. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1177. }
  1178. TEST_F(ValidateVulkan100DebugInfo, DebugTypeArrayFailVariableSizeTypeFloat) {
  1179. const std::string src = R"(
  1180. %src = OpString "simple.hlsl"
  1181. %code = OpString "main() {}"
  1182. %float_name = OpString "float"
  1183. %foo_name = OpString "foo"
  1184. )";
  1185. const std::string constants = R"(
  1186. %u32_6 = OpConstant %u32 6
  1187. )";
  1188. const std::string dbg_inst_header = R"(
  1189. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1190. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1191. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1192. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  1193. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  1194. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_1 %main_info %u32_4
  1195. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
  1196. )";
  1197. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1198. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  1199. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1200. EXPECT_THAT(getDiagnosticString(),
  1201. HasSubstr("Component Count must be OpConstant with a 32- or "
  1202. "64-bits integer scalar type or DebugGlobalVariable or "
  1203. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1204. "integer scalar type"));
  1205. }
  1206. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVector) {
  1207. const std::string src = R"(
  1208. %src = OpString "simple.hlsl"
  1209. %code = OpString "main() {}"
  1210. %float_name = OpString "float"
  1211. )";
  1212. const std::string size_const = R"(
  1213. %int_32 = OpConstant %u32 32
  1214. )";
  1215. const std::string dbg_inst_header = R"(
  1216. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1217. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1218. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1219. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  1220. )";
  1221. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1222. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1223. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1224. }
  1225. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFail) {
  1226. const std::string src = R"(
  1227. %src = OpString "simple.hlsl"
  1228. %code = OpString "main() {}"
  1229. %float_name = OpString "float"
  1230. )";
  1231. const std::string size_const = R"(
  1232. %int_32 = OpConstant %u32 32
  1233. )";
  1234. const std::string dbg_inst_header = R"(
  1235. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1236. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1237. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1238. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 4
  1239. )";
  1240. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1241. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1242. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1243. EXPECT_THAT(getDiagnosticString(),
  1244. HasSubstr("expected operand Base Type must be a result id of "
  1245. "DebugTypeBasic"));
  1246. }
  1247. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFailComponentZero) {
  1248. const std::string src = R"(
  1249. %src = OpString "simple.hlsl"
  1250. %code = OpString "main() {}"
  1251. %float_name = OpString "float"
  1252. )";
  1253. const std::string size_const = R"(
  1254. %int_32 = OpConstant %u32 32
  1255. )";
  1256. const std::string dbg_inst_header = R"(
  1257. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1258. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1259. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1260. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 0
  1261. )";
  1262. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1263. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1264. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1265. EXPECT_THAT(getDiagnosticString(),
  1266. HasSubstr("expected operand Base Type must be a result id of "
  1267. "DebugTypeBasic"));
  1268. }
  1269. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFailComponentFive) {
  1270. const std::string src = R"(
  1271. %src = OpString "simple.hlsl"
  1272. %code = OpString "main() {}"
  1273. %float_name = OpString "float"
  1274. )";
  1275. const std::string size_const = R"(
  1276. %int_32 = OpConstant %u32 32
  1277. )";
  1278. const std::string dbg_inst_header = R"(
  1279. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1280. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1281. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1282. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 5
  1283. )";
  1284. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1285. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1286. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1287. EXPECT_THAT(getDiagnosticString(),
  1288. HasSubstr("expected operand Base Type must be a result id of "
  1289. "DebugTypeBasic"));
  1290. }
  1291. TEST_F(ValidateVulkan100DebugInfo, DebugTypeVector) {
  1292. const std::string src = R"(
  1293. %src = OpString "simple.hlsl"
  1294. %code = OpString "main() {}"
  1295. %float_name = OpString "float"
  1296. )";
  1297. const std::string dbg_inst_header = R"(
  1298. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1299. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1300. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1301. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  1302. )";
  1303. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1304. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1305. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1306. }
  1307. TEST_F(ValidateVulkan100DebugInfo, DebugTypeVectorFail) {
  1308. const std::string src = R"(
  1309. %src = OpString "simple.hlsl"
  1310. %code = OpString "main() {}"
  1311. %float_name = OpString "float"
  1312. )";
  1313. const std::string dbg_inst_header = R"(
  1314. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1315. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1316. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1317. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src %u32_4
  1318. )";
  1319. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1320. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1321. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1322. EXPECT_THAT(getDiagnosticString(),
  1323. HasSubstr("expected operand Base Type must be a result id of "
  1324. "DebugTypeBasic"));
  1325. }
  1326. TEST_F(ValidateVulkan100DebugInfo, DebugTypeVectorFailComponentZero) {
  1327. const std::string src = R"(
  1328. %src = OpString "simple.hlsl"
  1329. %code = OpString "main() {}"
  1330. %float_name = OpString "float"
  1331. )";
  1332. const std::string dbg_inst_header = R"(
  1333. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1334. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1335. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1336. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_0
  1337. )";
  1338. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1339. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1340. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1341. EXPECT_THAT(getDiagnosticString(),
  1342. HasSubstr("Component Count must be positive "
  1343. "integer less than or equal to 4"));
  1344. }
  1345. TEST_F(ValidateVulkan100DebugInfo, DebugTypeVectorFailComponentFive) {
  1346. const std::string src = R"(
  1347. %src = OpString "simple.hlsl"
  1348. %code = OpString "main() {}"
  1349. %float_name = OpString "float"
  1350. )";
  1351. const std::string dbg_inst_header = R"(
  1352. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1353. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1354. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1355. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_5
  1356. )";
  1357. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1358. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1359. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1360. EXPECT_THAT(getDiagnosticString(),
  1361. HasSubstr("Component Count must be positive "
  1362. "integer less than or equal to 4"));
  1363. }
  1364. TEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrix) {
  1365. const std::string src = R"(
  1366. %src = OpString "simple.hlsl"
  1367. %code = OpString "main() {}"
  1368. %float_name = OpString "float"
  1369. )";
  1370. const std::string constants = R"(
  1371. %true = OpConstantTrue %bool
  1372. )";
  1373. const std::string dbg_inst_header = R"(
  1374. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1375. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1376. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1377. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  1378. %mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %u32_4 %true
  1379. )";
  1380. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1381. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  1382. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1383. }
  1384. TEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorTypeType) {
  1385. const std::string src = R"(
  1386. %src = OpString "simple.hlsl"
  1387. %code = OpString "main() {}"
  1388. %float_name = OpString "float"
  1389. )";
  1390. const std::string constants = R"(
  1391. %true = OpConstantTrue %bool
  1392. )";
  1393. const std::string dbg_inst_header = R"(
  1394. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1395. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1396. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1397. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  1398. %mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %dbg_src %u32_4 %true
  1399. )";
  1400. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1401. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  1402. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1403. EXPECT_THAT(getDiagnosticString(),
  1404. HasSubstr("expected operand Vector Type must be a result id of "
  1405. "DebugTypeVector"));
  1406. }
  1407. TEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorCountType) {
  1408. const std::string src = R"(
  1409. %src = OpString "simple.hlsl"
  1410. %code = OpString "main() {}"
  1411. %float_name = OpString "float"
  1412. )";
  1413. const std::string constants = R"(
  1414. %true = OpConstantTrue %bool
  1415. )";
  1416. const std::string dbg_inst_header = R"(
  1417. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1418. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1419. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1420. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  1421. %mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %dbg_src %true
  1422. )";
  1423. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1424. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  1425. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1426. EXPECT_THAT(getDiagnosticString(),
  1427. HasSubstr("expected operand Vector Count must be a result id of "
  1428. "32-bit unsigned OpConstant"));
  1429. }
  1430. TEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorCountZero) {
  1431. const std::string src = R"(
  1432. %src = OpString "simple.hlsl"
  1433. %code = OpString "main() {}"
  1434. %float_name = OpString "float"
  1435. )";
  1436. const std::string constants = R"(
  1437. %true = OpConstantTrue %bool
  1438. )";
  1439. const std::string dbg_inst_header = R"(
  1440. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1441. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1442. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1443. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  1444. %mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %u32_0 %true
  1445. )";
  1446. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1447. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  1448. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1449. EXPECT_THAT(getDiagnosticString(),
  1450. HasSubstr("Vector Count must be positive "
  1451. "integer less than or equal to 4"));
  1452. }
  1453. TEST_F(ValidateVulkan100DebugInfo, DebugTypeMatrixFailVectorCountFive) {
  1454. const std::string src = R"(
  1455. %src = OpString "simple.hlsl"
  1456. %code = OpString "main() {}"
  1457. %float_name = OpString "float"
  1458. )";
  1459. const std::string constants = R"(
  1460. %true = OpConstantTrue %bool
  1461. )";
  1462. const std::string dbg_inst_header = R"(
  1463. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1464. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1465. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1466. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  1467. %mfloat_info = OpExtInst %void %DbgExt DebugTypeMatrix %vfloat_info %u32_5 %true
  1468. )";
  1469. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1470. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  1471. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1472. EXPECT_THAT(getDiagnosticString(),
  1473. HasSubstr("Vector Count must be positive "
  1474. "integer less than or equal to 4"));
  1475. }
  1476. TEST_F(ValidateOpenCL100DebugInfo, DebugTypedef) {
  1477. const std::string src = R"(
  1478. %src = OpString "simple.hlsl"
  1479. %code = OpString "main() {}"
  1480. %float_name = OpString "float"
  1481. %foo_name = OpString "foo"
  1482. )";
  1483. const std::string size_const = R"(
  1484. %int_32 = OpConstant %u32 32
  1485. )";
  1486. const std::string dbg_inst_header = R"(
  1487. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1488. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1489. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1490. %foo_info = OpExtInst %void %DbgExt DebugTypedef %foo_name %float_info %dbg_src 1 1 %comp_unit
  1491. )";
  1492. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1493. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1494. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1495. }
  1496. TEST_P(ValidateOpenCL100DebugInfoDebugTypedef, Fail) {
  1497. const std::string src = R"(
  1498. %src = OpString "simple.hlsl"
  1499. %code = OpString "main() {}"
  1500. %float_name = OpString "float"
  1501. %foo_name = OpString "foo"
  1502. )";
  1503. const std::string size_const = R"(
  1504. %int_32 = OpConstant %u32 32
  1505. )";
  1506. const auto& param = GetParam();
  1507. std::ostringstream ss;
  1508. ss << R"(
  1509. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1510. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1511. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1512. %foo_info = OpExtInst %void %DbgExt DebugTypedef )";
  1513. ss << param.first;
  1514. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1515. src, size_const, ss.str(), "", opencl_extension, "Vertex"));
  1516. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1517. EXPECT_THAT(getDiagnosticString(),
  1518. HasSubstr("expected operand " + param.second +
  1519. " must be a result id of "));
  1520. }
  1521. INSTANTIATE_TEST_SUITE_P(
  1522. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypedef,
  1523. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1524. std::make_pair(R"(%dbg_src %float_info %dbg_src 1 1 %comp_unit)",
  1525. "Name"),
  1526. std::make_pair(R"(%foo_name %dbg_src %dbg_src 1 1 %comp_unit)",
  1527. "Base Type"),
  1528. std::make_pair(R"(%foo_name %float_info %comp_unit 1 1 %comp_unit)",
  1529. "Source"),
  1530. std::make_pair(R"(%foo_name %float_info %dbg_src 1 1 %dbg_src)",
  1531. "Parent"),
  1532. }));
  1533. TEST_F(ValidateVulkan100DebugInfo, DebugTypedef) {
  1534. const std::string src = R"(
  1535. %src = OpString "simple.hlsl"
  1536. %code = OpString "main() {}"
  1537. %float_name = OpString "float"
  1538. %foo_name = OpString "foo"
  1539. )";
  1540. const std::string dbg_inst_header = R"(
  1541. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1542. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1543. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1544. %foo_info = OpExtInst %void %DbgExt DebugTypedef %foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit
  1545. )";
  1546. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1547. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1548. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1549. }
  1550. TEST_P(ValidateVulkan100DebugInfoDebugTypedef, Fail) {
  1551. const std::string src = R"(
  1552. %src = OpString "simple.hlsl"
  1553. %code = OpString "main() {}"
  1554. %float_name = OpString "float"
  1555. %foo_name = OpString "foo"
  1556. )";
  1557. const auto& param = GetParam();
  1558. std::ostringstream ss;
  1559. ss << R"(
  1560. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1561. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1562. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1563. %foo_info = OpExtInst %void %DbgExt DebugTypedef )";
  1564. ss << param.first;
  1565. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1566. src, "", ss.str(), "", shader_extension, "Vertex"));
  1567. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1568. EXPECT_THAT(getDiagnosticString(),
  1569. HasSubstr("expected operand " + param.second +
  1570. " must be a result id of "));
  1571. }
  1572. INSTANTIATE_TEST_SUITE_P(
  1573. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypedef,
  1574. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1575. std::make_pair(
  1576. R"(%dbg_src %float_info %dbg_src %u32_1 %u32_1 %comp_unit)",
  1577. "Name"),
  1578. std::make_pair(
  1579. R"(%foo_name %dbg_src %dbg_src %u32_1 %u32_1 %comp_unit)",
  1580. "Base Type"),
  1581. std::make_pair(
  1582. R"(%foo_name %float_info %comp_unit %u32_1 %u32_1 %comp_unit)",
  1583. "Source"),
  1584. std::make_pair(
  1585. R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %dbg_src)",
  1586. "Parent"),
  1587. }));
  1588. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunction) {
  1589. const std::string src = R"(
  1590. %src = OpString "simple.hlsl"
  1591. %code = OpString "main() {}"
  1592. %float_name = OpString "float"
  1593. )";
  1594. const std::string size_const = R"(
  1595. %int_32 = OpConstant %u32 32
  1596. )";
  1597. const std::string dbg_inst_header = R"(
  1598. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1599. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1600. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1601. %main_type_info1 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1602. %main_type_info2 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info
  1603. %main_type_info3 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info %float_info
  1604. %main_type_info4 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void %float_info %float_info
  1605. )";
  1606. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1607. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1608. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1609. }
  1610. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunctionFailReturn) {
  1611. const std::string src = R"(
  1612. %src = OpString "simple.hlsl"
  1613. %code = OpString "main() {}"
  1614. %float_name = OpString "float"
  1615. )";
  1616. const std::string size_const = R"(
  1617. %int_32 = OpConstant %u32 32
  1618. )";
  1619. const std::string dbg_inst_header = R"(
  1620. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1621. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1622. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1623. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %dbg_src %float_info
  1624. )";
  1625. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1626. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1627. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1628. EXPECT_THAT(
  1629. getDiagnosticString(),
  1630. HasSubstr("expected operand Return Type is not a valid debug type"));
  1631. }
  1632. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunctionFailParam) {
  1633. const std::string src = R"(
  1634. %src = OpString "simple.hlsl"
  1635. %code = OpString "main() {}"
  1636. %float_name = OpString "float"
  1637. )";
  1638. const std::string size_const = R"(
  1639. %int_32 = OpConstant %u32 32
  1640. )";
  1641. const std::string dbg_inst_header = R"(
  1642. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1643. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1644. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1645. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info %void
  1646. )";
  1647. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1648. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1649. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1650. EXPECT_THAT(
  1651. getDiagnosticString(),
  1652. HasSubstr("expected operand Parameter Types is not a valid debug type"));
  1653. }
  1654. TEST_F(ValidateVulkan100DebugInfo, DebugTypeFunctionAndParams) {
  1655. const std::string src = R"(
  1656. %src = OpString "simple.hlsl"
  1657. %code = OpString "main() {}"
  1658. %float_name = OpString "float"
  1659. )";
  1660. const std::string dbg_inst_header = R"(
  1661. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1662. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1663. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1664. %main_type_info1 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  1665. %main_type_info2 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %float_info
  1666. %main_type_info3 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %float_info %float_info
  1667. %main_type_info4 = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void %float_info %float_info
  1668. )";
  1669. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1670. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1671. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1672. }
  1673. TEST_F(ValidateVulkan100DebugInfo, DebugTypeFunctionFailReturn) {
  1674. const std::string src = R"(
  1675. %src = OpString "simple.hlsl"
  1676. %code = OpString "main() {}"
  1677. %float_name = OpString "float"
  1678. )";
  1679. const std::string dbg_inst_header = R"(
  1680. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1681. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1682. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1683. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %dbg_src %float_info
  1684. )";
  1685. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1686. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1687. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1688. EXPECT_THAT(
  1689. getDiagnosticString(),
  1690. HasSubstr("expected operand Return Type is not a valid debug type"));
  1691. }
  1692. TEST_F(ValidateVulkan100DebugInfo, DebugTypeFunctionFailParam) {
  1693. const std::string src = R"(
  1694. %src = OpString "simple.hlsl"
  1695. %code = OpString "main() {}"
  1696. %float_name = OpString "float"
  1697. )";
  1698. const std::string dbg_inst_header = R"(
  1699. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1700. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1701. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1702. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %float_info %void
  1703. )";
  1704. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1705. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1706. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1707. EXPECT_THAT(
  1708. getDiagnosticString(),
  1709. HasSubstr("expected operand Parameter Types is not a valid debug type"));
  1710. }
  1711. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeEnum) {
  1712. const std::string src = R"(
  1713. %src = OpString "simple.hlsl"
  1714. %code = OpString "main() {}"
  1715. %float_name = OpString "float"
  1716. %foo_name = OpString "foo"
  1717. )";
  1718. const std::string size_const = R"(
  1719. %int_32 = OpConstant %u32 32
  1720. )";
  1721. const std::string dbg_inst_header = R"(
  1722. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1723. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1724. %none = OpExtInst %void %DbgExt DebugInfoNone
  1725. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1726. %foo_info1 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name %u32_1 %foo_name
  1727. %foo_info2 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name %u32_1 %foo_name
  1728. %foo_info3 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic
  1729. )";
  1730. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1731. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1732. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1733. }
  1734. TEST_P(ValidateOpenCL100DebugInfoDebugTypeEnum, Fail) {
  1735. const std::string src = R"(
  1736. %src = OpString "simple.hlsl"
  1737. %code = OpString "main() {}"
  1738. %float_name = OpString "float"
  1739. %foo_name = OpString "foo"
  1740. )";
  1741. const std::string size_const = R"(
  1742. %int_32 = OpConstant %u32 32
  1743. )";
  1744. const auto& param = GetParam();
  1745. std::ostringstream ss;
  1746. ss << R"(
  1747. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1748. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1749. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1750. %foo_info = OpExtInst %void %DbgExt DebugTypeEnum )";
  1751. ss << param.first;
  1752. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1753. src, size_const, ss.str(), "", opencl_extension, "Vertex"));
  1754. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1755. EXPECT_THAT(getDiagnosticString(),
  1756. HasSubstr("expected operand " + param.second));
  1757. }
  1758. INSTANTIATE_TEST_SUITE_P(
  1759. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeEnum,
  1760. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1761. std::make_pair(
  1762. R"(%dbg_src %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
  1763. "Name"),
  1764. std::make_pair(
  1765. R"(%foo_name %dbg_src %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
  1766. "Underlying Types"),
  1767. std::make_pair(
  1768. R"(%foo_name %float_info %comp_unit 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
  1769. "Source"),
  1770. std::make_pair(
  1771. R"(%foo_name %float_info %dbg_src 1 1 %dbg_src %int_32 FlagIsPublic %u32_0 %foo_name)",
  1772. "Parent"),
  1773. std::make_pair(
  1774. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %void FlagIsPublic %u32_0 %foo_name)",
  1775. "Size"),
  1776. std::make_pair(
  1777. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %u32_0 FlagIsPublic %u32_0 %foo_name)",
  1778. "Size"),
  1779. std::make_pair(
  1780. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %foo_name %foo_name)",
  1781. "Value"),
  1782. std::make_pair(
  1783. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %u32_1)",
  1784. "Name"),
  1785. }));
  1786. TEST_F(ValidateVulkan100DebugInfo, DebugTypeEnum) {
  1787. const std::string src = R"(
  1788. %src = OpString "simple.hlsl"
  1789. %code = OpString "main() {}"
  1790. %float_name = OpString "float"
  1791. %foo_name = OpString "foo"
  1792. )";
  1793. const std::string dbg_inst_header = R"(
  1794. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1795. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1796. %none = OpExtInst %void %DbgExt DebugInfoNone
  1797. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1798. %foo_info1 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name %u32_1 %foo_name
  1799. %foo_info2 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name %u32_1 %foo_name
  1800. %foo_info3 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3
  1801. )";
  1802. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1803. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  1804. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1805. }
  1806. TEST_P(ValidateVulkan100DebugInfoDebugTypeEnum, Fail) {
  1807. const std::string src = R"(
  1808. %src = OpString "simple.hlsl"
  1809. %code = OpString "main() {}"
  1810. %float_name = OpString "float"
  1811. %foo_name = OpString "foo"
  1812. )";
  1813. const auto& param = GetParam();
  1814. std::ostringstream ss;
  1815. ss << R"(
  1816. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1817. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  1818. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  1819. %foo_info = OpExtInst %void %DbgExt DebugTypeEnum )";
  1820. ss << param.first;
  1821. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1822. src, "", ss.str(), "", shader_extension, "Vertex"));
  1823. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1824. EXPECT_THAT(getDiagnosticString(),
  1825. HasSubstr("expected operand " + param.second));
  1826. }
  1827. INSTANTIATE_TEST_SUITE_P(
  1828. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypeEnum,
  1829. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1830. std::make_pair(
  1831. R"(%dbg_src %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name)",
  1832. "Name"),
  1833. std::make_pair(
  1834. R"(%foo_name %dbg_src %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name)",
  1835. "Underlying Types"),
  1836. std::make_pair(
  1837. R"(%foo_name %float_info %comp_unit %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %foo_name)",
  1838. "Source"),
  1839. std::make_pair(
  1840. R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %dbg_src %u32_32 %u32_3 %u32_0 %foo_name)",
  1841. "Parent"),
  1842. std::make_pair(
  1843. R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %void %u32_3 %u32_0 %foo_name)",
  1844. "Size"),
  1845. std::make_pair(
  1846. R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_0 %u32_3 %u32_0 %foo_name)",
  1847. "Size"),
  1848. std::make_pair(
  1849. R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %foo_name %foo_name)",
  1850. "Value"),
  1851. std::make_pair(
  1852. R"(%foo_name %float_info %dbg_src %u32_1 %u32_1 %comp_unit %u32_32 %u32_3 %u32_0 %u32_1)",
  1853. "Name"),
  1854. }));
  1855. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeFunctionAndInheritance) {
  1856. const std::string src = R"(
  1857. %src = OpString "simple.hlsl"
  1858. %code = OpString "struct VS_OUTPUT {
  1859. float4 pos : SV_POSITION;
  1860. };
  1861. struct foo : VS_OUTPUT {
  1862. };
  1863. main() {}
  1864. "
  1865. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  1866. %float_name = OpString "float"
  1867. %foo_name = OpString "foo"
  1868. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  1869. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  1870. )";
  1871. const std::string size_const = R"(
  1872. %int_32 = OpConstant %u32 32
  1873. %int_128 = OpConstant %u32 128
  1874. )";
  1875. const std::string dbg_inst_header = R"(
  1876. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1877. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1878. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child
  1879. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1880. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  1881. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  1882. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
  1883. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %main
  1884. %foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  1885. %child = OpExtInst %void %DbgExt DebugTypeInheritance %foo_info %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
  1886. )";
  1887. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1888. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  1889. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1890. }
  1891. TEST_P(ValidateOpenCL100DebugInfoDebugTypeComposite, Fail) {
  1892. const std::string src = R"(
  1893. %src = OpString "simple.hlsl"
  1894. %code = OpString "struct VS_OUTPUT {
  1895. float4 pos : SV_POSITION;
  1896. };
  1897. struct foo : VS_OUTPUT {
  1898. };
  1899. main() {}
  1900. "
  1901. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  1902. %float_name = OpString "float"
  1903. %foo_name = OpString "foo"
  1904. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  1905. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  1906. )";
  1907. const std::string size_const = R"(
  1908. %int_32 = OpConstant %u32 32
  1909. %int_128 = OpConstant %u32 128
  1910. )";
  1911. const auto& param = GetParam();
  1912. std::ostringstream ss;
  1913. ss << R"(
  1914. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1915. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1916. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite )";
  1917. ss << param.first;
  1918. ss << R"(
  1919. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1920. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  1921. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  1922. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
  1923. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %main
  1924. %foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  1925. %child = OpExtInst %void %DbgExt DebugTypeInheritance %foo_info %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
  1926. )";
  1927. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1928. src, size_const, ss.str(), "", opencl_extension, "Vertex"));
  1929. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1930. EXPECT_THAT(getDiagnosticString(),
  1931. HasSubstr("expected operand " + param.second + " must be "));
  1932. }
  1933. INSTANTIATE_TEST_SUITE_P(
  1934. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeComposite,
  1935. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1936. std::make_pair(
  1937. R"(%dbg_src Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1938. "Name"),
  1939. std::make_pair(
  1940. R"(%VS_OUTPUT_name Structure %comp_unit 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1941. "Source"),
  1942. std::make_pair(
  1943. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %dbg_src %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1944. "Parent"),
  1945. std::make_pair(
  1946. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %int_128 %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1947. "Linkage Name"),
  1948. std::make_pair(
  1949. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %dbg_src FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1950. "Size"),
  1951. std::make_pair(
  1952. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %dbg_src %main_info %child)",
  1953. "Members"),
  1954. std::make_pair(
  1955. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %dbg_src %child)",
  1956. "Members"),
  1957. std::make_pair(
  1958. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %dbg_src)",
  1959. "Members"),
  1960. }));
  1961. TEST_P(ValidateOpenCL100DebugInfoDebugTypeMember, Fail) {
  1962. const std::string src = R"(
  1963. %src = OpString "simple.hlsl"
  1964. %code = OpString "struct VS_OUTPUT {
  1965. float pos : SV_POSITION;
  1966. };
  1967. main() {}
  1968. "
  1969. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  1970. %float_name = OpString "float"
  1971. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  1972. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  1973. )";
  1974. const std::string size_const = R"(
  1975. %int_32 = OpConstant %u32 32
  1976. )";
  1977. const auto& param = GetParam();
  1978. std::ostringstream ss;
  1979. ss << R"(
  1980. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1981. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1982. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_32 FlagIsPublic %VS_OUTPUT_pos_info
  1983. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1984. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember )";
  1985. ss << param.first;
  1986. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1987. src, size_const, ss.str(), "", opencl_extension, "Vertex"));
  1988. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1989. if (!param.second.empty()) {
  1990. EXPECT_THAT(getDiagnosticString(),
  1991. HasSubstr("expected operand " + param.second +
  1992. " must be a result id of "));
  1993. }
  1994. }
  1995. INSTANTIATE_TEST_SUITE_P(
  1996. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeMember,
  1997. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1998. std::make_pair(
  1999. R"(%dbg_src %float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
  2000. "Name"),
  2001. std::make_pair(
  2002. R"(%VS_OUTPUT_pos_name %dbg_src %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
  2003. ""),
  2004. std::make_pair(
  2005. R"(%VS_OUTPUT_pos_name %float_info %float_info 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
  2006. "Source"),
  2007. std::make_pair(
  2008. R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %float_info %u32_0 %int_32 FlagIsPublic)",
  2009. "Parent"),
  2010. std::make_pair(
  2011. R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %VS_OUTPUT_info %void %int_32 FlagIsPublic)",
  2012. "Offset"),
  2013. std::make_pair(
  2014. R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %void FlagIsPublic)",
  2015. "Size"),
  2016. }));
  2017. TEST_P(ValidateOpenCL100DebugInfoDebugTypeInheritance, Fail) {
  2018. const std::string src = R"(
  2019. %src = OpString "simple.hlsl"
  2020. %code = OpString "struct VS_OUTPUT {};
  2021. struct foo : VS_OUTPUT {};
  2022. "
  2023. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  2024. %foo_name = OpString "foo"
  2025. )";
  2026. const auto& param = GetParam();
  2027. std::ostringstream ss;
  2028. ss << R"(
  2029. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2030. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2031. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_name %u32_0 FlagIsPublic %child
  2032. %foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  2033. %bar_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Union %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  2034. %child = OpExtInst %void %DbgExt DebugTypeInheritance )"
  2035. << param.first;
  2036. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2037. src, "", ss.str(), "", opencl_extension, "Vertex"));
  2038. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2039. EXPECT_THAT(getDiagnosticString(),
  2040. HasSubstr("expected operand " + param.second));
  2041. }
  2042. INSTANTIATE_TEST_SUITE_P(
  2043. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeInheritance,
  2044. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2045. std::make_pair(R"(%dbg_src %VS_OUTPUT_info %u32_0 %u32_0 FlagIsPublic)",
  2046. "Child must be a result id of"),
  2047. std::make_pair(R"(%foo_info %dbg_src %u32_0 %u32_0 FlagIsPublic)",
  2048. "Parent must be a result id of"),
  2049. std::make_pair(
  2050. R"(%bar_info %VS_OUTPUT_info %u32_0 %u32_0 FlagIsPublic)",
  2051. "Child must be class or struct debug type"),
  2052. std::make_pair(R"(%foo_info %bar_info %u32_0 %u32_0 FlagIsPublic)",
  2053. "Parent must be class or struct debug type"),
  2054. std::make_pair(R"(%foo_info %VS_OUTPUT_info %void %u32_0 FlagIsPublic)",
  2055. "Offset"),
  2056. std::make_pair(R"(%foo_info %VS_OUTPUT_info %u32_0 %void FlagIsPublic)",
  2057. "Size"),
  2058. }));
  2059. TEST_F(ValidateVulkan100DebugInfo, DebugTypeComposite) {
  2060. const std::string src = R"(
  2061. %src = OpString "simple.hlsl"
  2062. %code = OpString "struct VS_OUTPUT {
  2063. float4 pos : SV_POSITION;
  2064. };
  2065. struct foo : VS_OUTPUT {
  2066. };
  2067. main() {}
  2068. "
  2069. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  2070. %float_name = OpString "float"
  2071. %foo_name = OpString "foo"
  2072. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  2073. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  2074. )";
  2075. const std::string constants = R"(
  2076. %u32_128 = OpConstant %u32 128
  2077. )";
  2078. const std::string dbg_inst_header = R"(
  2079. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2080. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2081. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2082. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  2083. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_128 %u32_3
  2084. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info
  2085. %foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %foo_name %u32_0 %u32_3
  2086. )";
  2087. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2088. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  2089. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2090. }
  2091. TEST_P(ValidateVulkan100DebugInfoDebugTypeComposite, Fail) {
  2092. const std::string src = R"(
  2093. %src = OpString "simple.hlsl"
  2094. %code = OpString "struct VS_OUTPUT {
  2095. float4 pos : SV_POSITION;
  2096. };
  2097. struct foo : VS_OUTPUT {
  2098. };
  2099. main() {}
  2100. "
  2101. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  2102. %float_name = OpString "float"
  2103. %foo_name = OpString "foo"
  2104. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  2105. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  2106. )";
  2107. const std::string constants = R"(
  2108. %u32_128 = OpConstant %u32 128
  2109. )";
  2110. const auto& param = GetParam();
  2111. std::ostringstream ss;
  2112. ss << R"(
  2113. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2114. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2115. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2116. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  2117. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_128 %u32_3
  2118. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite )";
  2119. ss << param.first;
  2120. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2121. src, constants, ss.str(), "", shader_extension, "Vertex"));
  2122. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2123. EXPECT_THAT(getDiagnosticString(),
  2124. HasSubstr("expected operand " + param.second + " must be "));
  2125. }
  2126. INSTANTIATE_TEST_SUITE_P(
  2127. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypeComposite,
  2128. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2129. std::make_pair(
  2130. R"(%dbg_src %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
  2131. "Name"),
  2132. std::make_pair(
  2133. R"(%VS_OUTPUT_name %u32_1 %comp_unit %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
  2134. "Source"),
  2135. std::make_pair(
  2136. R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %dbg_src %VS_OUTPUT_linkage_name %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
  2137. "Parent"),
  2138. std::make_pair(
  2139. R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %u32_128 %u32_128 %u32_3 %VS_OUTPUT_pos_info)",
  2140. "Linkage Name"),
  2141. std::make_pair(
  2142. R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %dbg_src %u32_3 %VS_OUTPUT_pos_info)",
  2143. "Size"),
  2144. std::make_pair(
  2145. R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %dbg_src %VS_OUTPUT_pos_info)",
  2146. "Flags"),
  2147. std::make_pair(
  2148. R"(%VS_OUTPUT_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %VS_OUTPUT_linkage_name %u32_128 %u32_3 %dbg_src)",
  2149. "Members"),
  2150. }));
  2151. TEST_P(ValidateVulkan100DebugInfoDebugTypeMember, Fail) {
  2152. const std::string src = R"(
  2153. %src = OpString "simple.hlsl"
  2154. %code = OpString "struct VS_OUTPUT {
  2155. float pos : SV_POSITION;
  2156. };
  2157. main() {}
  2158. "
  2159. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  2160. %float_name = OpString "float"
  2161. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  2162. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  2163. )";
  2164. const std::string constants = R"(
  2165. %u32_128 = OpConstant %u32 128
  2166. )";
  2167. const auto& param = GetParam();
  2168. std::ostringstream ss;
  2169. ss << R"(
  2170. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2171. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2172. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2173. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember )";
  2174. ss << param.first;
  2175. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2176. src, constants, ss.str(), "", shader_extension, "Vertex"));
  2177. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2178. if (!param.second.empty()) {
  2179. EXPECT_THAT(getDiagnosticString(),
  2180. HasSubstr("expected operand " + param.second +
  2181. " must be a result id of "));
  2182. }
  2183. }
  2184. INSTANTIATE_TEST_SUITE_P(
  2185. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugTypeMember,
  2186. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2187. std::make_pair(
  2188. R"(%dbg_src %float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_32 %u32_3)",
  2189. "Name"),
  2190. std::make_pair(
  2191. R"(%VS_OUTPUT_pos_name %dbg_src %dbg_src %u32_2 %u32_3 %u32_0 %u32_32 %u32_3)",
  2192. ""),
  2193. std::make_pair(
  2194. R"(%VS_OUTPUT_pos_name %float_info %float_info %u32_2 %u32_3 %u32_0 %u32_32 %u32_3)",
  2195. "Source"),
  2196. std::make_pair(
  2197. R"(%VS_OUTPUT_pos_name %float_info %dbg_src %u32_2 %u32_3 %void %u32_32 %u32_3)",
  2198. "Offset"),
  2199. std::make_pair(
  2200. R"(%VS_OUTPUT_pos_name %float_info %dbg_src %u32_2 %u32_3 %u32_0 %void %u32_3)",
  2201. "Size"),
  2202. std::make_pair(
  2203. R"(%VS_OUTPUT_pos_name %float_info %dbg_src %u32_2 %u32_3 %u32_0 %u32_32 %void)",
  2204. "Flags"),
  2205. }));
  2206. TEST_F(ValidateOpenCL100DebugInfo, DebugFunctionDeclaration) {
  2207. const std::string src = R"(
  2208. %src = OpString "simple.hlsl"
  2209. %code = OpString "struct VS_OUTPUT {
  2210. float4 pos : SV_POSITION;
  2211. };
  2212. main() {}
  2213. "
  2214. )";
  2215. const std::string dbg_inst_header = R"(
  2216. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2217. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2218. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  2219. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic
  2220. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %main)";
  2221. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2222. src, "", dbg_inst_header, "", opencl_extension, "Vertex"));
  2223. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2224. }
  2225. TEST_P(ValidateOpenCL100DebugInfoDebugFunction, Fail) {
  2226. const std::string src = R"(
  2227. %src = OpString "simple.hlsl"
  2228. %code = OpString "struct VS_OUTPUT {
  2229. float4 pos : SV_POSITION;
  2230. };
  2231. main() {}
  2232. "
  2233. )";
  2234. const auto& param = GetParam();
  2235. std::ostringstream ss;
  2236. ss << R"(
  2237. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2238. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2239. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  2240. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic
  2241. %main_info = OpExtInst %void %DbgExt DebugFunction )"
  2242. << param.first;
  2243. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2244. src, "", ss.str(), "", opencl_extension, "Vertex"));
  2245. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2246. EXPECT_THAT(getDiagnosticString(),
  2247. HasSubstr("expected operand " + param.second));
  2248. }
  2249. INSTANTIATE_TEST_SUITE_P(
  2250. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugFunction,
  2251. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2252. std::make_pair(
  2253. R"(%u32_0 %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %main)",
  2254. "Name"),
  2255. std::make_pair(
  2256. R"(%main_name %dbg_src %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %main)",
  2257. "Type"),
  2258. std::make_pair(
  2259. R"(%main_name %main_type_info %comp_unit 12 1 %comp_unit %main_name FlagIsPublic 13 %main)",
  2260. "Source"),
  2261. std::make_pair(
  2262. R"(%main_name %main_type_info %dbg_src 12 1 %dbg_src %main_name FlagIsPublic 13 %main)",
  2263. "Parent"),
  2264. std::make_pair(
  2265. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %void FlagIsPublic 13 %main)",
  2266. "Linkage Name"),
  2267. std::make_pair(
  2268. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %void)",
  2269. "Function"),
  2270. std::make_pair(
  2271. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic 13 %main %dbg_src)",
  2272. "Declaration"),
  2273. }));
  2274. TEST_P(ValidateOpenCL100DebugInfoDebugFunctionDeclaration, Fail) {
  2275. const std::string src = R"(
  2276. %src = OpString "simple.hlsl"
  2277. %code = OpString "struct VS_OUTPUT {
  2278. float4 pos : SV_POSITION;
  2279. };
  2280. main() {}
  2281. "
  2282. )";
  2283. const auto& param = GetParam();
  2284. std::ostringstream ss;
  2285. ss << R"(
  2286. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2287. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2288. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  2289. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration )"
  2290. << param.first;
  2291. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2292. src, "", ss.str(), "", opencl_extension, "Vertex"));
  2293. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2294. EXPECT_THAT(getDiagnosticString(),
  2295. HasSubstr("expected operand " + param.second));
  2296. }
  2297. INSTANTIATE_TEST_SUITE_P(
  2298. AllOpenCL100DebugInfoFail,
  2299. ValidateOpenCL100DebugInfoDebugFunctionDeclaration,
  2300. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2301. std::make_pair(
  2302. R"(%u32_0 %main_type_info %dbg_src 12 1 %comp_unit %main_name FlagIsPublic)",
  2303. "Name"),
  2304. std::make_pair(
  2305. R"(%main_name %dbg_src %dbg_src 12 1 %comp_unit %main_name FlagIsPublic)",
  2306. "Type"),
  2307. std::make_pair(
  2308. R"(%main_name %main_type_info %comp_unit 12 1 %comp_unit %main_name FlagIsPublic)",
  2309. "Source"),
  2310. std::make_pair(
  2311. R"(%main_name %main_type_info %dbg_src 12 1 %dbg_src %main_name FlagIsPublic)",
  2312. "Parent"),
  2313. std::make_pair(
  2314. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %void FlagIsPublic)",
  2315. "Linkage Name"),
  2316. }));
  2317. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionDeclaration) {
  2318. const std::string src = R"(
  2319. %src = OpString "simple.hlsl"
  2320. %code = OpString "struct VS_OUTPUT {
  2321. float4 pos : SV_POSITION;
  2322. };
  2323. main() {}
  2324. "
  2325. )";
  2326. const std::string constants = R"(
  2327. %u32_12 = OpConstant %u32 12
  2328. %u32_13 = OpConstant %u32 13
  2329. )";
  2330. const std::string dbg_inst_header = R"(
  2331. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2332. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2333. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  2334. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3
  2335. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3 %u32_13
  2336. )";
  2337. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2338. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  2339. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2340. }
  2341. TEST_P(ValidateVulkan100DebugInfoDebugFunction, Fail) {
  2342. const std::string src = R"(
  2343. %src = OpString "simple.hlsl"
  2344. %code = OpString "struct VS_OUTPUT {
  2345. float4 pos : SV_POSITION;
  2346. };
  2347. main() {}
  2348. "
  2349. )";
  2350. const std::string constants = R"(
  2351. %u32_12 = OpConstant %u32 12
  2352. %u32_13 = OpConstant %u32 13
  2353. )";
  2354. const auto& param = GetParam();
  2355. std::ostringstream ss;
  2356. ss << R"(
  2357. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2358. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2359. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  2360. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3
  2361. %main_info = OpExtInst %void %DbgExt DebugFunction )"
  2362. << param.first;
  2363. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2364. src, constants, ss.str(), "", shader_extension, "Vertex"));
  2365. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2366. EXPECT_THAT(getDiagnosticString(),
  2367. HasSubstr("expected operand " + param.second));
  2368. }
  2369. INSTANTIATE_TEST_SUITE_P(
  2370. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugFunction,
  2371. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2372. std::make_pair(
  2373. R"(%u32_0 %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3 %u32_13)",
  2374. "Name"),
  2375. std::make_pair(
  2376. R"(%main_name %dbg_src %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3 %u32_13)",
  2377. "Type"),
  2378. std::make_pair(
  2379. R"(%main_name %main_type_info %comp_unit %u32_12 %u32_1 %comp_unit %main_name %u32_3 %u32_13)",
  2380. "Source"),
  2381. std::make_pair(
  2382. R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %dbg_src %main_name %u32_3 %u32_13)",
  2383. "Parent"),
  2384. std::make_pair(
  2385. R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %void %u32_3 %u32_13)",
  2386. "Linkage Name"),
  2387. std::make_pair(
  2388. R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3 %u32_13 %dbg_src)",
  2389. "Declaration"),
  2390. }));
  2391. TEST_P(ValidateVulkan100DebugInfoDebugFunctionDeclaration, Fail) {
  2392. const std::string src = R"(
  2393. %src = OpString "simple.hlsl"
  2394. %code = OpString "struct VS_OUTPUT {
  2395. float4 pos : SV_POSITION;
  2396. };
  2397. main() {}
  2398. "
  2399. )";
  2400. const std::string constants = R"(
  2401. %u32_12 = OpConstant %u32 12
  2402. %u32_13 = OpConstant %u32 13
  2403. )";
  2404. const auto& param = GetParam();
  2405. std::ostringstream ss;
  2406. ss << R"(
  2407. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2408. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2409. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  2410. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration )"
  2411. << param.first;
  2412. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2413. src, constants, ss.str(), "", shader_extension, "Vertex"));
  2414. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2415. EXPECT_THAT(getDiagnosticString(),
  2416. HasSubstr("expected operand " + param.second));
  2417. }
  2418. INSTANTIATE_TEST_SUITE_P(
  2419. AllVulkan100DebugInfoFail,
  2420. ValidateVulkan100DebugInfoDebugFunctionDeclaration,
  2421. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2422. std::make_pair(
  2423. R"(%u32_0 %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3)",
  2424. "Name"),
  2425. std::make_pair(
  2426. R"(%main_name %dbg_src %dbg_src %u32_12 %u32_1 %comp_unit %main_name %u32_3)",
  2427. "Type"),
  2428. std::make_pair(
  2429. R"(%main_name %main_type_info %comp_unit %u32_12 %u32_1 %comp_unit %main_name %u32_3)",
  2430. "Source"),
  2431. std::make_pair(
  2432. R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %dbg_src %main_name %u32_3)",
  2433. "Parent"),
  2434. std::make_pair(
  2435. R"(%main_name %main_type_info %dbg_src %u32_12 %u32_1 %comp_unit %void %u32_3)",
  2436. "Linkage Name"),
  2437. }));
  2438. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionType) {
  2439. const std::string src = R"(
  2440. %src = OpString "simple.hlsl"
  2441. %code = OpString "main() {}"
  2442. %float_name = OpString "float"
  2443. %uint_name = OpString "uint"
  2444. )";
  2445. const std::string constants = R"(
  2446. %u32_6 = OpConstant %u32 6
  2447. )";
  2448. const std::string dbg_inst_header = R"(
  2449. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2450. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2451. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2452. %uint_info = OpExtInst %void %DbgExt DebugTypeBasic %uint_name %u32_32 %u32_6 %u32_0
  2453. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %uint_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  2454. )";
  2455. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2456. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  2457. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2458. EXPECT_THAT(getDiagnosticString(),
  2459. HasSubstr("DebugFunction: expected operand Type must be a result "
  2460. "id of DebugTypeFunction"));
  2461. }
  2462. TEST_F(ValidateOpenCL100DebugInfo, DebugLexicalBlock) {
  2463. const std::string src = R"(
  2464. %src = OpString "simple.hlsl"
  2465. %code = OpString "main() {}"
  2466. )";
  2467. const std::string dbg_inst_header = R"(
  2468. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2469. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2470. %main_block = OpExtInst %void %DbgExt DebugLexicalBlock %dbg_src 1 1 %comp_unit %main_name)";
  2471. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2472. src, "", dbg_inst_header, "", opencl_extension, "Vertex"));
  2473. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2474. }
  2475. TEST_P(ValidateOpenCL100DebugInfoDebugLexicalBlock, Fail) {
  2476. const std::string src = R"(
  2477. %src = OpString "simple.hlsl"
  2478. %code = OpString "main() {}"
  2479. )";
  2480. const auto& param = GetParam();
  2481. std::ostringstream ss;
  2482. ss << R"(
  2483. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2484. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2485. %main_block = OpExtInst %void %DbgExt DebugLexicalBlock )"
  2486. << param.first;
  2487. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2488. src, "", ss.str(), "", opencl_extension, "Vertex"));
  2489. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2490. EXPECT_THAT(getDiagnosticString(),
  2491. HasSubstr("expected operand " + param.second));
  2492. }
  2493. INSTANTIATE_TEST_SUITE_P(
  2494. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugLexicalBlock,
  2495. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2496. std::make_pair(R"(%comp_unit 1 1 %comp_unit %main_name)", "Source"),
  2497. std::make_pair(R"(%dbg_src 1 1 %dbg_src %main_name)", "Parent"),
  2498. std::make_pair(R"(%dbg_src 1 1 %comp_unit %void)", "Name"),
  2499. }));
  2500. TEST_F(ValidateOpenCL100DebugInfo, DebugScopeFailScope) {
  2501. const std::string src = R"(
  2502. %src = OpString "simple.hlsl"
  2503. %code = OpString "void main() {}"
  2504. )";
  2505. const std::string dbg_inst_header = R"(
  2506. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2507. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2508. )";
  2509. const std::string body = R"(
  2510. %main_scope = OpExtInst %void %DbgExt DebugScope %dbg_src
  2511. )";
  2512. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2513. src, "", dbg_inst_header, body, opencl_extension, "Vertex"));
  2514. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2515. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
  2516. }
  2517. TEST_F(ValidateOpenCL100DebugInfo, DebugScopeFailInlinedAt) {
  2518. const std::string src = R"(
  2519. %src = OpString "simple.hlsl"
  2520. %code = OpString "void main() {}"
  2521. )";
  2522. const std::string dbg_inst_header = R"(
  2523. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2524. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2525. )";
  2526. const std::string body = R"(
  2527. %main_scope = OpExtInst %void %DbgExt DebugScope %comp_unit %dbg_src
  2528. )";
  2529. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2530. src, "", dbg_inst_header, body, opencl_extension, "Vertex"));
  2531. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2532. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined At"));
  2533. }
  2534. TEST_F(ValidateVulkan100DebugInfo, DebugLexicalBlock) {
  2535. const std::string src = R"(
  2536. %src = OpString "simple.hlsl"
  2537. %code = OpString "main() {}"
  2538. )";
  2539. const std::string dbg_inst_header = R"(
  2540. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2541. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2542. %main_block = OpExtInst %void %DbgExt DebugLexicalBlock %dbg_src %u32_1 %u32_1 %comp_unit %main_name
  2543. )";
  2544. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2545. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  2546. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2547. }
  2548. TEST_P(ValidateVulkan100DebugInfoDebugLexicalBlock, Fail) {
  2549. const std::string src = R"(
  2550. %src = OpString "simple.hlsl"
  2551. %code = OpString "main() {}"
  2552. )";
  2553. const auto& param = GetParam();
  2554. std::ostringstream ss;
  2555. ss << R"(
  2556. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2557. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2558. %main_block = OpExtInst %void %DbgExt DebugLexicalBlock )"
  2559. << param.first;
  2560. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2561. src, "", ss.str(), "", shader_extension, "Vertex"));
  2562. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2563. EXPECT_THAT(getDiagnosticString(),
  2564. HasSubstr("expected operand " + param.second));
  2565. }
  2566. INSTANTIATE_TEST_SUITE_P(
  2567. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugLexicalBlock,
  2568. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2569. std::make_pair(R"(%comp_unit %u32_1 %u32_1 %comp_unit %main_name)",
  2570. "Source"),
  2571. std::make_pair(R"(%dbg_src %u32_1 %u32_1 %dbg_src %main_name)",
  2572. "Parent"),
  2573. std::make_pair(R"(%dbg_src %u32_1 %u32_1 %comp_unit %void)", "Name"),
  2574. }));
  2575. TEST_F(ValidateVulkan100DebugInfo, DebugScopeFailScope) {
  2576. const std::string src = R"(
  2577. %src = OpString "simple.hlsl"
  2578. %code = OpString "void main() {}"
  2579. )";
  2580. const std::string dbg_inst_header = R"(
  2581. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2582. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2583. )";
  2584. const std::string body = R"(
  2585. %main_scope = OpExtInst %void %DbgExt DebugScope %dbg_src
  2586. )";
  2587. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2588. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  2589. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2590. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
  2591. }
  2592. TEST_F(ValidateVulkan100DebugInfo, DebugScopeFailInlinedAt) {
  2593. const std::string src = R"(
  2594. %src = OpString "simple.hlsl"
  2595. %code = OpString "void main() {}"
  2596. )";
  2597. const std::string dbg_inst_header = R"(
  2598. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2599. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2600. )";
  2601. const std::string body = R"(
  2602. %main_scope = OpExtInst %void %DbgExt DebugScope %comp_unit %dbg_src
  2603. )";
  2604. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2605. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  2606. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2607. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined At"));
  2608. }
  2609. TEST_F(ValidateOpenCL100DebugInfo, DebugLocalVariable) {
  2610. const std::string src = R"(
  2611. %src = OpString "simple.hlsl"
  2612. %code = OpString "void main() { float foo; }"
  2613. %float_name = OpString "float"
  2614. %foo_name = OpString "foo"
  2615. )";
  2616. const std::string size_const = R"(
  2617. %int_32 = OpConstant %u32 32
  2618. )";
  2619. const std::string dbg_inst_header = R"(
  2620. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2621. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2622. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2623. %foo = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2624. )";
  2625. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2626. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  2627. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2628. }
  2629. TEST_P(ValidateOpenCL100DebugInfoDebugLocalVariable, Fail) {
  2630. const std::string src = R"(
  2631. %src = OpString "simple.hlsl"
  2632. %code = OpString "void main() { float foo; }"
  2633. %float_name = OpString "float"
  2634. %foo_name = OpString "foo"
  2635. )";
  2636. const std::string size_const = R"(
  2637. %int_32 = OpConstant %u32 32
  2638. )";
  2639. const auto& param = GetParam();
  2640. std::ostringstream ss;
  2641. ss << R"(
  2642. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2643. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2644. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2645. %foo = OpExtInst %void %DbgExt DebugLocalVariable )"
  2646. << param.first;
  2647. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2648. src, size_const, ss.str(), "", opencl_extension, "Vertex"));
  2649. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2650. EXPECT_THAT(getDiagnosticString(),
  2651. HasSubstr("expected operand " + param.second));
  2652. }
  2653. INSTANTIATE_TEST_SUITE_P(
  2654. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugLocalVariable,
  2655. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2656. std::make_pair(
  2657. R"(%void %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0)",
  2658. "Name"),
  2659. std::make_pair(
  2660. R"(%foo_name %dbg_src %dbg_src 1 10 %comp_unit FlagIsLocal 0)",
  2661. "Type"),
  2662. std::make_pair(
  2663. R"(%foo_name %float_info %comp_unit 1 10 %comp_unit FlagIsLocal 0)",
  2664. "Source"),
  2665. std::make_pair(
  2666. R"(%foo_name %float_info %dbg_src 1 10 %dbg_src FlagIsLocal 0)",
  2667. "Parent"),
  2668. }));
  2669. TEST_F(ValidateVulkan100DebugInfo, DebugLocalVariable) {
  2670. const std::string src = R"(
  2671. %src = OpString "simple.hlsl"
  2672. %code = OpString "void main() { float foo; }"
  2673. %float_name = OpString "float"
  2674. %foo_name = OpString "foo"
  2675. )";
  2676. const std::string constants = R"(
  2677. %u32_10 = OpConstant %u32 10
  2678. )";
  2679. const std::string dbg_inst_header = R"(
  2680. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2681. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2682. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2683. %foo = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
  2684. )";
  2685. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2686. src, constants, dbg_inst_header, "", shader_extension, "Vertex"));
  2687. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2688. }
  2689. TEST_P(ValidateVulkan100DebugInfoDebugLocalVariable, Fail) {
  2690. const std::string src = R"(
  2691. %src = OpString "simple.hlsl"
  2692. %code = OpString "void main() { float foo; }"
  2693. %float_name = OpString "float"
  2694. %foo_name = OpString "foo"
  2695. )";
  2696. const std::string constants = R"(
  2697. %u32_10 = OpConstant %u32 10
  2698. )";
  2699. const auto& param = GetParam();
  2700. std::ostringstream ss;
  2701. ss << R"(
  2702. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2703. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2704. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2705. %foo = OpExtInst %void %DbgExt DebugLocalVariable )"
  2706. << param.first;
  2707. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2708. src, constants, ss.str(), "", shader_extension, "Vertex"));
  2709. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2710. EXPECT_THAT(getDiagnosticString(),
  2711. HasSubstr("expected operand " + param.second));
  2712. }
  2713. INSTANTIATE_TEST_SUITE_P(
  2714. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugLocalVariable,
  2715. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2716. std::make_pair(
  2717. R"(%void %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_3 %u32_0)",
  2718. "Name"),
  2719. std::make_pair(
  2720. R"(%foo_name %dbg_src %dbg_src %u32_1 %u32_10 %comp_unit %u32_3 %u32_0)",
  2721. "Type"),
  2722. std::make_pair(
  2723. R"(%foo_name %float_info %comp_unit %u32_1 %u32_10 %comp_unit %u32_3 %u32_0)",
  2724. "Source"),
  2725. std::make_pair(
  2726. R"(%foo_name %float_info %dbg_src %u32_1 %u32_10 %dbg_src %u32_3 %u32_0)",
  2727. "Parent"),
  2728. }));
  2729. TEST_F(ValidateOpenCL100DebugInfo, DebugDeclare) {
  2730. const std::string src = R"(
  2731. %src = OpString "simple.hlsl"
  2732. %code = OpString "void main() { float foo; }"
  2733. %float_name = OpString "float"
  2734. %foo_name = OpString "foo"
  2735. )";
  2736. const std::string size_const = R"(
  2737. %int_32 = OpConstant %u32 32
  2738. )";
  2739. const std::string dbg_inst_header = R"(
  2740. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2741. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2742. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2743. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2744. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2745. )";
  2746. const std::string body = R"(
  2747. %foo = OpVariable %f32_ptr_function Function
  2748. %decl = OpExtInst %void %DbgExt DebugDeclare %foo_info %foo %null_expr
  2749. )";
  2750. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2751. src, size_const, dbg_inst_header, body, opencl_extension, "Vertex"));
  2752. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2753. }
  2754. TEST_F(ValidateOpenCL100DebugInfo, DebugDeclareParam) {
  2755. CompileSuccessfully(R"(
  2756. OpCapability Shader
  2757. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  2758. OpMemoryModel Logical GLSL450
  2759. OpEntryPoint Vertex %main "main" %in_var_COLOR
  2760. %4 = OpString "test.hlsl"
  2761. OpSource HLSL 620 %4 "#line 1 \"test.hlsl\"
  2762. void main(float foo:COLOR) {}
  2763. "
  2764. %11 = OpString "#line 1 \"test.hlsl\"
  2765. void main(float foo:COLOR) {}
  2766. "
  2767. %14 = OpString "float"
  2768. %17 = OpString "src.main"
  2769. %20 = OpString "foo"
  2770. OpName %in_var_COLOR "in.var.COLOR"
  2771. OpName %main "main"
  2772. OpName %param_var_foo "param.var.foo"
  2773. OpName %src_main "src.main"
  2774. OpName %foo "foo"
  2775. OpName %bb_entry "bb.entry"
  2776. OpDecorate %in_var_COLOR Location 0
  2777. %uint = OpTypeInt 32 0
  2778. %uint_32 = OpConstant %uint 32
  2779. %float = OpTypeFloat 32
  2780. %_ptr_Input_float = OpTypePointer Input %float
  2781. %void = OpTypeVoid
  2782. %23 = OpTypeFunction %void
  2783. %_ptr_Function_float = OpTypePointer Function %float
  2784. %29 = OpTypeFunction %void %_ptr_Function_float
  2785. OpLine %4 1 21
  2786. %in_var_COLOR = OpVariable %_ptr_Input_float Input
  2787. %10 = OpExtInst %void %1 DebugExpression
  2788. %12 = OpExtInst %void %1 DebugSource %4 %11
  2789. %13 = OpExtInst %void %1 DebugCompilationUnit 1 4 %12 HLSL
  2790. %15 = OpExtInst %void %1 DebugTypeBasic %14 %uint_32 Float
  2791. %16 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %void %15
  2792. %18 = OpExtInst %void %1 DebugFunction %17 %16 %12 1 1 %13 %17 FlagIsProtected|FlagIsPrivate 1 %src_main
  2793. %21 = OpExtInst %void %1 DebugLocalVariable %20 %15 %12 1 17 %18 FlagIsLocal 0
  2794. %22 = OpExtInst %void %1 DebugLexicalBlock %12 1 28 %18
  2795. OpLine %4 1 1
  2796. %main = OpFunction %void None %23
  2797. %24 = OpLabel
  2798. OpLine %4 1 17
  2799. %param_var_foo = OpVariable %_ptr_Function_float Function
  2800. %27 = OpLoad %float %in_var_COLOR
  2801. OpLine %4 1 1
  2802. %28 = OpFunctionCall %void %src_main %param_var_foo
  2803. OpReturn
  2804. OpFunctionEnd
  2805. %src_main = OpFunction %void None %29
  2806. OpLine %4 1 17
  2807. %foo = OpFunctionParameter %_ptr_Function_float
  2808. %31 = OpExtInst %void %1 DebugDeclare %21 %foo %10
  2809. %bb_entry = OpLabel
  2810. OpLine %4 1 29
  2811. OpReturn
  2812. OpFunctionEnd
  2813. )");
  2814. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2815. }
  2816. TEST_P(ValidateOpenCL100DebugInfoDebugDeclare, Fail) {
  2817. const std::string src = R"(
  2818. %src = OpString "simple.hlsl"
  2819. %code = OpString "void main() { float foo; }"
  2820. %float_name = OpString "float"
  2821. %foo_name = OpString "foo"
  2822. )";
  2823. const std::string size_const = R"(
  2824. %int_32 = OpConstant %u32 32
  2825. )";
  2826. const std::string dbg_inst_header = R"(
  2827. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2828. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2829. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2830. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2831. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2832. )";
  2833. const auto& param = GetParam();
  2834. std::ostringstream ss;
  2835. ss << R"(
  2836. %foo = OpVariable %f32_ptr_function Function
  2837. %decl = OpExtInst %void %DbgExt DebugDeclare )"
  2838. << param.first;
  2839. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2840. src, size_const, dbg_inst_header, ss.str(), opencl_extension, "Vertex"));
  2841. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2842. EXPECT_THAT(getDiagnosticString(),
  2843. HasSubstr("expected operand " + param.second));
  2844. }
  2845. INSTANTIATE_TEST_SUITE_P(
  2846. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugDeclare,
  2847. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2848. std::make_pair(R"(%dbg_src %foo %null_expr)", "Local Variable"),
  2849. std::make_pair(R"(%foo_info %void %null_expr)", "Variable"),
  2850. std::make_pair(R"(%foo_info %foo %dbg_src)", "Expression"),
  2851. }));
  2852. TEST_F(ValidateVulkan100DebugInfo, DebugDeclare) {
  2853. const std::string src = R"(
  2854. %src = OpString "simple.hlsl"
  2855. %code = OpString "void main() { float foo; }"
  2856. %float_name = OpString "float"
  2857. %foo_name = OpString "foo"
  2858. )";
  2859. const std::string constants = R"(
  2860. %u32_10 = OpConstant %u32 10
  2861. )";
  2862. const std::string dbg_inst_header = R"(
  2863. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2864. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2865. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2866. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2867. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
  2868. )";
  2869. const std::string body = R"(
  2870. %foo = OpVariable %f32_ptr_function Function
  2871. %decl = OpExtInst %void %DbgExt DebugDeclare %foo_info %foo %null_expr
  2872. )";
  2873. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2874. src, constants, dbg_inst_header, body, shader_extension, "Vertex"));
  2875. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2876. }
  2877. TEST_F(ValidateVulkan100DebugInfo, DebugDeclareParam) {
  2878. CompileSuccessfully(R"(
  2879. OpCapability Shader
  2880. OpExtension "SPV_KHR_non_semantic_info"
  2881. %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
  2882. OpMemoryModel Logical GLSL450
  2883. OpEntryPoint Vertex %main "main" %in_var_COLOR
  2884. %4 = OpString "test.hlsl"
  2885. OpSource HLSL 620 %4 "#line 1 \"test.hlsl\"
  2886. void main(float foo:COLOR) {}
  2887. "
  2888. %11 = OpString "#line 1 \"test.hlsl\"
  2889. void main(float foo:COLOR) {}
  2890. "
  2891. %14 = OpString "float"
  2892. %17 = OpString "src.main"
  2893. %20 = OpString "foo"
  2894. OpName %in_var_COLOR "in.var.COLOR"
  2895. OpName %main "main"
  2896. OpName %param_var_foo "param.var.foo"
  2897. OpName %src_main "src.main"
  2898. OpName %foo "foo"
  2899. OpName %bb_entry "bb.entry"
  2900. OpDecorate %in_var_COLOR Location 0
  2901. %uint = OpTypeInt 32 0
  2902. %u32_0 = OpConstant %uint 0
  2903. %u32_1 = OpConstant %uint 1
  2904. %u32_2 = OpConstant %uint 2
  2905. %u32_3 = OpConstant %uint 3
  2906. %u32_4 = OpConstant %uint 4
  2907. %u32_5 = OpConstant %uint 5
  2908. %u32_10 = OpConstant %uint 10
  2909. %u32_17 = OpConstant %uint 17
  2910. %u32_28 = OpConstant %uint 28
  2911. %u32_32 = OpConstant %uint 32
  2912. %uint_32 = OpConstant %uint 32
  2913. %float = OpTypeFloat 32
  2914. %_ptr_Input_float = OpTypePointer Input %float
  2915. %void = OpTypeVoid
  2916. %23 = OpTypeFunction %void
  2917. %_ptr_Function_float = OpTypePointer Function %float
  2918. %29 = OpTypeFunction %void %_ptr_Function_float
  2919. OpLine %4 1 21
  2920. %in_var_COLOR = OpVariable %_ptr_Input_float Input
  2921. %10 = OpExtInst %void %1 DebugExpression
  2922. %12 = OpExtInst %void %1 DebugSource %4 %11
  2923. %13 = OpExtInst %void %1 DebugCompilationUnit %u32_1 %u32_4 %12 %u32_5
  2924. %15 = OpExtInst %void %1 DebugTypeBasic %14 %uint_32 %u32_3 %u32_0
  2925. %16 = OpExtInst %void %1 DebugTypeFunction %u32_3 %void %15
  2926. %18 = OpExtInst %void %1 DebugFunction %17 %16 %12 %u32_1 %u32_1 %13 %17 %u32_3 %u32_1
  2927. %21 = OpExtInst %void %1 DebugLocalVariable %20 %15 %12 %u32_1 %u32_17 %18 %u32_4 %u32_0
  2928. %22 = OpExtInst %void %1 DebugLexicalBlock %12 %u32_1 %u32_28 %18
  2929. %main = OpFunction %void None %23
  2930. %24 = OpLabel
  2931. %param_var_foo = OpVariable %_ptr_Function_float Function
  2932. %27 = OpLoad %float %in_var_COLOR
  2933. %28 = OpFunctionCall %void %src_main %param_var_foo
  2934. OpReturn
  2935. OpFunctionEnd
  2936. %src_main = OpFunction %void None %29
  2937. %foo = OpFunctionParameter %_ptr_Function_float
  2938. %31 = OpExtInst %void %1 DebugDeclare %21 %foo %10
  2939. %bb_entry = OpLabel
  2940. OpReturn
  2941. OpFunctionEnd
  2942. )");
  2943. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2944. }
  2945. TEST_P(ValidateVulkan100DebugInfoDebugDeclare, Fail) {
  2946. const std::string src = R"(
  2947. %src = OpString "simple.hlsl"
  2948. %code = OpString "void main() { float foo; }"
  2949. %float_name = OpString "float"
  2950. %foo_name = OpString "foo"
  2951. )";
  2952. const std::string constants = R"(
  2953. %u32_10 = OpConstant %u32 10
  2954. )";
  2955. const std::string dbg_inst_header = R"(
  2956. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2957. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  2958. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2959. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  2960. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
  2961. )";
  2962. const auto& param = GetParam();
  2963. std::ostringstream ss;
  2964. ss << R"(
  2965. %foo = OpVariable %f32_ptr_function Function
  2966. %decl = OpExtInst %void %DbgExt DebugDeclare )"
  2967. << param.first;
  2968. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2969. src, constants, dbg_inst_header, ss.str(), shader_extension, "Vertex"));
  2970. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2971. EXPECT_THAT(getDiagnosticString(),
  2972. HasSubstr("expected operand " + param.second));
  2973. }
  2974. INSTANTIATE_TEST_SUITE_P(
  2975. AllVulkan100DebugInfoFail, ValidateVulkan100DebugInfoDebugDeclare,
  2976. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2977. std::make_pair(R"(%dbg_src %foo %null_expr)", "Local Variable"),
  2978. std::make_pair(R"(%foo_info %void %null_expr)", "Variable"),
  2979. std::make_pair(R"(%foo_info %foo %dbg_src)", "Expression"),
  2980. }));
  2981. TEST_F(ValidateOpenCL100DebugInfo, DebugExpression) {
  2982. const std::string dbg_inst_header = R"(
  2983. %op0 = OpExtInst %void %DbgExt DebugOperation Deref
  2984. %op1 = OpExtInst %void %DbgExt DebugOperation Plus
  2985. %null_expr = OpExtInst %void %DbgExt DebugExpression %op0 %op1
  2986. )";
  2987. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2988. "", "", dbg_inst_header, "", opencl_extension, "Vertex"));
  2989. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2990. }
  2991. TEST_F(ValidateOpenCL100DebugInfo, DebugExpressionFail) {
  2992. const std::string dbg_inst_header = R"(
  2993. %op = OpExtInst %void %DbgExt DebugOperation Deref
  2994. %null_expr = OpExtInst %void %DbgExt DebugExpression %op %void
  2995. )";
  2996. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2997. "", "", dbg_inst_header, "", opencl_extension, "Vertex"));
  2998. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2999. EXPECT_THAT(
  3000. getDiagnosticString(),
  3001. HasSubstr(
  3002. "expected operand Operation must be a result id of DebugOperation"));
  3003. }
  3004. TEST_F(ValidateVulkan100DebugInfo, DebugExpression) {
  3005. const std::string dbg_inst_header = R"(
  3006. %op0 = OpExtInst %void %DbgExt DebugOperation %u32_0
  3007. %op1 = OpExtInst %void %DbgExt DebugOperation %u32_1
  3008. %null_expr = OpExtInst %void %DbgExt DebugExpression %op0 %op1
  3009. )";
  3010. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3011. "", "", dbg_inst_header, "", shader_extension, "Vertex"));
  3012. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3013. }
  3014. TEST_F(ValidateVulkan100DebugInfo, DebugExpressionFail) {
  3015. const std::string dbg_inst_header = R"(
  3016. %op = OpExtInst %void %DbgExt DebugOperation %u32_0
  3017. %null_expr = OpExtInst %void %DbgExt DebugExpression %op %void
  3018. )";
  3019. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3020. "", "", dbg_inst_header, "", shader_extension, "Vertex"));
  3021. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3022. EXPECT_THAT(
  3023. getDiagnosticString(),
  3024. HasSubstr(
  3025. "expected operand Operation must be a result id of DebugOperation"));
  3026. }
  3027. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplate) {
  3028. const std::string src = R"(
  3029. %src = OpString "simple.hlsl"
  3030. %code = OpString "OpaqueType foo;
  3031. main() {}
  3032. "
  3033. %float_name = OpString "float"
  3034. %ty_name = OpString "Texture"
  3035. %t_name = OpString "T"
  3036. )";
  3037. const std::string size_const = R"(
  3038. %int_32 = OpConstant %u32 32
  3039. %int_128 = OpConstant %u32 128
  3040. )";
  3041. const std::string dbg_inst_header = R"(
  3042. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3043. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3044. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3045. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3046. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
  3047. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  3048. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
  3049. )";
  3050. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3051. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3052. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3053. }
  3054. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateUsedForVariableType) {
  3055. const std::string src = R"(
  3056. %src = OpString "simple.hlsl"
  3057. %code = OpString "OpaqueType foo;
  3058. main() {}
  3059. "
  3060. %float_name = OpString "float"
  3061. %ty_name = OpString "Texture"
  3062. %t_name = OpString "T"
  3063. %foo_name = OpString "foo"
  3064. )";
  3065. const std::string size_const = R"(
  3066. %int_32 = OpConstant %u32 32
  3067. %int_128 = OpConstant %u32 128
  3068. )";
  3069. const std::string dbg_inst_header = R"(
  3070. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3071. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3072. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3073. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3074. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
  3075. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  3076. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
  3077. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %temp %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate
  3078. )";
  3079. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3080. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3081. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3082. }
  3083. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFunction) {
  3084. const std::string src = R"(
  3085. %src = OpString "simple.hlsl"
  3086. %code = OpString "OpaqueType foo;
  3087. main() {}
  3088. "
  3089. %float_name = OpString "float"
  3090. %ty_name = OpString "Texture"
  3091. %t_name = OpString "T"
  3092. )";
  3093. const std::string size_const = R"(
  3094. %int_32 = OpConstant %u32 32
  3095. %int_128 = OpConstant %u32 128
  3096. )";
  3097. const std::string dbg_inst_header = R"(
  3098. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3099. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3100. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3101. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3102. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  3103. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %param %param
  3104. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  3105. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %param
  3106. )";
  3107. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3108. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3109. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3110. }
  3111. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFailTarget) {
  3112. const std::string src = R"(
  3113. %src = OpString "simple.hlsl"
  3114. %code = OpString "OpaqueType foo;
  3115. main() {}
  3116. "
  3117. %float_name = OpString "float"
  3118. %ty_name = OpString "Texture"
  3119. %t_name = OpString "T"
  3120. )";
  3121. const std::string size_const = R"(
  3122. %int_32 = OpConstant %u32 32
  3123. %int_128 = OpConstant %u32 128
  3124. )";
  3125. const std::string dbg_inst_header = R"(
  3126. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3127. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3128. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3129. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3130. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  3131. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %float_info %param
  3132. )";
  3133. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3134. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3135. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3136. EXPECT_THAT(getDiagnosticString(),
  3137. HasSubstr("expected operand Target must be DebugTypeComposite or "
  3138. "DebugFunction"));
  3139. }
  3140. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFailParam) {
  3141. const std::string src = R"(
  3142. %src = OpString "simple.hlsl"
  3143. %code = OpString "OpaqueType foo;
  3144. main() {}
  3145. "
  3146. %float_name = OpString "float"
  3147. %ty_name = OpString "Texture"
  3148. %t_name = OpString "T"
  3149. )";
  3150. const std::string size_const = R"(
  3151. %int_32 = OpConstant %u32 32
  3152. %int_128 = OpConstant %u32 128
  3153. )";
  3154. const std::string dbg_inst_header = R"(
  3155. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3156. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3157. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3158. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3159. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  3160. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %param %param
  3161. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  3162. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %float_info
  3163. )";
  3164. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3165. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3166. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3167. EXPECT_THAT(
  3168. getDiagnosticString(),
  3169. HasSubstr(
  3170. "expected operand Parameters must be DebugTypeTemplateParameter or "
  3171. "DebugTypeTemplateTemplateParameter"));
  3172. }
  3173. TEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplate) {
  3174. const std::string src = R"(
  3175. %src = OpString "simple.hlsl"
  3176. %code = OpString "OpaqueType foo;
  3177. main() {}
  3178. "
  3179. %float_name = OpString "float"
  3180. %ty_name = OpString "Texture"
  3181. %t_name = OpString "T"
  3182. )";
  3183. const std::string dbg_inst_header = R"(
  3184. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3185. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3186. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3187. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3188. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %ty_name %dbg_none %u32_3
  3189. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
  3190. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
  3191. )";
  3192. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3193. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3194. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3195. }
  3196. TEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateUsedForVariableType) {
  3197. const std::string src = R"(
  3198. %src = OpString "simple.hlsl"
  3199. %code = OpString "OpaqueType foo;
  3200. main() {}
  3201. "
  3202. %float_name = OpString "float"
  3203. %ty_name = OpString "Texture"
  3204. %t_name = OpString "T"
  3205. %foo_name = OpString "foo"
  3206. )";
  3207. const std::string dbg_inst_header = R"(
  3208. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3209. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3210. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3211. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3212. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %ty_name %dbg_none %u32_3
  3213. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
  3214. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
  3215. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %temp %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3
  3216. )";
  3217. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3218. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3219. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3220. }
  3221. TEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateFunction) {
  3222. const std::string src = R"(
  3223. %src = OpString "simple.hlsl"
  3224. %code = OpString "OpaqueType foo;
  3225. main() {}
  3226. "
  3227. %float_name = OpString "float"
  3228. %ty_name = OpString "Texture"
  3229. %t_name = OpString "T"
  3230. )";
  3231. const std::string dbg_inst_header = R"(
  3232. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3233. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3234. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3235. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3236. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
  3237. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %param %param
  3238. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  3239. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %param
  3240. )";
  3241. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3242. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3243. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3244. }
  3245. TEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateFailTarget) {
  3246. const std::string src = R"(
  3247. %src = OpString "simple.hlsl"
  3248. %code = OpString "OpaqueType foo;
  3249. main() {}
  3250. "
  3251. %float_name = OpString "float"
  3252. %ty_name = OpString "Texture"
  3253. %t_name = OpString "T"
  3254. )";
  3255. const std::string dbg_inst_header = R"(
  3256. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3257. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3258. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3259. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3260. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
  3261. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %float_info %param
  3262. )";
  3263. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3264. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3265. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3266. EXPECT_THAT(getDiagnosticString(),
  3267. HasSubstr("expected operand Target must be DebugTypeComposite or "
  3268. "DebugFunction"));
  3269. }
  3270. TEST_F(ValidateVulkan100DebugInfo, DebugTypeTemplateFailParam) {
  3271. const std::string src = R"(
  3272. %src = OpString "simple.hlsl"
  3273. %code = OpString "OpaqueType foo;
  3274. main() {}
  3275. "
  3276. %float_name = OpString "float"
  3277. %ty_name = OpString "Texture"
  3278. %t_name = OpString "T"
  3279. )";
  3280. const std::string dbg_inst_header = R"(
  3281. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  3282. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3283. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3284. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3285. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name %u32_1 %dbg_src %u32_1 %u32_1 %comp_unit %ty_name %dbg_none %u32_3
  3286. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src %u32_0 %u32_0
  3287. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %float_info
  3288. )";
  3289. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3290. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3291. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3292. EXPECT_THAT(
  3293. getDiagnosticString(),
  3294. HasSubstr(
  3295. "expected operand Parameters must be DebugTypeTemplateParameter or "
  3296. "DebugTypeTemplateTemplateParameter"));
  3297. }
  3298. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariable) {
  3299. const std::string src = R"(
  3300. %src = OpString "simple.hlsl"
  3301. %code = OpString "float foo; void main() {}"
  3302. %float_name = OpString "float"
  3303. %foo_name = OpString "foo"
  3304. )";
  3305. const std::string size_const = R"(
  3306. %int_32 = OpConstant %u32 32
  3307. )";
  3308. const std::string dbg_inst_header = R"(
  3309. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3310. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3311. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3312. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate
  3313. )";
  3314. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3315. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3316. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3317. }
  3318. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableStaticMember) {
  3319. const std::string src = R"(
  3320. %src = OpString "simple.hlsl"
  3321. %code = OpString "float foo; void main() {}"
  3322. %float_name = OpString "float"
  3323. %foo_name = OpString "foo"
  3324. )";
  3325. const std::string size_const = R"(
  3326. %int_32 = OpConstant %u32 32
  3327. )";
  3328. const std::string dbg_inst_header = R"(
  3329. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3330. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3331. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3332. %t = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Class %dbg_src 0 0 %comp_unit %foo_name %int_32 FlagIsPublic %a
  3333. %a = OpExtInst %void %DbgExt DebugTypeMember %foo_name %float_info %dbg_src 0 0 %t %u32_0 %int_32 FlagIsPublic
  3334. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate %a
  3335. )";
  3336. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3337. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3338. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3339. }
  3340. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableDebugInfoNone) {
  3341. const std::string src = R"(
  3342. %src = OpString "simple.hlsl"
  3343. %code = OpString "float foo; void main() {}"
  3344. %float_name = OpString "float"
  3345. %foo_name = OpString "foo"
  3346. )";
  3347. const std::string size_const = R"(
  3348. %int_32 = OpConstant %u32 32
  3349. )";
  3350. const std::string dbg_inst_header = R"(
  3351. %dbgNone = OpExtInst %void %DbgExt DebugInfoNone
  3352. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3353. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3354. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3355. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %dbgNone FlagIsProtected|FlagIsPrivate
  3356. )";
  3357. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3358. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3359. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3360. }
  3361. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableConst) {
  3362. const std::string src = R"(
  3363. %src = OpString "simple.hlsl"
  3364. %code = OpString "float foo; void main() {}"
  3365. %float_name = OpString "float"
  3366. %foo_name = OpString "foo"
  3367. )";
  3368. const std::string size_const = R"(
  3369. %int_32 = OpConstant %u32 32
  3370. )";
  3371. const std::string dbg_inst_header = R"(
  3372. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3373. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3374. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3375. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %int_32 FlagIsProtected|FlagIsPrivate
  3376. )";
  3377. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3378. src, size_const, dbg_inst_header, "", opencl_extension, "Vertex"));
  3379. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3380. }
  3381. TEST_P(ValidateOpenCL100DebugInfoDebugGlobalVariable, Fail) {
  3382. const std::string src = R"(
  3383. %src = OpString "simple.hlsl"
  3384. %code = OpString "float foo; void main() {}"
  3385. %float_name = OpString "float"
  3386. %foo_name = OpString "foo"
  3387. )";
  3388. const std::string size_const = R"(
  3389. %int_32 = OpConstant %u32 32
  3390. )";
  3391. const auto& param = GetParam();
  3392. std::ostringstream ss;
  3393. ss << R"(
  3394. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3395. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3396. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3397. %foo = OpExtInst %void %DbgExt DebugGlobalVariable )"
  3398. << param.first;
  3399. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3400. src, size_const, ss.str(), "", opencl_extension, "Vertex"));
  3401. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3402. EXPECT_THAT(getDiagnosticString(),
  3403. HasSubstr("expected operand " + param.second));
  3404. }
  3405. INSTANTIATE_TEST_SUITE_P(
  3406. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugGlobalVariable,
  3407. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  3408. std::make_pair(
  3409. R"(%void %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  3410. "Name"),
  3411. std::make_pair(
  3412. R"(%foo_name %dbg_src %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  3413. "Type"),
  3414. std::make_pair(
  3415. R"(%foo_name %float_info %comp_unit 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  3416. "Source"),
  3417. std::make_pair(
  3418. R"(%foo_name %float_info %dbg_src 0 0 %dbg_src %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  3419. "Scope"),
  3420. std::make_pair(
  3421. R"(%foo_name %float_info %dbg_src 0 0 %comp_unit %void %f32_input FlagIsProtected|FlagIsPrivate)",
  3422. "Linkage Name"),
  3423. std::make_pair(
  3424. R"(%foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %void FlagIsProtected|FlagIsPrivate)",
  3425. "Variable"),
  3426. }));
  3427. TEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariable) {
  3428. const std::string src = R"(
  3429. %src = OpString "simple.hlsl"
  3430. %code = OpString "float foo; void main() {}"
  3431. %float_name = OpString "float"
  3432. %foo_name = OpString "foo"
  3433. )";
  3434. const std::string dbg_inst_header = R"(
  3435. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3436. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3437. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3438. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3
  3439. )";
  3440. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3441. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3442. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3443. }
  3444. TEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariableStaticMember) {
  3445. const std::string src = R"(
  3446. %src = OpString "simple.hlsl"
  3447. %code = OpString "float foo; void main() {}"
  3448. %float_name = OpString "float"
  3449. %foo_name = OpString "foo"
  3450. )";
  3451. const std::string dbg_inst_header = R"(
  3452. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3453. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3454. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3455. %a = OpExtInst %void %DbgExt DebugTypeMember %foo_name %float_info %dbg_src %u32_0 %u32_0 %u32_0 %u32_32 %u32_3
  3456. %t = OpExtInst %void %DbgExt DebugTypeComposite %foo_name %u32_1 %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %u32_32 %u32_3 %a
  3457. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %t %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3
  3458. )";
  3459. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3460. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3461. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3462. }
  3463. TEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariableDebugInfoNone) {
  3464. const std::string src = R"(
  3465. %src = OpString "simple.hlsl"
  3466. %code = OpString "float foo; void main() {}"
  3467. %float_name = OpString "float"
  3468. %foo_name = OpString "foo"
  3469. )";
  3470. const std::string dbg_inst_header = R"(
  3471. %dbgNone = OpExtInst %void %DbgExt DebugInfoNone
  3472. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3473. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3474. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3475. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %dbgNone %u32_3
  3476. )";
  3477. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3478. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3479. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3480. }
  3481. TEST_F(ValidateVulkan100DebugInfo, DebugGlobalVariableConst) {
  3482. const std::string src = R"(
  3483. %src = OpString "simple.hlsl"
  3484. %code = OpString "float foo; void main() {}"
  3485. %float_name = OpString "float"
  3486. %foo_name = OpString "foo"
  3487. )";
  3488. const std::string dbg_inst_header = R"(
  3489. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3490. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3491. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3492. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %u32_32 %u32_3
  3493. )";
  3494. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3495. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  3496. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3497. }
  3498. TEST_P(ValidateVulkan100DebugInfoDebugGlobalVariable, Fail) {
  3499. const std::string src = R"(
  3500. %src = OpString "simple.hlsl"
  3501. %code = OpString "float foo; void main() {}"
  3502. %float_name = OpString "float"
  3503. %foo_name = OpString "foo"
  3504. )";
  3505. const auto& param = GetParam();
  3506. std::ostringstream ss;
  3507. ss << R"(
  3508. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3509. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3510. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3511. %foo = OpExtInst %void %DbgExt DebugGlobalVariable )"
  3512. << param.first;
  3513. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3514. src, "", ss.str(), "", shader_extension, "Vertex"));
  3515. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3516. EXPECT_THAT(getDiagnosticString(),
  3517. HasSubstr("expected operand " + param.second));
  3518. }
  3519. INSTANTIATE_TEST_SUITE_P(
  3520. AllOpenCL100DebugInfoFail, ValidateVulkan100DebugInfoDebugGlobalVariable,
  3521. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  3522. std::make_pair(
  3523. R"(%void %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3)",
  3524. "Name"),
  3525. std::make_pair(
  3526. R"(%foo_name %dbg_src %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3)",
  3527. "Type"),
  3528. std::make_pair(
  3529. R"(%foo_name %float_info %comp_unit %u32_0 %u32_0 %comp_unit %foo_name %f32_input %u32_3)",
  3530. "Source"),
  3531. std::make_pair(
  3532. R"(%foo_name %float_info %dbg_src %u32_0 %u32_0 %dbg_src %foo_name %f32_input %u32_3)",
  3533. "Scope"),
  3534. std::make_pair(
  3535. R"(%foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %void %f32_input %u32_3)",
  3536. "Linkage Name"),
  3537. std::make_pair(
  3538. R"(%foo_name %float_info %dbg_src %u32_0 %u32_0 %comp_unit %foo_name %void %u32_3)",
  3539. "Variable"),
  3540. }));
  3541. TEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAt) {
  3542. const std::string src = R"(
  3543. %src = OpString "simple.hlsl"
  3544. %code = OpString "void main() {}"
  3545. %void_name = OpString "void"
  3546. )";
  3547. const std::string dbg_inst_header = R"(
  3548. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3549. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3550. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  3551. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  3552. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
  3553. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info %inlined_at
  3554. )";
  3555. const std::string body = R"(
  3556. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  3557. )";
  3558. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3559. src, "", dbg_inst_header, body, opencl_extension, "Vertex"));
  3560. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3561. }
  3562. TEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAtFail) {
  3563. const std::string src = R"(
  3564. %src = OpString "simple.hlsl"
  3565. %code = OpString "void main() {}"
  3566. %void_name = OpString "void"
  3567. )";
  3568. const std::string dbg_inst_header = R"(
  3569. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3570. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3571. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  3572. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  3573. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
  3574. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %inlined_at
  3575. )";
  3576. const std::string body = R"(
  3577. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  3578. )";
  3579. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3580. src, "", dbg_inst_header, body, opencl_extension, "Vertex"));
  3581. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3582. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
  3583. }
  3584. TEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAtFail2) {
  3585. const std::string src = R"(
  3586. %src = OpString "simple.hlsl"
  3587. %code = OpString "void main() {}"
  3588. %void_name = OpString "void"
  3589. )";
  3590. const std::string dbg_inst_header = R"(
  3591. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3592. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3593. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  3594. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  3595. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
  3596. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info %main_info
  3597. )";
  3598. const std::string body = R"(
  3599. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  3600. )";
  3601. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3602. src, "", dbg_inst_header, body, opencl_extension, "Vertex"));
  3603. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3604. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined"));
  3605. }
  3606. TEST_F(ValidateVulkan100DebugInfo, DebugInlinedAt) {
  3607. const std::string src = R"(
  3608. %src = OpString "simple.hlsl"
  3609. %code = OpString "void main() {}"
  3610. %void_name = OpString "void"
  3611. )";
  3612. const std::string dbg_inst_header = R"(
  3613. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3614. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3615. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  3616. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  3617. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info
  3618. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info %inlined_at
  3619. )";
  3620. const std::string body = R"(
  3621. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  3622. )";
  3623. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3624. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  3625. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3626. }
  3627. TEST_F(ValidateVulkan100DebugInfo, DebugInlinedAtFail) {
  3628. const std::string src = R"(
  3629. %src = OpString "simple.hlsl"
  3630. %code = OpString "void main() {}"
  3631. %void_name = OpString "void"
  3632. )";
  3633. const std::string dbg_inst_header = R"(
  3634. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3635. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3636. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  3637. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  3638. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info
  3639. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %inlined_at %inlined_at
  3640. )";
  3641. const std::string body = R"(
  3642. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  3643. )";
  3644. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3645. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  3646. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3647. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
  3648. }
  3649. TEST_F(ValidateVulkan100DebugInfo, DebugInlinedAtFail2) {
  3650. const std::string src = R"(
  3651. %src = OpString "simple.hlsl"
  3652. %code = OpString "void main() {}"
  3653. %void_name = OpString "void"
  3654. )";
  3655. const std::string dbg_inst_header = R"(
  3656. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3657. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3658. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  3659. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  3660. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info
  3661. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt %u32_0 %main_info %main_info
  3662. )";
  3663. const std::string body = R"(
  3664. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  3665. )";
  3666. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3667. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  3668. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3669. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined"));
  3670. }
  3671. TEST_F(ValidateOpenCL100DebugInfo, DebugValue) {
  3672. const std::string src = R"(
  3673. %src = OpString "simple.hlsl"
  3674. %code = OpString "void main() { float foo; }"
  3675. %float_name = OpString "float"
  3676. %foo_name = OpString "foo"
  3677. )";
  3678. const std::string size_const = R"(
  3679. %int_3 = OpConstant %u32 3
  3680. %int_32 = OpConstant %u32 32
  3681. )";
  3682. const std::string dbg_inst_header = R"(
  3683. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3684. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3685. %null_expr = OpExtInst %void %DbgExt DebugExpression
  3686. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3687. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  3688. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  3689. )";
  3690. const std::string body = R"(
  3691. %value = OpExtInst %void %DbgExt DebugValue %foo_info %int_32 %null_expr %int_3
  3692. )";
  3693. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3694. src, size_const, dbg_inst_header, body, opencl_extension, "Vertex"));
  3695. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3696. }
  3697. TEST_F(ValidateOpenCL100DebugInfo, DebugValueWithVariableIndex) {
  3698. const std::string src = R"(
  3699. %src = OpString "simple.hlsl"
  3700. %code = OpString "void main() { float foo; }"
  3701. %float_name = OpString "float"
  3702. %int_name = OpString "int"
  3703. %foo_name = OpString "foo"
  3704. %len_name = OpString "length"
  3705. )";
  3706. const std::string size_const = R"(
  3707. %int_3 = OpConstant %u32 3
  3708. %int_32 = OpConstant %u32 32
  3709. )";
  3710. const std::string dbg_inst_header = R"(
  3711. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3712. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3713. %null_expr = OpExtInst %void %DbgExt DebugExpression
  3714. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3715. %int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %int_32 Signed
  3716. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  3717. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src 1 10 %comp_unit FlagIsLocal
  3718. %len_info = OpExtInst %void %DbgExt DebugLocalVariable %len_name %int_info %dbg_src 0 0 %comp_unit FlagIsLocal
  3719. )";
  3720. const std::string body = R"(
  3721. %value = OpExtInst %void %DbgExt DebugValue %foo_info %int_32 %null_expr %len_info
  3722. )";
  3723. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3724. src, size_const, dbg_inst_header, body, opencl_extension, "Vertex"));
  3725. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3726. }
  3727. TEST_P(ValidateOpenCL100DebugInfoDebugValue, Fail) {
  3728. const std::string src = R"(
  3729. %src = OpString "simple.hlsl"
  3730. %code = OpString "void main() { float foo; }"
  3731. %float_name = OpString "float"
  3732. %foo_name = OpString "foo"
  3733. )";
  3734. const std::string size_const = R"(
  3735. %int_32 = OpConstant %u32 32
  3736. )";
  3737. const std::string dbg_inst_header = R"(
  3738. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3739. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  3740. %null_expr = OpExtInst %void %DbgExt DebugExpression
  3741. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  3742. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  3743. )";
  3744. const auto& param = GetParam();
  3745. std::ostringstream ss;
  3746. ss << R"(
  3747. %decl = OpExtInst %void %DbgExt DebugValue )"
  3748. << param.first;
  3749. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3750. src, size_const, dbg_inst_header, ss.str(), opencl_extension, "Vertex"));
  3751. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3752. EXPECT_THAT(getDiagnosticString(),
  3753. HasSubstr("expected operand " + param.second));
  3754. }
  3755. INSTANTIATE_TEST_SUITE_P(
  3756. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugValue,
  3757. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  3758. std::make_pair(R"(%dbg_src %int_32 %null_expr)", "Local Variable"),
  3759. std::make_pair(R"(%foo_info %int_32 %dbg_src)", "Expression"),
  3760. std::make_pair(R"(%foo_info %int_32 %null_expr %dbg_src)", "Indexes"),
  3761. }));
  3762. TEST_F(ValidateVulkan100DebugInfo, DebugValue) {
  3763. const std::string src = R"(
  3764. %src = OpString "simple.hlsl"
  3765. %code = OpString "void main() { float foo; }"
  3766. %float_name = OpString "float"
  3767. %foo_name = OpString "foo"
  3768. )";
  3769. const std::string constants = R"(
  3770. %u32_10 = OpConstant %u32 10
  3771. )";
  3772. const std::string dbg_inst_header = R"(
  3773. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3774. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3775. %null_expr = OpExtInst %void %DbgExt DebugExpression
  3776. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3777. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  3778. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4
  3779. )";
  3780. const std::string body = R"(
  3781. %value = OpExtInst %void %DbgExt DebugValue %foo_info %u32_32 %null_expr %u32_3
  3782. )";
  3783. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3784. src, constants, dbg_inst_header, body, shader_extension, "Vertex"));
  3785. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3786. }
  3787. TEST_F(ValidateVulkan100DebugInfo, DebugValueWithVariableIndex) {
  3788. const std::string src = R"(
  3789. %src = OpString "simple.hlsl"
  3790. %code = OpString "void main() { float foo; }"
  3791. %float_name = OpString "float"
  3792. %int_name = OpString "int"
  3793. %foo_name = OpString "foo"
  3794. %len_name = OpString "length"
  3795. )";
  3796. const std::string constants = R"(
  3797. %u32_10 = OpConstant %u32 10
  3798. )";
  3799. const std::string dbg_inst_header = R"(
  3800. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3801. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3802. %null_expr = OpExtInst %void %DbgExt DebugExpression
  3803. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3804. %int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_32 %u32_4 %u32_0
  3805. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  3806. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4 %u32_0
  3807. %len_info = OpExtInst %void %DbgExt DebugLocalVariable %len_name %int_info %dbg_src %u32_0 %u32_0 %comp_unit %u32_4
  3808. )";
  3809. const std::string body = R"(
  3810. %value = OpExtInst %void %DbgExt DebugValue %foo_info %u32_32 %null_expr %len_info
  3811. )";
  3812. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3813. src, constants, dbg_inst_header, body, shader_extension, "Vertex"));
  3814. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3815. }
  3816. TEST_P(ValidateVulkan100DebugInfoDebugValue, Fail) {
  3817. const std::string src = R"(
  3818. %src = OpString "simple.hlsl"
  3819. %code = OpString "void main() { float foo; }"
  3820. %float_name = OpString "float"
  3821. %foo_name = OpString "foo"
  3822. )";
  3823. const std::string constants = R"(
  3824. %u32_10 = OpConstant %u32 10
  3825. )";
  3826. const std::string dbg_inst_header = R"(
  3827. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  3828. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  3829. %null_expr = OpExtInst %void %DbgExt DebugExpression
  3830. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %u32_32 %u32_3 %u32_0
  3831. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info %u32_4
  3832. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src %u32_1 %u32_10 %comp_unit %u32_4 %u32_0
  3833. )";
  3834. const auto& param = GetParam();
  3835. std::ostringstream ss;
  3836. ss << R"(
  3837. %decl = OpExtInst %void %DbgExt DebugValue )"
  3838. << param.first;
  3839. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  3840. src, constants, dbg_inst_header, ss.str(), shader_extension, "Vertex"));
  3841. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3842. EXPECT_THAT(getDiagnosticString(),
  3843. HasSubstr("expected operand " + param.second));
  3844. }
  3845. INSTANTIATE_TEST_SUITE_P(
  3846. AllOpenCL100DebugInfoFail, ValidateVulkan100DebugInfoDebugValue,
  3847. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  3848. std::make_pair(R"(%dbg_src %u32_32 %null_expr %u32_3)",
  3849. "Local Variable"),
  3850. std::make_pair(R"(%foo_info %u32_32 %dbg_src %u32_3)", "Expression"),
  3851. std::make_pair(R"(%foo_info %u32_32 %null_expr %dbg_src)", "Indexes"),
  3852. }));
  3853. TEST_F(ValidateVulkan100DebugInfo, VulkanDebugInfoSample) {
  3854. std::ostringstream ss;
  3855. ss << R"(
  3856. OpCapability Shader
  3857. OpExtension "SPV_KHR_non_semantic_info"
  3858. %id_1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
  3859. OpMemoryModel Logical GLSL450
  3860. OpEntryPoint Fragment %id_MainPs "MainPs" %id_in_var_TEXCOORD2 %id_out_var_SV_Target0
  3861. OpExecutionMode %id_MainPs OriginUpperLeft
  3862. %id_7 = OpString "foo.frag"
  3863. %id_27 = OpString "float"
  3864. %id_32 = OpString "vColor"
  3865. %id_36 = OpString "PS_OUTPUT"
  3866. %id_42 = OpString "vTextureCoords"
  3867. %id_46 = OpString "PS_INPUT"
  3868. %id_49 = OpString "MainPs"
  3869. %id_50 = OpString ""
  3870. %id_55 = OpString "ps_output"
  3871. %id_59 = OpString "i"
  3872. %id_63 = OpString "@type.sampler"
  3873. %id_64 = OpString "type.sampler"
  3874. %id_66 = OpString "g_sAniso"
  3875. %id_69 = OpString "@type.2d.image"
  3876. %id_70 = OpString "type.2d.image"
  3877. %id_72 = OpString "TemplateParam"
  3878. %id_75 = OpString "g_tColor"
  3879. OpName %id_type_2d_image "type.2d.image"
  3880. OpName %id_g_tColor "g_tColor"
  3881. OpName %id_type_sampler "type.sampler"
  3882. OpName %id_g_sAniso "g_sAniso"
  3883. OpName %id_in_var_TEXCOORD2 "in.var.TEXCOORD2"
  3884. OpName %id_out_var_SV_Target0 "out.var.SV_Target0"
  3885. OpName %id_MainPs "MainPs"
  3886. OpName %id_PS_INPUT "PS_INPUT"
  3887. OpMemberName %id_PS_INPUT 0 "vTextureCoords"
  3888. OpName %id_param_var_i "param.var.i"
  3889. OpName %id_PS_OUTPUT "PS_OUTPUT"
  3890. OpMemberName %id_PS_OUTPUT 0 "vColor"
  3891. OpName %id_src_MainPs "src.MainPs"
  3892. OpName %id_i "i"
  3893. OpName %id_bb_entry "bb.entry"
  3894. OpName %id_ps_output "ps_output"
  3895. OpName %id_type_sampled_image "type.sampled.image"
  3896. OpDecorate %id_in_var_TEXCOORD2 Location 0
  3897. OpDecorate %id_out_var_SV_Target0 Location 0
  3898. OpDecorate %id_g_tColor DescriptorSet 0
  3899. OpDecorate %id_g_tColor Binding 0
  3900. OpDecorate %id_g_sAniso DescriptorSet 0
  3901. OpDecorate %id_g_sAniso Binding 1
  3902. %id_int = OpTypeInt 32 1
  3903. %id_int_0 = OpConstant %id_int 0
  3904. %id_uint = OpTypeInt 32 0
  3905. %id_uint_32 = OpConstant %id_uint 32
  3906. %id_float = OpTypeFloat 32
  3907. %id_type_2d_image = OpTypeImage %id_float 2D 2 0 0 1 Unknown
  3908. %id__ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %id_type_2d_image
  3909. %id_type_sampler = OpTypeSampler
  3910. %id__ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %id_type_sampler
  3911. %id_v2float = OpTypeVector %id_float 2
  3912. %id__ptr_Input_v2float = OpTypePointer Input %id_v2float
  3913. %id_v4float = OpTypeVector %id_float 4
  3914. %id__ptr_Output_v4float = OpTypePointer Output %id_v4float
  3915. %id_void = OpTypeVoid
  3916. %id_uint_1 = OpConstant %id_uint 1
  3917. %id_uint_4 = OpConstant %id_uint 4
  3918. %id_uint_5 = OpConstant %id_uint 5
  3919. %id_uint_3 = OpConstant %id_uint 3
  3920. %id_uint_0 = OpConstant %id_uint 0
  3921. %id_uint_128 = OpConstant %id_uint 128
  3922. %id_uint_12 = OpConstant %id_uint 12
  3923. %id_uint_10 = OpConstant %id_uint 10
  3924. %id_uint_8 = OpConstant %id_uint 8
  3925. %id_uint_2 = OpConstant %id_uint 2
  3926. %id_uint_64 = OpConstant %id_uint 64
  3927. %id_uint_7 = OpConstant %id_uint 7
  3928. %id_uint_15 = OpConstant %id_uint 15
  3929. %id_uint_16 = OpConstant %id_uint 16
  3930. %id_uint_17 = OpConstant %id_uint 17
  3931. %id_uint_29 = OpConstant %id_uint 29
  3932. %id_uint_14 = OpConstant %id_uint 14
  3933. %id_uint_11 = OpConstant %id_uint 11
  3934. %id_78 = OpTypeFunction %id_void
  3935. %id_PS_INPUT = OpTypeStruct %id_v2float
  3936. %id__ptr_Function_PS_INPUT = OpTypePointer Function %id_PS_INPUT
  3937. %id_PS_OUTPUT = OpTypeStruct %id_v4float
  3938. %id_89 = OpTypeFunction %id_PS_OUTPUT %id__ptr_Function_PS_INPUT
  3939. %id__ptr_Function_PS_OUTPUT = OpTypePointer Function %id_PS_OUTPUT
  3940. %id_uint_20 = OpConstant %id_uint 20
  3941. %id_uint_19 = OpConstant %id_uint 19
  3942. %id_uint_26 = OpConstant %id_uint 26
  3943. %id_uint_46 = OpConstant %id_uint 46
  3944. %id__ptr_Function_v2float = OpTypePointer Function %id_v2float
  3945. %id_uint_57 = OpConstant %id_uint 57
  3946. %id_uint_78 = OpConstant %id_uint 78
  3947. %id_type_sampled_image = OpTypeSampledImage %id_type_2d_image
  3948. %id_uint_81 = OpConstant %id_uint 81
  3949. %id__ptr_Function_v4float = OpTypePointer Function %id_v4float
  3950. %id_g_tColor = OpVariable %id__ptr_UniformConstant_type_2d_image UniformConstant
  3951. %id_g_sAniso = OpVariable %id__ptr_UniformConstant_type_sampler UniformConstant
  3952. %id_in_var_TEXCOORD2 = OpVariable %id__ptr_Input_v2float Input
  3953. %id_out_var_SV_Target0 = OpVariable %id__ptr_Output_v4float Output
  3954. %id_22 = OpExtInst %id_void %id_1 DebugSource %id_7
  3955. %id_23 = OpExtInst %id_void %id_1 DebugCompilationUnit %id_uint_1 %id_uint_4 %id_22 %id_uint_5
  3956. %id_28 = OpExtInst %id_void %id_1 DebugTypeBasic %id_27 %id_uint_32 %id_uint_3 %id_uint_0
  3957. %id_31 = OpExtInst %id_void %id_1 DebugTypeVector %id_28 %id_uint_4
  3958. %id_34 = OpExtInst %id_void %id_1 DebugTypeMember %id_32 %id_31 %id_22 %id_uint_12 %id_uint_12 %id_uint_0 %id_uint_128 %id_uint_3
  3959. %id_37 = OpExtInst %id_void %id_1 DebugTypeComposite %id_36 %id_uint_1 %id_22 %id_uint_10 %id_uint_8 %id_23 %id_36 %id_uint_128 %id_uint_3 %id_34
  3960. %id_40 = OpExtInst %id_void %id_1 DebugTypeVector %id_28 %id_uint_2
  3961. %id_44 = OpExtInst %id_void %id_1 DebugTypeMember %id_42 %id_40 %id_22 %id_uint_7 %id_uint_12 %id_uint_0 %id_uint_64 %id_uint_3
  3962. %id_47 = OpExtInst %id_void %id_1 DebugTypeComposite %id_46 %id_uint_1 %id_22 %id_uint_5 %id_uint_8 %id_23 %id_46 %id_uint_64 %id_uint_3 %id_44
  3963. %id_48 = OpExtInst %id_void %id_1 DebugTypeFunction %id_uint_3 %id_37 %id_47
  3964. %id_51 = OpExtInst %id_void %id_1 DebugFunction %id_49 %id_48 %id_22 %id_uint_15 %id_uint_1 %id_23 %id_50 %id_uint_3 %id_uint_16
  3965. %id_54 = OpExtInst %id_void %id_1 DebugLexicalBlock %id_22 %id_uint_16 %id_uint_1 %id_51
  3966. %id_56 = OpExtInst %id_void %id_1 DebugLocalVariable %id_55 %id_37 %id_22 %id_uint_17 %id_uint_15 %id_54 %id_uint_4
  3967. %id_58 = OpExtInst %id_void %id_1 DebugExpression
  3968. %id_60 = OpExtInst %id_void %id_1 DebugLocalVariable %id_59 %id_47 %id_22 %id_uint_15 %id_uint_29 %id_51 %id_uint_4 %id_uint_1
  3969. %id_62 = OpExtInst %id_void %id_1 DebugInfoNone
  3970. %id_65 = OpExtInst %id_void %id_1 DebugTypeComposite %id_63 %id_uint_1 %id_22 %id_uint_0 %id_uint_0 %id_23 %id_64 %id_62 %id_uint_3
  3971. %id_67 = OpExtInst %id_void %id_1 DebugGlobalVariable %id_66 %id_65 %id_22 %id_uint_3 %id_uint_14 %id_23 %id_66 %id_g_sAniso %id_uint_8
  3972. %id_71 = OpExtInst %id_void %id_1 DebugTypeComposite %id_69 %id_uint_0 %id_22 %id_uint_0 %id_uint_0 %id_23 %id_70 %id_62 %id_uint_3
  3973. %id_73 = OpExtInst %id_void %id_1 DebugTypeTemplateParameter %id_72 %id_31 %id_62 %id_22 %id_uint_0 %id_uint_0
  3974. %id_74 = OpExtInst %id_void %id_1 DebugTypeTemplate %id_71 %id_73
  3975. %id_76 = OpExtInst %id_void %id_1 DebugGlobalVariable %id_75 %id_74 %id_22 %id_uint_1 %id_uint_11 %id_23 %id_75 %id_g_tColor %id_uint_8
  3976. %id_MainPs = OpFunction %id_void None %id_78
  3977. %id_79 = OpLabel
  3978. %id_param_var_i = OpVariable %id__ptr_Function_PS_INPUT Function
  3979. %id_83 = OpLoad %id_v2float %id_in_var_TEXCOORD2
  3980. %id_84 = OpCompositeConstruct %id_PS_INPUT %id_83
  3981. OpStore %id_param_var_i %id_84
  3982. %id_86 = OpFunctionCall %id_PS_OUTPUT %id_src_MainPs %id_param_var_i
  3983. %id_88 = OpCompositeExtract %id_v4float %id_86 0
  3984. OpStore %id_out_var_SV_Target0 %id_88
  3985. OpReturn
  3986. OpFunctionEnd
  3987. %id_src_MainPs = OpFunction %id_PS_OUTPUT None %id_89
  3988. %id_i = OpFunctionParameter %id__ptr_Function_PS_INPUT
  3989. %id_bb_entry = OpLabel
  3990. %id_ps_output = OpVariable %id__ptr_Function_PS_OUTPUT Function
  3991. %id_94 = OpExtInst %id_void %id_1 DebugScope %id_51
  3992. %id_97 = OpExtInst %id_void %id_1 DebugDeclare %id_60 %id_i %id_58
  3993. %id_99 = OpExtInst %id_void %id_1 DebugFunctionDefinition %id_51 %id_src_MainPs
  3994. %id_100 = OpExtInst %id_void %id_1 DebugScope %id_54
  3995. %id_102 = OpExtInst %id_void %id_1 DebugDeclare %id_56 %id_ps_output %id_58
  3996. %id_106 = OpLoad %id_type_2d_image %id_g_tColor
  3997. %id_109 = OpLoad %id_type_sampler %id_g_sAniso
  3998. %id_114 = OpAccessChain %id__ptr_Function_v2float %id_i %id_int_0
  3999. %id_115 = OpLoad %id_v2float %id_114
  4000. %id_119 = OpSampledImage %id_type_sampled_image %id_106 %id_109
  4001. %id_120 = OpImageSampleImplicitLod %id_v4float %id_119 %id_115 None
  4002. %id_123 = OpAccessChain %id__ptr_Function_v4float %id_ps_output %id_int_0
  4003. OpStore %id_123 %id_120
  4004. %id_125 = OpLoad %id_PS_OUTPUT %id_ps_output
  4005. OpReturnValue %id_125
  4006. OpFunctionEnd
  4007. )";
  4008. CompileSuccessfully(ss.str());
  4009. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4010. }
  4011. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionDefinition) {
  4012. const std::string src = R"(
  4013. %src = OpString "simple.hlsl"
  4014. %code = OpString "int main() { }"
  4015. )";
  4016. const std::string dbg_inst_header = R"(
  4017. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4018. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4019. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4020. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4021. )";
  4022. const std::string body = R"(
  4023. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main
  4024. )";
  4025. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4026. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4027. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4028. }
  4029. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionDefinitionFailFunction) {
  4030. const std::string src = R"(
  4031. %src = OpString "simple.hlsl"
  4032. %code = OpString "int main() { }"
  4033. )";
  4034. const std::string dbg_inst_header = R"(
  4035. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4036. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4037. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4038. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4039. )";
  4040. const std::string body = R"(
  4041. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_type_info %main
  4042. )";
  4043. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4044. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4045. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4046. EXPECT_THAT(getDiagnosticString(),
  4047. HasSubstr("DebugFunctionDefinition: expected operand Function "
  4048. "must be a result id of DebugFunction"));
  4049. }
  4050. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionDefinitionFailDefinition) {
  4051. const std::string src = R"(
  4052. %src = OpString "simple.hlsl"
  4053. %code = OpString "int main() { }"
  4054. )";
  4055. const std::string dbg_inst_header = R"(
  4056. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4057. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4058. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4059. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4060. )";
  4061. const std::string body = R"(
  4062. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main_name
  4063. )";
  4064. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4065. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4066. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4067. EXPECT_THAT(getDiagnosticString(),
  4068. HasSubstr("DebugFunctionDefinition: expected operand Definition "
  4069. "must be a result id of OpFunction"));
  4070. }
  4071. // TODO - Need to track in function scope
  4072. TEST_F(ValidateVulkan100DebugInfo, DISABLED_DebugFunctionDefinitionDuplicate) {
  4073. const std::string src = R"(
  4074. %src = OpString "simple.hlsl"
  4075. %code = OpString "int main() { }"
  4076. )";
  4077. const std::string dbg_inst_header = R"(
  4078. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4079. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4080. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4081. %main_info1 = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4082. %main_info2 = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4083. )";
  4084. const std::string body = R"(
  4085. %main_def1 = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info1 %main
  4086. %main_def2 = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info2 %main
  4087. )";
  4088. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4089. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4090. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4091. EXPECT_THAT(getDiagnosticString(),
  4092. HasSubstr("DebugFunctionDefinition: Was used multiple times in "
  4093. "single function block"));
  4094. }
  4095. // TODO - Need to track in function scope
  4096. TEST_F(ValidateVulkan100DebugInfo,
  4097. DISABLED_DebugFunctionDefinitionDuplicateReference) {
  4098. const std::string src = R"(
  4099. %src = OpString "simple.hlsl"
  4100. %code = OpString "int main() { }"
  4101. )";
  4102. const std::string dbg_inst_header = R"(
  4103. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4104. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4105. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4106. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4107. )";
  4108. const std::string body = R"(
  4109. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main
  4110. OpReturn
  4111. OpFunctionEnd
  4112. %foo = OpFunction %void None %func
  4113. %foo_entry = OpLabel
  4114. %foo_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %foo
  4115. )";
  4116. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4117. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4118. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4119. EXPECT_THAT(getDiagnosticString(),
  4120. HasSubstr("DebugFunctionDefinition: Was referenced a "
  4121. "DebugFunction that was already referenced before"));
  4122. }
  4123. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionDefinitionWrongDefinition) {
  4124. const std::string src = R"(
  4125. %src = OpString "simple.hlsl"
  4126. %code = OpString "int main() { }"
  4127. )";
  4128. const std::string dbg_inst_header = R"(
  4129. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4130. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4131. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4132. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4133. %foo_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4134. )";
  4135. const std::string body = R"(
  4136. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main
  4137. OpReturn
  4138. OpFunctionEnd
  4139. %foo = OpFunction %void None %func
  4140. %foo_entry = OpLabel
  4141. %foo_def = OpExtInst %void %DbgExt DebugFunctionDefinition %foo_info %main
  4142. )";
  4143. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4144. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4145. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4146. EXPECT_THAT(getDiagnosticString(),
  4147. HasSubstr("DebugFunctionDefinition: operand Definition must "
  4148. "point to the OpFunction it is inside"));
  4149. }
  4150. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionDefinitionNonEntryBlock) {
  4151. const std::string src = R"(
  4152. %src = OpString "simple.hlsl"
  4153. %code = OpString "int main() { }"
  4154. )";
  4155. const std::string constants = R"(
  4156. %false = OpConstantFalse %bool
  4157. )";
  4158. const std::string dbg_inst_header = R"(
  4159. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4160. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4161. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4162. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4163. )";
  4164. const std::string body = R"(
  4165. OpSelectionMerge %merge_block None
  4166. OpBranchConditional %false %second_block %merge_block
  4167. %second_block = OpLabel
  4168. OpReturn
  4169. %merge_block = OpLabel
  4170. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main
  4171. )";
  4172. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4173. src, constants, dbg_inst_header, body, shader_extension, "Vertex"));
  4174. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4175. EXPECT_THAT(getDiagnosticString(),
  4176. HasSubstr("DebugFunctionDefinition: must be in the entry basic "
  4177. "block of the function"));
  4178. }
  4179. TEST_F(ValidateVulkan100DebugInfo, DebugFunctionDefinitionMultiFunctions) {
  4180. const std::string src = R"(
  4181. %src = OpString "simple.hlsl"
  4182. %code = OpString "int main() { }"
  4183. )";
  4184. const std::string dbg_inst_header = R"(
  4185. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4186. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit %u32_2 %u32_4 %dbg_src %u32_5
  4187. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction %u32_3 %void
  4188. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4189. %foo_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src %u32_1 %u32_1 %comp_unit %main_name %u32_3 %u32_1
  4190. )";
  4191. const std::string body = R"(
  4192. %main_def = OpExtInst %void %DbgExt DebugFunctionDefinition %main_info %main
  4193. OpReturn
  4194. OpFunctionEnd
  4195. %foo = OpFunction %void None %func
  4196. %foo_entry = OpLabel
  4197. %foo_def = OpExtInst %void %DbgExt DebugFunctionDefinition %foo_info %foo
  4198. )";
  4199. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4200. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4201. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4202. }
  4203. TEST_F(ValidateVulkan100DebugInfo, DebugLine) {
  4204. const std::string src = R"(
  4205. %src = OpString "simple.hlsl"
  4206. %code = OpString "int main() { }"
  4207. )";
  4208. const std::string dbg_inst_header = R"(
  4209. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4210. )";
  4211. const std::string body = R"(
  4212. %line1 = OpExtInst %void %DbgExt DebugLine %dbg_src %u32_1 %u32_2 %u32_0 %u32_0
  4213. %line2 = OpExtInst %void %DbgExt DebugLine %dbg_src %u32_1 %u32_2 %u32_0 %u32_0
  4214. %no_line = OpExtInst %void %DbgExt DebugNoLine
  4215. %line3 = OpExtInst %void %DbgExt DebugLine %dbg_src %u32_1 %u32_2 %u32_0 %u32_0
  4216. )";
  4217. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4218. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4219. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4220. }
  4221. TEST_F(ValidateVulkan100DebugInfo, DebugNoLineOutOfBlock) {
  4222. const std::string src = R"(
  4223. %src = OpString "simple.hlsl"
  4224. %code = OpString "int main() { }"
  4225. )";
  4226. const std::string dbg_inst_header = R"(
  4227. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4228. %no_line = OpExtInst %void %DbgExt DebugNoLine
  4229. )";
  4230. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4231. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  4232. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  4233. EXPECT_THAT(getDiagnosticString(),
  4234. HasSubstr("debug info extension must appear in a function body"));
  4235. }
  4236. TEST_F(ValidateVulkan100DebugInfo, DebugLineOutOfBlock) {
  4237. const std::string src = R"(
  4238. %src = OpString "simple.hlsl"
  4239. %code = OpString "int main() { }"
  4240. )";
  4241. const std::string dbg_inst_header = R"(
  4242. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4243. %line = OpExtInst %void %DbgExt DebugLine %dbg_src %u32_1 %u32_2 %u32_0 %u32_0
  4244. )";
  4245. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4246. src, "", dbg_inst_header, "", shader_extension, "Vertex"));
  4247. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  4248. EXPECT_THAT(getDiagnosticString(),
  4249. HasSubstr("debug info extension must appear in a function body"));
  4250. }
  4251. TEST_F(ValidateVulkan100DebugInfo, DebugLineSource) {
  4252. const std::string src = R"(
  4253. %src = OpString "simple.hlsl"
  4254. %code = OpString "int main() { }"
  4255. %int_name = OpString "int"
  4256. )";
  4257. const std::string dbg_inst_header = R"(
  4258. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4259. %int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_0 %u32_1 %u32_0
  4260. )";
  4261. const std::string body = R"(
  4262. %line = OpExtInst %void %DbgExt DebugLine %int_info %u32_2 %u32_2 %u32_0 %u32_0
  4263. )";
  4264. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4265. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4266. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4267. EXPECT_THAT(getDiagnosticString(),
  4268. HasSubstr("DebugLine: expected operand Source must be a result "
  4269. "id of DebugSource"));
  4270. }
  4271. TEST_F(ValidateVulkan100DebugInfo, DebugLineFloat) {
  4272. const std::string src = R"(
  4273. %src = OpString "simple.hlsl"
  4274. %code = OpString "int main() { }"
  4275. )";
  4276. const std::string dbg_inst_header = R"(
  4277. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4278. )";
  4279. const std::string body = R"(
  4280. %line1 = OpExtInst %void %DbgExt DebugLine %dbg_src %f32_1 %u32_2 %u32_0 %u32_0
  4281. )";
  4282. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4283. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4284. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4285. EXPECT_THAT(getDiagnosticString(),
  4286. HasSubstr("DebugLine: expected operand Line Start must be a "
  4287. "result id of 32-bit unsigned OpConstant"));
  4288. }
  4289. TEST_F(ValidateVulkan100DebugInfo, DebugLineInt64) {
  4290. const std::string src = R"(
  4291. %src = OpString "simple.hlsl"
  4292. %code = OpString "int main() { }"
  4293. )";
  4294. const std::string dbg_inst_header = R"(
  4295. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4296. )";
  4297. const std::string body = R"(
  4298. %line1 = OpExtInst %void %DbgExt DebugLine %dbg_src %u64_1 %u64_1 %u32_0 %u32_0
  4299. )";
  4300. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4301. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4302. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4303. EXPECT_THAT(getDiagnosticString(),
  4304. HasSubstr("DebugLine: expected operand Line Start must be a "
  4305. "result id of 32-bit unsigned OpConstant"));
  4306. }
  4307. TEST_F(ValidateVulkan100DebugInfo, DebugLineSpecConstant) {
  4308. const std::string src = R"(
  4309. %src = OpString "simple.hlsl"
  4310. %code = OpString "int main() { }"
  4311. )";
  4312. const std::string dbg_inst_header = R"(
  4313. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4314. %spec_int = OpSpecConstant %u32 2
  4315. )";
  4316. const std::string body = R"(
  4317. %line1 = OpExtInst %void %DbgExt DebugLine %dbg_src %spec_int %u32_1 %u32_0 %u32_0
  4318. )";
  4319. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4320. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4321. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4322. EXPECT_THAT(getDiagnosticString(),
  4323. HasSubstr("DebugLine: expected operand Line Start must be a "
  4324. "result id of 32-bit unsigned OpConstant"));
  4325. }
  4326. TEST_F(ValidateVulkan100DebugInfo, DebugLineLineEndSmaller) {
  4327. const std::string src = R"(
  4328. %src = OpString "simple.hlsl"
  4329. %code = OpString "int main() { }"
  4330. )";
  4331. const std::string dbg_inst_header = R"(
  4332. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4333. )";
  4334. const std::string body = R"(
  4335. %line1 = OpExtInst %void %DbgExt DebugLine %dbg_src %u32_2 %u32_1 %u32_0 %u32_0
  4336. )";
  4337. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4338. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4339. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4340. EXPECT_THAT(
  4341. getDiagnosticString(),
  4342. HasSubstr("DebugLine: operand Line End (1) is less than Line Start (2)"));
  4343. }
  4344. TEST_F(ValidateVulkan100DebugInfo, DebugLineColumnEndSmaller) {
  4345. const std::string src = R"(
  4346. %src = OpString "simple.hlsl"
  4347. %code = OpString "int main() { }"
  4348. )";
  4349. const std::string dbg_inst_header = R"(
  4350. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4351. )";
  4352. const std::string body = R"(
  4353. %line1 = OpExtInst %void %DbgExt DebugLine %dbg_src %u32_1 %u32_1 %u32_1 %u32_0
  4354. )";
  4355. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4356. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4357. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4358. EXPECT_THAT(getDiagnosticString(),
  4359. HasSubstr("DebugLine: operand Column End (0) is less than Column "
  4360. "Start (1) when Line Start equals Line End"));
  4361. }
  4362. TEST_F(ValidateVulkan100DebugInfo, DebugLineColumnEndSmallerMultiline) {
  4363. const std::string src = R"(
  4364. %src = OpString "simple.hlsl"
  4365. %code = OpString "int main() { }"
  4366. )";
  4367. const std::string dbg_inst_header = R"(
  4368. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  4369. )";
  4370. const std::string body = R"(
  4371. %line1 = OpExtInst %void %DbgExt DebugLine %dbg_src %u32_1 %u32_2 %u32_1 %u32_0
  4372. )";
  4373. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  4374. src, "", dbg_inst_header, body, shader_extension, "Vertex"));
  4375. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4376. }
  4377. } // namespace
  4378. } // namespace val
  4379. } // namespace spvtools