| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619 |
- // Copyright (c) 2017-2022 Valve Corporation
- // Copyright (c) 2017-2022 LunarG Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // Bindless Check Instrumentation Tests.
- #include <string>
- #include <vector>
- #include "test/opt/assembly_builder.h"
- #include "test/opt/pass_fixture.h"
- #include "test/opt/pass_utils.h"
- namespace spvtools {
- namespace opt {
- namespace {
- using InstBindlessTest = PassTest<::testing::Test>;
- static const std::string kOutputDecorations = R"(
- ; CHECK: OpDecorate [[output_buffer_type:%inst_bindless_OutputBuffer]] Block
- ; CHECK: OpMemberDecorate [[output_buffer_type]] 0 Offset 0
- ; CHECK: OpMemberDecorate [[output_buffer_type]] 1 Offset 4
- ; CHECK: OpDecorate [[output_buffer_var:%\w+]] DescriptorSet 7
- ; CHECK: OpDecorate [[output_buffer_var]] Binding 0
- )";
- static const std::string kOutputGlobals = R"(
- ; CHECK: [[output_buffer_type]] = OpTypeStruct %uint %uint %_runtimearr_uint
- ; CHECK: [[output_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[output_buffer_type]]
- ; CHECK: [[output_buffer_var]] = OpVariable [[output_ptr_type]] StorageBuffer
- )";
- static const std::string kStreamWrite4Begin = R"(
- ; CHECK: %inst_bindless_stream_write_4 = OpFunction %void None {{%\w+}}
- ; CHECK: [[param_1:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_3:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_4:%\w+]] = OpFunctionParameter %uint
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1
- ; CHECK: {{%\w+}} = OpAtomicIAdd %uint {{%\w+}} %uint_4 %uint_0 %uint_10
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_10
- ; CHECK: {{%\w+}} = OpArrayLength %uint [[output_buffer_var]] 2
- ; CHECK: {{%\w+}} = OpULessThanEqual %bool {{%\w+}} {{%\w+}}
- ; CHECK: OpSelectionMerge {{%\w+}} None
- ; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_0
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_10
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_1
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_23
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_2
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_1]]
- )";
- static const std::string kStreamWrite4End = R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_2]]
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_8
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_3]]
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_9
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_4]]
- ; CHECK: OpBranch {{%\w+}}
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: OpReturn
- ; CHECK: OpFunctionEnd
- )";
- // clang-format off
- static const std::string kStreamWrite4Frag = kStreamWrite4Begin + R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
- ; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- )" + kStreamWrite4End;
- static const std::string kStreamWrite4Tese = kStreamWrite4Begin + R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_2
- ; CHECK: {{%\w+}} = OpLoad %uint %gl_PrimitiveID
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %v3float %gl_TessCoord
- ; CHECK: {{%\w+}} = OpBitcast %v3uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_6
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- )" + kStreamWrite4End;
- static const std::string kStreamWrite4Vert = kStreamWrite4Begin + R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_0
- ; CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- )" + kStreamWrite4End;
- static const std::string kStreamWrite4Compute = kStreamWrite4Begin + R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_6
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- )" + kStreamWrite4End;
- static const std::string kStreamWrite4Ray = kStreamWrite4Begin + R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %v3uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_6
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- )" + kStreamWrite4End;
- // clang-format on
- static const std::string kStreamWrite5Begin = R"(
- ; CHECK: %inst_bindless_stream_write_5 = OpFunction %void None {{%\w+}}
- ; CHECK: [[param_1:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_3:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_4:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_5:%\w+]] = OpFunctionParameter %uint
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1
- ; CHECK: {{%\w+}} = OpAtomicIAdd %uint {{%\w+}} %uint_4 %uint_0 %uint_11
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_11
- ; CHECK: {{%\w+}} = OpArrayLength %uint [[output_buffer_var]] 2
- ; CHECK: {{%\w+}} = OpULessThanEqual %bool {{%\w+}} {{%\w+}}
- ; CHECK: OpSelectionMerge {{%\w+}} None
- ; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_0
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_11
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_1
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_23
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_2
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_1]]
- )";
- static const std::string kStreamWrite5End = R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_2]]
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_8
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_3]]
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_9
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_4]]
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_10
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} [[param_5]]
- ; CHECK: OpBranch {{%\w+}}
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: OpReturn
- ; CHECK: OpFunctionEnd
- )";
- // clang-format off
- static const std::string kStreamWrite5Frag = kStreamWrite5Begin + R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
- ; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- )" + kStreamWrite4End;
- static const std::string kStreamWrite5Vert = kStreamWrite5Begin + R"(
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} %uint_0
- ; CHECK: {{%\w+}} = OpLoad %uint %gl_VertexIndex
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %uint %gl_InstanceIndex
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_2 {{%\w+}}
- ; CHECK: OpStore {{%\w+}} {{%\w+}}
- )" + kStreamWrite5End;
- // clang-format on
- static const std::string kInputDecorations = R"(
- ; CHECK: OpDecorate [[input_buffer_type:%inst_bindless_InputBuffer]] Block
- ; CHECK: OpMemberDecorate [[input_buffer_type]] 0 Offset 0
- ; CHECK: OpDecorate [[input_buffer_var:%\w+]] DescriptorSet 7
- ; CHECK: OpDecorate [[input_buffer_var]] Binding 1
- )";
- static const std::string kInputGlobals = R"(
- ; CHECK: [[input_buffer_type]] = OpTypeStruct %_runtimearr_uint
- ; CHECK: [[input_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[input_buffer_type]]
- ; CHECK: [[input_buffer_var]] = OpVariable [[input_ptr_type]] StorageBuffer
- )";
- static const std::string kDirectRead2 = R"(
- ; CHECK: %inst_bindless_direct_read_2 = OpFunction %uint None {{%\w+}}
- ; CHECK: [[param_1:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 [[param_1]]
- ; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[param_2]]
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ; CHECK: OpReturnValue {{%\w+}}
- ; CHECK: OpFunctionEnd
- )";
- static const std::string kDirectRead3 = R"(
- ;CHECK: %inst_bindless_direct_read_3 = OpFunction %uint None {{%\w+}}
- ; CHECK: [[param_1:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_3:%\w+]] = OpFunctionParameter %uint
- ;CHECK: {{%\w+}} = OpLabel
- ;CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 [[param_1]]
- ;CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[param_2]]
- ;CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 {{%\w+}}
- ;CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ;CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[param_3]]
- ;CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 {{%\w+}}
- ;CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ;CHECK: OpReturnValue {{%\w+}}
- ;CHECK: OpFunctionEnd
- )";
- static const std::string kDirectRead4 = R"(
- ; CHECK: %inst_bindless_direct_read_4 = OpFunction %uint None {{%\w+}}
- ; CHECK: [[param_1:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_3:%\w+]] = OpFunctionParameter %uint
- ; CHECK: [[param_4:%\w+]] = OpFunctionParameter %uint
- ; CHECK: {{%\w+}} = OpLabel
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 [[param_1]]
- ; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[param_2]]
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[param_3]]
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} [[param_4]]
- ; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[input_buffer_var]] %uint_0 {{%\w+}}
- ; CHECK: {{%\w+}} = OpLoad %uint {{%\w+}}
- ; CHECK: OpReturnValue {{%\w+}}
- ; CHECK: OpFunctionEnd
- )";
- TEST_F(InstBindlessTest, NoInstrumentConstIndexInbounds) {
- // Texture2D g_tColor[128];
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- //
- // ps_output.vColor = g_tColor[ 37 ].Sample(g_sAniso, i.vTextureCoords.xy);
- // return ps_output;
- // }
- const std::string before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_37 = OpConstant %int 37
- %15 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_15_uint_128 = OpTypeArray %15 %uint_128
- %_ptr_UniformConstant__arr_15_uint_128 = OpTypePointer UniformConstant %_arr_15_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_15_uint_128 UniformConstant
- %_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
- %21 = OpTypeSampler
- %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
- %g_sAniso = OpVariable %_ptr_UniformConstant_21 UniformConstant
- %23 = OpTypeSampledImage %15
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %MainPs = OpFunction %void None %8
- %26 = OpLabel
- %27 = OpLoad %v2float %i_vTextureCoords
- %28 = OpAccessChain %_ptr_UniformConstant_15 %g_tColor %int_37
- %29 = OpLoad %15 %28
- %30 = OpLoad %21 %g_sAniso
- %31 = OpSampledImage %23 %29 %30
- %32 = OpImageSampleImplicitLod %v4float %31 %27
- OpStore %_entryPointOutput_vColor %32
- OpReturn
- OpFunctionEnd
- )";
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- before, before, true, true, 7u, 23u, false, false, false, false, false);
- }
- TEST_F(InstBindlessTest, NoInstrumentNonBindless) {
- // This test verifies that the pass will correctly not instrument vanilla
- // texture sample.
- //
- // Texture2D g_tColor;
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- // ps_output.vColor =
- // g_tColor.Sample(g_sAniso, i.vTextureCoords.xy);
- // return ps_output;
- // }
- const std::string whole_file =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
- %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %16 = OpTypeSampledImage %12
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %MainPs = OpFunction %void None %8
- %19 = OpLabel
- %20 = OpLoad %v2float %i_vTextureCoords
- %21 = OpLoad %12 %g_tColor
- %22 = OpLoad %14 %g_sAniso
- %23 = OpSampledImage %16 %21 %22
- %24 = OpImageSampleImplicitLod %v4float %23 %20
- OpStore %_entryPointOutput_vColor %24
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(whole_file, whole_file, true,
- true, 7u, 23u, false, false,
- false, false, false);
- }
- TEST_F(InstBindlessTest, Simple) {
- // Texture2D g_tColor[128];
- //
- // layout(push_constant) cbuffer PerViewConstantBuffer_t
- // {
- // uint g_nDataIdx;
- // };
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- // ps_output.vColor =
- // g_tColor[ g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
- // return ps_output;
- // }
- const std::string entry = R"(
- OpCapability Shader
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- )";
- // clang-format off
- const std::string names_annots = R"(
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- )";
- const std::string consts_types_vars = R"(
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_16_uint_128 = OpTypeArray %16 %uint_128
- %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %24 = OpTypeSampler
- %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
- %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
- %26 = OpTypeSampledImage %16
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- ; CHECK: %bool = OpTypeBool
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func = R"(
- %MainPs = OpFunction %void None %10
- %29 = OpLabel
- %30 = OpLoad %v2float %i_vTextureCoords
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
- %34 = OpLoad %16 %33
- %35 = OpLoad %24 %g_sAniso
- %36 = OpSampledImage %26 %34 %35
- %37 = OpImageSampleImplicitLod %v4float %36 %30
- OpStore %_entryPointOutput_vColor %37
- ; CHECK-NOT: %37 = OpImageSampleImplicitLod %v4float %36 %30
- ; CHECK-NOT: OpStore %_entryPointOutput_vColor %37
- ; CHECK: %40 = OpULessThan %bool %32 %uint_128
- ; CHECK: OpSelectionMerge %41 None
- ; CHECK: OpBranchConditional %40 %42 %43
- ; CHECK: %42 = OpLabel
- ; CHECK: %44 = OpLoad %16 %33
- ; CHECK: %45 = OpSampledImage %26 %44 %35
- ; CHECK: %46 = OpImageSampleImplicitLod %v4float %45 %30
- ; CHECK: OpBranch %41
- ; CHECK: %43 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_56 %uint_0 %32 %uint_128
- ; CHECK: OpBranch %41
- ; CHECK: %41 = OpLabel
- ; CHECK: %104 = OpPhi %v4float %46 %42 [[null_v4float]] %43
- ; CHECK: OpStore %_entryPointOutput_vColor %104
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Frag;
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass, uint32_t, uint32_t, bool, bool>(
- entry + names_annots + consts_types_vars + main_func + output_func, true,
- 7u, 23u, false, false, false, false, false);
- }
- TEST_F(InstBindlessTest, InstrumentMultipleInstructions) {
- // Texture2D g_tColor[128];
- //
- // layout(push_constant) cbuffer PerViewConstantBuffer_t
- // {
- // uint g_nDataIdx;
- // uint g_nDataIdx2;
- // };
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- //
- // float t = g_tColor[g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
- // float t2 = g_tColor[g_nDataIdx2].Sample(g_sAniso, i.vTextureCoords.xy);
- // ps_output.vColor = t + t2;
- // return ps_output;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_1 = OpConstant %int 1
- %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_17_uint_128 = OpTypeArray %17 %uint_128
- %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
- %25 = OpTypeSampler
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
- %27 = OpTypeSampledImage %17
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- ; CHECK: %bool = OpTypeBool
- ; CHECK: {{%\w+}} = OpTypeFunction %void %uint %uint %uint %uint
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func =
- R"(%MainPs = OpFunction %void None %10
- %30 = OpLabel
- %31 = OpLoad %v2float %i_vTextureCoords
- %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %33 = OpLoad %uint %32
- %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
- %35 = OpLoad %17 %34
- %36 = OpLoad %25 %g_sAniso
- %37 = OpSampledImage %27 %35 %36
- %38 = OpImageSampleImplicitLod %v4float %37 %31
- ; CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31
- ; CHECK: %48 = OpULessThan %bool %33 %uint_128
- ; CHECK: OpSelectionMerge %49 None
- ; CHECK: OpBranchConditional %48 %50 %51
- ; CHECK: %50 = OpLabel
- ; CHECK: %52 = OpLoad %17 %34
- ; CHECK: %53 = OpSampledImage %27 %52 %36
- ; CHECK: %54 = OpImageSampleImplicitLod %v4float %53 %31
- ; CHECK: OpBranch %49
- ; CHECK: %51 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_58 %uint_0 %33 %uint_128
- ; CHECK: OpBranch %49
- ; CHECK: %49 = OpLabel
- ; CHECK: %112 = OpPhi %v4float %54 %50 [[null_v4float]] %51
- %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
- %40 = OpLoad %uint %39
- %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
- %42 = OpLoad %17 %41
- %43 = OpSampledImage %27 %42 %36
- %44 = OpImageSampleImplicitLod %v4float %43 %31
- %45 = OpFAdd %v4float %38 %44
- ; CHECK-NOT: %44 = OpImageSampleImplicitLod %v4float %43 %31
- ; CHECK-NOT: %45 = OpFAdd %v4float %38 %44
- ; CHECK: %113 = OpULessThan %bool %40 %uint_128
- ; CHECK: OpSelectionMerge %114 None
- ; CHECK: OpBranchConditional %113 %115 %116
- ; CHECK: %115 = OpLabel
- ; CHECK: %117 = OpLoad %17 %41
- ; CHECK: %118 = OpSampledImage %27 %117 %36
- ; CHECK: %119 = OpImageSampleImplicitLod %v4float %118 %31
- ; CHECK: OpBranch %114
- ; CHECK: %116 = OpLabel
- ; CHECK: %121 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_64 %uint_0 %40 %uint_128
- ; CHECK: OpBranch %114
- ; CHECK: %114 = OpLabel
- ; CHECK: %122 = OpPhi %v4float %119 %115 [[null_v4float]] %116
- ; CHECK: %45 = OpFAdd %v4float %112 %122
- OpStore %_entryPointOutput_vColor %45
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Frag;
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + output_func,
- true, 7u, 23u, false, false,
- false, false, false);
- }
- TEST_F(InstBindlessTest, InstrumentOpImage) {
- // This test verifies that the pass will correctly instrument shader
- // using OpImage. This test was created by editing the SPIR-V
- // from the Simple test.
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability StorageImageReadWithoutFormat
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %39 = OpTypeSampledImage %20
- %_arr_39_uint_128 = OpTypeArray %39 %uint_128
- %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- ; CHECK: uint_0 = OpConstant %uint 0
- ; CHECK: bool = OpTypeBool
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func = R"(
- %MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2int %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
- %66 = OpLoad %39 %65
- %75 = OpImage %20 %66
- %71 = OpImageRead %v4float %75 %53
- OpStore %_entryPointOutput_vColor %71
- ; CHECK-NOT: %71 = OpImageRead %v4float %75 %53
- ; CHECK-NOT: OpStore %_entryPointOutput_vColor %71
- ; CHECK: %78 = OpULessThan %bool %64 %uint_128
- ; CHECK: OpSelectionMerge %79 None
- ; CHECK: OpBranchConditional %78 %80 %81
- ; CHECK: %80 = OpLabel
- ; CHECK: %82 = OpLoad %39 %65
- ; CHECK: %83 = OpImage %20 %82
- ; CHECK: %84 = OpImageRead %v4float %83 %53
- ; CHECK: OpBranch %79
- ; CHECK: %81 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %64 %uint_128
- ; CHECK: OpBranch %79
- ; CHECK: %79 = OpLabel
- ; CHECK: %142 = OpPhi %v4float %84 %80 [[null_v4float]] %81
- ; CHECK: OpStore %_entryPointOutput_vColor %142
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Frag;
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + output_func,
- true, 7u, 23u, false, false,
- false, false, false);
- }
- TEST_F(InstBindlessTest, InstrumentSampledImage) {
- // This test verifies that the pass will correctly instrument shader
- // using sampled image. This test was created by editing the SPIR-V
- // from the Simple test.
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %39 = OpTypeSampledImage %20
- %_arr_39_uint_128 = OpTypeArray %39 %uint_128
- %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- ; CHECK: uint_0 = OpConstant %uint 0
- ; CHECK: bool = OpTypeBool
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func = R"(
- %MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2float %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
- %66 = OpLoad %39 %65
- %71 = OpImageSampleImplicitLod %v4float %66 %53
- OpStore %_entryPointOutput_vColor %71
- ; CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %66 %53
- ; CHECK-NOT: OpStore %_entryPointOutput_vColor %71
- ; CHECK: %74 = OpULessThan %bool %64 %uint_128
- ; CHECK: OpSelectionMerge %75 None
- ; CHECK: OpBranchConditional %74 %76 %77
- ; CHECK: %76 = OpLabel
- ; CHECK: %78 = OpLoad %39 %65
- ; CHECK: %79 = OpImageSampleImplicitLod %v4float %78 %53
- ; CHECK: OpBranch %75
- ; CHECK: %77 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_49 %uint_0 %64 %uint_128
- ; CHECK: OpBranch %75
- ; CHECK: %75 = OpLabel
- ; CHECK: %137 = OpPhi %v4float %79 %76 [[null_v4float]] %77
- ; CHECK: OpStore %_entryPointOutput_vColor %137
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Frag;
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + output_func,
- true, 7u, 23u, false, false,
- false, false, false);
- }
- TEST_F(InstBindlessTest, InstrumentImageWrite) {
- // This test verifies that the pass will correctly instrument shader
- // doing bindless image write. This test was created by editing the SPIR-V
- // from the Simple test.
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability StorageImageWriteWithoutFormat
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %80 = OpConstantNull %v4float
- %_arr_20_uint_128 = OpTypeArray %20 %uint_128
- %_ptr_UniformConstant__arr_20_uint_128 = OpTypePointer UniformConstant %_arr_20_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_20_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- )";
- // clang-format on
- const std::string main_func = R"(
- %MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2int %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
- %66 = OpLoad %20 %65
- OpImageWrite %66 %53 %80
- OpStore %_entryPointOutput_vColor %80
- ; CHECK-NOT: OpImageWrite %66 %53 %80
- ; CHECK-NOT: OpStore %_entryPointOutput_vColor %80
- ; CHECK: %35 = OpULessThan %bool %30 %uint_128
- ; CHECK: OpSelectionMerge %36 None
- ; CHECK: OpBranchConditional %35 %37 %38
- ; CHECK: %37 = OpLabel
- ; CHECK: %39 = OpLoad %16 %31
- ; CHECK: OpImageWrite %39 %28 %19
- ; CHECK: OpBranch %36
- ; CHECK: %38 = OpLabel
- ; CHECK: %95 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %30 %uint_128
- ; CHECK: OpBranch %36
- ; CHECK: %36 = OpLabel
- ; CHECK: OpStore %_entryPointOutput_vColor %19
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Frag;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + output_func,
- true, 7u, 23u, false, false,
- false, false, false);
- }
- TEST_F(InstBindlessTest, InstrumentVertexSimple) {
- // This test verifies that the pass will correctly instrument shader
- // doing bindless image write. This test was created by editing the SPIR-V
- // from the Simple test.
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability Sampled1D
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %_ %coords2D
- OpSource GLSL 450
- OpName %main "main"
- OpName %lod "lod"
- OpName %coords1D "coords1D"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %texSampler1D "texSampler1D"
- OpName %foo "foo"
- OpMemberName %foo 0 "g_idx"
- OpName %__0 ""
- OpName %coords2D "coords2D"
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
- ; CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpDecorate %texSampler1D DescriptorSet 0
- OpDecorate %texSampler1D Binding 3
- OpMemberDecorate %foo 0 Offset 0
- OpDecorate %foo Block
- OpDecorate %__0 DescriptorSet 0
- OpDecorate %__0 Binding 5
- OpDecorate %coords2D Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Function_float = OpTypePointer Function %float
- %float_3 = OpConstant %float 3
- %float_1_78900003 = OpConstant %float 1.78900003
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %21 = OpTypeImage %float 1D 0 0 0 1 Unknown
- %22 = OpTypeSampledImage %21
- %uint_128 = OpConstant %uint 128
- %_arr_22_uint_128 = OpTypeArray %22 %uint_128
- %_ptr_UniformConstant__arr_22_uint_128 = OpTypePointer UniformConstant %_arr_22_uint_128
- %texSampler1D = OpVariable %_ptr_UniformConstant__arr_22_uint_128 UniformConstant
- %foo = OpTypeStruct %int
- %_ptr_Uniform_foo = OpTypePointer Uniform %foo
- %__0 = OpVariable %_ptr_Uniform_foo Uniform
- %_ptr_Uniform_int = OpTypePointer Uniform %int
- %_ptr_UniformConstant_22 = OpTypePointer UniformConstant %22
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %v2float = OpTypeVector %float 2
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %coords2D = OpVariable %_ptr_Input_v2float Input
- ; CHECK: %bool = OpTypeBool
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_uint = OpTypePointer Input %uint
- ; CHECK: %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
- ; CHECK: %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %lod = OpVariable %_ptr_Function_float Function
- %coords1D = OpVariable %_ptr_Function_float Function
- OpStore %lod %float_3
- OpStore %coords1D %float_1_78900003
- %31 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
- %32 = OpLoad %int %31
- %34 = OpAccessChain %_ptr_UniformConstant_22 %texSampler1D %32
- %35 = OpLoad %22 %34
- %36 = OpLoad %float %coords1D
- %37 = OpLoad %float %lod
- %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
- %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %40 %38
- ; CHECK-NOT: %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
- ; CHECK-NOT: %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- ; CHECK-NOT: OpStore %40 %38
- ; CHECK: %46 = OpULessThan %bool %37 %uint_128
- ; CHECK: OpSelectionMerge %47 None
- ; CHECK: OpBranchConditional %46 %48 %49
- ; CHECK: %48 = OpLabel
- ; CHECK: %50 = OpLoad %25 %38
- ; CHECK: %51 = OpImageSampleExplicitLod %v4float %50 %40 Lod %41
- ; CHECK: OpBranch %47
- ; CHECK: %49 = OpLabel
- ; CHECK: [[bitcast_result:%\w+]] = OpBitcast %uint %37
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_74 %uint_0 [[bitcast_result]] %uint_128
- ; CHECK: OpBranch %47
- ; CHECK: %47 = OpLabel
- ; CHECK: %107 = OpPhi %v4float %51 %48 [[null_v4float]] %49
- ; CHECK: %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- ; CHECK: OpStore %43 %107
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Vert;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + output_func,
- true, 7u, 23u, false, false,
- false, false, false);
- }
- TEST_F(InstBindlessTest, InstrumentTeseSimple) {
- // This test verifies that the pass will correctly instrument tessellation
- // evaluation shader doing bindless buffer load.
- //
- // clang-format off
- //
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(std140, set = 0, binding = 0) uniform ufoo { uint index; } uniform_index_buffer;
- //
- // layout(set = 0, binding = 1) buffer bfoo { vec4 val; } adds[11];
- //
- // layout(triangles, equal_spacing, cw) in;
- //
- // void main() {
- // gl_Position = adds[uniform_index_buffer.index].val;
- // }
- //
- const std::string defs = R"(
- OpCapability Tessellation
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main" %_
- ; CHECK: OpEntryPoint TessellationEvaluation %main "main" %_ %gl_PrimitiveID %gl_TessCoord
- OpExecutionMode %main Triangles
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main VertexOrderCw
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %bfoo "bfoo"
- OpMemberName %bfoo 0 "val"
- OpName %adds "adds"
- OpName %ufoo "ufoo"
- OpMemberName %ufoo 0 "index"
- OpName %uniform_index_buffer "uniform_index_buffer"
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpMemberDecorate %bfoo 0 Offset 0
- OpDecorate %bfoo Block
- OpDecorate %adds DescriptorSet 0
- OpDecorate %adds Binding 1
- OpMemberDecorate %ufoo 0 Offset 0
- OpDecorate %ufoo Block
- OpDecorate %uniform_index_buffer DescriptorSet 0
- OpDecorate %uniform_index_buffer Binding 0
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId
- ; CHECK: OpDecorate %gl_TessCoord BuiltIn TessCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %bfoo = OpTypeStruct %v4float
- %uint_11 = OpConstant %uint 11
- %_arr_bfoo_uint_11 = OpTypeArray %bfoo %uint_11
- %_ptr_StorageBuffer__arr_bfoo_uint_11 = OpTypePointer StorageBuffer %_arr_bfoo_uint_11
- %adds = OpVariable %_ptr_StorageBuffer__arr_bfoo_uint_11 StorageBuffer
- %ufoo = OpTypeStruct %uint
- %_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
- %uniform_index_buffer = OpVariable %_ptr_Uniform_ufoo Uniform
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- ; CHECK: %bool = OpTypeBool
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_uint = OpTypePointer Input %uint
- ; CHECK: %gl_PrimitiveID = OpVariable %_ptr_Input_uint Input
- ; CHECK: %v3float = OpTypeVector %float 3
- ; CHECK: %_ptr_Input_v3float = OpTypePointer Input %v3float
- ; CHECK: %gl_TessCoord = OpVariable %_ptr_Input_v3float Input
- ; CHECK: %v3uint = OpTypeVector %uint 3
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0
- %26 = OpLoad %uint %25
- %28 = OpAccessChain %_ptr_StorageBuffer_v4float %adds %26 %int_0
- %29 = OpLoad %v4float %28
- ; CHECK-NOT: %29 = OpLoad %v4float %28
- ; CHECK: %34 = OpULessThan %bool %28 %uint_11
- ; CHECK: OpSelectionMerge %35 None
- ; CHECK: OpBranchConditional %34 %36 %37
- ; CHECK: %36 = OpLabel
- ; CHECK: %38 = OpLoad %v4float %29
- ; CHECK: OpBranch %35
- ; CHECK: %37 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_63 %uint_0 %28 %uint_11
- ; CHECK: OpBranch %35
- ; CHECK: %35 = OpLabel
- ; CHECK: %102 = OpPhi %v4float %38 %36 [[null_v4float]] %37
- %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %31 %29
- ; CHECK-NOT: OpStore %31 %29
- ; CHECK: OpStore %31 %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Tese;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + output_func,
- true, 7u, 23u, false, false,
- false, false, false);
- }
- TEST_F(InstBindlessTest, MultipleDebugFunctions) {
- // Same source as Simple, but compiled -g and not optimized, especially not
- // inlined. The OpSource has had the source extracted for the sake of brevity.
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %2 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- %1 = OpString "foo5.frag"
- OpSource HLSL 500 %1
- OpName %MainPs "MainPs"
- OpName %PS_INPUT "PS_INPUT"
- OpMemberName %PS_INPUT 0 "vTextureCoords"
- OpName %PS_OUTPUT "PS_OUTPUT"
- OpMemberName %PS_OUTPUT 0 "vColor"
- OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
- OpName %i "i"
- OpName %ps_output "ps_output"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_0 "i"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpName %param "param"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 1
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %4 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %PS_INPUT = OpTypeStruct %v2float
- %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
- %v4float = OpTypeVector %float 4
- %PS_OUTPUT = OpTypeStruct %v4float
- %13 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
- %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %21 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_21_uint_128 = OpTypeArray %21 %uint_128
- %_ptr_UniformConstant__arr_21_uint_128 = OpTypePointer UniformConstant %_arr_21_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_21_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
- %36 = OpTypeSampler
- %_ptr_UniformConstant_36 = OpTypePointer UniformConstant %36
- %g_sAniso = OpVariable %_ptr_UniformConstant_36 UniformConstant
- %40 = OpTypeSampledImage %21
- %_ptr_Function_v2float = OpTypePointer Function %v2float
- %_ptr_Function_v4float = OpTypePointer Function %v4float
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- ; CHECK: %bool = OpTypeBool
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string func1 = R"(
- %MainPs = OpFunction %void None %4
- %6 = OpLabel
- %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
- %param = OpVariable %_ptr_Function_PS_INPUT Function
- OpLine %1 21 0
- %54 = OpLoad %v2float %i_vTextureCoords
- %55 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
- OpStore %55 %54
- %59 = OpLoad %PS_INPUT %i_0
- OpStore %param %59
- %60 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
- %61 = OpCompositeExtract %v4float %60 0
- OpStore %_entryPointOutput_vColor %61
- OpReturn
- OpFunctionEnd
- )";
- const std::string func2 = R"(
- %_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %13
- %i = OpFunctionParameter %_ptr_Function_PS_INPUT
- %16 = OpLabel
- %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
- OpLine %1 24 0
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %34 = OpAccessChain %_ptr_UniformConstant_21 %g_tColor %32
- %35 = OpLoad %21 %34
- %39 = OpLoad %36 %g_sAniso
- %41 = OpSampledImage %40 %35 %39
- %43 = OpAccessChain %_ptr_Function_v2float %i %int_0
- %44 = OpLoad %v2float %43
- %45 = OpImageSampleImplicitLod %v4float %41 %44
- ; CHECK-NOT: %45 = OpImageSampleImplicitLod %v4float %41 %44
- ; CHECK: OpNoLine
- ; CHECK: %62 = OpULessThan %bool %50 %uint_128
- ; CHECK: OpSelectionMerge %63 None
- ; CHECK: OpBranchConditional %62 %64 %65
- ; CHECK: %64 = OpLabel
- ; CHECK: %66 = OpLoad %27 %51
- ; CHECK: %67 = OpSampledImage %37 %66 %53
- ; CHECK: OpLine %5 24 0
- ; CHECK: %68 = OpImageSampleImplicitLod %v4float %67 %56
- ; CHECK: OpNoLine
- ; CHECK: OpBranch %63
- ; CHECK: %65 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_109 %uint_0 %50 %uint_128
- ; CHECK: OpBranch %63
- ; CHECK: %63 = OpLabel
- ; CHECK: [[phi_result:%\w+]] = OpPhi %v4float %68 %64 [[null_v4float]] %65
- ; CHECK: OpLine %5 24 0
- %47 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
- OpStore %47 %45
- ; CHECK-NOT: OpStore %47 %45
- ; CHECK: [[store_loc:%\w+]] = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
- ; CHECK: OpStore [[store_loc]] [[phi_result]]
- OpLine %1 25 0
- %48 = OpLoad %PS_OUTPUT %ps_output
- OpReturnValue %48
- OpFunctionEnd
- )";
- const std::string output_func = kStreamWrite4Frag;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(
- defs + func1 + func2 + output_func, true, 7u, 23u, false, false, false,
- false, false);
- }
- TEST_F(InstBindlessTest, RuntimeArray) {
- // This test verifies that the pass will correctly instrument shader
- // with runtime descriptor array. This test was created by editing the
- // SPIR-V from the Simple test.
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 1
- OpDecorate %g_tColor Binding 2
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 1
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_rarr_20 = OpTypeRuntimeArray %20
- %_ptr_UniformConstant__arr_20 = OpTypePointer UniformConstant %_rarr_20
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_20 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
- %35 = OpTypeSampler
- %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
- %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
- %39 = OpTypeSampledImage %20
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- ; CHECK: %41 = OpTypeFunction %uint %uint %uint
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kInputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %bool = OpTypeBool
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func = R"(
- %MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2float %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
- %66 = OpLoad %20 %65
- %67 = OpLoad %35 %g_sAniso
- %68 = OpSampledImage %39 %66 %67
- %71 = OpImageSampleImplicitLod %v4float %68 %53
- OpStore %_entryPointOutput_vColor %71
- ; CHECK-NOT: %71 = OpImageSampleImplicitLod %v4float %68 %53
- ; CHECK-NOT: OpStore %_entryPointOutput_vColor %71
- ; CHECK: %55 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_2 %uint_2
- ; CHECK: %57 = OpULessThan %bool %32 %55
- ; CHECK: OpSelectionMerge %58 None
- ; CHECK: OpBranchConditional %57 %59 %60
- ; CHECK: %59 = OpLabel
- ; CHECK: %61 = OpLoad %16 %33
- ; CHECK: %62 = OpSampledImage %26 %61 %35
- ; CHECK: %136 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_1 %uint_2 %32
- ; CHECK: %137 = OpULessThan %bool %uint_0 %136
- ; CHECK: OpSelectionMerge %138 None
- ; CHECK: OpBranchConditional %137 %139 %140
- ; CHECK: %139 = OpLabel
- ; CHECK: %141 = OpLoad %16 %33
- ; CHECK: %142 = OpSampledImage %26 %141 %35
- ; CHECK: %143 = OpImageSampleImplicitLod %v4float %142 %30
- ; CHECK: OpBranch %138
- ; CHECK: %140 = OpLabel
- ; CHECK: %144 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_59 %uint_1 %32 %uint_0
- ; CHECK: OpBranch %138
- ; CHECK: %138 = OpLabel
- ; CHECK: [[phi_result_1:%\w+]] = OpPhi %v4float %143 %139 [[null_v4float]] %140
- ; CHECK: OpBranch %58
- ; CHECK: %60 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_59 %uint_0 %32 %55
- ; CHECK: OpBranch %58
- ; CHECK: %58 = OpLabel
- ; CHECK: [[phi_result_2:%\w+]] = OpPhi %v4float [[phi_result_1]] %138 [[null_v4float]] %60
- ; CHECK: OpStore %_entryPointOutput_vColor [[phi_result_2]]
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Frag + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptor) {
- // This test verifies that the pass will correctly instrument vanilla
- // texture sample on a scalar descriptor with an initialization check if the
- // input_init_enable argument is set to true. This can happen when the
- // descriptor indexing extension is enabled in the API but the SPIR-V
- // does not have the extension enabled because it does not contain a
- // runtime array. This is the same shader as NoInstrumentNonBindless.
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- ; CHECK: OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ; check: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; check: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
- %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %16 = OpTypeSampledImage %12
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- ; CHECK: %uint = OpTypeInt 32 0
- ; CHECK: %28 = OpTypeFunction %uint %uint %uint %uint %uint
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kInputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %bool = OpTypeBool
- )" + kOutputGlobals + R"(
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )";
- // clang-format on
- const std::string main_func = R"(
- %MainPs = OpFunction %void None %8
- %19 = OpLabel
- %20 = OpLoad %v2float %i_vTextureCoords
- %21 = OpLoad %12 %g_tColor
- %22 = OpLoad %14 %g_sAniso
- %23 = OpSampledImage %16 %21 %22
- %24 = OpImageSampleImplicitLod %v4float %23 %20
- OpStore %_entryPointOutput_vColor %24
- ; CHECK-NOT: %24 = OpImageSampleImplicitLod %v4float %23 %20
- ; CHECK-NOT: OpStore %_entryPointOutput_vColor %24
- ; CHECK: %50 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %52 = OpULessThan %bool %uint_0 %50
- ; CHECK: OpSelectionMerge %54 None
- ; CHECK: OpBranchConditional %52 %55 %56
- ; CHECK: %55 = OpLabel
- ; CHECK: %57 = OpLoad %12 %g_tColor
- ; CHECK: %58 = OpSampledImage %16 %57 %22
- ; CHECK: %59 = OpImageSampleImplicitLod %v4float %58 %20
- ; CHECK: OpBranch %54
- ; CHECK: %56 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_39 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %54
- ; CHECK: %54 = OpLabel
- ; CHECK: [[phi_result:%\w+]] = OpPhi %v4float %59 %55 [[null_v4float]] %56
- ; CHECK: OpStore %_entryPointOutput_vColor [[phi_result]]
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead4 + kStreamWrite4Frag;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, SPV14AddToEntryPoint) {
- const std::string text = R"(
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpDecorate [[v1]] DescriptorSet 7
- ; CHECK: OpDecorate [[v2]] DescriptorSet 7
- ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
- ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
- OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
- OpExecutionMode %foo OriginUpperLeft
- OpDecorate %image_var DescriptorSet 0
- OpDecorate %image_var Binding 0
- OpDecorate %sampler_var DescriptorSet 0
- OpDecorate %sampler_var Binding 1
- OpDecorate %gid DescriptorSet 0
- OpDecorate %gid Binding 2
- OpDecorate %struct Block
- OpMemberDecorate %struct 0 Offset 0
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int_0 = OpConstant %int 0
- %v3int = OpTypeVector %int 3
- %float = OpTypeFloat 32
- %v3float = OpTypeVector %float 3
- %v4float = OpTypeVector %float 4
- %struct = OpTypeStruct %v3int
- %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
- %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
- %gid = OpVariable %ptr_ssbo_struct StorageBuffer
- %image = OpTypeImage %float 3D 0 0 0 1 Unknown
- %ptr_uc_image = OpTypePointer UniformConstant %image
- %sampler = OpTypeSampler
- %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
- %image_var = OpVariable %ptr_uc_image UniformConstant
- %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
- %sampled = OpTypeSampledImage %image
- %void_fn = OpTypeFunction %void
- %foo = OpFunction %void None %void_fn
- %entry = OpLabel
- %ld_image = OpLoad %image %image_var
- %ld_sampler = OpLoad %sampler %sampler_var
- %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
- %ld_gid = OpLoad %v3int %gep
- %convert = OpConvertUToF %v3float %ld_gid
- %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
- %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
- OpReturn
- OpFunctionEnd
- )";
- SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
- false, false, false);
- }
- TEST_F(InstBindlessTest, SPV14AddToEntryPoints) {
- const std::string text = R"(
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpDecorate [[v1]] DescriptorSet 7
- ; CHECK: OpDecorate [[v2]] DescriptorSet 7
- ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
- ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
- OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
- OpEntryPoint Fragment %foo "bar" %gid %image_var %sampler_var
- OpExecutionMode %foo OriginUpperLeft
- OpDecorate %image_var DescriptorSet 0
- OpDecorate %image_var Binding 0
- OpDecorate %sampler_var DescriptorSet 0
- OpDecorate %sampler_var Binding 1
- OpDecorate %gid DescriptorSet 0
- OpDecorate %gid Binding 2
- OpDecorate %struct Block
- OpMemberDecorate %struct 0 Offset 0
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int_0 = OpConstant %int 0
- %v3int = OpTypeVector %int 3
- %float = OpTypeFloat 32
- %v3float = OpTypeVector %float 3
- %v4float = OpTypeVector %float 4
- %struct = OpTypeStruct %v3int
- %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
- %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
- %gid = OpVariable %ptr_ssbo_struct StorageBuffer
- %image = OpTypeImage %float 3D 0 0 0 1 Unknown
- %ptr_uc_image = OpTypePointer UniformConstant %image
- %sampler = OpTypeSampler
- %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
- %image_var = OpVariable %ptr_uc_image UniformConstant
- %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
- %sampled = OpTypeSampledImage %image
- %void_fn = OpTypeFunction %void
- %foo = OpFunction %void None %void_fn
- %entry = OpLabel
- %ld_image = OpLoad %image %image_var
- %ld_sampler = OpLoad %sampler %sampler_var
- %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
- %ld_gid = OpLoad %v3int %gep
- %convert = OpConvertUToF %v3float %ld_gid
- %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
- %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
- OpReturn
- OpFunctionEnd
- )";
- SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
- false, false, false);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedUBOArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) uniform uname { float a; } uniformBuffer[];
- //
- // void main()
- // {
- // b = uniformBuffer[nu_ii].a;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- ; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + R"(
- ; CHECK: OpDecorate %130 NonUniform
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- ; CHECK: OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_runtimearr_uname = OpTypeRuntimeArray %uname
- %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
- %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- ; CHECK: %uint = OpTypeInt 32 0
- ; CHECK: %26 = OpTypeFunction %uint %uint %uint
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kInputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %bool = OpTypeBool
- )" + kOutputGlobals + R"(
- ; CHECK: %v4float = OpTypeVector %float 4
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_float:%\w+]] = OpConstantNull %float
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- ; CHECK-NOT: %20 = OpLoad %float %19
- ; CHECK-NOT: OpStore %b %20
- ; CHECK: %40 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_3
- ; CHECK: %42 = OpULessThan %bool %7 %40
- ; CHECK: OpSelectionMerge %43 None
- ; CHECK: OpBranchConditional %42 %44 %45
- ; CHECK: %44 = OpLabel
- ; CHECK: %103 = OpBitcast %uint %7
- ; CHECK: %122 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_3 %103
- ; CHECK: %123 = OpULessThan %bool %uint_0 %122
- ; CHECK: OpSelectionMerge %124 None
- ; CHECK: OpBranchConditional %123 %125 %126
- ; CHECK: %125 = OpLabel
- ; CHECK: %127 = OpLoad %float %20
- ; CHECK: OpBranch %124
- ; CHECK: %126 = OpLabel
- ; CHECK: %128 = OpBitcast %uint %7
- ; CHECK: %129 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_1 %128 %uint_0
- ; CHECK: OpBranch %124
- ; CHECK: %124 = OpLabel
- ; CHECK: [[phi_result_1:%\w+]] = OpPhi %float %127 %125 [[null_float]] %126
- ; CHECK: OpBranch %43
- ; CHECK: %45 = OpLabel
- ; CHECK: [[bitcast_result:%\w+]] = OpBitcast %uint %7
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_0 [[bitcast_result]] %40
- ; CHECK: OpBranch %43
- ; CHECK: %43 = OpLabel
- ; CHECK: [[phi_result_2:%\w+]] = OpPhi %float [[phi_result_1]] %124 [[null_float]] %45
- ; CHECK: OpStore %b [[phi_result_2]]
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Frag + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayDeprecated) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) buffer bname { float b; } storageBuffer[];
- //
- // void main()
- // {
- // b = storageBuffer[nu_ii].b;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- ; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + R"(
- ; CHECK: OpDecorate %130 NonUniform
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- ; CHECK: OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- ; CHECK: %uint = OpTypeInt 32 0
- ; CHECK: %26 = OpTypeFunction %uint %uint %uint
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kInputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %bool = OpTypeBool
- )" + kOutputGlobals + R"(
- ; CHECK: %v4float = OpTypeVector %float 4
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_float:%\w+]] = OpConstantNull %float
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- ; CHECK-NOT: %20 = OpLoad %float %19
- ; CHECK-NOT: OpStore %b %20
- ; CHECK: %40 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_3
- ; CHECK: %42 = OpULessThan %bool %7 %40
- ; CHECK: OpSelectionMerge %43 None
- ; CHECK: OpBranchConditional %42 %44 %45
- ; CHECK: %44 = OpLabel
- ; CHECK: [[bitcast_result_1:%\w+]] = OpBitcast %uint %7
- ; CHECK: %122 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_3 [[bitcast_result_1]]
- ; CHECK: %123 = OpULessThan %bool %uint_0 %122
- ; CHECK: OpSelectionMerge %124 None
- ; CHECK: OpBranchConditional %123 %125 %126
- ; CHECK: %125 = OpLabel
- ; CHECK: %127 = OpLoad %float %20
- ; CHECK: OpBranch %124
- ; CHECK: %126 = OpLabel
- ; CHECK: %128 = OpBitcast %uint %7
- ; CHECK: %129 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_1 %128 %uint_0
- ; CHECK: OpBranch %124
- ; CHECK: %124 = OpLabel
- ; CHECK: [[phi_result_1:%\w+]] = OpPhi %float %127 %125 [[null_float]] %126
- ; CHECK: OpBranch %43
- ; CHECK: %45 = OpLabel
- ; CHECK: [[bitcast_result_2:%\w+]] = OpBitcast %uint %7
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_0 [[bitcast_result_2]] %40
- ; CHECK: OpBranch %43
- ; CHECK: %43 = OpLabel
- ; CHECK: [[phi_result_2:%\w+]] = OpPhi %float [[phi_result_1]] %124 [[null_float]] %45
- ; CHECK: OpStore %b [[phi_result_2]]
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Frag + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArray) {
- // Same as Deprecated but declaring as StorageBuffer Block
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- ; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + R"(
- ; CHECK: OpDecorate %130 NonUniform
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- ; CHECK: OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- ; CHECK: %uint = OpTypeInt 32 0
- ; CHECK: %26 = OpTypeFunction %uint %uint %uint
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kInputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %bool = OpTypeBool
- )" + kOutputGlobals + R"(
- ; CHECK: %v4float = OpTypeVector %float 4
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_float:%\w+]] = OpConstantNull %float
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- ; CHECK-NOT: %20 = OpLoad %float %19
- ; CHECK-NOT: OpStore %b %20
- ; CHECK: %40 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_3
- ; CHECK: %42 = OpULessThan %bool %7 %40
- ; CHECK: OpSelectionMerge %43 None
- ; CHECK: OpBranchConditional %42 %44 %45
- ; CHECK: %44 = OpLabel
- ; CHECK: %103 = OpBitcast %uint %7
- ; CHECK: %122 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_3 %103
- ; CHECK: %123 = OpULessThan %bool %uint_0 %122
- ; CHECK: OpSelectionMerge %124 None
- ; CHECK: OpBranchConditional %123 %125 %126
- ; CHECK: %125 = OpLabel
- ; CHECK: %127 = OpLoad %float %20
- ; CHECK: OpBranch %124
- ; CHECK: %126 = OpLabel
- ; CHECK: %128 = OpBitcast %uint %7
- ; CHECK: %129 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_1 %128 %uint_0
- ; CHECK: OpBranch %124
- ; CHECK: %124 = OpLabel
- ; CHECK: [[phi_result_1:%\w+]] = OpPhi %float %127 %125 [[null_float]] %126
- ; CHECK: OpBranch %43
- ; CHECK: %45 = OpLabel
- ; CHECK: [[bitcast_result:%\w+]] = OpBitcast %uint %7
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_0 [[bitcast_result]] %40
- ; CHECK: OpBranch %43
- ; CHECK: %43 = OpLabel
- ; CHECK: [[phi_result_2:%\w+]] = OpPhi %float [[phi_result_1]] %124 [[null_float]] %45
- ; CHECK: OpStore %b [[phi_result_2]]
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Frag + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, InstInitLoadUBOScalar) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) out float b;
- // layout(binding=3) uniform uname { float a; } uniformBuffer;
- //
- // void main()
- // {
- // b = uniformBuffer.a;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b
- ; CHECK: OpEntryPoint Fragment %main "main" %b %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_ptr_Uniform_uname = OpTypePointer Uniform %uname
- %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- ; CHECK: %int = OpTypeInt 32 1
- ; CHECK: %_ptr_Uniform_float = OpTypePointer Uniform %float
- ; CHECK: %uint = OpTypeInt 32 0
- ; CHECK: %21 = OpTypeFunction %uint %uint %uint %uint %uint
- ; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kInputGlobals + R"(
- ; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ; CHECK: %bool = OpTypeBool
- )" + kOutputGlobals + R"(
- ; CHECK: %v4float = OpTypeVector %float 4
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_float:%\w+]] = OpConstantNull %float
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
- %16 = OpLoad %float %15
- OpStore %b %16
- ; CHECK-NOT: %16 = OpLoad %float %15
- ; CHECK-NOT: OpStore %b %16
- ; CHECK: %43 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_3 %uint_0
- ; CHECK: %45 = OpULessThan %bool %uint_0 %43
- ; CHECK: OpSelectionMerge %47 None
- ; CHECK: OpBranchConditional %45 %48 %49
- ; CHECK: %48 = OpLabel
- ; CHECK: %50 = OpLoad %float %15
- ; CHECK: OpBranch %47
- ; CHECK: %49 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_32 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %47
- ; CHECK: %47 = OpLabel
- ; CHECK: [[phi_result:%\w+]] = OpPhi %float %50 %48 [[null_float]] %49
- ; CHECK: OpStore %b [[phi_result]]
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead4 + kStreamWrite4Frag;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=1) in float b;
- //
- // layout(binding=4) buffer bname { float b; } storageBuffer[];
- //
- // void main()
- // {
- // storageBuffer[nu_ii].b = b;
- // }
- // clang-format off
- const std::string defs = R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %nu_ii %b
- ; CHECK: OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %bname "bname"
- OpMemberName %bname 0 "b"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpName %b "b"
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname BufferBlock
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 4
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %14 NonUniform
- OpDecorate %b Location 1
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Input_float = OpTypePointer Input %float
- %b = OpVariable %_ptr_Input_float Input
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: %102 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %14 = OpLoad %int %nu_ii
- %18 = OpLoad %float %b
- %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %14 %int_0
- OpStore %20 %18
- ; CHECK-NOT: OpStore %20 %18
- ; CHECK: %40 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_4
- ; CHECK: %42 = OpULessThan %bool %7 %40
- ; CHECK: OpSelectionMerge %43 None
- ; CHECK: OpBranchConditional %42 %44 %45
- ; CHECK: %44 = OpLabel
- ; CHECK: %100 = OpBitcast %uint %7
- ; CHECK: %119 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_4 %100
- ; CHECK: %120 = OpULessThan %bool %uint_0 %119
- ; CHECK: OpSelectionMerge %121 None
- ; CHECK: OpBranchConditional %120 %122 %123
- ; CHECK: %122 = OpLabel
- ; CHECK: OpStore %20 %19
- ; CHECK: OpBranch %121
- ; CHECK: %123 = OpLabel
- ; CHECK: %124 = OpBitcast %uint %7
- ; CHECK: %125 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_1 %124 %uint_0
- ; CHECK: OpBranch %121
- ; CHECK: %121 = OpLabel
- ; CHECK: OpBranch %43
- ; CHECK: %45 = OpLabel
- ; CHECK: %46 = OpBitcast %uint %7
- ; CHECK: %99 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_45 %uint_0 %46 %40
- ; CHECK: OpBranch %43
- ; CHECK: %43 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Frag + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) uniform uname { float a; } uniformBuffer[128];
- //
- // void main()
- // {
- // b = uniformBuffer[nu_ii].a;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- ; CHECK: OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %18 NonUniform
- OpDecorate %22 NonUniform
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- )" + kInputDecorations + R"(
- ; CHECK: OpDecorate %117 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
- %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
- %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kOutputGlobals + R"(
- ; CHECK: %v4float = OpTypeVector %float 4
- ; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ; CHECK: %v4uint = OpTypeVector %uint 4
- ; CHECK: [[null_float:%\w+]] = OpConstantNull %float
- )" + kInputGlobals;
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %18 = OpLoad %int %nu_ii
- %21 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %18 %int_0
- %22 = OpLoad %float %21
- OpStore %b %22
- ; CHECK-NOT: %22 = OpLoad %float %21
- ; CHECK-NOT: OpStore %b %22
- ; CHECK: %25 = OpULessThan %bool %7 %uint_128
- ; CHECK: OpSelectionMerge %26 None
- ; CHECK: OpBranchConditional %25 %27 %28
- ; CHECK: %27 = OpLabel
- ; CHECK: %90 = OpBitcast %uint %7
- ; CHECK: %112 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_3 %90
- ; CHECK: %113 = OpULessThan %bool %uint_0 %112
- ; CHECK: OpSelectionMerge %114 None
- ; CHECK: OpBranchConditional %113 %115 %116
- ; CHECK: %115 = OpLabel
- ; CHECK: %117 = OpLoad %float %22
- ; CHECK: OpBranch %114
- ; CHECK: %116 = OpLabel
- ; CHECK: %118 = OpBitcast %uint %7
- ; CHECK: %119 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_46 %uint_1 %118 %uint_0
- ; CHECK: OpBranch %114
- ; CHECK: %114 = OpLabel
- ; CHECK: [[phi_result_1:%\w+]] = OpPhi %float %117 %115 [[null_float]] %116
- ; CHECK: OpBranch %26
- ; CHECK: %28 = OpLabel
- ; CHECK: [[bitcast_result:%\w+]] = OpBitcast %uint %7
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_46 %uint_0 [[bitcast_result]] %uint_128
- ; CHECK: OpBranch %26
- ; CHECK: %26 = OpLabel
- ; CHECK: [[phi_result_2:%\w+]] = OpPhi %float [[phi_result_1]] %114 [[null_float]] %28
- ; CHECK: OpStore %b [[phi_result_2]]
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kStreamWrite4Frag + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest,
- InstBoundsComputeShaderInitLoadVariableSizedSampledImagesArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout (local_size_x = 1, local_size_y = 1) in;
- //
- // layout(set = 0, binding = 0, std140) buffer Input {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- ; CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
- OpExecutionMode %main LocalSize 1 1 1
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %Input "Input"
- OpMemberName %Input 0 "index"
- OpMemberName %Input 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %Input 0 Offset 0
- OpMemberDecorate %Input 1 Offset 4
- OpDecorate %Input BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %Input = OpTypeStruct %uint %float
- %_ptr_Uniform_Input = OpTypePointer Uniform %Input
- %sbo = OpVariable %_ptr_Uniform_Input Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: %v3uint = OpTypeVector %uint 3
- ; CHECK: %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- ; CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- ; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- ; CHECK-NOT: OpStore %31 %29
- ; CHECK: %132 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %133 = OpULessThan %bool %uint_0 %132
- ; CHECK: OpSelectionMerge %134 None
- ; CHECK: OpBranchConditional %133 %135 %136
- ; CHECK: %135 = OpLabel
- ; CHECK: %137 = OpLoad %uint %25
- ; CHECK: OpBranch %134
- ; CHECK: %136 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_47 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %134
- ; CHECK: %134 = OpLabel
- ; CHECK: [[phi_result_1:%\w+]] = OpPhi %uint %137 %135 [[null_uint]] %136
- ; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images %141
- ; CHECK: %28 = OpLoad %13 %27
- ; CHECK: %48 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_1
- ; CHECK: %50 = OpULessThan %bool %141 %48
- ; CHECK: OpSelectionMerge %51 None
- ; CHECK: OpBranchConditional %50 %52 %53
- ; CHECK: %52 = OpLabel
- ; CHECK: %54 = OpLoad %13 %27
- ; CHECK: {{%\w+}} = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_1 [[phi_result_1]]
- ; CHECK: %143 = OpULessThan %bool %uint_0 %142
- ; CHECK: OpSelectionMerge %144 None
- ; CHECK: OpBranchConditional %143 %145 %146
- ; CHECK: %145 = OpLabel
- ; CHECK: %147 = OpLoad %13 %27
- ; CHECK: %148 = OpImageRead %v4float %147 %20
- ; CHECK: OpBranch %144
- ; CHECK: %146 = OpLabel
- ; CHECK: %149 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_50 %uint_1 %141 %uint_0
- ; CHECK: OpBranch %144
- ; CHECK: %144 = OpLabel
- ; CHECK: [[phi_result_2:%\w+]] = OpPhi %v4float %148 %145 [[null_v4float]] %146
- ; CHECK: OpBranch %51
- ; CHECK: %53 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_50 %uint_0 %141 %48
- ; CHECK: OpBranch %51
- ; CHECK: %51 = OpLabel
- ; CHECK: %113 = OpPhi %v4float [[phi_result_2]] %144 [[null_v4float]] %53
- ; CHECK: %30 = OpCompositeExtract %float %113 0
- ; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- ; CHECK: %151 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %152 = OpULessThan %bool %uint_0 %151
- ; CHECK: OpSelectionMerge %153 None
- ; CHECK: OpBranchConditional %152 %154 %155
- ; CHECK: %154 = OpLabel
- ; CHECK: OpStore %31 %30
- ; CHECK: OpBranch %153
- ; CHECK: %155 = OpLabel
- ; CHECK: %157 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_53 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %153
- ; CHECK: %153 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- kDirectRead2 + kStreamWrite4Compute + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest,
- InstBoundsRayGenerationInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint RayGenerationNV %main "main"
- ; CHECK: OpEntryPoint RayGenerationNV %main "main" [[launch_id:%\w+]]
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- ; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- ; CHECK-NOT: OpStore %31 %29
- ; CHECK: %133 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %134 = OpULessThan %bool %uint_0 %133
- ; CHECK: OpSelectionMerge %135 None
- ; CHECK: OpBranchConditional %134 %136 %137
- ; CHECK: %136 = OpLabel
- ; CHECK: %138 = OpLoad %uint %25
- ; CHECK: OpBranch %135
- ; CHECK: %137 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_48 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %135
- ; CHECK: %135 = OpLabel
- ; CHECK: %142 = OpPhi %uint %138 %136 [[null_uint]] %137
- ; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- ; CHECK: %28 = OpLoad %13 %27
- ; CHECK: %48 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_1
- ; CHECK: %50 = OpULessThan %bool %142 %48
- ; CHECK: OpSelectionMerge %51 None
- ; CHECK: OpBranchConditional %50 %52 %53
- ; CHECK: %52 = OpLabel
- ; CHECK: %54 = OpLoad %13 %27
- ; CHECK: %143 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_1 %142
- ; CHECK: %144 = OpULessThan %bool %uint_0 %143
- ; CHECK: OpSelectionMerge %145 None
- ; CHECK: OpBranchConditional %144 %146 %147
- ; CHECK: %146 = OpLabel
- ; CHECK: %148 = OpLoad %13 %27
- ; CHECK: %149 = OpImageRead %v4float %148 %20
- ; CHECK: OpBranch %145
- ; CHECK: %147 = OpLabel
- ; CHECK: %150 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_1 %142 %uint_0
- ; CHECK: OpBranch %145
- ; CHECK: %145 = OpLabel
- ; CHECK: %151 = OpPhi %v4float %149 %146 [[null_v4float]] %147
- ; CHECK: OpBranch %51
- ; CHECK: %53 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %142 %48
- ; CHECK: OpBranch %51
- ; CHECK: %51 = OpLabel
- ; CHECK: %114 = OpPhi %v4float %151 %145 [[null_v4float]] %53
- ; CHECK: %30 = OpCompositeExtract %float %114 0
- ; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- ; CHECK: %152 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %153 = OpULessThan %bool %uint_0 %152
- ; CHECK: OpSelectionMerge %154 None
- ; CHECK: OpBranchConditional %153 %155 %156
- ; CHECK: %155 = OpLabel
- ; CHECK: OpStore %31 %30
- ; CHECK: OpBranch %154
- ; CHECK: %156 = OpLabel
- ; CHECK: %158 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_54 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %154
- ; CHECK: %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Ray + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest,
- InstBoundsIntersectionInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint IntersectionNV %main "main"
- ; CHECK: OpEntryPoint IntersectionNV %main "main" [[launch_id:%\w+]]
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- ; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- ; CHECK-NOT: OpStore %31 %29
- ; CHECK: %133 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %134 = OpULessThan %bool %uint_0 %133
- ; CHECK: OpSelectionMerge %135 None
- ; CHECK: OpBranchConditional %134 %136 %137
- ; CHECK: %136 = OpLabel
- ; CHECK: %138 = OpLoad %uint %25
- ; CHECK: OpBranch %135
- ; CHECK: %137 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_48 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %135
- ; CHECK: %135 = OpLabel
- ; CHECK: %142 = OpPhi %uint %138 %136 [[null_uint]] %137
- ; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- ; CHECK: %28 = OpLoad %13 %27
- ; CHECK: %48 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_1
- ; CHECK: %50 = OpULessThan %bool %142 %48
- ; CHECK: OpSelectionMerge %51 None
- ; CHECK: OpBranchConditional %50 %52 %53
- ; CHECK: %52 = OpLabel
- ; CHECK: %54 = OpLoad %13 %27
- ; CHECK: %143 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_1 %142
- ; CHECK: %144 = OpULessThan %bool %uint_0 %143
- ; CHECK: OpSelectionMerge %145 None
- ; CHECK: OpBranchConditional %144 %146 %147
- ; CHECK: %146 = OpLabel
- ; CHECK: %148 = OpLoad %13 %27
- ; CHECK: %149 = OpImageRead %v4float %148 %20
- ; CHECK: OpBranch %145
- ; CHECK: %147 = OpLabel
- ; CHECK: %150 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_1 %142 %uint_0
- ; CHECK: OpBranch %145
- ; CHECK: %145 = OpLabel
- ; CHECK: %151 = OpPhi %v4float %149 %146 [[null_v4float]] %147
- ; CHECK: OpBranch %51
- ; CHECK: %53 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %142 %48
- ; CHECK: OpBranch %51
- ; CHECK: %51 = OpLabel
- ; CHECK: %114 = OpPhi %v4float %151 %145 [[null_v4float]] %53
- ; CHECK: %30 = OpCompositeExtract %float %114 0
- ; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- ; CHECK: %152 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %153 = OpULessThan %bool %uint_0 %152
- ; CHECK: OpSelectionMerge %154 None
- ; CHECK: OpBranchConditional %153 %155 %156
- ; CHECK: %155 = OpLabel
- ; CHECK: OpStore %31 %30
- ; CHECK: OpBranch %154
- ; CHECK: %156 = OpLabel
- ; CHECK: %158 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_54 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %154
- ; CHECK: %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Ray + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest,
- InstBoundsAnyHitInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint AnyHitNV %main "main"
- ; CHECK: OpEntryPoint AnyHitNV %main "main" [[launch_id:%\w+]]
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- ; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- ; CHECK-NOT: OpStore %31 %29
- ; CHECK: %133 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %134 = OpULessThan %bool %uint_0 %133
- ; CHECK: OpSelectionMerge %135 None
- ; CHECK: OpBranchConditional %134 %136 %137
- ; CHECK: %136 = OpLabel
- ; CHECK: %138 = OpLoad %uint %25
- ; CHECK: OpBranch %135
- ; CHECK: %137 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_48 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %135
- ; CHECK: %135 = OpLabel
- ; CHECK: %142 = OpPhi %uint %138 %136 [[null_uint]] %137
- ; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- ; CHECK: %28 = OpLoad %13 %27
- ; CHECK: %48 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_1
- ; CHECK: %50 = OpULessThan %bool %142 %48
- ; CHECK: OpSelectionMerge %51 None
- ; CHECK: OpBranchConditional %50 %52 %53
- ; CHECK: %52 = OpLabel
- ; CHECK: %54 = OpLoad %13 %27
- ; CHECK: %143 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_1 %142
- ; CHECK: %144 = OpULessThan %bool %uint_0 %143
- ; CHECK: OpSelectionMerge %145 None
- ; CHECK: OpBranchConditional %144 %146 %147
- ; CHECK: %146 = OpLabel
- ; CHECK: %148 = OpLoad %13 %27
- ; CHECK: %149 = OpImageRead %v4float %148 %20
- ; CHECK: OpBranch %145
- ; CHECK: %147 = OpLabel
- ; CHECK: %150 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_1 %142 %uint_0
- ; CHECK: OpBranch %145
- ; CHECK: %145 = OpLabel
- ; CHECK: %151 = OpPhi %v4float %149 %146 [[null_v4float]] %147
- ; CHECK: OpBranch %51
- ; CHECK: %53 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %142 %48
- ; CHECK: OpBranch %51
- ; CHECK: %51 = OpLabel
- ; CHECK: %114 = OpPhi %v4float %151 %145 [[null_v4float]] %53
- ; CHECK: %30 = OpCompositeExtract %float %114 0
- ; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- ; CHECK: %152 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %153 = OpULessThan %bool %uint_0 %152
- ; CHECK: OpSelectionMerge %154 None
- ; CHECK: OpBranchConditional %153 %155 %156
- ; CHECK: %155 = OpLabel
- ; CHECK: OpStore %31 %30
- ; CHECK: OpBranch %154
- ; CHECK: %156 = OpLabel
- ; CHECK: %158 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_54 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %154
- ; CHECK: %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Ray + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest,
- InstBoundsClosestHitInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint ClosestHitNV %main "main"
- ; CHECK: OpEntryPoint ClosestHitNV %main "main" [[launch_id:%\w+]]
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- ; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- ; CHECK-NOT: OpStore %31 %29
- ; CHECK: %133 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %134 = OpULessThan %bool %uint_0 %133
- ; CHECK: OpSelectionMerge %135 None
- ; CHECK: OpBranchConditional %134 %136 %137
- ; CHECK: %136 = OpLabel
- ; CHECK: %138 = OpLoad %uint %25
- ; CHECK: OpBranch %135
- ; CHECK: %137 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_48 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %135
- ; CHECK: %135 = OpLabel
- ; CHECK: %142 = OpPhi %uint %138 %136 [[null_uint]] %137
- ; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- ; CHECK: %28 = OpLoad %13 %27
- ; CHECK: %48 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_1
- ; CHECK: %50 = OpULessThan %bool %142 %48
- ; CHECK: OpSelectionMerge %51 None
- ; CHECK: OpBranchConditional %50 %52 %53
- ; CHECK: %52 = OpLabel
- ; CHECK: %54 = OpLoad %13 %27
- ; CHECK: %143 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_1 %142
- ; CHECK: %144 = OpULessThan %bool %uint_0 %143
- ; CHECK: OpSelectionMerge %145 None
- ; CHECK: OpBranchConditional %144 %146 %147
- ; CHECK: %146 = OpLabel
- ; CHECK: %148 = OpLoad %13 %27
- ; CHECK: %149 = OpImageRead %v4float %148 %20
- ; CHECK: OpBranch %145
- ; CHECK: %147 = OpLabel
- ; CHECK: %150 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_1 %142 %uint_0
- ; CHECK: OpBranch %145
- ; CHECK: %145 = OpLabel
- ; CHECK: %151 = OpPhi %v4float %149 %146 [[null_v4float]] %147
- ; CHECK: OpBranch %51
- ; CHECK: %53 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %142 %48
- ; CHECK: OpBranch %51
- ; CHECK: %51 = OpLabel
- ; CHECK: %114 = OpPhi %v4float %151 %145 [[null_v4float]] %53
- ; CHECK: %30 = OpCompositeExtract %float %114 0
- ; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- ; CHECK: %152 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %153 = OpULessThan %bool %uint_0 %152
- ; CHECK: OpSelectionMerge %154 None
- ; CHECK: OpBranchConditional %153 %155 %156
- ; CHECK: %155 = OpLabel
- ; CHECK: OpStore %31 %30
- ; CHECK: OpBranch %154
- ; CHECK: %156 = OpLabel
- ; CHECK: %158 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_54 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %154
- ; CHECK: %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Ray + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest,
- InstBoundsMissInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint MissNV %main "main"
- ; CHECK: OpEntryPoint MissNV %main "main" [[launch_id:%\w+]]
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: [[launch_id]] = OpVariable %_ptr_Input_v3uint Input
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- ; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- ; CHECK-NOT OpStore %31 %29
- ; CHECK: %133 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %134 = OpULessThan %bool %uint_0 %133
- ; CHECK: OpSelectionMerge %135 None
- ; CHECK: OpBranchConditional %134 %136 %137
- ; CHECK: %136 = OpLabel
- ; CHECK: %138 = OpLoad %uint %25
- ; CHECK: OpBranch %135
- ; CHECK: %137 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_48 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %135
- ; CHECK: %135 = OpLabel
- ; CHECK: %142 = OpPhi %uint %138 %136 [[null_uint]] %137
- ; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- ; CHECK: %28 = OpLoad %13 %27
- ; CHECK: %48 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_1
- ; CHECK: %50 = OpULessThan %bool %142 %48
- ; CHECK: OpSelectionMerge %51 None
- ; CHECK: OpBranchConditional %50 %52 %53
- ; CHECK: %52 = OpLabel
- ; CHECK: %54 = OpLoad %13 %27
- ; CHECK: %143 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_1 %142
- ; CHECK: %144 = OpULessThan %bool %uint_0 %143
- ; CHECK: OpSelectionMerge %145 None
- ; CHECK: OpBranchConditional %144 %146 %147
- ; CHECK: %146 = OpLabel
- ; CHECK: %148 = OpLoad %13 %27
- ; CHECK: %149 = OpImageRead %v4float %148 %20
- ; CHECK: OpBranch %145
- ; CHECK: %147 = OpLabel
- ; CHECK: %150 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_1 %142 %uint_0
- ; CHECK: OpBranch %145
- ; CHECK: %145 = OpLabel
- ; CHECK: %151 = OpPhi %v4float %149 %146 [[null_v4float]] %147
- ; CHECK: OpBranch %51
- ; CHECK: %53 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %142 %48
- ; CHECK: OpBranch %51
- ; CHECK: %51 = OpLabel
- ; CHECK: %114 = OpPhi %v4float %151 %145 [[null_v4float]] %53
- ; CHECK: %30 = OpCompositeExtract %float %114 0
- ; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- ; CHECK: %152 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %153 = OpULessThan %bool %uint_0 %152
- ; CHECK: OpSelectionMerge %154 None
- ; CHECK: OpBranchConditional %153 %155 %156
- ; CHECK: %155 = OpLabel
- ; CHECK: OpStore %31 %30
- ; CHECK: OpBranch %154
- ; CHECK: %156 = OpLabel
- ; CHECK: %158 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_54 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %154
- ; CHECK: %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Ray + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest,
- InstBoundsCallableInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- // clang-format off
- const std::string defs = R"(
- OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint CallableNV %main "main"
- ; CHECK: OpEntryPoint CallableNV %main "main" [[launch_id:%\w+]]
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ; CHECK: OpDecorate [[launch_id]] BuiltIn LaunchIdNV
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )" + kInputGlobals + kOutputGlobals + R"(
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- ; CHECK: [[null_uint:%\w+]] = OpConstantNull %uint
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- ; CHECK-NOT: OpStore %31 %29
- ; CHECK: %133 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %134 = OpULessThan %bool %uint_0 %133
- ; CHECK: OpSelectionMerge %135 None
- ; CHECK: OpBranchConditional %134 %136 %137
- ; CHECK: %136 = OpLabel
- ; CHECK: %138 = OpLoad %uint %25
- ; CHECK: OpBranch %135
- ; CHECK: %137 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_48 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %135
- ; CHECK: %135 = OpLabel
- ; CHECK: %142 = OpPhi %uint %138 %136 [[null_uint]] %137
- ; CHECK: %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- ; CHECK: %28 = OpLoad %13 %27
- ; CHECK: %48 = OpFunctionCall %uint %inst_bindless_direct_read_2 %uint_1 %uint_1
- ; CHECK: %50 = OpULessThan %bool %142 %48
- ; CHECK: OpSelectionMerge %51 None
- ; CHECK: OpBranchConditional %50 %52 %53
- ; CHECK: %52 = OpLabel
- ; CHECK: %54 = OpLoad %13 %27
- ; CHECK: %143 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_1 %142
- ; CHECK: %144 = OpULessThan %bool %uint_0 %143
- ; CHECK: OpSelectionMerge %145 None
- ; CHECK: OpBranchConditional %144 %146 %147
- ; CHECK: %146 = OpLabel
- ; CHECK: %148 = OpLoad %13 %27
- ; CHECK: %149 = OpImageRead %v4float %148 %20
- ; CHECK: OpBranch %145
- ; CHECK: %147 = OpLabel
- ; CHECK: %150 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_1 %142 %uint_0
- ; CHECK: OpBranch %145
- ; CHECK: %145 = OpLabel
- ; CHECK: %151 = OpPhi %v4float %149 %146 [[null_v4float]] %147
- ; CHECK: OpBranch %51
- ; CHECK: %53 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_51 %uint_0 %142 %48
- ; CHECK: OpBranch %51
- ; CHECK: %51 = OpLabel
- ; CHECK: %114 = OpPhi %v4float %151 %145 [[null_v4float]] %53
- ; CHECK: %30 = OpCompositeExtract %float %114 0
- ; CHECK: %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- ; CHECK: %152 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %153 = OpULessThan %bool %uint_0 %152
- ; CHECK: OpSelectionMerge %154 None
- ; CHECK: OpBranchConditional %153 %155 %156
- ; CHECK: %155 = OpLabel
- ; CHECK: OpStore %31 %30
- ; CHECK: OpBranch %154
- ; CHECK: %156 = OpLabel
- ; CHECK: %158 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_54 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %154
- ; CHECK: %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kDirectRead2 + kStreamWrite4Ray + kDirectRead4;
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, InstBoundsInitSameBlockOpReplication) {
- // Test that same block ops like OpSampledImage are replicated properly
- // where needed.
- //
- // clang-format off
- //
- // #version 450 core
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location = 0) in vec2 inTexcoord;
- // layout(location = 0) out vec4 outColor;
- //
- // layout(set = 0, binding = 0) uniform Uniforms {
- // vec2 var0;
- // } uniforms;
- //
- // layout(set = 0, binding = 1) uniform sampler uniformSampler;
- // layout(set = 0, binding = 2) uniform texture2D uniformTex;
- // layout(set = 0, binding = 3) uniform texture2D uniformTexArr[8];
- //
- // void main() {
- // int index = 0;
- // float x = texture(sampler2D(uniformTexArr[nonuniformEXT(index)], uniformSampler), inTexcoord.xy).x;
- // float y = texture(sampler2D(uniformTex, uniformSampler), inTexcoord.xy * uniforms.var0.xy).x;
- // outColor = vec4(x, y, 0.0, 0.0);
- // }
- //
- const std::string defs = R"(
- OpCapability Shader
- OpCapability ShaderNonUniformEXT
- OpCapability SampledImageArrayNonUniformIndexingEXT
- OpExtension "SPV_EXT_descriptor_indexing"
- ; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %inTexcoord %outColor
- ; CHECK: OpEntryPoint Fragment %main "main" %inTexcoord %outColor %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %index "index"
- OpName %x "x"
- OpName %uniformTexArr "uniformTexArr"
- OpName %uniformSampler "uniformSampler"
- OpName %inTexcoord "inTexcoord"
- OpName %y "y"
- OpName %uniformTex "uniformTex"
- OpName %Uniforms "Uniforms"
- OpMemberName %Uniforms 0 "var0"
- OpName %uniforms "uniforms"
- OpName %outColor "outColor"
- OpDecorate %uniformTexArr DescriptorSet 0
- OpDecorate %uniformTexArr Binding 3
- OpDecorate %19 NonUniformEXT
- OpDecorate %22 NonUniformEXT
- OpDecorate %uniformSampler DescriptorSet 0
- OpDecorate %uniformSampler Binding 1
- OpDecorate %inTexcoord Location 0
- OpDecorate %uniformTex DescriptorSet 0
- OpDecorate %uniformTex Binding 2
- OpMemberDecorate %Uniforms 0 Offset 0
- OpDecorate %Uniforms Block
- OpDecorate %uniforms DescriptorSet 0
- OpDecorate %uniforms Binding 0
- OpDecorate %outColor Location 0
- ; CHECK: OpDecorate %63 NonUniform
- ; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- )" + kInputDecorations + R"(
- ; CHECK: OpDecorate %151 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %int = OpTypeInt 32 1
- %_ptr_Function_int = OpTypePointer Function %int
- %int_0 = OpConstant %int 0
- %float = OpTypeFloat 32
- %_ptr_Function_float = OpTypePointer Function %float
- %13 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_8 = OpConstant %uint 8
- %_arr_13_uint_8 = OpTypeArray %13 %uint_8
- %_ptr_UniformConstant__arr_13_uint_8 = OpTypePointer UniformConstant %_arr_13_uint_8
- %uniformTexArr = OpVariable %_ptr_UniformConstant__arr_13_uint_8 UniformConstant
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %23 = OpTypeSampler
- %_ptr_UniformConstant_23 = OpTypePointer UniformConstant %23
- %uniformSampler = OpVariable %_ptr_UniformConstant_23 UniformConstant
- %27 = OpTypeSampledImage %13
- %v2float = OpTypeVector %float 2
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %inTexcoord = OpVariable %_ptr_Input_v2float Input
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %uniformTex = OpVariable %_ptr_UniformConstant_13 UniformConstant
- %Uniforms = OpTypeStruct %v2float
- %_ptr_Uniform_Uniforms = OpTypePointer Uniform %Uniforms
- %uniforms = OpVariable %_ptr_Uniform_Uniforms Uniform
- %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %outColor = OpVariable %_ptr_Output_v4float Output
- %float_0 = OpConstant %float 0
- )" + kOutputGlobals + R"(
- ; CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )" + kInputGlobals + R"(
- ; CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
- )";
- // clang-format on
- const std::string main_func = R"(
- %main = OpFunction %void None %3
- %5 = OpLabel
- %index = OpVariable %_ptr_Function_int Function
- %x = OpVariable %_ptr_Function_float Function
- %y = OpVariable %_ptr_Function_float Function
- OpStore %index %int_0
- %19 = OpLoad %int %index
- %21 = OpAccessChain %_ptr_UniformConstant_13 %uniformTexArr %19
- %22 = OpLoad %13 %21
- %26 = OpLoad %23 %uniformSampler
- %28 = OpSampledImage %27 %22 %26
- %32 = OpLoad %v2float %inTexcoord
- %34 = OpImageSampleImplicitLod %v4float %28 %32
- %36 = OpCompositeExtract %float %34 0
- OpStore %x %36
- %39 = OpLoad %13 %uniformTex
- %40 = OpLoad %23 %uniformSampler
- %41 = OpSampledImage %27 %39 %40
- %42 = OpLoad %v2float %inTexcoord
- %47 = OpAccessChain %_ptr_Uniform_v2float %uniforms %int_0
- %48 = OpLoad %v2float %47
- %49 = OpFMul %v2float %42 %48
- %50 = OpImageSampleImplicitLod %v4float %41 %49
- %51 = OpCompositeExtract %float %50 0
- ; CHECK-NOT: %51 = OpCompositeExtract %float %50 0
- ; CHECK: %157 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ; CHECK: %158 = OpULessThan %bool %uint_0 %157
- ; CHECK: OpSelectionMerge %159 None
- ; CHECK: OpBranchConditional %158 %160 %161
- ; CHECK: %160 = OpLabel
- ; CHECK: %162 = OpLoad %v2float %47
- ; CHECK: OpBranch %159
- ; CHECK: %161 = OpLabel
- ; CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_87 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %159
- ; CHECK: %159 = OpLabel
- ; CHECK: %166 = OpPhi %v2float %162 %160 [[null_v2float]] %161
- ; CHECK: %49 = OpFMul %v2float %42 %166
- ; CHECK: %167 = OpSampledImage %27 %39 %40
- ; CHECK: %168 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_2 %uint_0
- ; CHECK: %169 = OpULessThan %bool %uint_0 %168
- ; CHECK: OpSelectionMerge %170 None
- ; CHECK: OpBranchConditional %169 %171 %172
- ; CHECK: %171 = OpLabel
- ; CHECK: %173 = OpLoad %13 %uniformTex
- ; CHECK: %174 = OpSampledImage %27 %173 %40
- ; CHECK: %175 = OpImageSampleImplicitLod %v4float %174 %49
- ; CHECK: OpBranch %170
- ; CHECK: %172 = OpLabel
- ; CHECK: %177 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_89 %uint_1 %uint_0 %uint_0
- ; CHECK: OpBranch %170
- ; CHECK: %170 = OpLabel
- ; CHECK: %178 = OpPhi %v4float %175 %171 [[null_v4float]] %172
- ; CHECK: %51 = OpCompositeExtract %float %178 0
- OpStore %y %51
- %54 = OpLoad %float %x
- %55 = OpLoad %float %y
- %57 = OpCompositeConstruct %v4float %54 %55 %float_0 %float_0
- OpStore %outColor %57
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs = kStreamWrite4Frag + kDirectRead4;
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(defs + main_func + new_funcs,
- true, 7u, 23u, true, true, false,
- false, false);
- }
- TEST_F(InstBindlessTest, MultipleUniformNonAggregateRefsNoDescInit) {
- // Check that uniform refs do not go out-of-bounds. All checks use same input
- // buffer read function call result at top of function for uniform buffer
- // length. Because descriptor indexing is not being checked, we can avoid one
- // buffer load.
- //
- // Texture2D g_tColor;
- // SamplerState g_sAniso;
- //
- // layout(push_constant) cbuffer PerViewPushConst_t { bool g_B; };
- //
- // cbuffer PerViewConstantBuffer_t {
- // float2 g_TexOff0;
- // float2 g_TexOff1;
- // };
- //
- // struct PS_INPUT {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i) {
- // PS_OUTPUT ps_output;
- // float2 off;
- // float2 vtc;
- // if (g_B)
- // off = g_TexOff0;
- // else
- // off = g_TexOff1;
- // vtc = i.vTextureCoords.xy + off;
- // ps_output.vColor = g_tColor.Sample(g_sAniso, vtc);
- // return ps_output;
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
- ;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %PerViewPushConst_t "PerViewPushConst_t"
- OpMemberName %PerViewPushConst_t 0 "g_B"
- OpName %_ ""
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_TexOff0"
- OpMemberName %PerViewConstantBuffer_t 1 "g_TexOff1"
- OpName %__0 ""
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpMemberDecorate %PerViewPushConst_t 0 Offset 0
- OpDecorate %PerViewPushConst_t Block
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 8
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %__0 DescriptorSet 0
- OpDecorate %__0 Binding 1
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 2
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %PerViewPushConst_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
- %_ = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %bool = OpTypeBool
- %uint_0 = OpConstant %uint 0
- %PerViewConstantBuffer_t = OpTypeStruct %v2float %v2float
- %_ptr_Uniform_PerViewConstantBuffer_t = OpTypePointer Uniform %PerViewConstantBuffer_t
- %__0 = OpVariable %_ptr_Uniform_PerViewConstantBuffer_t Uniform
- %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
- %int_1 = OpConstant %int 1
- %49 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_49 = OpTypePointer UniformConstant %49
- %g_tColor = OpVariable %_ptr_UniformConstant_49 UniformConstant
- %53 = OpTypeSampler
- %_ptr_UniformConstant_53 = OpTypePointer UniformConstant %53
- %g_sAniso = OpVariable %_ptr_UniformConstant_53 UniformConstant
- %57 = OpTypeSampledImage %49
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )" + kInputGlobals + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: %v4uint = OpTypeVector %uint 4
- ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
- %MainPs = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: %140 = OpFunctionCall %uint %inst_bindless_direct_read_3 %uint_1 %uint_1 %uint_0
- ;CHECK: OpBranch %117
- ;CHECK: %117 = OpLabel
- ;CHECK: OpBranch %116
- ;CHECK: %116 = OpLabel
- %69 = OpLoad %v2float %i_vTextureCoords
- %82 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %83 = OpLoad %uint %82
- %84 = OpINotEqual %bool %83 %uint_0
- OpSelectionMerge %91 None
- OpBranchConditional %84 %85 %88
- %85 = OpLabel
- %86 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_0
- %87 = OpLoad %v2float %86
- ;CHECK-NOT: %87 = OpLoad %v2float %86
- ;CHECK: %119 = OpIAdd %uint %uint_0 %uint_7
- ;CHECK: %141 = OpULessThan %bool %119 %140
- ;CHECK: OpSelectionMerge %143 None
- ;CHECK: OpBranchConditional %141 %144 %145
- ;CHECK: %144 = OpLabel
- ;CHECK: %146 = OpLoad %v2float %86
- ;CHECK: OpBranch %143
- ;CHECK: %145 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_71 %uint_4 %uint_0 %119 %140
- ;CHECK: OpBranch %143
- ;CHECK: %143 = OpLabel
- ;CHECK: %203 = OpPhi %v2float %146 %144 [[null_v2float]] %145
- OpBranch %91
- %88 = OpLabel
- %89 = OpAccessChain %_ptr_Uniform_v2float %__0 %int_1
- %90 = OpLoad %v2float %89
- ;CHECK-NOT: %90 = OpLoad %v2float %89
- ;CHECK: %204 = OpIAdd %uint %uint_8 %uint_7
- ;CHECK: %205 = OpULessThan %bool %204 %140
- ;CHECK: OpSelectionMerge %206 None
- ;CHECK: OpBranchConditional %205 %207 %208
- ;CHECK: %207 = OpLabel
- ;CHECK: %209 = OpLoad %v2float %89
- ;CHECK: OpBranch %206
- ;CHECK: %208 = OpLabel
- ;CHECK: %211 = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_75 %uint_4 %uint_0 %204 %140
- ;CHECK: OpBranch %206
- ;CHECK: %206 = OpLabel
- ;CHECK: %212 = OpPhi %v2float %209 %207 [[null_v2float]] %208
- OpBranch %91
- %91 = OpLabel
- %115 = OpPhi %v2float %87 %85 %90 %88
- ;CHECK-NOT: %115 = OpPhi %v2float %87 %85 %90 %88
- ;CHECK: %115 = OpPhi %v2float %203 %143 %212 %206
- %95 = OpFAdd %v2float %69 %115
- %96 = OpLoad %49 %g_tColor
- %97 = OpLoad %53 %g_sAniso
- %98 = OpSampledImage %57 %96 %97
- %100 = OpImageSampleImplicitLod %v4float %98 %95
- OpStore %_entryPointOutput_vColor %100
- OpReturn
- OpFunctionEnd
- )" + kDirectRead3 + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, false, true);
- }
- TEST_F(InstBindlessTest, UniformArrayRefNoDescInit) {
- // Check that uniform array ref does not go out-of-bounds.
- //
- // Texture2D g_tColor;
- // SamplerState g_sAniso;
- //
- // layout(push_constant) cbuffer PerViewPushConst_t { uint g_c; };
- //
- // struct PerBatchEnvMapConstantBuffer_t {
- // float4x3 g_matEnvMapWorldToLocal;
- // float4 g_vEnvironmentMapBoxMins;
- // float2 g_TexOff;
- // };
- //
- // cbuffer _BindlessFastEnvMapCB_PS_t {
- // PerBatchEnvMapConstantBuffer_t g_envMapConstants[128];
- // };
- //
- // struct PS_INPUT {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i) {
- // PS_OUTPUT ps_output;
- // float2 off;
- // float2 vtc;
- // off = g_envMapConstants[g_c].g_TexOff;
- // vtc = i.vTextureCoords.xy + off;
- // ps_output.vColor = g_tColor.Sample(g_sAniso, vtc);
- // return ps_output;
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff"
- OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t"
- OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants"
- OpName %_ ""
- OpName %PerViewPushConst_t "PerViewPushConst_t"
- OpMemberName %PerViewPushConst_t 0 "g_c"
- OpName %__0 ""
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64
- OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80
- OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0
- OpDecorate %_BindlessFastEnvMapCB_PS_t Block
- OpDecorate %_ DescriptorSet 0
- OpDecorate %_ Binding 2
- OpMemberDecorate %PerViewPushConst_t 0 Offset 0
- OpDecorate %PerViewPushConst_t Block
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 1
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %v3float = OpTypeVector %float 3
- %mat4v3float = OpTypeMatrix %v3float 4
- %PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128
- %_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128
- %_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t
- %_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %PerViewPushConst_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
- %__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %int_2 = OpConstant %int 2
- %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
- %46 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
- %g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant
- %50 = OpTypeSampler
- %_ptr_UniformConstant_50 = OpTypePointer UniformConstant %50
- %g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant
- %54 = OpTypeSampledImage %46
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )" + kInputGlobals + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: %v4uint = OpTypeVector %uint 4
- ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
- %MainPs = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: %123 = OpFunctionCall %uint %inst_bindless_direct_read_3 %uint_1 %uint_2 %uint_0
- ;CHECK: OpBranch %93
- ;CHECK: %93 = OpLabel
- ;CHECK: OpBranch %92
- ;CHECK: %92 = OpLabel
- %66 = OpLoad %v2float %i_vTextureCoords
- %79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0
- %80 = OpLoad %uint %79
- %81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2
- %82 = OpLoad %v2float %81
- ;CHECK-NOT: %82 = OpLoad %v2float %81
- ;CHECK: %96 = OpIMul %uint %uint_80 %80
- ;CHECK: %97 = OpIAdd %uint %uint_0 %96
- ;CHECK: %99 = OpIAdd %uint %97 %uint_64
- ;CHECK: %101 = OpIAdd %uint %99 %uint_7
- ;CHECK: %125 = OpULessThan %bool %101 %123
- ;CHECK: OpSelectionMerge %127 None
- ;CHECK: OpBranchConditional %125 %128 %129
- ;CHECK: %128 = OpLabel
- ;CHECK: %130 = OpLoad %v2float %81
- ;CHECK: OpBranch %127
- ;CHECK: %129 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_78 %uint_4 %uint_0 %101 %123
- ;CHECK: OpBranch %127
- ;CHECK: %127 = OpLabel
- ;CHECK: %186 = OpPhi %v2float %130 %128 [[null_v2float]] %129
- %86 = OpFAdd %v2float %66 %82
- ;CHECK-NOT: %86 = OpFAdd %v2float %66 %82
- ;CHECK: %86 = OpFAdd %v2float %66 %186
- %87 = OpLoad %46 %g_tColor
- %88 = OpLoad %50 %g_sAniso
- %89 = OpSampledImage %54 %87 %88
- %91 = OpImageSampleImplicitLod %v4float %89 %86
- OpStore %_entryPointOutput_vColor %91
- OpReturn
- OpFunctionEnd
- )" + kDirectRead3 + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, false, true);
- }
- TEST_F(InstBindlessTest, UniformArrayRefWithDescInit) {
- // The buffer-oob and desc-init checks should use the same debug
- // output buffer write function.
- //
- // Same source as UniformArrayRefNoDescInit
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
- ;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff"
- OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t"
- OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants"
- OpName %_ ""
- OpName %PerViewPushConst_t "PerViewPushConst_t"
- OpMemberName %PerViewPushConst_t 0 "g_c"
- OpName %__0 ""
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64
- OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80
- OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0
- OpDecorate %_BindlessFastEnvMapCB_PS_t Block
- OpDecorate %_ DescriptorSet 0
- OpDecorate %_ Binding 2
- OpMemberDecorate %PerViewPushConst_t 0 Offset 0
- OpDecorate %PerViewPushConst_t Block
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 1
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %v3float = OpTypeVector %float 3
- %mat4v3float = OpTypeMatrix %v3float 4
- %PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128
- %_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128
- %_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t
- %_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %PerViewPushConst_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
- %__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %int_2 = OpConstant %int 2
- %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
- %46 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_46 = OpTypePointer UniformConstant %46
- %g_tColor = OpVariable %_ptr_UniformConstant_46 UniformConstant
- %50 = OpTypeSampler
- %_ptr_UniformConstant_50 = OpTypePointer UniformConstant %50
- %g_sAniso = OpVariable %_ptr_UniformConstant_50 UniformConstant
- %54 = OpTypeSampledImage %46
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )" + kInputGlobals + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: %v4uint = OpTypeVector %uint 4
- ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
- ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- %MainPs = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: %126 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_2 %uint_0
- ;CHECK: %191 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %uint_0
- ;CHECK: OpBranch %93
- ;CHECK: %93 = OpLabel
- ;CHECK: OpBranch %92
- ;CHECK: %92 = OpLabel
- %66 = OpLoad %v2float %i_vTextureCoords
- %79 = OpAccessChain %_ptr_PushConstant_uint %__0 %int_0
- %80 = OpLoad %uint %79
- %81 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %80 %int_2
- %82 = OpLoad %v2float %81
- %86 = OpFAdd %v2float %66 %82
- ;CHECK-NOT: %82 = OpLoad %v2float %81
- ;CHECK-NOT: %86 = OpFAdd %v2float %66 %82
- ;CHECK: %96 = OpIMul %uint %uint_80 %80
- ;CHECK: %97 = OpIAdd %uint %uint_0 %96
- ;CHECK: %99 = OpIAdd %uint %97 %uint_64
- ;CHECK: %101 = OpIAdd %uint %99 %uint_7
- ;CHECK: %128 = OpULessThan %bool %101 %126
- ;CHECK: OpSelectionMerge %130 None
- ;CHECK: OpBranchConditional %128 %131 %132
- ;CHECK: %131 = OpLabel
- ;CHECK: %133 = OpLoad %v2float %81
- ;CHECK: OpBranch %130
- ;CHECK: %132 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_78 %uint_4 %uint_0 %101 %126
- ;CHECK: OpBranch %130
- ;CHECK: %130 = OpLabel
- ;CHECK: %190 = OpPhi %v2float %133 %131 [[null_v2float]] %132
- ;CHECK: %86 = OpFAdd %v2float %66 %190
- %87 = OpLoad %46 %g_tColor
- %88 = OpLoad %50 %g_sAniso
- %89 = OpSampledImage %54 %87 %88
- %91 = OpImageSampleImplicitLod %v4float %89 %86
- OpStore %_entryPointOutput_vColor %91
- ;CHECK-NOT: %91 = OpImageSampleImplicitLod %v4float %89 %86
- ;CHECK-NOT: OpStore %_entryPointOutput_vColor %91
- ;CHECK: %192 = OpULessThan %bool %uint_0 %191
- ;CHECK: OpSelectionMerge %193 None
- ;CHECK: OpBranchConditional %192 %194 %195
- ;CHECK: %194 = OpLabel
- ;CHECK: %196 = OpLoad %46 %g_tColor
- ;CHECK: %197 = OpSampledImage %54 %196 %88
- ;CHECK: %198 = OpImageSampleImplicitLod %v4float %197 %86
- ;CHECK: OpBranch %193
- ;CHECK: %195 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_83 %uint_1 %uint_0 %uint_0 %uint_0
- ;CHECK: OpBranch %193
- ;CHECK: %193 = OpLabel
- ;CHECK: %202 = OpPhi %v4float %198 %194 [[null_v4float]] %195
- ;CHECK: OpStore %_entryPointOutput_vColor %202
- OpReturn
- OpFunctionEnd
- )" + kDirectRead4 + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
- true, false, true);
- }
- TEST_F(InstBindlessTest, Descriptor16BitIdxRef) {
- // Check that descriptor indexed with 16bit index is inbounds and
- // initialized
- //
- // Use Simple source with min16uint g_nDataIdx
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability Int16
- OpCapability StoragePushConstant16
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
- ;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %_ %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_output_buffer %gl_FragCoord %inst_bindless_input_buffer
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- )" + kInputDecorations + R"(
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_16_uint_128 = OpTypeArray %16 %uint_128
- %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
- %ushort = OpTypeInt 16 0
- %PerViewConstantBuffer_t = OpTypeStruct %ushort
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_ushort = OpTypePointer PushConstant %ushort
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %25 = OpTypeSampler
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
- %27 = OpTypeSampledImage %16
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )" + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- )" + kInputGlobals + R"(
- %MainPs = OpFunction %void None %10
- %30 = OpLabel
- ;CHECK: OpBranch %108
- ;CHECK: %108 = OpLabel
- ;CHECK: OpBranch %39
- ;CHECK: %39 = OpLabel
- %31 = OpLoad %v2float %i_vTextureCoords
- %32 = OpAccessChain %_ptr_PushConstant_ushort %_ %int_0
- %33 = OpLoad %ushort %32
- %34 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %33
- %35 = OpLoad %16 %34
- %36 = OpLoad %25 %g_sAniso
- %37 = OpSampledImage %27 %35 %36
- %38 = OpImageSampleImplicitLod %v4float %37 %31
- OpStore %_entryPointOutput_vColor %38
- ;CHECK-NOT: %38 = OpImageSampleImplicitLod %v4float %37 %31
- ;CHECK-NOT: OpStore %_entryPointOutput_vColor %38
- ;CHECK: %41 = OpUConvert %uint %33
- ;CHECK: %43 = OpULessThan %bool %41 %uint_128
- ;CHECK: OpSelectionMerge %44 None
- ;CHECK: OpBranchConditional %43 %45 %46
- ;CHECK: %45 = OpLabel
- ;CHECK: %47 = OpLoad %16 %34
- ;CHECK: %48 = OpSampledImage %27 %47 %36
- ;CHECK: %109 = OpUConvert %uint %33
- ;CHECK: %131 = OpFunctionCall %uint %inst_bindless_direct_read_4 %uint_0 %uint_0 %uint_0 %109
- ;CHECK: %132 = OpULessThan %bool %uint_0 %131
- ;CHECK: OpSelectionMerge %133 None
- ;CHECK: OpBranchConditional %132 %134 %135
- ;CHECK: %134 = OpLabel
- ;CHECK: %136 = OpLoad %16 %34
- ;CHECK: %137 = OpSampledImage %27 %136 %36
- ;CHECK: %138 = OpImageSampleImplicitLod %v4float %137 %31
- ;CHECK: OpBranch %133
- ;CHECK: %135 = OpLabel
- ;CHECK: %139 = OpUConvert %uint %33
- ;CHECK: %140 = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_60 %uint_1 %139 %uint_0
- ;CHECK: OpBranch %133
- ;CHECK: %133 = OpLabel
- ;CHECK: [[phi_result_1:%\w+]] = OpPhi %v4float %138 %134 [[null_v4float]] %135
- ;CHECK: OpBranch %44
- ;CHECK: %46 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_4 %uint_60 %uint_0 %41 %uint_128
- ;CHECK: OpBranch %44
- ;CHECK: %44 = OpLabel
- ;CHECK: [[phi_result_2:%\w+]] = OpPhi %v4float [[phi_result_1]] %133 [[null_v4float]] %46
- ;CHECK: OpStore %_entryPointOutput_vColor [[phi_result_2]]
- OpReturn
- OpFunctionEnd
- )" + kStreamWrite4Frag + kDirectRead4;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
- false, false, true);
- }
- TEST_F(InstBindlessTest, UniformArray16bitIdxRef) {
- // Check that uniform array ref with 16bit index does not go out-of-bounds.
- //
- // Texture2D g_tColor;
- // SamplerState g_sAniso;
- //
- // layout(push_constant) cbuffer PerViewPushConst_t { min16uint g_c; };
- //
- // struct PerBatchEnvMapConstantBuffer_t {
- // float4x3 g_matEnvMapWorldToLocal;
- // float4 g_vEnvironmentMapBoxMins;
- // float2 g_TexOff;
- // };
- //
- // cbuffer _BindlessFastEnvMapCB_PS_t {
- // PerBatchEnvMapConstantBuffer_t g_envMapConstants[128];
- // };
- //
- // struct PS_INPUT {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i) {
- // PS_OUTPUT ps_output;
- // float2 off;
- // float2 vtc;
- // off = g_envMapConstants[g_c].g_TexOff;
- // vtc = i.vTextureCoords.xy + off;
- // ps_output.vColor = g_tColor.Sample(g_sAniso, vtc);
- // return ps_output;
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability Int16
- OpCapability StoragePushConstant16
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor
- ;CHECK: OpEntryPoint Fragment %MainPs "MainPs" %_ %__0 %g_tColor %g_sAniso %i_vTextureCoords %_entryPointOutput_vColor %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %PerBatchEnvMapConstantBuffer_t "PerBatchEnvMapConstantBuffer_t"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 0 "g_matEnvMapWorldToLocal"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 1 "g_vEnvironmentMapBoxMins"
- OpMemberName %PerBatchEnvMapConstantBuffer_t 2 "g_TexOff"
- OpName %_BindlessFastEnvMapCB_PS_t "_BindlessFastEnvMapCB_PS_t"
- OpMemberName %_BindlessFastEnvMapCB_PS_t 0 "g_envMapConstants"
- OpName %_ ""
- OpName %PerViewPushConst_t "PerViewPushConst_t"
- OpMemberName %PerViewPushConst_t 0 "g_c"
- OpName %__0 ""
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 RowMajor
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 0 MatrixStride 16
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 1 Offset 48
- OpMemberDecorate %PerBatchEnvMapConstantBuffer_t 2 Offset 64
- OpDecorate %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 ArrayStride 80
- OpMemberDecorate %_BindlessFastEnvMapCB_PS_t 0 Offset 0
- OpDecorate %_BindlessFastEnvMapCB_PS_t Block
- OpDecorate %_ DescriptorSet 0
- OpDecorate %_ Binding 0
- OpMemberDecorate %PerViewPushConst_t 0 Offset 0
- OpDecorate %PerViewPushConst_t Block
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %14 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %v3float = OpTypeVector %float 3
- %mat4v3float = OpTypeMatrix %v3float 4
- %PerBatchEnvMapConstantBuffer_t = OpTypeStruct %mat4v3float %v4float %v2float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_PerBatchEnvMapConstantBuffer_t_uint_128 = OpTypeArray %PerBatchEnvMapConstantBuffer_t %uint_128
- %_BindlessFastEnvMapCB_PS_t = OpTypeStruct %_arr_PerBatchEnvMapConstantBuffer_t_uint_128
- %_ptr_Uniform__BindlessFastEnvMapCB_PS_t = OpTypePointer Uniform %_BindlessFastEnvMapCB_PS_t
- %_ = OpVariable %_ptr_Uniform__BindlessFastEnvMapCB_PS_t Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %ushort = OpTypeInt 16 0
- %PerViewPushConst_t = OpTypeStruct %ushort
- %_ptr_PushConstant_PerViewPushConst_t = OpTypePointer PushConstant %PerViewPushConst_t
- %__0 = OpVariable %_ptr_PushConstant_PerViewPushConst_t PushConstant
- %_ptr_PushConstant_ushort = OpTypePointer PushConstant %ushort
- %int_2 = OpConstant %int 2
- %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
- %30 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_30 = OpTypePointer UniformConstant %30
- %g_tColor = OpVariable %_ptr_UniformConstant_30 UniformConstant
- %32 = OpTypeSampler
- %_ptr_UniformConstant_32 = OpTypePointer UniformConstant %32
- %g_sAniso = OpVariable %_ptr_UniformConstant_32 UniformConstant
- %34 = OpTypeSampledImage %30
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )" + kInputGlobals + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK:%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
- %MainPs = OpFunction %void None %14
- %37 = OpLabel
- ;CHECK: %79 = OpFunctionCall %uint %inst_bindless_direct_read_3 %uint_1 %uint_0 %uint_0
- ;CHECK: OpBranch %49
- ;CHECK: %49 = OpLabel
- ;CHECK: OpBranch %48
- ;CHECK: %48 = OpLabel
- %38 = OpLoad %v2float %i_vTextureCoords
- %39 = OpAccessChain %_ptr_PushConstant_ushort %__0 %int_0
- %40 = OpLoad %ushort %39
- %41 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %40 %int_2
- %42 = OpLoad %v2float %41
- %43 = OpFAdd %v2float %38 %42
- ;CHECK-NOT: %42 = OpLoad %v2float %41
- ;CHECK-NOT: %43 = OpFAdd %v2float %38 %42
- ;CHECK: %52 = OpUConvert %uint %40
- ;CHECK: %53 = OpIMul %uint %uint_80 %52
- ;CHECK: %54 = OpIAdd %uint %uint_0 %53
- ;CHECK: %56 = OpIAdd %uint %54 %uint_64
- ;CHECK: %58 = OpIAdd %uint %56 %uint_7
- ;CHECK: %81 = OpULessThan %bool %58 %79
- ;CHECK: OpSelectionMerge %83 None
- ;CHECK: OpBranchConditional %81 %84 %85
- ;CHECK: %84 = OpLabel
- ;CHECK: %86 = OpLoad %v2float %41
- ;CHECK: OpBranch %83
- ;CHECK: %85 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_81 %uint_4 %uint_0 %58 %79
- ;CHECK: OpBranch %83
- ;CHECK: %83 = OpLabel
- ;CHECK: %143 = OpPhi %v2float %86 %84 [[null_v2float]] %85
- ;CHECK: %43 = OpFAdd %v2float %38 %143
- %44 = OpLoad %30 %g_tColor
- %45 = OpLoad %32 %g_sAniso
- %46 = OpSampledImage %34 %44 %45
- %47 = OpImageSampleImplicitLod %v4float %46 %43
- OpStore %_entryPointOutput_vColor %47
- OpReturn
- OpFunctionEnd
- )" + kDirectRead3 + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, false, true);
- }
- TEST_F(InstBindlessTest, UniformMatrixRefRowMajor) {
- // The buffer-oob row major matrix check
- //
- // #version 450
- // #extension GL_EXT_scalar_block_layout : enable
- //
- // layout(location = 0) in highp vec4 a_position;
- // layout(location = 0) out mediump float v_vtxResult;
- //
- // layout(set = 0, binding = 0, std430, row_major) uniform Block
- // {
- // lowp mat4x2 var;
- // };
- //
- // void main (void)
- // {
- // v_vtxResult = var[2][1];
- // }
- // clang-format off
- std::string text = R"(
- OpCapability Shader
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position
- ;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_scalar_block_layout"
- OpName %main "main"
- OpName %v_vtxResult "v_vtxResult"
- OpName %Block "Block"
- OpMemberName %Block 0 "var"
- OpName %_ ""
- OpName %a_position "a_position"
- OpDecorate %v_vtxResult RelaxedPrecision
- OpDecorate %v_vtxResult Location 0
- OpMemberDecorate %Block 0 RowMajor
- OpMemberDecorate %Block 0 RelaxedPrecision
- OpMemberDecorate %Block 0 Offset 0
- OpMemberDecorate %Block 0 MatrixStride 16
- OpDecorate %Block Block
- OpDecorate %_ DescriptorSet 0
- OpDecorate %_ Binding 0
- OpDecorate %21 RelaxedPrecision
- ;CHECK-NOT: OpDecorate %21 RelaxedPrecision
- ;CHECK: OpDecorate %116 RelaxedPrecision
- OpDecorate %a_position Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + R"(
- ;CHECK: OpDecorate %61 RelaxedPrecision
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
- ;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %v_vtxResult = OpVariable %_ptr_Output_float Output
- %v2float = OpTypeVector %float 2
- %mat4v2float = OpTypeMatrix %v2float 4
- %Block = OpTypeStruct %mat4v2float
- %_ptr_Uniform_Block = OpTypePointer Uniform %Block
- %_ = OpVariable %_ptr_Uniform_Block Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_2 = OpConstant %int 2
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %a_position = OpVariable %_ptr_Input_v4float Input
- )" + kInputGlobals + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_uint = OpTypePointer Input %uint
- ;CHECK:%gl_VertexIndex = OpVariable %_ptr_Input_uint Input
- ;CHECK:%gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
- ;CHECK: [[null_float:%\w+]] = OpConstantNull %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: %55 = OpFunctionCall %uint %inst_bindless_direct_read_3 %uint_1 %uint_0 %uint_0
- ;CHECK: OpBranch %26
- ;CHECK: %26 = OpLabel
- ;CHECK: OpBranch %25
- ;CHECK: %25 = OpLabel
- %20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1
- %21 = OpLoad %float %20
- ;CHECK-NOT: %21 = OpLoad %float %20
- ;CHECK: %30 = OpIMul %uint %uint_4 %int_2
- ;CHECK: %31 = OpIAdd %uint %uint_0 %30
- ;CHECK: %32 = OpIMul %uint %uint_16 %uint_1
- ;CHECK: %33 = OpIAdd %uint %31 %32
- ;CHECK: %35 = OpIAdd %uint %33 %uint_3
- ;CHECK: %57 = OpULessThan %bool %35 %55
- ;CHECK: OpSelectionMerge %58 None
- ;CHECK: OpBranchConditional %57 %59 %60
- ;CHECK: %59 = OpLabel
- ;CHECK: %61 = OpLoad %float %20
- ;CHECK: OpBranch %58
- ;CHECK: %60 = OpLabel
- ;CHECK: {{\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_45 %uint_4 %uint_0 %35 %55
- ;CHECK: OpBranch %58
- ;CHECK: %58 = OpLabel
- ;CHECK: %116 = OpPhi %float %61 %59 [[null_float]] %60
- OpStore %v_vtxResult %21
- ;CHECK-NOT: OpStore %v_vtxResult %21
- ;CHECK: OpStore %v_vtxResult %116
- OpReturn
- OpFunctionEnd
- )" + kDirectRead3 + kStreamWrite5Vert;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, false, true);
- }
- TEST_F(InstBindlessTest, UniformMatrixRefColumnMajor) {
- // The buffer-oob column major matrix check
- //
- // #version 450
- // #extension GL_EXT_scalar_block_layout : enable
- //
- // layout(location = 0) in highp vec4 a_position;
- // layout(location = 0) out mediump float v_vtxResult;
- //
- // layout(set = 0, binding = 0, std430, column_major) uniform Block
- // {
- // lowp mat4x2 var;
- // };
- //
- // void main (void)
- // {
- // v_vtxResult = var[2][1];
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position
- ;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_scalar_block_layout"
- OpName %main "main"
- OpName %v_vtxResult "v_vtxResult"
- OpName %Block "Block"
- OpMemberName %Block 0 "var"
- OpName %_ ""
- OpName %a_position "a_position"
- OpDecorate %v_vtxResult RelaxedPrecision
- OpDecorate %v_vtxResult Location 0
- OpMemberDecorate %Block 0 ColMajor
- OpMemberDecorate %Block 0 RelaxedPrecision
- OpMemberDecorate %Block 0 Offset 0
- OpMemberDecorate %Block 0 MatrixStride 8
- OpDecorate %Block Block
- OpDecorate %_ DescriptorSet 0
- OpDecorate %_ Binding 0
- OpDecorate %21 RelaxedPrecision
- ;CHECK-NOT: OpDecorate %21 RelaxedPrecision
- ;CHECK: OpDecorate %115 RelaxedPrecision
- OpDecorate %a_position Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + R"(
- ;CHECK: OpDecorate %61 RelaxedPrecision
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
- ;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %v_vtxResult = OpVariable %_ptr_Output_float Output
- %v2float = OpTypeVector %float 2
- %mat4v2float = OpTypeMatrix %v2float 4
- %Block = OpTypeStruct %mat4v2float
- %_ptr_Uniform_Block = OpTypePointer Uniform %Block
- %_ = OpVariable %_ptr_Uniform_Block Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_2 = OpConstant %int 2
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %a_position = OpVariable %_ptr_Input_v4float Input
- )" + kInputGlobals + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_uint = OpTypePointer Input %uint
- ;CHECK:%gl_VertexIndex = OpVariable %_ptr_Input_uint Input
- ;CHECK:%gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
- ;CHECK: [[null_float:%\w+]] = OpConstantNull %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: %55 = OpFunctionCall %uint %inst_bindless_direct_read_3 %uint_1 %uint_0 %uint_0
- ;CHECK: OpBranch %26
- ;CHECK: %26 = OpLabel
- ;CHECK: OpBranch %25
- ;CHECK: %25 = OpLabel
- %20 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %int_2 %uint_1
- %21 = OpLoad %float %20
- ;CHECK-NOT: %21 = OpLoad %float %20
- ;CHECK: %29 = OpIMul %uint %uint_8 %int_2
- ;CHECK: %30 = OpIAdd %uint %uint_0 %29
- ;CHECK: %32 = OpIMul %uint %uint_4 %uint_1
- ;CHECK: %33 = OpIAdd %uint %30 %32
- ;CHECK: %35 = OpIAdd %uint %33 %uint_3
- ;CHECK: %57 = OpULessThan %bool %35 %55
- ;CHECK: OpSelectionMerge %58 None
- ;CHECK: OpBranchConditional %57 %59 %60
- ;CHECK: %59 = OpLabel
- ;CHECK: %61 = OpLoad %float %20
- ;CHECK: OpBranch %58
- ;CHECK: %60 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_45 %uint_4 %uint_0 %35 %55
- ;CHECK: OpBranch %58
- ;CHECK: %58 = OpLabel
- ;CHECK: %115 = OpPhi %float %61 %59 [[null_float]] %60
- OpStore %v_vtxResult %21
- ;CHECK-NOT: OpStore %v_vtxResult %21
- ;CHECK: OpStore %v_vtxResult %115
- OpReturn
- OpFunctionEnd
- )" + kDirectRead3 + kStreamWrite5Vert;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- ValidatorOptions()->uniform_buffer_standard_layout = true;
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, false, true);
- }
- TEST_F(InstBindlessTest, UniformMatrixVecRefRowMajor) {
- // The buffer-oob row major matrix vector ref check
- //
- // #version 450
- // #extension GL_EXT_scalar_block_layout : enable
- //
- // layout(location = 0) in highp vec4 a_position;
- // layout(location = 0) out highp vec2 v_vtxResult;
- //
- // layout(set = 0, binding = 0, std430, row_major) uniform Block
- // {
- // lowp mat2 var[3][4];
- // };
- //
- // void main (void)
- // {
- // v_vtxResult = var[2][3][1];
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position
- ;CHECK: OpEntryPoint Vertex %main "main" %v_vtxResult %_ %a_position %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_scalar_block_layout"
- OpName %main "main"
- OpName %v_vtxResult "v_vtxResult"
- OpName %Block "Block"
- OpMemberName %Block 0 "var"
- OpName %_ ""
- OpName %a_position "a_position"
- OpDecorate %v_vtxResult Location 0
- OpDecorate %_arr_mat2v2float_uint_4 ArrayStride 32
- OpDecorate %_arr__arr_mat2v2float_uint_4_uint_3 ArrayStride 128
- OpMemberDecorate %Block 0 RowMajor
- OpMemberDecorate %Block 0 RelaxedPrecision
- OpMemberDecorate %Block 0 Offset 0
- OpMemberDecorate %Block 0 MatrixStride 16
- OpDecorate %Block Block
- OpDecorate %_ DescriptorSet 0
- OpDecorate %_ Binding 0
- OpDecorate %26 RelaxedPrecision
- ;CHECK-NOT: OpDecorate %26 RelaxedPrecision
- ;CHECK: OpDecorate %125 RelaxedPrecision
- OpDecorate %a_position Location 0
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kInputDecorations + R"(
- ;CHECK: OpDecorate %70 RelaxedPrecision
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_VertexIndex BuiltIn VertexIndex
- ;CHECK: OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %_ptr_Output_v2float = OpTypePointer Output %v2float
- %v_vtxResult = OpVariable %_ptr_Output_v2float Output
- %mat2v2float = OpTypeMatrix %v2float 2
- %uint = OpTypeInt 32 0
- %uint_4 = OpConstant %uint 4
- %_arr_mat2v2float_uint_4 = OpTypeArray %mat2v2float %uint_4
- %uint_3 = OpConstant %uint 3
- %_arr__arr_mat2v2float_uint_4_uint_3 = OpTypeArray %_arr_mat2v2float_uint_4 %uint_3
- %Block = OpTypeStruct %_arr__arr_mat2v2float_uint_4_uint_3
- %_ptr_Uniform_Block = OpTypePointer Uniform %Block
- %_ = OpVariable %_ptr_Uniform_Block Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_2 = OpConstant %int 2
- %int_3 = OpConstant %int 3
- %int_1 = OpConstant %int 1
- %_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %a_position = OpVariable %_ptr_Input_v4float Input
- )" + kInputGlobals + kOutputGlobals + R"(
- ;CHECK:%_ptr_Input_uint = OpTypePointer Input %uint
- ;CHECK:%gl_VertexIndex = OpVariable %_ptr_Input_uint Input
- ;CHECK:%gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
- ;CHECK: [[null_v2float:%\w+]] = OpConstantNull %v2float
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: %64 = OpFunctionCall %uint %inst_bindless_direct_read_3 %uint_1 %uint_0 %uint_0
- ;CHECK: OpBranch %31
- ;CHECK: %31 = OpLabel
- ;CHECK: OpBranch %30
- ;CHECK: %30 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_v2float %_ %int_0 %int_2 %int_3 %int_1
- %26 = OpLoad %v2float %25
- OpStore %v_vtxResult %26
- ;CHECK-NOT: %26 = OpLoad %v2float %25
- ;CHECK-NOT: OpStore %v_vtxResult %26
- ;CHECK: %34 = OpIMul %uint %uint_128 %int_2
- ;CHECK: %35 = OpIAdd %uint %uint_0 %34
- ;CHECK: %37 = OpIMul %uint %uint_32 %int_3
- ;CHECK: %38 = OpIAdd %uint %35 %37
- ;CHECK: %40 = OpIMul %uint %uint_4 %int_1
- ;CHECK: %41 = OpIAdd %uint %38 %40
- ;CHECK: %43 = OpIAdd %uint %41 %uint_19
- ;CHECK: %66 = OpULessThan %bool %43 %64
- ;CHECK: OpSelectionMerge %67 None
- ;CHECK: OpBranchConditional %66 %68 %69
- ;CHECK: %68 = OpLabel
- ;CHECK: %70 = OpLoad %v2float %25
- ;CHECK: OpBranch %67
- ;CHECK: %69 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_51 %uint_4 %uint_0 %43 %64
- ;CHECK: OpBranch %67
- ;CHECK: %67 = OpLabel
- ;CHECK: %125 = OpPhi %v2float %70 %68 [[null_v2float]] %69
- ;CHECK: OpStore %v_vtxResult %125
- OpReturn
- OpFunctionEnd
- )" + kDirectRead3 + kStreamWrite5Vert;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, false, true);
- }
- TEST_F(InstBindlessTest, ImageBufferOOBRead) {
- // Texel buffer (imagebuffer) oob check for ImageRead
- //
- // #version 450
- // layout(set=3, binding=7, r32f) uniform readonly imageBuffer s;
- // layout(location=11) out vec4 x;
- // layout(location=13) in flat int ii;
- //
- // void main(){
- // x = imageLoad(s, ii);
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability ImageBuffer
- ;CHECK: OpCapability ImageQuery
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %x %s %ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpName %main "main"
- OpName %x "x"
- OpName %s "s"
- OpName %ii "ii"
- OpDecorate %x Location 11
- OpDecorate %s DescriptorSet 3
- OpDecorate %s Binding 7
- OpDecorate %s NonWritable
- OpDecorate %ii Flat
- OpDecorate %ii Location 13
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %x = OpVariable %_ptr_Output_v4float Output
- %10 = OpTypeImage %float Buffer 0 0 0 2 R32f
- %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
- %s = OpVariable %_ptr_UniformConstant_10 UniformConstant
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %ii = OpVariable %_ptr_Input_int Input
- ;CHECK: %uint = OpTypeInt 32 0
- ;CHECK: %bool = OpTypeBool
- ;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: OpBranch %21
- ;CHECK: %21 = OpLabel
- ;CHECK: OpBranch %20
- ;CHECK: %20 = OpLabel
- ;CHECK: OpBranch %19
- ;CHECK: %19 = OpLabel
- %13 = OpLoad %10 %s
- %17 = OpLoad %int %ii
- %18 = OpImageRead %v4float %13 %17
- OpStore %x %18
- ;CHECK-NOT: %18 = OpImageRead %v4float %13 %17
- ;CHECK-NOT: OpStore %x %18
- ;CHECK: %23 = OpBitcast %uint %17
- ;CHECK: %25 = OpImageQuerySize %uint %13
- ;CHECK: %27 = OpULessThan %bool %23 %25
- ;CHECK: OpSelectionMerge %29 None
- ;CHECK: OpBranchConditional %27 %30 %31
- ;CHECK: %30 = OpLabel
- ;CHECK: %32 = OpLoad %10 %s
- ;CHECK: %33 = OpImageRead %v4float %32 %17
- ;CHECK: OpBranch %29
- ;CHECK: %31 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_33 %uint_7 %uint_0 %23 %25
- ;CHECK: OpBranch %29
- ;CHECK: %29 = OpLabel
- ;CHECK: %94 = OpPhi %v4float %33 %30 [[null_v4float]] %31
- ;CHECK: OpStore %x %94
- OpReturn
- OpFunctionEnd
- )" + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, true, true);
- }
- TEST_F(InstBindlessTest, ImageBufferOOBWrite) {
- // Texel buffer (imagebuffer) oob check for ImageWrite
- //
- // #version 450
- // layout(set=3, binding=7, r32f) uniform readonly imageBuffer s;
- // layout(location=11) out vec4 x;
- // layout(location=13) in flat int ii;
- //
- // void main(){
- // imageStore(s, ii, x);
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability ImageBuffer
- ;CHECK: OpCapability ImageQuery
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %s %ii %x
- ;CHECK: OpEntryPoint Fragment %main "main" %s %ii %x %inst_bindless_output_buffer %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpName %main "main"
- OpName %s "s"
- OpName %ii "ii"
- OpName %x "x"
- OpDecorate %s DescriptorSet 3
- OpDecorate %s Binding 7
- OpDecorate %s NonReadable
- OpDecorate %ii Flat
- OpDecorate %ii Location 13
- OpDecorate %x Location 11
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %7 = OpTypeImage %float Buffer 0 0 0 2 R32f
- %_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
- %s = OpVariable %_ptr_UniformConstant_7 UniformConstant
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %ii = OpVariable %_ptr_Input_int Input
- %v4float = OpTypeVector %float 4
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %x = OpVariable %_ptr_Output_v4float Output
- ;CHECK: %uint = OpTypeInt 32 0
- ;CHECK: %bool = OpTypeBool
- ;CHECK: {{%\w+}} = OpTypeFunction %void %uint %uint %uint %uint %uint
- ;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: %v4uint = OpTypeVector %uint 4
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: OpBranch %21
- ;CHECK: %21 = OpLabel
- ;CHECK: OpBranch %20
- ;CHECK: %20 = OpLabel
- ;CHECK: OpBranch %19
- ;CHECK: %19 = OpLabel
- %10 = OpLoad %7 %s
- %14 = OpLoad %int %ii
- %18 = OpLoad %v4float %x
- OpImageWrite %10 %14 %18
- ;CHECK-NOT: OpImageWrite %10 %14 %18
- ;CHECK: %23 = OpBitcast %uint %14
- ;CHECK: %25 = OpImageQuerySize %uint %10
- ;CHECK: %27 = OpULessThan %bool %23 %25
- ;CHECK: OpSelectionMerge %29 None
- ;CHECK: OpBranchConditional %27 %30 %31
- ;CHECK: %30 = OpLabel
- ;CHECK: %32 = OpLoad %7 %s
- ;CHECK: OpImageWrite %32 %14 %18
- ;CHECK: OpBranch %29
- ;CHECK: %31 = OpLabel
- ;CHECK: %91 = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_34 %uint_7 %uint_0 %23 %25
- ;CHECK: OpBranch %29
- ;CHECK: %29 = OpLabel
- OpReturn
- OpFunctionEnd
- )" + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, true, true);
- }
- TEST_F(InstBindlessTest, TextureBufferOOBFetch) {
- // Texel buffer (texturebuffer) oob check for ImageFetch
- //
- // #version 450
- // layout(set=3, binding=7) uniform textureBuffer s;
- // layout(location=11) out vec4 x;
- // layout(location=13) in flat int ii;
- //
- // void main(){
- // x = texelFetch(s, ii);
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability SampledBuffer
- ;CHECK: OpCapability ImageQuery
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %x %s %ii
- ;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %inst_bindless_output_buffer %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpName %main "main"
- OpName %x "x"
- OpName %s "s"
- OpName %ii "ii"
- OpDecorate %x Location 11
- OpDecorate %s DescriptorSet 3
- OpDecorate %s Binding 7
- OpDecorate %ii Flat
- OpDecorate %ii Location 13
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %x = OpVariable %_ptr_Output_v4float Output
- %10 = OpTypeImage %float Buffer 0 0 0 1 Unknown
- %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
- %s = OpVariable %_ptr_UniformConstant_10 UniformConstant
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %ii = OpVariable %_ptr_Input_int Input
- ;CHECK: %uint = OpTypeInt 32 0
- ;CHECK: %bool = OpTypeBool
- ;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: OpBranch %21
- ;CHECK: %21 = OpLabel
- ;CHECK: OpBranch %20
- ;CHECK: %20 = OpLabel
- ;CHECK: OpBranch %19
- ;CHECK: %19 = OpLabel
- %13 = OpLoad %10 %s
- %17 = OpLoad %int %ii
- %18 = OpImageFetch %v4float %13 %17
- OpStore %x %18
- ;CHECK-NOT: %18 = OpImageFetch %v4float %13 %17
- ;CHECK-NOT: OpStore %x %18
- ;CHECK: %23 = OpBitcast %uint %17
- ;CHECK: %25 = OpImageQuerySize %uint %13
- ;CHECK: %27 = OpULessThan %bool %23 %25
- ;CHECK: OpSelectionMerge %29 None
- ;CHECK: OpBranchConditional %27 %30 %31
- ;CHECK: %30 = OpLabel
- ;CHECK: %32 = OpLoad %10 %s
- ;CHECK: %33 = OpImageFetch %v4float %32 %17
- ;CHECK: OpBranch %29
- ;CHECK: %31 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_32 %uint_6 %uint_0 %23 %25
- ;CHECK: OpBranch %29
- ;CHECK: %29 = OpLabel
- ;CHECK: %95 = OpPhi %v4float %33 %30 [[null_v4float]] %31
- ;CHECK: OpStore %x %95
- OpReturn
- OpFunctionEnd
- )" + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, true, true);
- }
- TEST_F(InstBindlessTest, SamplerBufferOOBFetch) {
- // Texel buffer (samplerbuffer) oob check for ImageFetch
- //
- // #version 450
- // layout(set=3, binding=7) uniform samplerBuffer s;
- // layout(location=11) out vec4 x;
- // layout(location=13) in flat int ii;
- //
- // void main(){
- // x = texelFetch(s, ii);
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability SampledBuffer
- ;CHECK: OpCapability ImageQuery
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %x %s %ii
- ;CHECK: OpEntryPoint Fragment %main "main" %x %s %ii %inst_bindless_output_buffer %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpName %main "main"
- OpName %x "x"
- OpName %s "s"
- OpName %ii "ii"
- OpDecorate %x Location 11
- OpDecorate %s DescriptorSet 3
- OpDecorate %s Binding 7
- OpDecorate %ii Flat
- OpDecorate %ii Location 13
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %x = OpVariable %_ptr_Output_v4float Output
- %10 = OpTypeImage %float Buffer 0 0 0 1 Unknown
- %11 = OpTypeSampledImage %10
- %_ptr_UniformConstant_11 = OpTypePointer UniformConstant %11
- %s = OpVariable %_ptr_UniformConstant_11 UniformConstant
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %ii = OpVariable %_ptr_Input_int Input
- ;CHECK: %uint = OpTypeInt 32 0
- ;CHECK: %bool = OpTypeBool
- ;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: OpBranch %23
- ;CHECK: %23 = OpLabel
- ;CHECK: OpBranch %22
- ;CHECK: %22 = OpLabel
- ;CHECK: OpBranch %21
- ;CHECK: %21 = OpLabel
- %14 = OpLoad %11 %s
- %18 = OpLoad %int %ii
- %19 = OpImage %10 %14
- %20 = OpImageFetch %v4float %19 %18
- OpStore %x %20
- ;CHECK-NOT: %20 = OpImageFetch %v4float %19 %18
- ;CHECK-NOT: OpStore %x %20
- ;CHECK: %25 = OpBitcast %uint %18
- ;CHECK: %27 = OpImageQuerySize %uint %19
- ;CHECK: %29 = OpULessThan %bool %25 %27
- ;CHECK: OpSelectionMerge %31 None
- ;CHECK: OpBranchConditional %29 %32 %33
- ;CHECK: %32 = OpLabel
- ;CHECK: %34 = OpLoad %11 %s
- ;CHECK: %35 = OpImage %10 %34
- ;CHECK: %36 = OpImageFetch %v4float %35 %18
- ;CHECK: OpBranch %31
- ;CHECK: %33 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_34 %uint_6 %uint_0 %25 %27
- ;CHECK: OpBranch %31
- ;CHECK: %31 = OpLabel
- ;CHECK: %98 = OpPhi %v4float %36 %32 [[null_v4float]] %33
- ;CHECK: OpStore %x %98
- OpReturn
- OpFunctionEnd
- )" + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, true, true);
- }
- TEST_F(InstBindlessTest, SamplerBufferConstructorOOBFetch) {
- // Texel buffer (samplerbuffer constructor) oob check for ImageFetch
- //
- // #version 450
- // layout(set=3, binding=7) uniform textureBuffer tBuf;
- // layout(set=3, binding=8) uniform sampler s;
- // layout(location=11) out vec4 x;
- // layout(location=13) in flat int ii;
- //
- // void main(){
- // x = texelFetch(samplerBuffer(tBuf, s), ii);
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability SampledBuffer
- ;CHECK: OpCapability ImageQuery
- ;CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %x %tBuf %s %ii
- ;CHECK: OpEntryPoint Fragment %main "main" %x %tBuf %s %ii %inst_bindless_output_buffer %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpName %main "main"
- OpName %x "x"
- OpName %tBuf "tBuf"
- OpName %s "s"
- OpName %ii "ii"
- OpDecorate %x Location 11
- OpDecorate %tBuf DescriptorSet 3
- OpDecorate %tBuf Binding 7
- OpDecorate %s DescriptorSet 3
- OpDecorate %s Binding 8
- OpDecorate %ii Flat
- OpDecorate %ii Location 13
- ;CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
- )" + kOutputDecorations + R"(
- ;CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %x = OpVariable %_ptr_Output_v4float Output
- %10 = OpTypeImage %float Buffer 0 0 0 1 Unknown
- %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
- %tBuf = OpVariable %_ptr_UniformConstant_10 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %s = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %18 = OpTypeSampledImage %10
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %ii = OpVariable %_ptr_Input_int Input
- ;CHECK: %uint = OpTypeInt 32 0
- ;CHECK: %bool = OpTypeBool
- ;CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
- )" + kOutputGlobals + R"(
- ;CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- ;CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
- ;CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- ;CHECK: [[null_v4float:%\w+]] = OpConstantNull %v4float
- %main = OpFunction %void None %3
- %5 = OpLabel
- ;CHECK: OpBranch %28
- ;CHECK: %28 = OpLabel
- ;CHECK: OpBranch %27
- ;CHECK: %27 = OpLabel
- ;CHECK: OpBranch %26
- ;CHECK: %26 = OpLabel
- %13 = OpLoad %10 %tBuf
- %17 = OpLoad %14 %s
- %19 = OpSampledImage %18 %13 %17
- %23 = OpLoad %int %ii
- %24 = OpImage %10 %19
- %25 = OpImageFetch %v4float %24 %23
- OpStore %x %25
- ;CHECK-NOT: %25 = OpImageFetch %v4float %24 %23
- ;CHECK-NOT: OpStore %x %25
- ;CHECK: %30 = OpBitcast %uint %23
- ;CHECK: %32 = OpImageQuerySize %uint %24
- ;CHECK: %34 = OpULessThan %bool %30 %32
- ;CHECK: OpSelectionMerge %36 None
- ;CHECK: OpBranchConditional %34 %37 %38
- ;CHECK: %37 = OpLabel
- ;CHECK: %39 = OpLoad %10 %tBuf
- ;CHECK: %40 = OpSampledImage %18 %39 %17
- ;CHECK: %41 = OpImage %10 %40
- ;CHECK: %42 = OpImageFetch %v4float %41 %23
- ;CHECK: OpBranch %36
- ;CHECK: %38 = OpLabel
- ;CHECK: {{%\w+}} = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_42 %uint_6 %uint_0 %30 %32
- ;CHECK: OpBranch %36
- ;CHECK: %36 = OpLabel
- ;CHECK: %104 = OpPhi %v4float %42 %37 [[null_v4float]] %38
- ;CHECK: OpStore %x %104
- OpReturn
- OpFunctionEnd
- )" + kStreamWrite5Frag;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false,
- false, true, true, true);
- }
- TEST_F(InstBindlessTest, DeviceBufferAddressOOB) {
- // #version 450
- // #extension GL_EXT_buffer_reference : enable
- // layout(buffer_reference, buffer_reference_align = 16) buffer bufStruct;
- // layout(set = 0, binding = 0) uniform ufoo {
- // bufStruct data;
- // int nWrites;
- // } u_info;
- // layout(buffer_reference, std140) buffer bufStruct {
- // int a[4];
- // };
- // void main() {
- // for (int i=0; i < u_info.nWrites; ++i) {
- // u_info.data.a[i] = 0xdeadca71;
- // }
- // }
- // clang-format off
- const std::string text = R"(
- OpCapability Shader
- OpCapability PhysicalStorageBufferAddresses
- ;CHECK: OpCapability Int64
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel PhysicalStorageBuffer64 GLSL450
- OpEntryPoint Vertex %main "main" %u_info
- ;CHECK: OpEntryPoint Vertex %main "main" %u_info %inst_bindless_input_buffer %inst_bindless_output_buffer %gl_VertexIndex %gl_InstanceIndex
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_buffer_reference"
- OpName %main "main"
- OpName %i "i"
- OpName %ufoo "ufoo"
- OpMemberName %ufoo 0 "data"
- OpMemberName %ufoo 1 "nWrites"
- OpName %bufStruct "bufStruct"
- OpMemberName %bufStruct 0 "a"
- OpName %u_info "u_info"
- OpMemberDecorate %ufoo 0 Offset 0
- OpMemberDecorate %ufoo 1 Offset 8
- OpDecorate %ufoo Block
- OpDecorate %_arr_int_uint_4 ArrayStride 16
- OpMemberDecorate %bufStruct 0 Offset 0
- OpDecorate %bufStruct Block
- OpDecorate %u_info DescriptorSet 0
- OpDecorate %u_info Binding 0)"
- + kInputDecorations + kOutputDecorations +
- R"(%void = OpTypeVoid
- %3 = OpTypeFunction %void
- %int = OpTypeInt 32 1
- %_ptr_Function_int = OpTypePointer Function %int
- %int_0 = OpConstant %int 0
- OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer
- %ufoo = OpTypeStruct %_ptr_PhysicalStorageBuffer_bufStruct %int
- %uint = OpTypeInt 32 0
- %uint_4 = OpConstant %uint 4
- %_arr_int_uint_4 = OpTypeArray %int %uint_4
- %bufStruct = OpTypeStruct %_arr_int_uint_4
- %_ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer PhysicalStorageBuffer %bufStruct
- %_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
- %u_info = OpVariable %_ptr_Uniform_ufoo Uniform
- %int_1 = OpConstant %int 1
- %_ptr_Uniform_int = OpTypePointer Uniform %int
- %bool = OpTypeBool
- %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_bufStruct
- %int_n559035791 = OpConstant %int -559035791
- %_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int)"
- + kInputGlobals + kOutputGlobals +
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %i = OpVariable %_ptr_Function_int Function
- ;CHECK: OpBranch %137
- ;CHECK: %137 = OpLabel
- ;CHECK: 65 = OpFunctionCall %uint %inst_bindless_direct_read_3 %uint_1 %uint_0 %uint_0
- ;CHECK: OpBranch %40
- ;CHECK: 40 = OpLabel
- ;CHECK: OpBranch %39
- ;CHECK: 39 = OpLabel
- OpStore %i %int_0
- OpBranch %10
- %10 = OpLabel
- OpLoopMerge %12 %13 None
- OpBranch %14
- %14 = OpLabel
- %15 = OpLoad %int %i
- %26 = OpAccessChain %_ptr_Uniform_int %u_info %int_1
- %27 = OpLoad %int %26
- %29 = OpSLessThan %bool %15 %27
- ;CHECK-NOT: %27 = OpLoad %int %26
- ;CHECK-NOT: %29 = OpSLessThan %bool %15 %27
- ;CHECK: 43 = OpIAdd %uint %uint_8 %uint_3
- ;CHECK: 66 = OpULessThan %bool %43 %65
- ;CHECK: OpSelectionMerge %67 None
- ;CHECK: OpBranchConditional %66 %68 %69
- ;CHECK: 68 = OpLabel
- ;CHECK: 70 = OpLoad %int %26
- ;CHECK: OpBranch %67
- ;CHECK: 69 = OpLabel
- ;CHECK: 122 = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_54 %uint_4 %uint_0 %43 %65
- ;CHECK: OpBranch %67
- ;CHECK: 67 = OpLabel
- ;CHECK: 124 = OpPhi %int %70 %68 %123 %69
- ;CHECK: 29 = OpSLessThan %bool %15 %124
- OpBranchConditional %29 %11 %12
- %11 = OpLabel
- %31 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0
- %32 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %31
- ;CHECK-NOT: %32 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %31
- ;CHECK: 125 = OpIAdd %uint %uint_0 %uint_7
- ;CHECK: 126 = OpULessThan %bool %125 %65
- ;CHECK: OpSelectionMerge %127 None
- ;CHECK: OpBranchConditional %126 %128 %129
- ;CHECK: 128 = OpLabel
- ;CHECK: 130 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %31
- ;CHECK: OpBranch %127
- ;CHECK: 129 = OpLabel
- ;CHECK: 132 = OpFunctionCall %void %inst_bindless_stream_write_5 %uint_59 %uint_4 %uint_0 %125 %65
- ;CHECK: 135 = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_bufStruct %134
- ;CHECK: OpBranch %127
- ;CHECK: 127 = OpLabel
- ;CHECK: 136 = OpPhi %_ptr_PhysicalStorageBuffer_bufStruct %130 %128 %135 %129
- %33 = OpLoad %int %i
- %36 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %32 %int_0 %33
- ;CHECK-NOT: %36 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %32 %int_0 %33
- ;CHECK: %36 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %136 %int_0 %33
- OpStore %36 %int_n559035791 Aligned 16
- OpBranch %13
- %13 = OpLabel
- %37 = OpLoad %int %i
- %38 = OpIAdd %int %37 %int_1
- OpStore %i %38
- OpBranch %10
- %12 = OpLabel
- OpReturn
- OpFunctionEnd)"
- + kDirectRead3 + kStreamWrite5Vert;
- // clang-format on
- SetTargetEnv(SPV_ENV_VULKAN_1_2);
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, false, true,
- true, true, true);
- }
- // TODO(greg-lunarg): Add tests to verify handling of these cases:
- //
- // Compute shader
- // Geometry shader
- // Tessellation control shader
- // Tessellation eval shader
- // OpImage
- // SampledImage variable
- } // namespace
- } // namespace opt
- } // namespace spvtools
|