inst_bindless_check_test.cpp 362 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834
  1. // Copyright (c) 2017 Valve Corporation
  2. // Copyright (c) 2017 LunarG Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // Bindless Check Instrumentation Tests.
  16. // Tests ending with V2 use version 2 record format.
  17. #include <string>
  18. #include <vector>
  19. #include "test/opt/assembly_builder.h"
  20. #include "test/opt/pass_fixture.h"
  21. #include "test/opt/pass_utils.h"
  22. namespace spvtools {
  23. namespace opt {
  24. namespace {
  25. using InstBindlessTest = PassTest<::testing::Test>;
  26. TEST_F(InstBindlessTest, Simple) {
  27. // Texture2D g_tColor[128];
  28. //
  29. // layout(push_constant) cbuffer PerViewConstantBuffer_t
  30. // {
  31. // uint g_nDataIdx;
  32. // };
  33. //
  34. // SamplerState g_sAniso;
  35. //
  36. // struct PS_INPUT
  37. // {
  38. // float2 vTextureCoords : TEXCOORD2;
  39. // };
  40. //
  41. // struct PS_OUTPUT
  42. // {
  43. // float4 vColor : SV_Target0;
  44. // };
  45. //
  46. // PS_OUTPUT MainPs(PS_INPUT i)
  47. // {
  48. // PS_OUTPUT ps_output;
  49. // ps_output.vColor =
  50. // g_tColor[ g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
  51. // return ps_output;
  52. // }
  53. const std::string entry_before =
  54. R"(OpCapability Shader
  55. %1 = OpExtInstImport "GLSL.std.450"
  56. OpMemoryModel Logical GLSL450
  57. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  58. OpExecutionMode %MainPs OriginUpperLeft
  59. OpSource HLSL 500
  60. )";
  61. const std::string entry_after =
  62. R"(OpCapability Shader
  63. OpExtension "SPV_KHR_storage_buffer_storage_class"
  64. %1 = OpExtInstImport "GLSL.std.450"
  65. OpMemoryModel Logical GLSL450
  66. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  67. OpExecutionMode %MainPs OriginUpperLeft
  68. OpSource HLSL 500
  69. )";
  70. const std::string names_annots =
  71. R"(OpName %MainPs "MainPs"
  72. OpName %g_tColor "g_tColor"
  73. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  74. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  75. OpName %_ ""
  76. OpName %g_sAniso "g_sAniso"
  77. OpName %i_vTextureCoords "i.vTextureCoords"
  78. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  79. OpDecorate %g_tColor DescriptorSet 3
  80. OpDecorate %g_tColor Binding 0
  81. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  82. OpDecorate %PerViewConstantBuffer_t Block
  83. OpDecorate %g_sAniso DescriptorSet 0
  84. OpDecorate %i_vTextureCoords Location 0
  85. OpDecorate %_entryPointOutput_vColor Location 0
  86. )";
  87. const std::string new_annots =
  88. R"(OpDecorate %_runtimearr_uint ArrayStride 4
  89. OpDecorate %_struct_55 Block
  90. OpMemberDecorate %_struct_55 0 Offset 0
  91. OpMemberDecorate %_struct_55 1 Offset 4
  92. OpDecorate %57 DescriptorSet 7
  93. OpDecorate %57 Binding 0
  94. OpDecorate %gl_FragCoord BuiltIn FragCoord
  95. )";
  96. const std::string consts_types_vars =
  97. R"(%void = OpTypeVoid
  98. %10 = OpTypeFunction %void
  99. %float = OpTypeFloat 32
  100. %v2float = OpTypeVector %float 2
  101. %v4float = OpTypeVector %float 4
  102. %int = OpTypeInt 32 1
  103. %int_0 = OpConstant %int 0
  104. %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
  105. %uint = OpTypeInt 32 0
  106. %uint_128 = OpConstant %uint 128
  107. %_arr_16_uint_128 = OpTypeArray %16 %uint_128
  108. %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
  109. %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
  110. %PerViewConstantBuffer_t = OpTypeStruct %uint
  111. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  112. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  113. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  114. %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
  115. %24 = OpTypeSampler
  116. %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
  117. %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
  118. %26 = OpTypeSampledImage %16
  119. %_ptr_Input_v2float = OpTypePointer Input %v2float
  120. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  121. %_ptr_Output_v4float = OpTypePointer Output %v4float
  122. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  123. )";
  124. const std::string new_consts_types_vars =
  125. R"(%uint_0 = OpConstant %uint 0
  126. %bool = OpTypeBool
  127. %48 = OpTypeFunction %void %uint %uint %uint %uint
  128. %_runtimearr_uint = OpTypeRuntimeArray %uint
  129. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  130. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  131. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  132. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  133. %uint_9 = OpConstant %uint 9
  134. %uint_4 = OpConstant %uint 4
  135. %uint_1 = OpConstant %uint 1
  136. %uint_23 = OpConstant %uint 23
  137. %uint_2 = OpConstant %uint 2
  138. %uint_3 = OpConstant %uint 3
  139. %_ptr_Input_v4float = OpTypePointer Input %v4float
  140. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  141. %v4uint = OpTypeVector %uint 4
  142. %uint_5 = OpConstant %uint 5
  143. %uint_6 = OpConstant %uint 6
  144. %uint_7 = OpConstant %uint 7
  145. %uint_8 = OpConstant %uint 8
  146. %uint_56 = OpConstant %uint 56
  147. %103 = OpConstantNull %v4float
  148. )";
  149. const std::string func_pt1 =
  150. R"(%MainPs = OpFunction %void None %10
  151. %29 = OpLabel
  152. %30 = OpLoad %v2float %i_vTextureCoords
  153. %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  154. %32 = OpLoad %uint %31
  155. %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
  156. %34 = OpLoad %16 %33
  157. %35 = OpLoad %24 %g_sAniso
  158. %36 = OpSampledImage %26 %34 %35
  159. )";
  160. const std::string func_pt2_before =
  161. R"(%37 = OpImageSampleImplicitLod %v4float %36 %30
  162. OpStore %_entryPointOutput_vColor %37
  163. OpReturn
  164. OpFunctionEnd
  165. )";
  166. const std::string func_pt2_after =
  167. R"(%40 = OpULessThan %bool %32 %uint_128
  168. OpSelectionMerge %41 None
  169. OpBranchConditional %40 %42 %43
  170. %42 = OpLabel
  171. %44 = OpLoad %16 %33
  172. %45 = OpSampledImage %26 %44 %35
  173. %46 = OpImageSampleImplicitLod %v4float %45 %30
  174. OpBranch %41
  175. %43 = OpLabel
  176. %102 = OpFunctionCall %void %47 %uint_56 %uint_0 %32 %uint_128
  177. OpBranch %41
  178. %41 = OpLabel
  179. %104 = OpPhi %v4float %46 %42 %103 %43
  180. OpStore %_entryPointOutput_vColor %104
  181. OpReturn
  182. OpFunctionEnd
  183. )";
  184. const std::string output_func =
  185. R"(%47 = OpFunction %void None %48
  186. %49 = OpFunctionParameter %uint
  187. %50 = OpFunctionParameter %uint
  188. %51 = OpFunctionParameter %uint
  189. %52 = OpFunctionParameter %uint
  190. %53 = OpLabel
  191. %59 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  192. %62 = OpAtomicIAdd %uint %59 %uint_4 %uint_0 %uint_9
  193. %63 = OpIAdd %uint %62 %uint_9
  194. %64 = OpArrayLength %uint %57 1
  195. %65 = OpULessThanEqual %bool %63 %64
  196. OpSelectionMerge %66 None
  197. OpBranchConditional %65 %67 %66
  198. %67 = OpLabel
  199. %68 = OpIAdd %uint %62 %uint_0
  200. %70 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %68
  201. OpStore %70 %uint_9
  202. %72 = OpIAdd %uint %62 %uint_1
  203. %73 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %72
  204. OpStore %73 %uint_23
  205. %75 = OpIAdd %uint %62 %uint_2
  206. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  207. OpStore %76 %49
  208. %78 = OpIAdd %uint %62 %uint_3
  209. %79 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %78
  210. OpStore %79 %uint_4
  211. %82 = OpLoad %v4float %gl_FragCoord
  212. %84 = OpBitcast %v4uint %82
  213. %85 = OpCompositeExtract %uint %84 0
  214. %86 = OpIAdd %uint %62 %uint_4
  215. %87 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %86
  216. OpStore %87 %85
  217. %88 = OpCompositeExtract %uint %84 1
  218. %90 = OpIAdd %uint %62 %uint_5
  219. %91 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %90
  220. OpStore %91 %88
  221. %93 = OpIAdd %uint %62 %uint_6
  222. %94 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %93
  223. OpStore %94 %50
  224. %96 = OpIAdd %uint %62 %uint_7
  225. %97 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %96
  226. OpStore %97 %51
  227. %99 = OpIAdd %uint %62 %uint_8
  228. %100 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %99
  229. OpStore %100 %52
  230. OpBranch %66
  231. %66 = OpLabel
  232. OpReturn
  233. OpFunctionEnd
  234. )";
  235. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  236. SinglePassRunAndCheck<InstBindlessCheckPass>(
  237. entry_before + names_annots + consts_types_vars + func_pt1 +
  238. func_pt2_before,
  239. entry_after + names_annots + new_annots + consts_types_vars +
  240. new_consts_types_vars + func_pt1 + func_pt2_after + output_func,
  241. true, true, 7u, 23u, false, false, 1u);
  242. }
  243. TEST_F(InstBindlessTest, NoInstrumentConstIndexInbounds) {
  244. // Texture2D g_tColor[128];
  245. //
  246. // SamplerState g_sAniso;
  247. //
  248. // struct PS_INPUT
  249. // {
  250. // float2 vTextureCoords : TEXCOORD2;
  251. // };
  252. //
  253. // struct PS_OUTPUT
  254. // {
  255. // float4 vColor : SV_Target0;
  256. // };
  257. //
  258. // PS_OUTPUT MainPs(PS_INPUT i)
  259. // {
  260. // PS_OUTPUT ps_output;
  261. //
  262. // ps_output.vColor = g_tColor[ 37 ].Sample(g_sAniso, i.vTextureCoords.xy);
  263. // return ps_output;
  264. // }
  265. const std::string before =
  266. R"(OpCapability Shader
  267. %1 = OpExtInstImport "GLSL.std.450"
  268. OpMemoryModel Logical GLSL450
  269. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  270. OpExecutionMode %MainPs OriginUpperLeft
  271. OpSource HLSL 500
  272. OpName %MainPs "MainPs"
  273. OpName %g_tColor "g_tColor"
  274. OpName %g_sAniso "g_sAniso"
  275. OpName %i_vTextureCoords "i.vTextureCoords"
  276. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  277. OpDecorate %g_tColor DescriptorSet 3
  278. OpDecorate %g_tColor Binding 0
  279. OpDecorate %g_sAniso DescriptorSet 0
  280. OpDecorate %i_vTextureCoords Location 0
  281. OpDecorate %_entryPointOutput_vColor Location 0
  282. %void = OpTypeVoid
  283. %8 = OpTypeFunction %void
  284. %float = OpTypeFloat 32
  285. %v2float = OpTypeVector %float 2
  286. %v4float = OpTypeVector %float 4
  287. %int = OpTypeInt 32 1
  288. %int_0 = OpConstant %int 0
  289. %int_37 = OpConstant %int 37
  290. %15 = OpTypeImage %float 2D 0 0 0 1 Unknown
  291. %uint = OpTypeInt 32 0
  292. %uint_128 = OpConstant %uint 128
  293. %_arr_15_uint_128 = OpTypeArray %15 %uint_128
  294. %_ptr_UniformConstant__arr_15_uint_128 = OpTypePointer UniformConstant %_arr_15_uint_128
  295. %g_tColor = OpVariable %_ptr_UniformConstant__arr_15_uint_128 UniformConstant
  296. %_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
  297. %21 = OpTypeSampler
  298. %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
  299. %g_sAniso = OpVariable %_ptr_UniformConstant_21 UniformConstant
  300. %23 = OpTypeSampledImage %15
  301. %_ptr_Input_v2float = OpTypePointer Input %v2float
  302. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  303. %_ptr_Output_v4float = OpTypePointer Output %v4float
  304. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  305. %MainPs = OpFunction %void None %8
  306. %26 = OpLabel
  307. %27 = OpLoad %v2float %i_vTextureCoords
  308. %28 = OpAccessChain %_ptr_UniformConstant_15 %g_tColor %int_37
  309. %29 = OpLoad %15 %28
  310. %30 = OpLoad %21 %g_sAniso
  311. %31 = OpSampledImage %23 %29 %30
  312. %32 = OpImageSampleImplicitLod %v4float %31 %27
  313. OpStore %_entryPointOutput_vColor %32
  314. OpReturn
  315. OpFunctionEnd
  316. )";
  317. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  318. SinglePassRunAndCheck<InstBindlessCheckPass>(before, before, true, true, 7u,
  319. 23u, false, false, 1u);
  320. }
  321. TEST_F(InstBindlessTest, InstrumentMultipleInstructions) {
  322. // Texture2D g_tColor[128];
  323. //
  324. // layout(push_constant) cbuffer PerViewConstantBuffer_t
  325. // {
  326. // uint g_nDataIdx;
  327. // uint g_nDataIdx2;
  328. // };
  329. //
  330. // SamplerState g_sAniso;
  331. //
  332. // struct PS_INPUT
  333. // {
  334. // float2 vTextureCoords : TEXCOORD2;
  335. // };
  336. //
  337. // struct PS_OUTPUT
  338. // {
  339. // float4 vColor : SV_Target0;
  340. // };
  341. //
  342. // PS_OUTPUT MainPs(PS_INPUT i)
  343. // {
  344. // PS_OUTPUT ps_output;
  345. //
  346. // float t = g_tColor[g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
  347. // float t2 = g_tColor[g_nDataIdx2].Sample(g_sAniso, i.vTextureCoords.xy);
  348. // ps_output.vColor = t + t2;
  349. // return ps_output;
  350. // }
  351. const std::string defs_before =
  352. R"(OpCapability Shader
  353. %1 = OpExtInstImport "GLSL.std.450"
  354. OpMemoryModel Logical GLSL450
  355. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  356. OpExecutionMode %MainPs OriginUpperLeft
  357. OpSource HLSL 500
  358. OpName %MainPs "MainPs"
  359. OpName %g_tColor "g_tColor"
  360. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  361. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  362. OpName %_ ""
  363. OpName %g_sAniso "g_sAniso"
  364. OpName %i_vTextureCoords "i.vTextureCoords"
  365. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  366. OpDecorate %g_tColor DescriptorSet 3
  367. OpDecorate %g_tColor Binding 0
  368. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  369. OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
  370. OpDecorate %PerViewConstantBuffer_t Block
  371. OpDecorate %g_sAniso DescriptorSet 0
  372. OpDecorate %i_vTextureCoords Location 0
  373. OpDecorate %_entryPointOutput_vColor Location 0
  374. %void = OpTypeVoid
  375. %10 = OpTypeFunction %void
  376. %float = OpTypeFloat 32
  377. %v2float = OpTypeVector %float 2
  378. %v4float = OpTypeVector %float 4
  379. %int = OpTypeInt 32 1
  380. %int_0 = OpConstant %int 0
  381. %int_1 = OpConstant %int 1
  382. %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
  383. %uint = OpTypeInt 32 0
  384. %uint_128 = OpConstant %uint 128
  385. %_arr_17_uint_128 = OpTypeArray %17 %uint_128
  386. %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
  387. %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
  388. %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
  389. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  390. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  391. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  392. %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
  393. %25 = OpTypeSampler
  394. %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
  395. %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
  396. %27 = OpTypeSampledImage %17
  397. %_ptr_Input_v2float = OpTypePointer Input %v2float
  398. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  399. %_ptr_Output_v4float = OpTypePointer Output %v4float
  400. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  401. )";
  402. const std::string defs_after =
  403. R"(OpCapability Shader
  404. OpExtension "SPV_KHR_storage_buffer_storage_class"
  405. %1 = OpExtInstImport "GLSL.std.450"
  406. OpMemoryModel Logical GLSL450
  407. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  408. OpExecutionMode %MainPs OriginUpperLeft
  409. OpSource HLSL 500
  410. OpName %MainPs "MainPs"
  411. OpName %g_tColor "g_tColor"
  412. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  413. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  414. OpName %_ ""
  415. OpName %g_sAniso "g_sAniso"
  416. OpName %i_vTextureCoords "i.vTextureCoords"
  417. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  418. OpDecorate %g_tColor DescriptorSet 3
  419. OpDecorate %g_tColor Binding 0
  420. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  421. OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
  422. OpDecorate %PerViewConstantBuffer_t Block
  423. OpDecorate %g_sAniso DescriptorSet 0
  424. OpDecorate %i_vTextureCoords Location 0
  425. OpDecorate %_entryPointOutput_vColor Location 0
  426. OpDecorate %_runtimearr_uint ArrayStride 4
  427. OpDecorate %_struct_63 Block
  428. OpMemberDecorate %_struct_63 0 Offset 0
  429. OpMemberDecorate %_struct_63 1 Offset 4
  430. OpDecorate %65 DescriptorSet 7
  431. OpDecorate %65 Binding 0
  432. OpDecorate %gl_FragCoord BuiltIn FragCoord
  433. %void = OpTypeVoid
  434. %10 = OpTypeFunction %void
  435. %float = OpTypeFloat 32
  436. %v2float = OpTypeVector %float 2
  437. %v4float = OpTypeVector %float 4
  438. %int = OpTypeInt 32 1
  439. %int_0 = OpConstant %int 0
  440. %int_1 = OpConstant %int 1
  441. %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
  442. %uint = OpTypeInt 32 0
  443. %uint_128 = OpConstant %uint 128
  444. %_arr_17_uint_128 = OpTypeArray %17 %uint_128
  445. %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
  446. %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
  447. %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
  448. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  449. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  450. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  451. %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
  452. %25 = OpTypeSampler
  453. %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
  454. %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
  455. %27 = OpTypeSampledImage %17
  456. %_ptr_Input_v2float = OpTypePointer Input %v2float
  457. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  458. %_ptr_Output_v4float = OpTypePointer Output %v4float
  459. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  460. %uint_0 = OpConstant %uint 0
  461. %bool = OpTypeBool
  462. %56 = OpTypeFunction %void %uint %uint %uint %uint
  463. %_runtimearr_uint = OpTypeRuntimeArray %uint
  464. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  465. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  466. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  467. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  468. %uint_9 = OpConstant %uint 9
  469. %uint_4 = OpConstant %uint 4
  470. %uint_1 = OpConstant %uint 1
  471. %uint_23 = OpConstant %uint 23
  472. %uint_2 = OpConstant %uint 2
  473. %uint_3 = OpConstant %uint 3
  474. %_ptr_Input_v4float = OpTypePointer Input %v4float
  475. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  476. %v4uint = OpTypeVector %uint 4
  477. %uint_5 = OpConstant %uint 5
  478. %uint_6 = OpConstant %uint 6
  479. %uint_7 = OpConstant %uint 7
  480. %uint_8 = OpConstant %uint 8
  481. %uint_58 = OpConstant %uint 58
  482. %111 = OpConstantNull %v4float
  483. %uint_64 = OpConstant %uint 64
  484. )";
  485. const std::string func_before =
  486. R"(%MainPs = OpFunction %void None %10
  487. %30 = OpLabel
  488. %31 = OpLoad %v2float %i_vTextureCoords
  489. %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  490. %33 = OpLoad %uint %32
  491. %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
  492. %35 = OpLoad %17 %34
  493. %36 = OpLoad %25 %g_sAniso
  494. %37 = OpSampledImage %27 %35 %36
  495. %38 = OpImageSampleImplicitLod %v4float %37 %31
  496. %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
  497. %40 = OpLoad %uint %39
  498. %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
  499. %42 = OpLoad %17 %41
  500. %43 = OpSampledImage %27 %42 %36
  501. %44 = OpImageSampleImplicitLod %v4float %43 %31
  502. %45 = OpFAdd %v4float %38 %44
  503. OpStore %_entryPointOutput_vColor %45
  504. OpReturn
  505. OpFunctionEnd
  506. )";
  507. const std::string func_after =
  508. R"(%MainPs = OpFunction %void None %10
  509. %30 = OpLabel
  510. %31 = OpLoad %v2float %i_vTextureCoords
  511. %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  512. %33 = OpLoad %uint %32
  513. %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
  514. %35 = OpLoad %17 %34
  515. %36 = OpLoad %25 %g_sAniso
  516. %37 = OpSampledImage %27 %35 %36
  517. %48 = OpULessThan %bool %33 %uint_128
  518. OpSelectionMerge %49 None
  519. OpBranchConditional %48 %50 %51
  520. %50 = OpLabel
  521. %52 = OpLoad %17 %34
  522. %53 = OpSampledImage %27 %52 %36
  523. %54 = OpImageSampleImplicitLod %v4float %53 %31
  524. OpBranch %49
  525. %51 = OpLabel
  526. %110 = OpFunctionCall %void %55 %uint_58 %uint_0 %33 %uint_128
  527. OpBranch %49
  528. %49 = OpLabel
  529. %112 = OpPhi %v4float %54 %50 %111 %51
  530. %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
  531. %40 = OpLoad %uint %39
  532. %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
  533. %42 = OpLoad %17 %41
  534. %43 = OpSampledImage %27 %42 %36
  535. %113 = OpULessThan %bool %40 %uint_128
  536. OpSelectionMerge %114 None
  537. OpBranchConditional %113 %115 %116
  538. %115 = OpLabel
  539. %117 = OpLoad %17 %41
  540. %118 = OpSampledImage %27 %117 %36
  541. %119 = OpImageSampleImplicitLod %v4float %118 %31
  542. OpBranch %114
  543. %116 = OpLabel
  544. %121 = OpFunctionCall %void %55 %uint_64 %uint_0 %40 %uint_128
  545. OpBranch %114
  546. %114 = OpLabel
  547. %122 = OpPhi %v4float %119 %115 %111 %116
  548. %45 = OpFAdd %v4float %112 %122
  549. OpStore %_entryPointOutput_vColor %45
  550. OpReturn
  551. OpFunctionEnd
  552. )";
  553. const std::string output_func =
  554. R"(%55 = OpFunction %void None %56
  555. %57 = OpFunctionParameter %uint
  556. %58 = OpFunctionParameter %uint
  557. %59 = OpFunctionParameter %uint
  558. %60 = OpFunctionParameter %uint
  559. %61 = OpLabel
  560. %67 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  561. %70 = OpAtomicIAdd %uint %67 %uint_4 %uint_0 %uint_9
  562. %71 = OpIAdd %uint %70 %uint_9
  563. %72 = OpArrayLength %uint %65 1
  564. %73 = OpULessThanEqual %bool %71 %72
  565. OpSelectionMerge %74 None
  566. OpBranchConditional %73 %75 %74
  567. %75 = OpLabel
  568. %76 = OpIAdd %uint %70 %uint_0
  569. %78 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %76
  570. OpStore %78 %uint_9
  571. %80 = OpIAdd %uint %70 %uint_1
  572. %81 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %80
  573. OpStore %81 %uint_23
  574. %83 = OpIAdd %uint %70 %uint_2
  575. %84 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %83
  576. OpStore %84 %57
  577. %86 = OpIAdd %uint %70 %uint_3
  578. %87 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %86
  579. OpStore %87 %uint_4
  580. %90 = OpLoad %v4float %gl_FragCoord
  581. %92 = OpBitcast %v4uint %90
  582. %93 = OpCompositeExtract %uint %92 0
  583. %94 = OpIAdd %uint %70 %uint_4
  584. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  585. OpStore %95 %93
  586. %96 = OpCompositeExtract %uint %92 1
  587. %98 = OpIAdd %uint %70 %uint_5
  588. %99 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %98
  589. OpStore %99 %96
  590. %101 = OpIAdd %uint %70 %uint_6
  591. %102 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %101
  592. OpStore %102 %58
  593. %104 = OpIAdd %uint %70 %uint_7
  594. %105 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %104
  595. OpStore %105 %59
  596. %107 = OpIAdd %uint %70 %uint_8
  597. %108 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %107
  598. OpStore %108 %60
  599. OpBranch %74
  600. %74 = OpLabel
  601. OpReturn
  602. OpFunctionEnd
  603. )";
  604. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  605. SinglePassRunAndCheck<InstBindlessCheckPass>(
  606. defs_before + func_before, defs_after + func_after + output_func, true,
  607. true, 7u, 23u, false, false, 1u);
  608. }
  609. TEST_F(InstBindlessTest, InstrumentOpImage) {
  610. // This test verifies that the pass will correctly instrument shader
  611. // using OpImage. This test was created by editing the SPIR-V
  612. // from the Simple test.
  613. const std::string defs_before =
  614. R"(OpCapability Shader
  615. OpCapability StorageImageReadWithoutFormat
  616. %1 = OpExtInstImport "GLSL.std.450"
  617. OpMemoryModel Logical GLSL450
  618. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  619. OpExecutionMode %MainPs OriginUpperLeft
  620. OpSource HLSL 500
  621. OpName %MainPs "MainPs"
  622. OpName %g_tColor "g_tColor"
  623. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  624. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  625. OpName %_ ""
  626. OpName %i_vTextureCoords "i.vTextureCoords"
  627. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  628. OpDecorate %g_tColor DescriptorSet 3
  629. OpDecorate %g_tColor Binding 0
  630. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  631. OpDecorate %PerViewConstantBuffer_t Block
  632. OpDecorate %i_vTextureCoords Location 0
  633. OpDecorate %_entryPointOutput_vColor Location 0
  634. %void = OpTypeVoid
  635. %3 = OpTypeFunction %void
  636. %float = OpTypeFloat 32
  637. %v4float = OpTypeVector %float 4
  638. %int = OpTypeInt 32 1
  639. %v2int = OpTypeVector %int 2
  640. %int_0 = OpConstant %int 0
  641. %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
  642. %uint = OpTypeInt 32 0
  643. %uint_128 = OpConstant %uint 128
  644. %39 = OpTypeSampledImage %20
  645. %_arr_39_uint_128 = OpTypeArray %39 %uint_128
  646. %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
  647. %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
  648. %PerViewConstantBuffer_t = OpTypeStruct %uint
  649. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  650. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  651. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  652. %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
  653. %_ptr_Input_v2int = OpTypePointer Input %v2int
  654. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  655. %_ptr_Output_v4float = OpTypePointer Output %v4float
  656. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  657. )";
  658. const std::string defs_after =
  659. R"(OpCapability Shader
  660. OpCapability StorageImageReadWithoutFormat
  661. OpExtension "SPV_KHR_storage_buffer_storage_class"
  662. %1 = OpExtInstImport "GLSL.std.450"
  663. OpMemoryModel Logical GLSL450
  664. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  665. OpExecutionMode %MainPs OriginUpperLeft
  666. OpSource HLSL 500
  667. OpName %MainPs "MainPs"
  668. OpName %g_tColor "g_tColor"
  669. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  670. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  671. OpName %_ ""
  672. OpName %i_vTextureCoords "i.vTextureCoords"
  673. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  674. OpDecorate %g_tColor DescriptorSet 3
  675. OpDecorate %g_tColor Binding 0
  676. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  677. OpDecorate %PerViewConstantBuffer_t Block
  678. OpDecorate %i_vTextureCoords Location 0
  679. OpDecorate %_entryPointOutput_vColor Location 0
  680. OpDecorate %_runtimearr_uint ArrayStride 4
  681. OpDecorate %_struct_51 Block
  682. OpMemberDecorate %_struct_51 0 Offset 0
  683. OpMemberDecorate %_struct_51 1 Offset 4
  684. OpDecorate %53 DescriptorSet 7
  685. OpDecorate %53 Binding 0
  686. OpDecorate %gl_FragCoord BuiltIn FragCoord
  687. %void = OpTypeVoid
  688. %9 = OpTypeFunction %void
  689. %float = OpTypeFloat 32
  690. %v4float = OpTypeVector %float 4
  691. %int = OpTypeInt 32 1
  692. %v2int = OpTypeVector %int 2
  693. %int_0 = OpConstant %int 0
  694. %15 = OpTypeImage %float 2D 0 0 0 0 Unknown
  695. %uint = OpTypeInt 32 0
  696. %uint_128 = OpConstant %uint 128
  697. %18 = OpTypeSampledImage %15
  698. %_arr_18_uint_128 = OpTypeArray %18 %uint_128
  699. %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
  700. %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
  701. %PerViewConstantBuffer_t = OpTypeStruct %uint
  702. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  703. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  704. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  705. %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
  706. %_ptr_Input_v2int = OpTypePointer Input %v2int
  707. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  708. %_ptr_Output_v4float = OpTypePointer Output %v4float
  709. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  710. %uint_0 = OpConstant %uint 0
  711. %bool = OpTypeBool
  712. %44 = OpTypeFunction %void %uint %uint %uint %uint
  713. %_runtimearr_uint = OpTypeRuntimeArray %uint
  714. %_struct_51 = OpTypeStruct %uint %_runtimearr_uint
  715. %_ptr_StorageBuffer__struct_51 = OpTypePointer StorageBuffer %_struct_51
  716. %53 = OpVariable %_ptr_StorageBuffer__struct_51 StorageBuffer
  717. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  718. %uint_9 = OpConstant %uint 9
  719. %uint_4 = OpConstant %uint 4
  720. %uint_1 = OpConstant %uint 1
  721. %uint_23 = OpConstant %uint 23
  722. %uint_2 = OpConstant %uint 2
  723. %uint_3 = OpConstant %uint 3
  724. %_ptr_Input_v4float = OpTypePointer Input %v4float
  725. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  726. %v4uint = OpTypeVector %uint 4
  727. %uint_5 = OpConstant %uint 5
  728. %uint_6 = OpConstant %uint 6
  729. %uint_7 = OpConstant %uint 7
  730. %uint_8 = OpConstant %uint 8
  731. %uint_51 = OpConstant %uint 51
  732. %99 = OpConstantNull %v4float
  733. )";
  734. const std::string func_before =
  735. R"(%MainPs = OpFunction %void None %3
  736. %5 = OpLabel
  737. %53 = OpLoad %v2int %i_vTextureCoords
  738. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  739. %64 = OpLoad %uint %63
  740. %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
  741. %66 = OpLoad %39 %65
  742. %75 = OpImage %20 %66
  743. %71 = OpImageRead %v4float %75 %53
  744. OpStore %_entryPointOutput_vColor %71
  745. OpReturn
  746. OpFunctionEnd
  747. )";
  748. const std::string func_after =
  749. R"(%MainPs = OpFunction %void None %9
  750. %26 = OpLabel
  751. %27 = OpLoad %v2int %i_vTextureCoords
  752. %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  753. %29 = OpLoad %uint %28
  754. %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
  755. %31 = OpLoad %18 %30
  756. %32 = OpImage %15 %31
  757. %36 = OpULessThan %bool %29 %uint_128
  758. OpSelectionMerge %37 None
  759. OpBranchConditional %36 %38 %39
  760. %38 = OpLabel
  761. %40 = OpLoad %18 %30
  762. %41 = OpImage %15 %40
  763. %42 = OpImageRead %v4float %41 %27
  764. OpBranch %37
  765. %39 = OpLabel
  766. %98 = OpFunctionCall %void %43 %uint_51 %uint_0 %29 %uint_128
  767. OpBranch %37
  768. %37 = OpLabel
  769. %100 = OpPhi %v4float %42 %38 %99 %39
  770. OpStore %_entryPointOutput_vColor %100
  771. OpReturn
  772. OpFunctionEnd
  773. )";
  774. const std::string output_func =
  775. R"(%43 = OpFunction %void None %44
  776. %45 = OpFunctionParameter %uint
  777. %46 = OpFunctionParameter %uint
  778. %47 = OpFunctionParameter %uint
  779. %48 = OpFunctionParameter %uint
  780. %49 = OpLabel
  781. %55 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_0
  782. %58 = OpAtomicIAdd %uint %55 %uint_4 %uint_0 %uint_9
  783. %59 = OpIAdd %uint %58 %uint_9
  784. %60 = OpArrayLength %uint %53 1
  785. %61 = OpULessThanEqual %bool %59 %60
  786. OpSelectionMerge %62 None
  787. OpBranchConditional %61 %63 %62
  788. %63 = OpLabel
  789. %64 = OpIAdd %uint %58 %uint_0
  790. %66 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %64
  791. OpStore %66 %uint_9
  792. %68 = OpIAdd %uint %58 %uint_1
  793. %69 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %68
  794. OpStore %69 %uint_23
  795. %71 = OpIAdd %uint %58 %uint_2
  796. %72 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %71
  797. OpStore %72 %45
  798. %74 = OpIAdd %uint %58 %uint_3
  799. %75 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %74
  800. OpStore %75 %uint_4
  801. %78 = OpLoad %v4float %gl_FragCoord
  802. %80 = OpBitcast %v4uint %78
  803. %81 = OpCompositeExtract %uint %80 0
  804. %82 = OpIAdd %uint %58 %uint_4
  805. %83 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %82
  806. OpStore %83 %81
  807. %84 = OpCompositeExtract %uint %80 1
  808. %86 = OpIAdd %uint %58 %uint_5
  809. %87 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %86
  810. OpStore %87 %84
  811. %89 = OpIAdd %uint %58 %uint_6
  812. %90 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %89
  813. OpStore %90 %46
  814. %92 = OpIAdd %uint %58 %uint_7
  815. %93 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %92
  816. OpStore %93 %47
  817. %95 = OpIAdd %uint %58 %uint_8
  818. %96 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %95
  819. OpStore %96 %48
  820. OpBranch %62
  821. %62 = OpLabel
  822. OpReturn
  823. OpFunctionEnd
  824. )";
  825. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  826. SinglePassRunAndCheck<InstBindlessCheckPass>(
  827. defs_before + func_before, defs_after + func_after + output_func, true,
  828. true, 7u, 23u, false, false, 1u);
  829. }
  830. TEST_F(InstBindlessTest, InstrumentSampledImage) {
  831. // This test verifies that the pass will correctly instrument shader
  832. // using sampled image. This test was created by editing the SPIR-V
  833. // from the Simple test.
  834. const std::string defs_before =
  835. R"(OpCapability Shader
  836. %1 = OpExtInstImport "GLSL.std.450"
  837. OpMemoryModel Logical GLSL450
  838. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  839. OpExecutionMode %MainPs OriginUpperLeft
  840. OpSource HLSL 500
  841. OpName %MainPs "MainPs"
  842. OpName %g_tColor "g_tColor"
  843. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  844. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  845. OpName %_ ""
  846. OpName %i_vTextureCoords "i.vTextureCoords"
  847. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  848. OpDecorate %g_tColor DescriptorSet 3
  849. OpDecorate %g_tColor Binding 0
  850. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  851. OpDecorate %PerViewConstantBuffer_t Block
  852. OpDecorate %i_vTextureCoords Location 0
  853. OpDecorate %_entryPointOutput_vColor Location 0
  854. %void = OpTypeVoid
  855. %3 = OpTypeFunction %void
  856. %float = OpTypeFloat 32
  857. %v2float = OpTypeVector %float 2
  858. %v4float = OpTypeVector %float 4
  859. %int = OpTypeInt 32 1
  860. %int_0 = OpConstant %int 0
  861. %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
  862. %uint = OpTypeInt 32 0
  863. %uint_128 = OpConstant %uint 128
  864. %39 = OpTypeSampledImage %20
  865. %_arr_39_uint_128 = OpTypeArray %39 %uint_128
  866. %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
  867. %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
  868. %PerViewConstantBuffer_t = OpTypeStruct %uint
  869. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  870. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  871. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  872. %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
  873. %_ptr_Input_v2float = OpTypePointer Input %v2float
  874. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  875. %_ptr_Output_v4float = OpTypePointer Output %v4float
  876. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  877. )";
  878. const std::string defs_after =
  879. R"(OpCapability Shader
  880. OpExtension "SPV_KHR_storage_buffer_storage_class"
  881. %1 = OpExtInstImport "GLSL.std.450"
  882. OpMemoryModel Logical GLSL450
  883. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  884. OpExecutionMode %MainPs OriginUpperLeft
  885. OpSource HLSL 500
  886. OpName %MainPs "MainPs"
  887. OpName %g_tColor "g_tColor"
  888. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  889. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  890. OpName %_ ""
  891. OpName %i_vTextureCoords "i.vTextureCoords"
  892. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  893. OpDecorate %g_tColor DescriptorSet 3
  894. OpDecorate %g_tColor Binding 0
  895. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  896. OpDecorate %PerViewConstantBuffer_t Block
  897. OpDecorate %i_vTextureCoords Location 0
  898. OpDecorate %_entryPointOutput_vColor Location 0
  899. OpDecorate %_runtimearr_uint ArrayStride 4
  900. OpDecorate %_struct_49 Block
  901. OpMemberDecorate %_struct_49 0 Offset 0
  902. OpMemberDecorate %_struct_49 1 Offset 4
  903. OpDecorate %51 DescriptorSet 7
  904. OpDecorate %51 Binding 0
  905. OpDecorate %gl_FragCoord BuiltIn FragCoord
  906. %void = OpTypeVoid
  907. %9 = OpTypeFunction %void
  908. %float = OpTypeFloat 32
  909. %v2float = OpTypeVector %float 2
  910. %v4float = OpTypeVector %float 4
  911. %int = OpTypeInt 32 1
  912. %int_0 = OpConstant %int 0
  913. %15 = OpTypeImage %float 2D 0 0 0 1 Unknown
  914. %uint = OpTypeInt 32 0
  915. %uint_128 = OpConstant %uint 128
  916. %18 = OpTypeSampledImage %15
  917. %_arr_18_uint_128 = OpTypeArray %18 %uint_128
  918. %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
  919. %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
  920. %PerViewConstantBuffer_t = OpTypeStruct %uint
  921. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  922. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  923. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  924. %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
  925. %_ptr_Input_v2float = OpTypePointer Input %v2float
  926. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  927. %_ptr_Output_v4float = OpTypePointer Output %v4float
  928. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  929. %uint_0 = OpConstant %uint 0
  930. %bool = OpTypeBool
  931. %42 = OpTypeFunction %void %uint %uint %uint %uint
  932. %_runtimearr_uint = OpTypeRuntimeArray %uint
  933. %_struct_49 = OpTypeStruct %uint %_runtimearr_uint
  934. %_ptr_StorageBuffer__struct_49 = OpTypePointer StorageBuffer %_struct_49
  935. %51 = OpVariable %_ptr_StorageBuffer__struct_49 StorageBuffer
  936. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  937. %uint_9 = OpConstant %uint 9
  938. %uint_4 = OpConstant %uint 4
  939. %uint_1 = OpConstant %uint 1
  940. %uint_23 = OpConstant %uint 23
  941. %uint_2 = OpConstant %uint 2
  942. %uint_3 = OpConstant %uint 3
  943. %_ptr_Input_v4float = OpTypePointer Input %v4float
  944. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  945. %v4uint = OpTypeVector %uint 4
  946. %uint_5 = OpConstant %uint 5
  947. %uint_6 = OpConstant %uint 6
  948. %uint_7 = OpConstant %uint 7
  949. %uint_8 = OpConstant %uint 8
  950. %uint_49 = OpConstant %uint 49
  951. %97 = OpConstantNull %v4float
  952. )";
  953. const std::string func_before =
  954. R"(%MainPs = OpFunction %void None %3
  955. %5 = OpLabel
  956. %53 = OpLoad %v2float %i_vTextureCoords
  957. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  958. %64 = OpLoad %uint %63
  959. %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
  960. %66 = OpLoad %39 %65
  961. %71 = OpImageSampleImplicitLod %v4float %66 %53
  962. OpStore %_entryPointOutput_vColor %71
  963. OpReturn
  964. OpFunctionEnd
  965. )";
  966. const std::string func_after =
  967. R"(%MainPs = OpFunction %void None %9
  968. %26 = OpLabel
  969. %27 = OpLoad %v2float %i_vTextureCoords
  970. %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  971. %29 = OpLoad %uint %28
  972. %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
  973. %31 = OpLoad %18 %30
  974. %35 = OpULessThan %bool %29 %uint_128
  975. OpSelectionMerge %36 None
  976. OpBranchConditional %35 %37 %38
  977. %37 = OpLabel
  978. %39 = OpLoad %18 %30
  979. %40 = OpImageSampleImplicitLod %v4float %39 %27
  980. OpBranch %36
  981. %38 = OpLabel
  982. %96 = OpFunctionCall %void %41 %uint_49 %uint_0 %29 %uint_128
  983. OpBranch %36
  984. %36 = OpLabel
  985. %98 = OpPhi %v4float %40 %37 %97 %38
  986. OpStore %_entryPointOutput_vColor %98
  987. OpReturn
  988. OpFunctionEnd
  989. )";
  990. const std::string output_func =
  991. R"(%41 = OpFunction %void None %42
  992. %43 = OpFunctionParameter %uint
  993. %44 = OpFunctionParameter %uint
  994. %45 = OpFunctionParameter %uint
  995. %46 = OpFunctionParameter %uint
  996. %47 = OpLabel
  997. %53 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_0
  998. %56 = OpAtomicIAdd %uint %53 %uint_4 %uint_0 %uint_9
  999. %57 = OpIAdd %uint %56 %uint_9
  1000. %58 = OpArrayLength %uint %51 1
  1001. %59 = OpULessThanEqual %bool %57 %58
  1002. OpSelectionMerge %60 None
  1003. OpBranchConditional %59 %61 %60
  1004. %61 = OpLabel
  1005. %62 = OpIAdd %uint %56 %uint_0
  1006. %64 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %62
  1007. OpStore %64 %uint_9
  1008. %66 = OpIAdd %uint %56 %uint_1
  1009. %67 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %66
  1010. OpStore %67 %uint_23
  1011. %69 = OpIAdd %uint %56 %uint_2
  1012. %70 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %69
  1013. OpStore %70 %43
  1014. %72 = OpIAdd %uint %56 %uint_3
  1015. %73 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %72
  1016. OpStore %73 %uint_4
  1017. %76 = OpLoad %v4float %gl_FragCoord
  1018. %78 = OpBitcast %v4uint %76
  1019. %79 = OpCompositeExtract %uint %78 0
  1020. %80 = OpIAdd %uint %56 %uint_4
  1021. %81 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %80
  1022. OpStore %81 %79
  1023. %82 = OpCompositeExtract %uint %78 1
  1024. %84 = OpIAdd %uint %56 %uint_5
  1025. %85 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %84
  1026. OpStore %85 %82
  1027. %87 = OpIAdd %uint %56 %uint_6
  1028. %88 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %87
  1029. OpStore %88 %44
  1030. %90 = OpIAdd %uint %56 %uint_7
  1031. %91 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %90
  1032. OpStore %91 %45
  1033. %93 = OpIAdd %uint %56 %uint_8
  1034. %94 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %93
  1035. OpStore %94 %46
  1036. OpBranch %60
  1037. %60 = OpLabel
  1038. OpReturn
  1039. OpFunctionEnd
  1040. )";
  1041. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1042. SinglePassRunAndCheck<InstBindlessCheckPass>(
  1043. defs_before + func_before, defs_after + func_after + output_func, true,
  1044. true, 7u, 23u, false, false, 1u);
  1045. }
  1046. TEST_F(InstBindlessTest, InstrumentImageWrite) {
  1047. // This test verifies that the pass will correctly instrument shader
  1048. // doing bindless image write. This test was created by editing the SPIR-V
  1049. // from the Simple test.
  1050. const std::string defs_before =
  1051. R"(OpCapability Shader
  1052. OpCapability StorageImageWriteWithoutFormat
  1053. %1 = OpExtInstImport "GLSL.std.450"
  1054. OpMemoryModel Logical GLSL450
  1055. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  1056. OpExecutionMode %MainPs OriginUpperLeft
  1057. OpSource HLSL 500
  1058. OpName %MainPs "MainPs"
  1059. OpName %g_tColor "g_tColor"
  1060. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  1061. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  1062. OpName %_ ""
  1063. OpName %i_vTextureCoords "i.vTextureCoords"
  1064. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  1065. OpDecorate %g_tColor DescriptorSet 3
  1066. OpDecorate %g_tColor Binding 0
  1067. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  1068. OpDecorate %PerViewConstantBuffer_t Block
  1069. OpDecorate %i_vTextureCoords Location 0
  1070. OpDecorate %_entryPointOutput_vColor Location 0
  1071. %void = OpTypeVoid
  1072. %3 = OpTypeFunction %void
  1073. %float = OpTypeFloat 32
  1074. %v2float = OpTypeVector %float 2
  1075. %v4float = OpTypeVector %float 4
  1076. %int = OpTypeInt 32 1
  1077. %v2int = OpTypeVector %int 2
  1078. %int_0 = OpConstant %int 0
  1079. %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
  1080. %uint = OpTypeInt 32 0
  1081. %uint_128 = OpConstant %uint 128
  1082. %80 = OpConstantNull %v4float
  1083. %_arr_20_uint_128 = OpTypeArray %20 %uint_128
  1084. %_ptr_UniformConstant__arr_20_uint_128 = OpTypePointer UniformConstant %_arr_20_uint_128
  1085. %g_tColor = OpVariable %_ptr_UniformConstant__arr_20_uint_128 UniformConstant
  1086. %PerViewConstantBuffer_t = OpTypeStruct %uint
  1087. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  1088. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  1089. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  1090. %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
  1091. %_ptr_Input_v2int = OpTypePointer Input %v2int
  1092. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  1093. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1094. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  1095. )";
  1096. const std::string defs_after =
  1097. R"(OpCapability Shader
  1098. OpCapability StorageImageWriteWithoutFormat
  1099. OpExtension "SPV_KHR_storage_buffer_storage_class"
  1100. %1 = OpExtInstImport "GLSL.std.450"
  1101. OpMemoryModel Logical GLSL450
  1102. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  1103. OpExecutionMode %MainPs OriginUpperLeft
  1104. OpSource HLSL 500
  1105. OpName %MainPs "MainPs"
  1106. OpName %g_tColor "g_tColor"
  1107. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  1108. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  1109. OpName %_ ""
  1110. OpName %i_vTextureCoords "i.vTextureCoords"
  1111. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  1112. OpDecorate %g_tColor DescriptorSet 3
  1113. OpDecorate %g_tColor Binding 0
  1114. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  1115. OpDecorate %PerViewConstantBuffer_t Block
  1116. OpDecorate %i_vTextureCoords Location 0
  1117. OpDecorate %_entryPointOutput_vColor Location 0
  1118. OpDecorate %_runtimearr_uint ArrayStride 4
  1119. OpDecorate %_struct_48 Block
  1120. OpMemberDecorate %_struct_48 0 Offset 0
  1121. OpMemberDecorate %_struct_48 1 Offset 4
  1122. OpDecorate %50 DescriptorSet 7
  1123. OpDecorate %50 Binding 0
  1124. OpDecorate %gl_FragCoord BuiltIn FragCoord
  1125. %void = OpTypeVoid
  1126. %9 = OpTypeFunction %void
  1127. %float = OpTypeFloat 32
  1128. %v2float = OpTypeVector %float 2
  1129. %v4float = OpTypeVector %float 4
  1130. %int = OpTypeInt 32 1
  1131. %v2int = OpTypeVector %int 2
  1132. %int_0 = OpConstant %int 0
  1133. %16 = OpTypeImage %float 2D 0 0 0 0 Unknown
  1134. %uint = OpTypeInt 32 0
  1135. %uint_128 = OpConstant %uint 128
  1136. %19 = OpConstantNull %v4float
  1137. %_arr_16_uint_128 = OpTypeArray %16 %uint_128
  1138. %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
  1139. %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
  1140. %PerViewConstantBuffer_t = OpTypeStruct %uint
  1141. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  1142. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  1143. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  1144. %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
  1145. %_ptr_Input_v2int = OpTypePointer Input %v2int
  1146. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  1147. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1148. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  1149. %uint_0 = OpConstant %uint 0
  1150. %bool = OpTypeBool
  1151. %41 = OpTypeFunction %void %uint %uint %uint %uint
  1152. %_runtimearr_uint = OpTypeRuntimeArray %uint
  1153. %_struct_48 = OpTypeStruct %uint %_runtimearr_uint
  1154. %_ptr_StorageBuffer__struct_48 = OpTypePointer StorageBuffer %_struct_48
  1155. %50 = OpVariable %_ptr_StorageBuffer__struct_48 StorageBuffer
  1156. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  1157. %uint_9 = OpConstant %uint 9
  1158. %uint_4 = OpConstant %uint 4
  1159. %uint_1 = OpConstant %uint 1
  1160. %uint_23 = OpConstant %uint 23
  1161. %uint_2 = OpConstant %uint 2
  1162. %uint_3 = OpConstant %uint 3
  1163. %_ptr_Input_v4float = OpTypePointer Input %v4float
  1164. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  1165. %v4uint = OpTypeVector %uint 4
  1166. %uint_5 = OpConstant %uint 5
  1167. %uint_6 = OpConstant %uint 6
  1168. %uint_7 = OpConstant %uint 7
  1169. %uint_8 = OpConstant %uint 8
  1170. %uint_51 = OpConstant %uint 51
  1171. )";
  1172. const std::string func_before =
  1173. R"(%MainPs = OpFunction %void None %3
  1174. %5 = OpLabel
  1175. %53 = OpLoad %v2int %i_vTextureCoords
  1176. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  1177. %64 = OpLoad %uint %63
  1178. %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
  1179. %66 = OpLoad %20 %65
  1180. OpImageWrite %66 %53 %80
  1181. OpStore %_entryPointOutput_vColor %80
  1182. OpReturn
  1183. OpFunctionEnd
  1184. )";
  1185. const std::string func_after =
  1186. R"(%MainPs = OpFunction %void None %9
  1187. %27 = OpLabel
  1188. %28 = OpLoad %v2int %i_vTextureCoords
  1189. %29 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  1190. %30 = OpLoad %uint %29
  1191. %31 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %30
  1192. %32 = OpLoad %16 %31
  1193. %35 = OpULessThan %bool %30 %uint_128
  1194. OpSelectionMerge %36 None
  1195. OpBranchConditional %35 %37 %38
  1196. %37 = OpLabel
  1197. %39 = OpLoad %16 %31
  1198. OpImageWrite %39 %28 %19
  1199. OpBranch %36
  1200. %38 = OpLabel
  1201. %95 = OpFunctionCall %void %40 %uint_51 %uint_0 %30 %uint_128
  1202. OpBranch %36
  1203. %36 = OpLabel
  1204. OpStore %_entryPointOutput_vColor %19
  1205. OpReturn
  1206. OpFunctionEnd
  1207. )";
  1208. const std::string output_func =
  1209. R"(%40 = OpFunction %void None %41
  1210. %42 = OpFunctionParameter %uint
  1211. %43 = OpFunctionParameter %uint
  1212. %44 = OpFunctionParameter %uint
  1213. %45 = OpFunctionParameter %uint
  1214. %46 = OpLabel
  1215. %52 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_0
  1216. %55 = OpAtomicIAdd %uint %52 %uint_4 %uint_0 %uint_9
  1217. %56 = OpIAdd %uint %55 %uint_9
  1218. %57 = OpArrayLength %uint %50 1
  1219. %58 = OpULessThanEqual %bool %56 %57
  1220. OpSelectionMerge %59 None
  1221. OpBranchConditional %58 %60 %59
  1222. %60 = OpLabel
  1223. %61 = OpIAdd %uint %55 %uint_0
  1224. %63 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %61
  1225. OpStore %63 %uint_9
  1226. %65 = OpIAdd %uint %55 %uint_1
  1227. %66 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %65
  1228. OpStore %66 %uint_23
  1229. %68 = OpIAdd %uint %55 %uint_2
  1230. %69 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %68
  1231. OpStore %69 %42
  1232. %71 = OpIAdd %uint %55 %uint_3
  1233. %72 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %71
  1234. OpStore %72 %uint_4
  1235. %75 = OpLoad %v4float %gl_FragCoord
  1236. %77 = OpBitcast %v4uint %75
  1237. %78 = OpCompositeExtract %uint %77 0
  1238. %79 = OpIAdd %uint %55 %uint_4
  1239. %80 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %79
  1240. OpStore %80 %78
  1241. %81 = OpCompositeExtract %uint %77 1
  1242. %83 = OpIAdd %uint %55 %uint_5
  1243. %84 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %83
  1244. OpStore %84 %81
  1245. %86 = OpIAdd %uint %55 %uint_6
  1246. %87 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %86
  1247. OpStore %87 %43
  1248. %89 = OpIAdd %uint %55 %uint_7
  1249. %90 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %89
  1250. OpStore %90 %44
  1251. %92 = OpIAdd %uint %55 %uint_8
  1252. %93 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %92
  1253. OpStore %93 %45
  1254. OpBranch %59
  1255. %59 = OpLabel
  1256. OpReturn
  1257. OpFunctionEnd
  1258. )";
  1259. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1260. SinglePassRunAndCheck<InstBindlessCheckPass>(
  1261. defs_before + func_before, defs_after + func_after + output_func, true,
  1262. true, 7u, 23u, false, false, 1u);
  1263. }
  1264. TEST_F(InstBindlessTest, InstrumentVertexSimple) {
  1265. // This test verifies that the pass will correctly instrument shader
  1266. // doing bindless image write. This test was created by editing the SPIR-V
  1267. // from the Simple test.
  1268. const std::string defs_before =
  1269. R"(OpCapability Shader
  1270. OpCapability Sampled1D
  1271. %1 = OpExtInstImport "GLSL.std.450"
  1272. OpMemoryModel Logical GLSL450
  1273. OpEntryPoint Vertex %main "main" %_ %coords2D
  1274. OpSource GLSL 450
  1275. OpName %main "main"
  1276. OpName %lod "lod"
  1277. OpName %coords1D "coords1D"
  1278. OpName %gl_PerVertex "gl_PerVertex"
  1279. OpMemberName %gl_PerVertex 0 "gl_Position"
  1280. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  1281. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  1282. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  1283. OpName %_ ""
  1284. OpName %texSampler1D "texSampler1D"
  1285. OpName %foo "foo"
  1286. OpMemberName %foo 0 "g_idx"
  1287. OpName %__0 ""
  1288. OpName %coords2D "coords2D"
  1289. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  1290. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  1291. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  1292. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  1293. OpDecorate %gl_PerVertex Block
  1294. OpDecorate %texSampler1D DescriptorSet 0
  1295. OpDecorate %texSampler1D Binding 3
  1296. OpMemberDecorate %foo 0 Offset 0
  1297. OpDecorate %foo Block
  1298. OpDecorate %__0 DescriptorSet 0
  1299. OpDecorate %__0 Binding 5
  1300. OpDecorate %coords2D Location 0
  1301. %void = OpTypeVoid
  1302. %3 = OpTypeFunction %void
  1303. %float = OpTypeFloat 32
  1304. %_ptr_Function_float = OpTypePointer Function %float
  1305. %float_3 = OpConstant %float 3
  1306. %float_1_78900003 = OpConstant %float 1.78900003
  1307. %v4float = OpTypeVector %float 4
  1308. %uint = OpTypeInt 32 0
  1309. %uint_1 = OpConstant %uint 1
  1310. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  1311. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  1312. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  1313. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  1314. %int = OpTypeInt 32 1
  1315. %int_0 = OpConstant %int 0
  1316. %21 = OpTypeImage %float 1D 0 0 0 1 Unknown
  1317. %22 = OpTypeSampledImage %21
  1318. %uint_128 = OpConstant %uint 128
  1319. %_arr_22_uint_128 = OpTypeArray %22 %uint_128
  1320. %_ptr_UniformConstant__arr_22_uint_128 = OpTypePointer UniformConstant %_arr_22_uint_128
  1321. %texSampler1D = OpVariable %_ptr_UniformConstant__arr_22_uint_128 UniformConstant
  1322. %foo = OpTypeStruct %int
  1323. %_ptr_Uniform_foo = OpTypePointer Uniform %foo
  1324. %__0 = OpVariable %_ptr_Uniform_foo Uniform
  1325. %_ptr_Uniform_int = OpTypePointer Uniform %int
  1326. %_ptr_UniformConstant_22 = OpTypePointer UniformConstant %22
  1327. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1328. %v2float = OpTypeVector %float 2
  1329. %_ptr_Input_v2float = OpTypePointer Input %v2float
  1330. %coords2D = OpVariable %_ptr_Input_v2float Input
  1331. )";
  1332. const std::string defs_after =
  1333. R"(OpCapability Shader
  1334. OpCapability Sampled1D
  1335. OpExtension "SPV_KHR_storage_buffer_storage_class"
  1336. %1 = OpExtInstImport "GLSL.std.450"
  1337. OpMemoryModel Logical GLSL450
  1338. OpEntryPoint Vertex %main "main" %_ %coords2D %gl_VertexIndex %gl_InstanceIndex
  1339. OpSource GLSL 450
  1340. OpName %main "main"
  1341. OpName %lod "lod"
  1342. OpName %coords1D "coords1D"
  1343. OpName %gl_PerVertex "gl_PerVertex"
  1344. OpMemberName %gl_PerVertex 0 "gl_Position"
  1345. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  1346. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  1347. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  1348. OpName %_ ""
  1349. OpName %texSampler1D "texSampler1D"
  1350. OpName %foo "foo"
  1351. OpMemberName %foo 0 "g_idx"
  1352. OpName %__0 ""
  1353. OpName %coords2D "coords2D"
  1354. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  1355. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  1356. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  1357. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  1358. OpDecorate %gl_PerVertex Block
  1359. OpDecorate %texSampler1D DescriptorSet 0
  1360. OpDecorate %texSampler1D Binding 3
  1361. OpMemberDecorate %foo 0 Offset 0
  1362. OpDecorate %foo Block
  1363. OpDecorate %__0 DescriptorSet 0
  1364. OpDecorate %__0 Binding 5
  1365. OpDecorate %coords2D Location 0
  1366. OpDecorate %_runtimearr_uint ArrayStride 4
  1367. OpDecorate %_struct_61 Block
  1368. OpMemberDecorate %_struct_61 0 Offset 0
  1369. OpMemberDecorate %_struct_61 1 Offset 4
  1370. OpDecorate %63 DescriptorSet 7
  1371. OpDecorate %63 Binding 0
  1372. OpDecorate %gl_VertexIndex BuiltIn VertexIndex
  1373. OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
  1374. %void = OpTypeVoid
  1375. %12 = OpTypeFunction %void
  1376. %float = OpTypeFloat 32
  1377. %_ptr_Function_float = OpTypePointer Function %float
  1378. %float_3 = OpConstant %float 3
  1379. %float_1_78900003 = OpConstant %float 1.78900003
  1380. %v4float = OpTypeVector %float 4
  1381. %uint = OpTypeInt 32 0
  1382. %uint_1 = OpConstant %uint 1
  1383. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  1384. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  1385. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  1386. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  1387. %int = OpTypeInt 32 1
  1388. %int_0 = OpConstant %int 0
  1389. %24 = OpTypeImage %float 1D 0 0 0 1 Unknown
  1390. %25 = OpTypeSampledImage %24
  1391. %uint_128 = OpConstant %uint 128
  1392. %_arr_25_uint_128 = OpTypeArray %25 %uint_128
  1393. %_ptr_UniformConstant__arr_25_uint_128 = OpTypePointer UniformConstant %_arr_25_uint_128
  1394. %texSampler1D = OpVariable %_ptr_UniformConstant__arr_25_uint_128 UniformConstant
  1395. %foo = OpTypeStruct %int
  1396. %_ptr_Uniform_foo = OpTypePointer Uniform %foo
  1397. %__0 = OpVariable %_ptr_Uniform_foo Uniform
  1398. %_ptr_Uniform_int = OpTypePointer Uniform %int
  1399. %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
  1400. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1401. %v2float = OpTypeVector %float 2
  1402. %_ptr_Input_v2float = OpTypePointer Input %v2float
  1403. %coords2D = OpVariable %_ptr_Input_v2float Input
  1404. %uint_0 = OpConstant %uint 0
  1405. %bool = OpTypeBool
  1406. %54 = OpTypeFunction %void %uint %uint %uint %uint
  1407. %_runtimearr_uint = OpTypeRuntimeArray %uint
  1408. %_struct_61 = OpTypeStruct %uint %_runtimearr_uint
  1409. %_ptr_StorageBuffer__struct_61 = OpTypePointer StorageBuffer %_struct_61
  1410. %63 = OpVariable %_ptr_StorageBuffer__struct_61 StorageBuffer
  1411. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  1412. %uint_9 = OpConstant %uint 9
  1413. %uint_4 = OpConstant %uint 4
  1414. %uint_23 = OpConstant %uint 23
  1415. %uint_2 = OpConstant %uint 2
  1416. %uint_3 = OpConstant %uint 3
  1417. %_ptr_Input_uint = OpTypePointer Input %uint
  1418. %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
  1419. %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
  1420. %uint_5 = OpConstant %uint 5
  1421. %uint_6 = OpConstant %uint 6
  1422. %uint_7 = OpConstant %uint 7
  1423. %uint_8 = OpConstant %uint 8
  1424. %uint_74 = OpConstant %uint 74
  1425. %106 = OpConstantNull %v4float
  1426. )";
  1427. const std::string func_before =
  1428. R"(%main = OpFunction %void None %3
  1429. %5 = OpLabel
  1430. %lod = OpVariable %_ptr_Function_float Function
  1431. %coords1D = OpVariable %_ptr_Function_float Function
  1432. OpStore %lod %float_3
  1433. OpStore %coords1D %float_1_78900003
  1434. %31 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
  1435. %32 = OpLoad %int %31
  1436. %34 = OpAccessChain %_ptr_UniformConstant_22 %texSampler1D %32
  1437. %35 = OpLoad %22 %34
  1438. %36 = OpLoad %float %coords1D
  1439. %37 = OpLoad %float %lod
  1440. %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
  1441. %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  1442. OpStore %40 %38
  1443. OpReturn
  1444. OpFunctionEnd
  1445. )";
  1446. const std::string func_after =
  1447. R"(%main = OpFunction %void None %12
  1448. %35 = OpLabel
  1449. %lod = OpVariable %_ptr_Function_float Function
  1450. %coords1D = OpVariable %_ptr_Function_float Function
  1451. OpStore %lod %float_3
  1452. OpStore %coords1D %float_1_78900003
  1453. %36 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
  1454. %37 = OpLoad %int %36
  1455. %38 = OpAccessChain %_ptr_UniformConstant_25 %texSampler1D %37
  1456. %39 = OpLoad %25 %38
  1457. %40 = OpLoad %float %coords1D
  1458. %41 = OpLoad %float %lod
  1459. %46 = OpULessThan %bool %37 %uint_128
  1460. OpSelectionMerge %47 None
  1461. OpBranchConditional %46 %48 %49
  1462. %48 = OpLabel
  1463. %50 = OpLoad %25 %38
  1464. %51 = OpImageSampleExplicitLod %v4float %50 %40 Lod %41
  1465. OpBranch %47
  1466. %49 = OpLabel
  1467. %52 = OpBitcast %uint %37
  1468. %105 = OpFunctionCall %void %53 %uint_74 %uint_0 %52 %uint_128
  1469. OpBranch %47
  1470. %47 = OpLabel
  1471. %107 = OpPhi %v4float %51 %48 %106 %49
  1472. %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  1473. OpStore %43 %107
  1474. OpReturn
  1475. OpFunctionEnd
  1476. )";
  1477. const std::string output_func =
  1478. R"(%53 = OpFunction %void None %54
  1479. %55 = OpFunctionParameter %uint
  1480. %56 = OpFunctionParameter %uint
  1481. %57 = OpFunctionParameter %uint
  1482. %58 = OpFunctionParameter %uint
  1483. %59 = OpLabel
  1484. %65 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_0
  1485. %68 = OpAtomicIAdd %uint %65 %uint_4 %uint_0 %uint_9
  1486. %69 = OpIAdd %uint %68 %uint_9
  1487. %70 = OpArrayLength %uint %63 1
  1488. %71 = OpULessThanEqual %bool %69 %70
  1489. OpSelectionMerge %72 None
  1490. OpBranchConditional %71 %73 %72
  1491. %73 = OpLabel
  1492. %74 = OpIAdd %uint %68 %uint_0
  1493. %75 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %74
  1494. OpStore %75 %uint_9
  1495. %77 = OpIAdd %uint %68 %uint_1
  1496. %78 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %77
  1497. OpStore %78 %uint_23
  1498. %80 = OpIAdd %uint %68 %uint_2
  1499. %81 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %80
  1500. OpStore %81 %55
  1501. %83 = OpIAdd %uint %68 %uint_3
  1502. %84 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %83
  1503. OpStore %84 %uint_0
  1504. %87 = OpLoad %uint %gl_VertexIndex
  1505. %88 = OpIAdd %uint %68 %uint_4
  1506. %89 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %88
  1507. OpStore %89 %87
  1508. %91 = OpLoad %uint %gl_InstanceIndex
  1509. %93 = OpIAdd %uint %68 %uint_5
  1510. %94 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %93
  1511. OpStore %94 %91
  1512. %96 = OpIAdd %uint %68 %uint_6
  1513. %97 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %96
  1514. OpStore %97 %56
  1515. %99 = OpIAdd %uint %68 %uint_7
  1516. %100 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %99
  1517. OpStore %100 %57
  1518. %102 = OpIAdd %uint %68 %uint_8
  1519. %103 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %102
  1520. OpStore %103 %58
  1521. OpBranch %72
  1522. %72 = OpLabel
  1523. OpReturn
  1524. OpFunctionEnd
  1525. )";
  1526. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1527. SinglePassRunAndCheck<InstBindlessCheckPass>(
  1528. defs_before + func_before, defs_after + func_after + output_func, true,
  1529. true, 7u, 23u, false, false, 1u);
  1530. }
  1531. TEST_F(InstBindlessTest, MultipleDebugFunctions) {
  1532. // Same source as Simple, but compiled -g and not optimized, especially not
  1533. // inlined. The OpSource has had the source extracted for the sake of brevity.
  1534. const std::string defs_before =
  1535. R"(OpCapability Shader
  1536. %2 = OpExtInstImport "GLSL.std.450"
  1537. OpMemoryModel Logical GLSL450
  1538. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  1539. OpExecutionMode %MainPs OriginUpperLeft
  1540. %1 = OpString "foo5.frag"
  1541. OpSource HLSL 500 %1
  1542. OpName %MainPs "MainPs"
  1543. OpName %PS_INPUT "PS_INPUT"
  1544. OpMemberName %PS_INPUT 0 "vTextureCoords"
  1545. OpName %PS_OUTPUT "PS_OUTPUT"
  1546. OpMemberName %PS_OUTPUT 0 "vColor"
  1547. OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
  1548. OpName %i "i"
  1549. OpName %ps_output "ps_output"
  1550. OpName %g_tColor "g_tColor"
  1551. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  1552. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  1553. OpName %_ ""
  1554. OpName %g_sAniso "g_sAniso"
  1555. OpName %i_0 "i"
  1556. OpName %i_vTextureCoords "i.vTextureCoords"
  1557. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  1558. OpName %param "param"
  1559. OpDecorate %g_tColor DescriptorSet 0
  1560. OpDecorate %g_tColor Binding 0
  1561. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  1562. OpDecorate %PerViewConstantBuffer_t Block
  1563. OpDecorate %g_sAniso DescriptorSet 0
  1564. OpDecorate %g_sAniso Binding 1
  1565. OpDecorate %i_vTextureCoords Location 0
  1566. OpDecorate %_entryPointOutput_vColor Location 0
  1567. %void = OpTypeVoid
  1568. %4 = OpTypeFunction %void
  1569. %float = OpTypeFloat 32
  1570. %v2float = OpTypeVector %float 2
  1571. %PS_INPUT = OpTypeStruct %v2float
  1572. %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
  1573. %v4float = OpTypeVector %float 4
  1574. %PS_OUTPUT = OpTypeStruct %v4float
  1575. %13 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
  1576. %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
  1577. %int = OpTypeInt 32 1
  1578. %int_0 = OpConstant %int 0
  1579. %21 = OpTypeImage %float 2D 0 0 0 1 Unknown
  1580. %uint = OpTypeInt 32 0
  1581. %uint_128 = OpConstant %uint 128
  1582. %_arr_21_uint_128 = OpTypeArray %21 %uint_128
  1583. %_ptr_UniformConstant__arr_21_uint_128 = OpTypePointer UniformConstant %_arr_21_uint_128
  1584. %g_tColor = OpVariable %_ptr_UniformConstant__arr_21_uint_128 UniformConstant
  1585. %PerViewConstantBuffer_t = OpTypeStruct %uint
  1586. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  1587. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  1588. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  1589. %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
  1590. %36 = OpTypeSampler
  1591. %_ptr_UniformConstant_36 = OpTypePointer UniformConstant %36
  1592. %g_sAniso = OpVariable %_ptr_UniformConstant_36 UniformConstant
  1593. %40 = OpTypeSampledImage %21
  1594. %_ptr_Function_v2float = OpTypePointer Function %v2float
  1595. %_ptr_Function_v4float = OpTypePointer Function %v4float
  1596. %_ptr_Input_v2float = OpTypePointer Input %v2float
  1597. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  1598. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1599. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  1600. )";
  1601. const std::string defs_after =
  1602. R"(OpCapability Shader
  1603. OpExtension "SPV_KHR_storage_buffer_storage_class"
  1604. %1 = OpExtInstImport "GLSL.std.450"
  1605. OpMemoryModel Logical GLSL450
  1606. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  1607. OpExecutionMode %MainPs OriginUpperLeft
  1608. %5 = OpString "foo5.frag"
  1609. OpSource HLSL 500 %5
  1610. OpName %MainPs "MainPs"
  1611. OpName %PS_INPUT "PS_INPUT"
  1612. OpMemberName %PS_INPUT 0 "vTextureCoords"
  1613. OpName %PS_OUTPUT "PS_OUTPUT"
  1614. OpMemberName %PS_OUTPUT 0 "vColor"
  1615. OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
  1616. OpName %i "i"
  1617. OpName %ps_output "ps_output"
  1618. OpName %g_tColor "g_tColor"
  1619. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  1620. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  1621. OpName %_ ""
  1622. OpName %g_sAniso "g_sAniso"
  1623. OpName %i_0 "i"
  1624. OpName %i_vTextureCoords "i.vTextureCoords"
  1625. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  1626. OpName %param "param"
  1627. OpDecorate %g_tColor DescriptorSet 0
  1628. OpDecorate %g_tColor Binding 0
  1629. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  1630. OpDecorate %PerViewConstantBuffer_t Block
  1631. OpDecorate %g_sAniso DescriptorSet 0
  1632. OpDecorate %g_sAniso Binding 1
  1633. OpDecorate %i_vTextureCoords Location 0
  1634. OpDecorate %_entryPointOutput_vColor Location 0
  1635. OpDecorate %_runtimearr_uint ArrayStride 4
  1636. OpDecorate %_struct_77 Block
  1637. OpMemberDecorate %_struct_77 0 Offset 0
  1638. OpMemberDecorate %_struct_77 1 Offset 4
  1639. OpDecorate %79 DescriptorSet 7
  1640. OpDecorate %79 Binding 0
  1641. OpDecorate %gl_FragCoord BuiltIn FragCoord
  1642. %void = OpTypeVoid
  1643. %18 = OpTypeFunction %void
  1644. %float = OpTypeFloat 32
  1645. %v2float = OpTypeVector %float 2
  1646. %PS_INPUT = OpTypeStruct %v2float
  1647. %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
  1648. %v4float = OpTypeVector %float 4
  1649. %PS_OUTPUT = OpTypeStruct %v4float
  1650. %23 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
  1651. %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
  1652. %int = OpTypeInt 32 1
  1653. %int_0 = OpConstant %int 0
  1654. %27 = OpTypeImage %float 2D 0 0 0 1 Unknown
  1655. %uint = OpTypeInt 32 0
  1656. %uint_128 = OpConstant %uint 128
  1657. %_arr_27_uint_128 = OpTypeArray %27 %uint_128
  1658. %_ptr_UniformConstant__arr_27_uint_128 = OpTypePointer UniformConstant %_arr_27_uint_128
  1659. %g_tColor = OpVariable %_ptr_UniformConstant__arr_27_uint_128 UniformConstant
  1660. %PerViewConstantBuffer_t = OpTypeStruct %uint
  1661. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  1662. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  1663. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  1664. %_ptr_UniformConstant_27 = OpTypePointer UniformConstant %27
  1665. %35 = OpTypeSampler
  1666. %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
  1667. %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
  1668. %37 = OpTypeSampledImage %27
  1669. %_ptr_Function_v2float = OpTypePointer Function %v2float
  1670. %_ptr_Function_v4float = OpTypePointer Function %v4float
  1671. %_ptr_Input_v2float = OpTypePointer Input %v2float
  1672. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  1673. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1674. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  1675. %uint_0 = OpConstant %uint 0
  1676. %bool = OpTypeBool
  1677. %70 = OpTypeFunction %void %uint %uint %uint %uint
  1678. %_runtimearr_uint = OpTypeRuntimeArray %uint
  1679. %_struct_77 = OpTypeStruct %uint %_runtimearr_uint
  1680. %_ptr_StorageBuffer__struct_77 = OpTypePointer StorageBuffer %_struct_77
  1681. %79 = OpVariable %_ptr_StorageBuffer__struct_77 StorageBuffer
  1682. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  1683. %uint_9 = OpConstant %uint 9
  1684. %uint_4 = OpConstant %uint 4
  1685. %uint_1 = OpConstant %uint 1
  1686. %uint_23 = OpConstant %uint 23
  1687. %uint_2 = OpConstant %uint 2
  1688. %uint_3 = OpConstant %uint 3
  1689. %_ptr_Input_v4float = OpTypePointer Input %v4float
  1690. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  1691. %v4uint = OpTypeVector %uint 4
  1692. %uint_5 = OpConstant %uint 5
  1693. %uint_6 = OpConstant %uint 6
  1694. %uint_7 = OpConstant %uint 7
  1695. %uint_8 = OpConstant %uint 8
  1696. %uint_93 = OpConstant %uint 93
  1697. %125 = OpConstantNull %v4float
  1698. )";
  1699. const std::string func1_before =
  1700. R"(%MainPs = OpFunction %void None %4
  1701. %6 = OpLabel
  1702. %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
  1703. %param = OpVariable %_ptr_Function_PS_INPUT Function
  1704. OpLine %1 21 0
  1705. %54 = OpLoad %v2float %i_vTextureCoords
  1706. %55 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
  1707. OpStore %55 %54
  1708. %59 = OpLoad %PS_INPUT %i_0
  1709. OpStore %param %59
  1710. %60 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
  1711. %61 = OpCompositeExtract %v4float %60 0
  1712. OpStore %_entryPointOutput_vColor %61
  1713. OpReturn
  1714. OpFunctionEnd
  1715. )";
  1716. const std::string func1_after =
  1717. R"(%MainPs = OpFunction %void None %18
  1718. %42 = OpLabel
  1719. %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
  1720. %param = OpVariable %_ptr_Function_PS_INPUT Function
  1721. OpLine %5 21 0
  1722. %43 = OpLoad %v2float %i_vTextureCoords
  1723. %44 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
  1724. OpStore %44 %43
  1725. %45 = OpLoad %PS_INPUT %i_0
  1726. OpStore %param %45
  1727. %46 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
  1728. %47 = OpCompositeExtract %v4float %46 0
  1729. OpStore %_entryPointOutput_vColor %47
  1730. OpReturn
  1731. OpFunctionEnd
  1732. )";
  1733. const std::string func2_before =
  1734. R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %13
  1735. %i = OpFunctionParameter %_ptr_Function_PS_INPUT
  1736. %16 = OpLabel
  1737. %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
  1738. OpLine %1 24 0
  1739. %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  1740. %32 = OpLoad %uint %31
  1741. %34 = OpAccessChain %_ptr_UniformConstant_21 %g_tColor %32
  1742. %35 = OpLoad %21 %34
  1743. %39 = OpLoad %36 %g_sAniso
  1744. %41 = OpSampledImage %40 %35 %39
  1745. %43 = OpAccessChain %_ptr_Function_v2float %i %int_0
  1746. %44 = OpLoad %v2float %43
  1747. %45 = OpImageSampleImplicitLod %v4float %41 %44
  1748. %47 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
  1749. OpStore %47 %45
  1750. OpLine %1 25 0
  1751. %48 = OpLoad %PS_OUTPUT %ps_output
  1752. OpReturnValue %48
  1753. OpFunctionEnd
  1754. )";
  1755. const std::string func2_after =
  1756. R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %23
  1757. %i = OpFunctionParameter %_ptr_Function_PS_INPUT
  1758. %48 = OpLabel
  1759. %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
  1760. OpLine %5 24 0
  1761. %49 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  1762. %50 = OpLoad %uint %49
  1763. %51 = OpAccessChain %_ptr_UniformConstant_27 %g_tColor %50
  1764. %52 = OpLoad %27 %51
  1765. %53 = OpLoad %35 %g_sAniso
  1766. %54 = OpSampledImage %37 %52 %53
  1767. %55 = OpAccessChain %_ptr_Function_v2float %i %int_0
  1768. %56 = OpLoad %v2float %55
  1769. %62 = OpULessThan %bool %50 %uint_128
  1770. OpSelectionMerge %63 None
  1771. OpBranchConditional %62 %64 %65
  1772. %64 = OpLabel
  1773. %66 = OpLoad %27 %51
  1774. %67 = OpSampledImage %37 %66 %53
  1775. %68 = OpImageSampleImplicitLod %v4float %67 %56
  1776. OpBranch %63
  1777. %65 = OpLabel
  1778. %124 = OpFunctionCall %void %69 %uint_93 %uint_0 %50 %uint_128
  1779. OpBranch %63
  1780. %63 = OpLabel
  1781. %126 = OpPhi %v4float %68 %64 %125 %65
  1782. %58 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
  1783. OpStore %58 %126
  1784. OpLine %5 25 0
  1785. %59 = OpLoad %PS_OUTPUT %ps_output
  1786. OpReturnValue %59
  1787. OpFunctionEnd
  1788. )";
  1789. const std::string output_func =
  1790. R"(%69 = OpFunction %void None %70
  1791. %71 = OpFunctionParameter %uint
  1792. %72 = OpFunctionParameter %uint
  1793. %73 = OpFunctionParameter %uint
  1794. %74 = OpFunctionParameter %uint
  1795. %75 = OpLabel
  1796. %81 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_0
  1797. %84 = OpAtomicIAdd %uint %81 %uint_4 %uint_0 %uint_9
  1798. %85 = OpIAdd %uint %84 %uint_9
  1799. %86 = OpArrayLength %uint %79 1
  1800. %87 = OpULessThanEqual %bool %85 %86
  1801. OpSelectionMerge %88 None
  1802. OpBranchConditional %87 %89 %88
  1803. %89 = OpLabel
  1804. %90 = OpIAdd %uint %84 %uint_0
  1805. %92 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %90
  1806. OpStore %92 %uint_9
  1807. %94 = OpIAdd %uint %84 %uint_1
  1808. %95 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %94
  1809. OpStore %95 %uint_23
  1810. %97 = OpIAdd %uint %84 %uint_2
  1811. %98 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %97
  1812. OpStore %98 %71
  1813. %100 = OpIAdd %uint %84 %uint_3
  1814. %101 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %100
  1815. OpStore %101 %uint_4
  1816. %104 = OpLoad %v4float %gl_FragCoord
  1817. %106 = OpBitcast %v4uint %104
  1818. %107 = OpCompositeExtract %uint %106 0
  1819. %108 = OpIAdd %uint %84 %uint_4
  1820. %109 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %108
  1821. OpStore %109 %107
  1822. %110 = OpCompositeExtract %uint %106 1
  1823. %112 = OpIAdd %uint %84 %uint_5
  1824. %113 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %112
  1825. OpStore %113 %110
  1826. %115 = OpIAdd %uint %84 %uint_6
  1827. %116 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %115
  1828. OpStore %116 %72
  1829. %118 = OpIAdd %uint %84 %uint_7
  1830. %119 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %118
  1831. OpStore %119 %73
  1832. %121 = OpIAdd %uint %84 %uint_8
  1833. %122 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %121
  1834. OpStore %122 %74
  1835. OpBranch %88
  1836. %88 = OpLabel
  1837. OpReturn
  1838. OpFunctionEnd
  1839. )";
  1840. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1841. SinglePassRunAndCheck<InstBindlessCheckPass>(
  1842. defs_before + func1_before + func2_before,
  1843. defs_after + func1_after + func2_after + output_func, true, true, 7u, 23u,
  1844. false, false, 1u);
  1845. }
  1846. TEST_F(InstBindlessTest, RuntimeArray) {
  1847. // This test verifies that the pass will correctly instrument shader
  1848. // with runtime descriptor array. This test was created by editing the
  1849. // SPIR-V from the Simple test.
  1850. const std::string defs_before =
  1851. R"(OpCapability Shader
  1852. OpCapability RuntimeDescriptorArray
  1853. OpExtension "SPV_EXT_descriptor_indexing"
  1854. %1 = OpExtInstImport "GLSL.std.450"
  1855. OpMemoryModel Logical GLSL450
  1856. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  1857. OpExecutionMode %MainPs OriginUpperLeft
  1858. OpSource HLSL 500
  1859. OpName %MainPs "MainPs"
  1860. OpName %g_tColor "g_tColor"
  1861. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  1862. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  1863. OpName %_ ""
  1864. OpName %g_sAniso "g_sAniso"
  1865. OpName %i_vTextureCoords "i.vTextureCoords"
  1866. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  1867. OpDecorate %g_tColor DescriptorSet 1
  1868. OpDecorate %g_tColor Binding 2
  1869. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  1870. OpDecorate %PerViewConstantBuffer_t Block
  1871. OpDecorate %g_sAniso DescriptorSet 1
  1872. OpDecorate %g_sAniso Binding 0
  1873. OpDecorate %i_vTextureCoords Location 0
  1874. OpDecorate %_entryPointOutput_vColor Location 0
  1875. %void = OpTypeVoid
  1876. %3 = OpTypeFunction %void
  1877. %float = OpTypeFloat 32
  1878. %v2float = OpTypeVector %float 2
  1879. %v4float = OpTypeVector %float 4
  1880. %int = OpTypeInt 32 1
  1881. %int_0 = OpConstant %int 0
  1882. %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
  1883. %uint = OpTypeInt 32 0
  1884. %uint_1 = OpConstant %uint 1
  1885. %_rarr_20 = OpTypeRuntimeArray %20
  1886. %_ptr_UniformConstant__arr_20 = OpTypePointer UniformConstant %_rarr_20
  1887. %g_tColor = OpVariable %_ptr_UniformConstant__arr_20 UniformConstant
  1888. %PerViewConstantBuffer_t = OpTypeStruct %uint
  1889. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  1890. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  1891. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  1892. %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
  1893. %35 = OpTypeSampler
  1894. %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
  1895. %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
  1896. %39 = OpTypeSampledImage %20
  1897. %_ptr_Input_v2float = OpTypePointer Input %v2float
  1898. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  1899. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1900. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  1901. )";
  1902. const std::string defs_after =
  1903. R"(OpCapability Shader
  1904. OpCapability RuntimeDescriptorArray
  1905. OpExtension "SPV_EXT_descriptor_indexing"
  1906. OpExtension "SPV_KHR_storage_buffer_storage_class"
  1907. %1 = OpExtInstImport "GLSL.std.450"
  1908. OpMemoryModel Logical GLSL450
  1909. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  1910. OpExecutionMode %MainPs OriginUpperLeft
  1911. OpSource HLSL 500
  1912. OpName %MainPs "MainPs"
  1913. OpName %g_tColor "g_tColor"
  1914. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  1915. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  1916. OpName %_ ""
  1917. OpName %g_sAniso "g_sAniso"
  1918. OpName %i_vTextureCoords "i.vTextureCoords"
  1919. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  1920. OpDecorate %g_tColor DescriptorSet 1
  1921. OpDecorate %g_tColor Binding 2
  1922. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  1923. OpDecorate %PerViewConstantBuffer_t Block
  1924. OpDecorate %g_sAniso DescriptorSet 1
  1925. OpDecorate %g_sAniso Binding 0
  1926. OpDecorate %i_vTextureCoords Location 0
  1927. OpDecorate %_entryPointOutput_vColor Location 0
  1928. OpDecorate %_runtimearr_uint ArrayStride 4
  1929. OpDecorate %_struct_46 Block
  1930. OpMemberDecorate %_struct_46 0 Offset 0
  1931. OpDecorate %48 DescriptorSet 7
  1932. OpDecorate %48 Binding 1
  1933. OpDecorate %_struct_71 Block
  1934. OpMemberDecorate %_struct_71 0 Offset 0
  1935. OpMemberDecorate %_struct_71 1 Offset 4
  1936. OpDecorate %73 DescriptorSet 7
  1937. OpDecorate %73 Binding 0
  1938. OpDecorate %gl_FragCoord BuiltIn FragCoord
  1939. %void = OpTypeVoid
  1940. %10 = OpTypeFunction %void
  1941. %float = OpTypeFloat 32
  1942. %v2float = OpTypeVector %float 2
  1943. %v4float = OpTypeVector %float 4
  1944. %int = OpTypeInt 32 1
  1945. %int_0 = OpConstant %int 0
  1946. %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
  1947. %uint = OpTypeInt 32 0
  1948. %uint_1 = OpConstant %uint 1
  1949. %_runtimearr_16 = OpTypeRuntimeArray %16
  1950. %_ptr_UniformConstant__runtimearr_16 = OpTypePointer UniformConstant %_runtimearr_16
  1951. %g_tColor = OpVariable %_ptr_UniformConstant__runtimearr_16 UniformConstant
  1952. %PerViewConstantBuffer_t = OpTypeStruct %uint
  1953. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  1954. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  1955. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  1956. %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
  1957. %24 = OpTypeSampler
  1958. %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
  1959. %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
  1960. %26 = OpTypeSampledImage %16
  1961. %_ptr_Input_v2float = OpTypePointer Input %v2float
  1962. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  1963. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1964. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  1965. %uint_0 = OpConstant %uint 0
  1966. %uint_2 = OpConstant %uint 2
  1967. %41 = OpTypeFunction %uint %uint %uint
  1968. %_runtimearr_uint = OpTypeRuntimeArray %uint
  1969. %_struct_46 = OpTypeStruct %_runtimearr_uint
  1970. %_ptr_StorageBuffer__struct_46 = OpTypePointer StorageBuffer %_struct_46
  1971. %48 = OpVariable %_ptr_StorageBuffer__struct_46 StorageBuffer
  1972. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  1973. %bool = OpTypeBool
  1974. %65 = OpTypeFunction %void %uint %uint %uint %uint
  1975. %_struct_71 = OpTypeStruct %uint %_runtimearr_uint
  1976. %_ptr_StorageBuffer__struct_71 = OpTypePointer StorageBuffer %_struct_71
  1977. %73 = OpVariable %_ptr_StorageBuffer__struct_71 StorageBuffer
  1978. %uint_9 = OpConstant %uint 9
  1979. %uint_4 = OpConstant %uint 4
  1980. %uint_23 = OpConstant %uint 23
  1981. %uint_3 = OpConstant %uint 3
  1982. %_ptr_Input_v4float = OpTypePointer Input %v4float
  1983. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  1984. %v4uint = OpTypeVector %uint 4
  1985. %uint_5 = OpConstant %uint 5
  1986. %uint_6 = OpConstant %uint 6
  1987. %uint_7 = OpConstant %uint 7
  1988. %uint_8 = OpConstant %uint 8
  1989. %uint_59 = OpConstant %uint 59
  1990. %116 = OpConstantNull %v4float
  1991. %119 = OpTypeFunction %uint %uint %uint %uint %uint
  1992. )";
  1993. const std::string func_before =
  1994. R"(%MainPs = OpFunction %void None %3
  1995. %5 = OpLabel
  1996. %53 = OpLoad %v2float %i_vTextureCoords
  1997. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  1998. %64 = OpLoad %uint %63
  1999. %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
  2000. %66 = OpLoad %20 %65
  2001. %67 = OpLoad %35 %g_sAniso
  2002. %68 = OpSampledImage %39 %66 %67
  2003. %71 = OpImageSampleImplicitLod %v4float %68 %53
  2004. OpStore %_entryPointOutput_vColor %71
  2005. OpReturn
  2006. OpFunctionEnd
  2007. )";
  2008. const std::string func_after =
  2009. R"(%MainPs = OpFunction %void None %10
  2010. %29 = OpLabel
  2011. %30 = OpLoad %v2float %i_vTextureCoords
  2012. %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  2013. %32 = OpLoad %uint %31
  2014. %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
  2015. %34 = OpLoad %16 %33
  2016. %35 = OpLoad %24 %g_sAniso
  2017. %36 = OpSampledImage %26 %34 %35
  2018. %55 = OpFunctionCall %uint %40 %uint_2 %uint_2
  2019. %57 = OpULessThan %bool %32 %55
  2020. OpSelectionMerge %58 None
  2021. OpBranchConditional %57 %59 %60
  2022. %59 = OpLabel
  2023. %61 = OpLoad %16 %33
  2024. %62 = OpSampledImage %26 %61 %35
  2025. %136 = OpFunctionCall %uint %118 %uint_0 %uint_1 %uint_2 %32
  2026. %137 = OpINotEqual %bool %136 %uint_0
  2027. OpSelectionMerge %138 None
  2028. OpBranchConditional %137 %139 %140
  2029. %139 = OpLabel
  2030. %141 = OpLoad %16 %33
  2031. %142 = OpSampledImage %26 %141 %35
  2032. %143 = OpImageSampleImplicitLod %v4float %142 %30
  2033. OpBranch %138
  2034. %140 = OpLabel
  2035. %144 = OpFunctionCall %void %64 %uint_59 %uint_1 %32 %uint_0
  2036. OpBranch %138
  2037. %138 = OpLabel
  2038. %145 = OpPhi %v4float %143 %139 %116 %140
  2039. OpBranch %58
  2040. %60 = OpLabel
  2041. %115 = OpFunctionCall %void %64 %uint_59 %uint_0 %32 %55
  2042. OpBranch %58
  2043. %58 = OpLabel
  2044. %117 = OpPhi %v4float %145 %138 %116 %60
  2045. OpStore %_entryPointOutput_vColor %117
  2046. OpReturn
  2047. OpFunctionEnd
  2048. )";
  2049. const std::string new_funcs =
  2050. R"(%40 = OpFunction %uint None %41
  2051. %42 = OpFunctionParameter %uint
  2052. %43 = OpFunctionParameter %uint
  2053. %44 = OpLabel
  2054. %50 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %42
  2055. %51 = OpLoad %uint %50
  2056. %52 = OpIAdd %uint %51 %43
  2057. %53 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %52
  2058. %54 = OpLoad %uint %53
  2059. OpReturnValue %54
  2060. OpFunctionEnd
  2061. %64 = OpFunction %void None %65
  2062. %66 = OpFunctionParameter %uint
  2063. %67 = OpFunctionParameter %uint
  2064. %68 = OpFunctionParameter %uint
  2065. %69 = OpFunctionParameter %uint
  2066. %70 = OpLabel
  2067. %74 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_0
  2068. %77 = OpAtomicIAdd %uint %74 %uint_4 %uint_0 %uint_9
  2069. %78 = OpIAdd %uint %77 %uint_9
  2070. %79 = OpArrayLength %uint %73 1
  2071. %80 = OpULessThanEqual %bool %78 %79
  2072. OpSelectionMerge %81 None
  2073. OpBranchConditional %80 %82 %81
  2074. %82 = OpLabel
  2075. %83 = OpIAdd %uint %77 %uint_0
  2076. %84 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %83
  2077. OpStore %84 %uint_9
  2078. %86 = OpIAdd %uint %77 %uint_1
  2079. %87 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %86
  2080. OpStore %87 %uint_23
  2081. %88 = OpIAdd %uint %77 %uint_2
  2082. %89 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %88
  2083. OpStore %89 %66
  2084. %91 = OpIAdd %uint %77 %uint_3
  2085. %92 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %91
  2086. OpStore %92 %uint_4
  2087. %95 = OpLoad %v4float %gl_FragCoord
  2088. %97 = OpBitcast %v4uint %95
  2089. %98 = OpCompositeExtract %uint %97 0
  2090. %99 = OpIAdd %uint %77 %uint_4
  2091. %100 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %99
  2092. OpStore %100 %98
  2093. %101 = OpCompositeExtract %uint %97 1
  2094. %103 = OpIAdd %uint %77 %uint_5
  2095. %104 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %103
  2096. OpStore %104 %101
  2097. %106 = OpIAdd %uint %77 %uint_6
  2098. %107 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %106
  2099. OpStore %107 %67
  2100. %109 = OpIAdd %uint %77 %uint_7
  2101. %110 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %109
  2102. OpStore %110 %68
  2103. %112 = OpIAdd %uint %77 %uint_8
  2104. %113 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %112
  2105. OpStore %113 %69
  2106. OpBranch %81
  2107. %81 = OpLabel
  2108. OpReturn
  2109. OpFunctionEnd
  2110. %118 = OpFunction %uint None %119
  2111. %120 = OpFunctionParameter %uint
  2112. %121 = OpFunctionParameter %uint
  2113. %122 = OpFunctionParameter %uint
  2114. %123 = OpFunctionParameter %uint
  2115. %124 = OpLabel
  2116. %125 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %120
  2117. %126 = OpLoad %uint %125
  2118. %127 = OpIAdd %uint %126 %121
  2119. %128 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %127
  2120. %129 = OpLoad %uint %128
  2121. %130 = OpIAdd %uint %129 %122
  2122. %131 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %130
  2123. %132 = OpLoad %uint %131
  2124. %133 = OpIAdd %uint %132 %123
  2125. %134 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %133
  2126. %135 = OpLoad %uint %134
  2127. OpReturnValue %135
  2128. OpFunctionEnd
  2129. )";
  2130. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  2131. SinglePassRunAndCheck<InstBindlessCheckPass>(
  2132. defs_before + func_before, defs_after + func_after + new_funcs, true,
  2133. true);
  2134. }
  2135. TEST_F(InstBindlessTest, NoInstrumentNonBindless) {
  2136. // This test verifies that the pass will correctly not instrument vanilla
  2137. // texture sample.
  2138. //
  2139. // Texture2D g_tColor;
  2140. //
  2141. // SamplerState g_sAniso;
  2142. //
  2143. // struct PS_INPUT
  2144. // {
  2145. // float2 vTextureCoords : TEXCOORD2;
  2146. // };
  2147. //
  2148. // struct PS_OUTPUT
  2149. // {
  2150. // float4 vColor : SV_Target0;
  2151. // };
  2152. //
  2153. // PS_OUTPUT MainPs(PS_INPUT i)
  2154. // {
  2155. // PS_OUTPUT ps_output;
  2156. // ps_output.vColor =
  2157. // g_tColor.Sample(g_sAniso, i.vTextureCoords.xy);
  2158. // return ps_output;
  2159. // }
  2160. const std::string whole_file =
  2161. R"(OpCapability Shader
  2162. %1 = OpExtInstImport "GLSL.std.450"
  2163. OpMemoryModel Logical GLSL450
  2164. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  2165. OpExecutionMode %MainPs OriginUpperLeft
  2166. OpSource HLSL 500
  2167. OpName %MainPs "MainPs"
  2168. OpName %g_tColor "g_tColor"
  2169. OpName %g_sAniso "g_sAniso"
  2170. OpName %i_vTextureCoords "i.vTextureCoords"
  2171. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  2172. OpDecorate %g_tColor DescriptorSet 0
  2173. OpDecorate %g_tColor Binding 0
  2174. OpDecorate %g_sAniso DescriptorSet 0
  2175. OpDecorate %g_sAniso Binding 0
  2176. OpDecorate %i_vTextureCoords Location 0
  2177. OpDecorate %_entryPointOutput_vColor Location 0
  2178. %void = OpTypeVoid
  2179. %8 = OpTypeFunction %void
  2180. %float = OpTypeFloat 32
  2181. %v2float = OpTypeVector %float 2
  2182. %v4float = OpTypeVector %float 4
  2183. %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
  2184. %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
  2185. %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
  2186. %14 = OpTypeSampler
  2187. %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
  2188. %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
  2189. %16 = OpTypeSampledImage %12
  2190. %_ptr_Input_v2float = OpTypePointer Input %v2float
  2191. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  2192. %_ptr_Output_v4float = OpTypePointer Output %v4float
  2193. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  2194. %MainPs = OpFunction %void None %8
  2195. %19 = OpLabel
  2196. %20 = OpLoad %v2float %i_vTextureCoords
  2197. %21 = OpLoad %12 %g_tColor
  2198. %22 = OpLoad %14 %g_sAniso
  2199. %23 = OpSampledImage %16 %21 %22
  2200. %24 = OpImageSampleImplicitLod %v4float %23 %20
  2201. OpStore %_entryPointOutput_vColor %24
  2202. OpReturn
  2203. OpFunctionEnd
  2204. )";
  2205. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  2206. SinglePassRunAndCheck<InstBindlessCheckPass>(whole_file, whole_file, true,
  2207. true, 7u, 23u, false, false, 1u);
  2208. }
  2209. TEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptor) {
  2210. // This test verifies that the pass will correctly instrument vanilla
  2211. // texture sample on a scalar descriptor with an initialization check if the
  2212. // input_init_enable argument is set to true. This can happen when the
  2213. // descriptor indexing extension is enabled in the API but the SPIR-V
  2214. // does not have the extension enabled because it does not contain a
  2215. // runtime array. This is the same shader as NoInstrumentNonBindless.
  2216. const std::string defs_before =
  2217. R"(OpCapability Shader
  2218. %1 = OpExtInstImport "GLSL.std.450"
  2219. OpMemoryModel Logical GLSL450
  2220. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  2221. OpExecutionMode %MainPs OriginUpperLeft
  2222. OpSource HLSL 500
  2223. OpName %MainPs "MainPs"
  2224. OpName %g_tColor "g_tColor"
  2225. OpName %g_sAniso "g_sAniso"
  2226. OpName %i_vTextureCoords "i.vTextureCoords"
  2227. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  2228. OpDecorate %g_tColor DescriptorSet 0
  2229. OpDecorate %g_tColor Binding 0
  2230. OpDecorate %g_sAniso DescriptorSet 0
  2231. OpDecorate %g_sAniso Binding 0
  2232. OpDecorate %i_vTextureCoords Location 0
  2233. OpDecorate %_entryPointOutput_vColor Location 0
  2234. %void = OpTypeVoid
  2235. %8 = OpTypeFunction %void
  2236. %float = OpTypeFloat 32
  2237. %v2float = OpTypeVector %float 2
  2238. %v4float = OpTypeVector %float 4
  2239. %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
  2240. %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
  2241. %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
  2242. %14 = OpTypeSampler
  2243. %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
  2244. %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
  2245. %16 = OpTypeSampledImage %12
  2246. %_ptr_Input_v2float = OpTypePointer Input %v2float
  2247. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  2248. %_ptr_Output_v4float = OpTypePointer Output %v4float
  2249. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  2250. )";
  2251. const std::string defs_after =
  2252. R"(OpCapability Shader
  2253. OpExtension "SPV_KHR_storage_buffer_storage_class"
  2254. %1 = OpExtInstImport "GLSL.std.450"
  2255. OpMemoryModel Logical GLSL450
  2256. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  2257. OpExecutionMode %MainPs OriginUpperLeft
  2258. OpSource HLSL 500
  2259. OpName %MainPs "MainPs"
  2260. OpName %g_tColor "g_tColor"
  2261. OpName %g_sAniso "g_sAniso"
  2262. OpName %i_vTextureCoords "i.vTextureCoords"
  2263. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  2264. OpDecorate %g_tColor DescriptorSet 0
  2265. OpDecorate %g_tColor Binding 0
  2266. OpDecorate %g_sAniso DescriptorSet 0
  2267. OpDecorate %g_sAniso Binding 0
  2268. OpDecorate %i_vTextureCoords Location 0
  2269. OpDecorate %_entryPointOutput_vColor Location 0
  2270. OpDecorate %_runtimearr_uint ArrayStride 4
  2271. OpDecorate %_struct_35 Block
  2272. OpMemberDecorate %_struct_35 0 Offset 0
  2273. OpDecorate %37 DescriptorSet 7
  2274. OpDecorate %37 Binding 1
  2275. OpDecorate %_struct_67 Block
  2276. OpMemberDecorate %_struct_67 0 Offset 0
  2277. OpMemberDecorate %_struct_67 1 Offset 4
  2278. OpDecorate %69 DescriptorSet 7
  2279. OpDecorate %69 Binding 0
  2280. OpDecorate %gl_FragCoord BuiltIn FragCoord
  2281. %void = OpTypeVoid
  2282. %8 = OpTypeFunction %void
  2283. %float = OpTypeFloat 32
  2284. %v2float = OpTypeVector %float 2
  2285. %v4float = OpTypeVector %float 4
  2286. %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
  2287. %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
  2288. %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
  2289. %14 = OpTypeSampler
  2290. %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
  2291. %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
  2292. %16 = OpTypeSampledImage %12
  2293. %_ptr_Input_v2float = OpTypePointer Input %v2float
  2294. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  2295. %_ptr_Output_v4float = OpTypePointer Output %v4float
  2296. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  2297. %uint = OpTypeInt 32 0
  2298. %uint_0 = OpConstant %uint 0
  2299. %28 = OpTypeFunction %uint %uint %uint %uint %uint
  2300. %_runtimearr_uint = OpTypeRuntimeArray %uint
  2301. %_struct_35 = OpTypeStruct %_runtimearr_uint
  2302. %_ptr_StorageBuffer__struct_35 = OpTypePointer StorageBuffer %_struct_35
  2303. %37 = OpVariable %_ptr_StorageBuffer__struct_35 StorageBuffer
  2304. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  2305. %bool = OpTypeBool
  2306. %uint_1 = OpConstant %uint 1
  2307. %61 = OpTypeFunction %void %uint %uint %uint %uint
  2308. %_struct_67 = OpTypeStruct %uint %_runtimearr_uint
  2309. %_ptr_StorageBuffer__struct_67 = OpTypePointer StorageBuffer %_struct_67
  2310. %69 = OpVariable %_ptr_StorageBuffer__struct_67 StorageBuffer
  2311. %uint_9 = OpConstant %uint 9
  2312. %uint_4 = OpConstant %uint 4
  2313. %uint_23 = OpConstant %uint 23
  2314. %uint_2 = OpConstant %uint 2
  2315. %uint_3 = OpConstant %uint 3
  2316. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2317. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  2318. %v4uint = OpTypeVector %uint 4
  2319. %uint_5 = OpConstant %uint 5
  2320. %uint_6 = OpConstant %uint 6
  2321. %uint_7 = OpConstant %uint 7
  2322. %uint_8 = OpConstant %uint 8
  2323. %uint_39 = OpConstant %uint 39
  2324. %113 = OpConstantNull %v4float
  2325. )";
  2326. const std::string func_before =
  2327. R"(%MainPs = OpFunction %void None %8
  2328. %19 = OpLabel
  2329. %20 = OpLoad %v2float %i_vTextureCoords
  2330. %21 = OpLoad %12 %g_tColor
  2331. %22 = OpLoad %14 %g_sAniso
  2332. %23 = OpSampledImage %16 %21 %22
  2333. %24 = OpImageSampleImplicitLod %v4float %23 %20
  2334. OpStore %_entryPointOutput_vColor %24
  2335. OpReturn
  2336. OpFunctionEnd
  2337. )";
  2338. const std::string func_after =
  2339. R"(%MainPs = OpFunction %void None %8
  2340. %19 = OpLabel
  2341. %20 = OpLoad %v2float %i_vTextureCoords
  2342. %21 = OpLoad %12 %g_tColor
  2343. %22 = OpLoad %14 %g_sAniso
  2344. %23 = OpSampledImage %16 %21 %22
  2345. %50 = OpFunctionCall %uint %27 %uint_0 %uint_0 %uint_0 %uint_0
  2346. %52 = OpINotEqual %bool %50 %uint_0
  2347. OpSelectionMerge %54 None
  2348. OpBranchConditional %52 %55 %56
  2349. %55 = OpLabel
  2350. %57 = OpLoad %12 %g_tColor
  2351. %58 = OpSampledImage %16 %57 %22
  2352. %59 = OpImageSampleImplicitLod %v4float %58 %20
  2353. OpBranch %54
  2354. %56 = OpLabel
  2355. %112 = OpFunctionCall %void %60 %uint_39 %uint_1 %uint_0 %uint_0
  2356. OpBranch %54
  2357. %54 = OpLabel
  2358. %114 = OpPhi %v4float %59 %55 %113 %56
  2359. OpStore %_entryPointOutput_vColor %114
  2360. OpReturn
  2361. OpFunctionEnd
  2362. )";
  2363. const std::string new_funcs =
  2364. R"(%27 = OpFunction %uint None %28
  2365. %29 = OpFunctionParameter %uint
  2366. %30 = OpFunctionParameter %uint
  2367. %31 = OpFunctionParameter %uint
  2368. %32 = OpFunctionParameter %uint
  2369. %33 = OpLabel
  2370. %39 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %29
  2371. %40 = OpLoad %uint %39
  2372. %41 = OpIAdd %uint %40 %30
  2373. %42 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %41
  2374. %43 = OpLoad %uint %42
  2375. %44 = OpIAdd %uint %43 %31
  2376. %45 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %44
  2377. %46 = OpLoad %uint %45
  2378. %47 = OpIAdd %uint %46 %32
  2379. %48 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %47
  2380. %49 = OpLoad %uint %48
  2381. OpReturnValue %49
  2382. OpFunctionEnd
  2383. %60 = OpFunction %void None %61
  2384. %62 = OpFunctionParameter %uint
  2385. %63 = OpFunctionParameter %uint
  2386. %64 = OpFunctionParameter %uint
  2387. %65 = OpFunctionParameter %uint
  2388. %66 = OpLabel
  2389. %70 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_0
  2390. %73 = OpAtomicIAdd %uint %70 %uint_4 %uint_0 %uint_9
  2391. %74 = OpIAdd %uint %73 %uint_9
  2392. %75 = OpArrayLength %uint %69 1
  2393. %76 = OpULessThanEqual %bool %74 %75
  2394. OpSelectionMerge %77 None
  2395. OpBranchConditional %76 %78 %77
  2396. %78 = OpLabel
  2397. %79 = OpIAdd %uint %73 %uint_0
  2398. %80 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %79
  2399. OpStore %80 %uint_9
  2400. %82 = OpIAdd %uint %73 %uint_1
  2401. %83 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %82
  2402. OpStore %83 %uint_23
  2403. %85 = OpIAdd %uint %73 %uint_2
  2404. %86 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %85
  2405. OpStore %86 %62
  2406. %88 = OpIAdd %uint %73 %uint_3
  2407. %89 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %88
  2408. OpStore %89 %uint_4
  2409. %92 = OpLoad %v4float %gl_FragCoord
  2410. %94 = OpBitcast %v4uint %92
  2411. %95 = OpCompositeExtract %uint %94 0
  2412. %96 = OpIAdd %uint %73 %uint_4
  2413. %97 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %96
  2414. OpStore %97 %95
  2415. %98 = OpCompositeExtract %uint %94 1
  2416. %100 = OpIAdd %uint %73 %uint_5
  2417. %101 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %100
  2418. OpStore %101 %98
  2419. %103 = OpIAdd %uint %73 %uint_6
  2420. %104 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %103
  2421. OpStore %104 %63
  2422. %106 = OpIAdd %uint %73 %uint_7
  2423. %107 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %106
  2424. OpStore %107 %64
  2425. %109 = OpIAdd %uint %73 %uint_8
  2426. %110 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %109
  2427. OpStore %110 %65
  2428. OpBranch %77
  2429. %77 = OpLabel
  2430. OpReturn
  2431. OpFunctionEnd
  2432. )";
  2433. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  2434. SinglePassRunAndCheck<InstBindlessCheckPass>(
  2435. defs_before + func_before, defs_after + func_after + new_funcs, true,
  2436. true);
  2437. }
  2438. TEST_F(InstBindlessTest, SPV14AddToEntryPoint) {
  2439. const std::string text = R"(
  2440. ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
  2441. ; CHECK: OpDecorate [[v1]] DescriptorSet 7
  2442. ; CHECK: OpDecorate [[v2]] DescriptorSet 7
  2443. ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
  2444. ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
  2445. OpCapability Shader
  2446. OpExtension "SPV_EXT_descriptor_indexing"
  2447. OpMemoryModel Logical GLSL450
  2448. OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
  2449. OpExecutionMode %foo OriginUpperLeft
  2450. OpDecorate %image_var DescriptorSet 0
  2451. OpDecorate %image_var Binding 0
  2452. OpDecorate %sampler_var DescriptorSet 0
  2453. OpDecorate %sampler_var Binding 1
  2454. OpDecorate %gid DescriptorSet 0
  2455. OpDecorate %gid Binding 2
  2456. OpDecorate %struct Block
  2457. OpMemberDecorate %struct 0 Offset 0
  2458. %void = OpTypeVoid
  2459. %int = OpTypeInt 32 0
  2460. %int_0 = OpConstant %int 0
  2461. %v3int = OpTypeVector %int 3
  2462. %float = OpTypeFloat 32
  2463. %v3float = OpTypeVector %float 3
  2464. %v4float = OpTypeVector %float 4
  2465. %struct = OpTypeStruct %v3int
  2466. %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
  2467. %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
  2468. %gid = OpVariable %ptr_ssbo_struct StorageBuffer
  2469. %image = OpTypeImage %float 3D 0 0 0 1 Unknown
  2470. %ptr_uc_image = OpTypePointer UniformConstant %image
  2471. %sampler = OpTypeSampler
  2472. %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
  2473. %image_var = OpVariable %ptr_uc_image UniformConstant
  2474. %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
  2475. %sampled = OpTypeSampledImage %image
  2476. %void_fn = OpTypeFunction %void
  2477. %foo = OpFunction %void None %void_fn
  2478. %entry = OpLabel
  2479. %ld_image = OpLoad %image %image_var
  2480. %ld_sampler = OpLoad %sampler %sampler_var
  2481. %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
  2482. %ld_gid = OpLoad %v3int %gep
  2483. %convert = OpConvertUToF %v3float %ld_gid
  2484. %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
  2485. %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
  2486. OpReturn
  2487. OpFunctionEnd
  2488. )";
  2489. SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
  2490. SinglePassRunAndMatch<InstBindlessCheckPass>(text, true);
  2491. }
  2492. TEST_F(InstBindlessTest, SPV14AddToEntryPoints) {
  2493. const std::string text = R"(
  2494. ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
  2495. ; CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
  2496. ; CHECK: OpDecorate [[v1]] DescriptorSet 7
  2497. ; CHECK: OpDecorate [[v2]] DescriptorSet 7
  2498. ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
  2499. ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
  2500. OpCapability Shader
  2501. OpExtension "SPV_EXT_descriptor_indexing"
  2502. OpMemoryModel Logical GLSL450
  2503. OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
  2504. OpEntryPoint Fragment %foo "bar" %gid %image_var %sampler_var
  2505. OpExecutionMode %foo OriginUpperLeft
  2506. OpDecorate %image_var DescriptorSet 0
  2507. OpDecorate %image_var Binding 0
  2508. OpDecorate %sampler_var DescriptorSet 0
  2509. OpDecorate %sampler_var Binding 1
  2510. OpDecorate %gid DescriptorSet 0
  2511. OpDecorate %gid Binding 2
  2512. OpDecorate %struct Block
  2513. OpMemberDecorate %struct 0 Offset 0
  2514. %void = OpTypeVoid
  2515. %int = OpTypeInt 32 0
  2516. %int_0 = OpConstant %int 0
  2517. %v3int = OpTypeVector %int 3
  2518. %float = OpTypeFloat 32
  2519. %v3float = OpTypeVector %float 3
  2520. %v4float = OpTypeVector %float 4
  2521. %struct = OpTypeStruct %v3int
  2522. %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
  2523. %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
  2524. %gid = OpVariable %ptr_ssbo_struct StorageBuffer
  2525. %image = OpTypeImage %float 3D 0 0 0 1 Unknown
  2526. %ptr_uc_image = OpTypePointer UniformConstant %image
  2527. %sampler = OpTypeSampler
  2528. %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
  2529. %image_var = OpVariable %ptr_uc_image UniformConstant
  2530. %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
  2531. %sampled = OpTypeSampledImage %image
  2532. %void_fn = OpTypeFunction %void
  2533. %foo = OpFunction %void None %void_fn
  2534. %entry = OpLabel
  2535. %ld_image = OpLoad %image %image_var
  2536. %ld_sampler = OpLoad %sampler %sampler_var
  2537. %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
  2538. %ld_gid = OpLoad %v3int %gep
  2539. %convert = OpConvertUToF %v3float %ld_gid
  2540. %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
  2541. %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
  2542. OpReturn
  2543. OpFunctionEnd
  2544. )";
  2545. SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
  2546. SinglePassRunAndMatch<InstBindlessCheckPass>(text, true);
  2547. }
  2548. TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedUBOArray) {
  2549. // #version 450
  2550. // #extension GL_EXT_nonuniform_qualifier : enable
  2551. //
  2552. // layout(location=0) in nonuniformEXT flat int nu_ii;
  2553. // layout(location=0) out float b;
  2554. //
  2555. // layout(binding=3) uniform uname { float a; } uniformBuffer[];
  2556. //
  2557. // void main()
  2558. // {
  2559. // b = uniformBuffer[nu_ii].a;
  2560. // }
  2561. const std::string defs_before =
  2562. R"(OpCapability Shader
  2563. OpCapability ShaderNonUniform
  2564. OpCapability RuntimeDescriptorArray
  2565. OpCapability UniformBufferArrayNonUniformIndexing
  2566. OpExtension "SPV_EXT_descriptor_indexing"
  2567. %1 = OpExtInstImport "GLSL.std.450"
  2568. OpMemoryModel Logical GLSL450
  2569. OpEntryPoint Fragment %main "main" %b %nu_ii
  2570. OpExecutionMode %main OriginUpperLeft
  2571. OpSource GLSL 450
  2572. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  2573. OpName %main "main"
  2574. OpName %b "b"
  2575. OpName %uname "uname"
  2576. OpMemberName %uname 0 "a"
  2577. OpName %uniformBuffer "uniformBuffer"
  2578. OpName %nu_ii "nu_ii"
  2579. OpDecorate %b Location 0
  2580. OpMemberDecorate %uname 0 Offset 0
  2581. OpDecorate %uname Block
  2582. OpDecorate %uniformBuffer DescriptorSet 0
  2583. OpDecorate %uniformBuffer Binding 3
  2584. OpDecorate %nu_ii Flat
  2585. OpDecorate %nu_ii Location 0
  2586. OpDecorate %nu_ii NonUniform
  2587. OpDecorate %16 NonUniform
  2588. OpDecorate %20 NonUniform
  2589. %void = OpTypeVoid
  2590. %3 = OpTypeFunction %void
  2591. %float = OpTypeFloat 32
  2592. %_ptr_Output_float = OpTypePointer Output %float
  2593. %b = OpVariable %_ptr_Output_float Output
  2594. %uname = OpTypeStruct %float
  2595. %_runtimearr_uname = OpTypeRuntimeArray %uname
  2596. %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
  2597. %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
  2598. %int = OpTypeInt 32 1
  2599. %_ptr_Input_int = OpTypePointer Input %int
  2600. %nu_ii = OpVariable %_ptr_Input_int Input
  2601. %int_0 = OpConstant %int 0
  2602. %_ptr_Uniform_float = OpTypePointer Uniform %float
  2603. )";
  2604. const std::string defs_after =
  2605. R"(OpCapability Shader
  2606. OpCapability ShaderNonUniform
  2607. OpCapability RuntimeDescriptorArray
  2608. OpCapability UniformBufferArrayNonUniformIndexing
  2609. OpExtension "SPV_EXT_descriptor_indexing"
  2610. OpExtension "SPV_KHR_storage_buffer_storage_class"
  2611. %1 = OpExtInstImport "GLSL.std.450"
  2612. OpMemoryModel Logical GLSL450
  2613. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  2614. OpExecutionMode %main OriginUpperLeft
  2615. OpSource GLSL 450
  2616. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  2617. OpName %main "main"
  2618. OpName %b "b"
  2619. OpName %uname "uname"
  2620. OpMemberName %uname 0 "a"
  2621. OpName %uniformBuffer "uniformBuffer"
  2622. OpName %nu_ii "nu_ii"
  2623. OpDecorate %b Location 0
  2624. OpMemberDecorate %uname 0 Offset 0
  2625. OpDecorate %uname Block
  2626. OpDecorate %uniformBuffer DescriptorSet 0
  2627. OpDecorate %uniformBuffer Binding 3
  2628. OpDecorate %nu_ii Flat
  2629. OpDecorate %nu_ii Location 0
  2630. OpDecorate %nu_ii NonUniform
  2631. OpDecorate %7 NonUniform
  2632. OpDecorate %102 NonUniform
  2633. OpDecorate %_runtimearr_uint ArrayStride 4
  2634. OpDecorate %_struct_31 Block
  2635. OpMemberDecorate %_struct_31 0 Offset 0
  2636. OpDecorate %33 DescriptorSet 7
  2637. OpDecorate %33 Binding 1
  2638. OpDecorate %130 NonUniform
  2639. OpDecorate %_struct_55 Block
  2640. OpMemberDecorate %_struct_55 0 Offset 0
  2641. OpMemberDecorate %_struct_55 1 Offset 4
  2642. OpDecorate %57 DescriptorSet 7
  2643. OpDecorate %57 Binding 0
  2644. OpDecorate %gl_FragCoord BuiltIn FragCoord
  2645. OpDecorate %127 NonUniform
  2646. %void = OpTypeVoid
  2647. %10 = OpTypeFunction %void
  2648. %float = OpTypeFloat 32
  2649. %_ptr_Output_float = OpTypePointer Output %float
  2650. %b = OpVariable %_ptr_Output_float Output
  2651. %uname = OpTypeStruct %float
  2652. %_runtimearr_uname = OpTypeRuntimeArray %uname
  2653. %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
  2654. %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
  2655. %int = OpTypeInt 32 1
  2656. %_ptr_Input_int = OpTypePointer Input %int
  2657. %nu_ii = OpVariable %_ptr_Input_int Input
  2658. %int_0 = OpConstant %int 0
  2659. %_ptr_Uniform_float = OpTypePointer Uniform %float
  2660. %uint = OpTypeInt 32 0
  2661. %uint_0 = OpConstant %uint 0
  2662. %uint_1 = OpConstant %uint 1
  2663. %uint_3 = OpConstant %uint 3
  2664. %26 = OpTypeFunction %uint %uint %uint
  2665. %_runtimearr_uint = OpTypeRuntimeArray %uint
  2666. %_struct_31 = OpTypeStruct %_runtimearr_uint
  2667. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  2668. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  2669. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  2670. %bool = OpTypeBool
  2671. %49 = OpTypeFunction %void %uint %uint %uint %uint
  2672. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  2673. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  2674. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  2675. %uint_9 = OpConstant %uint 9
  2676. %uint_4 = OpConstant %uint 4
  2677. %uint_23 = OpConstant %uint 23
  2678. %uint_2 = OpConstant %uint 2
  2679. %v4float = OpTypeVector %float 4
  2680. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2681. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  2682. %v4uint = OpTypeVector %uint 4
  2683. %uint_5 = OpConstant %uint 5
  2684. %uint_6 = OpConstant %uint 6
  2685. %uint_7 = OpConstant %uint 7
  2686. %uint_8 = OpConstant %uint 8
  2687. %uint_45 = OpConstant %uint 45
  2688. %101 = OpConstantNull %float
  2689. %105 = OpTypeFunction %uint %uint %uint %uint %uint
  2690. )";
  2691. const std::string func_before =
  2692. R"(%main = OpFunction %void None %3
  2693. %5 = OpLabel
  2694. %16 = OpLoad %int %nu_ii
  2695. %19 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %16 %int_0
  2696. %20 = OpLoad %float %19
  2697. OpStore %b %20
  2698. OpReturn
  2699. OpFunctionEnd
  2700. )";
  2701. const std::string func_after =
  2702. R"(%main = OpFunction %void None %10
  2703. %19 = OpLabel
  2704. %7 = OpLoad %int %nu_ii
  2705. %20 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
  2706. %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
  2707. %42 = OpULessThan %bool %7 %40
  2708. OpSelectionMerge %43 None
  2709. OpBranchConditional %42 %44 %45
  2710. %44 = OpLabel
  2711. %103 = OpBitcast %uint %7
  2712. %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
  2713. %123 = OpINotEqual %bool %122 %uint_0
  2714. OpSelectionMerge %124 None
  2715. OpBranchConditional %123 %125 %126
  2716. %125 = OpLabel
  2717. %127 = OpLoad %float %20
  2718. OpBranch %124
  2719. %126 = OpLabel
  2720. %128 = OpBitcast %uint %7
  2721. %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
  2722. OpBranch %124
  2723. %124 = OpLabel
  2724. %130 = OpPhi %float %127 %125 %101 %126
  2725. OpBranch %43
  2726. %45 = OpLabel
  2727. %47 = OpBitcast %uint %7
  2728. %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
  2729. OpBranch %43
  2730. %43 = OpLabel
  2731. %102 = OpPhi %float %130 %124 %101 %45
  2732. OpStore %b %102
  2733. OpReturn
  2734. OpFunctionEnd
  2735. )";
  2736. const std::string new_funcs =
  2737. R"(%25 = OpFunction %uint None %26
  2738. %27 = OpFunctionParameter %uint
  2739. %28 = OpFunctionParameter %uint
  2740. %29 = OpLabel
  2741. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  2742. %36 = OpLoad %uint %35
  2743. %37 = OpIAdd %uint %36 %28
  2744. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  2745. %39 = OpLoad %uint %38
  2746. OpReturnValue %39
  2747. OpFunctionEnd
  2748. %48 = OpFunction %void None %49
  2749. %50 = OpFunctionParameter %uint
  2750. %51 = OpFunctionParameter %uint
  2751. %52 = OpFunctionParameter %uint
  2752. %53 = OpFunctionParameter %uint
  2753. %54 = OpLabel
  2754. %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  2755. %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_9
  2756. %62 = OpIAdd %uint %61 %uint_9
  2757. %63 = OpArrayLength %uint %57 1
  2758. %64 = OpULessThanEqual %bool %62 %63
  2759. OpSelectionMerge %65 None
  2760. OpBranchConditional %64 %66 %65
  2761. %66 = OpLabel
  2762. %67 = OpIAdd %uint %61 %uint_0
  2763. %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
  2764. OpStore %68 %uint_9
  2765. %70 = OpIAdd %uint %61 %uint_1
  2766. %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
  2767. OpStore %71 %uint_23
  2768. %73 = OpIAdd %uint %61 %uint_2
  2769. %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
  2770. OpStore %74 %50
  2771. %75 = OpIAdd %uint %61 %uint_3
  2772. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  2773. OpStore %76 %uint_4
  2774. %80 = OpLoad %v4float %gl_FragCoord
  2775. %82 = OpBitcast %v4uint %80
  2776. %83 = OpCompositeExtract %uint %82 0
  2777. %84 = OpIAdd %uint %61 %uint_4
  2778. %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
  2779. OpStore %85 %83
  2780. %86 = OpCompositeExtract %uint %82 1
  2781. %88 = OpIAdd %uint %61 %uint_5
  2782. %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
  2783. OpStore %89 %86
  2784. %91 = OpIAdd %uint %61 %uint_6
  2785. %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
  2786. OpStore %92 %51
  2787. %94 = OpIAdd %uint %61 %uint_7
  2788. %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
  2789. OpStore %95 %52
  2790. %97 = OpIAdd %uint %61 %uint_8
  2791. %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
  2792. OpStore %98 %53
  2793. OpBranch %65
  2794. %65 = OpLabel
  2795. OpReturn
  2796. OpFunctionEnd
  2797. %104 = OpFunction %uint None %105
  2798. %106 = OpFunctionParameter %uint
  2799. %107 = OpFunctionParameter %uint
  2800. %108 = OpFunctionParameter %uint
  2801. %109 = OpFunctionParameter %uint
  2802. %110 = OpLabel
  2803. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
  2804. %112 = OpLoad %uint %111
  2805. %113 = OpIAdd %uint %112 %107
  2806. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  2807. %115 = OpLoad %uint %114
  2808. %116 = OpIAdd %uint %115 %108
  2809. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  2810. %118 = OpLoad %uint %117
  2811. %119 = OpIAdd %uint %118 %109
  2812. %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
  2813. %121 = OpLoad %uint %120
  2814. OpReturnValue %121
  2815. OpFunctionEnd
  2816. )";
  2817. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  2818. SinglePassRunAndCheck<InstBindlessCheckPass>(
  2819. defs_before + func_before, defs_after + func_after + new_funcs, true,
  2820. true);
  2821. }
  2822. TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayDeprecated) {
  2823. // #version 450
  2824. // #extension GL_EXT_nonuniform_qualifier : enable
  2825. //
  2826. // layout(location=0) in nonuniformEXT flat int nu_ii;
  2827. // layout(location=0) out float b;
  2828. //
  2829. // layout(binding=3) buffer bname { float b; } storageBuffer[];
  2830. //
  2831. // void main()
  2832. // {
  2833. // b = storageBuffer[nu_ii].b;
  2834. // }
  2835. const std::string defs_before =
  2836. R"(OpCapability Shader
  2837. OpCapability ShaderNonUniform
  2838. OpCapability RuntimeDescriptorArray
  2839. OpCapability UniformBufferArrayNonUniformIndexing
  2840. OpExtension "SPV_EXT_descriptor_indexing"
  2841. %1 = OpExtInstImport "GLSL.std.450"
  2842. OpMemoryModel Logical GLSL450
  2843. OpEntryPoint Fragment %main "main" %b %nu_ii
  2844. OpExecutionMode %main OriginUpperLeft
  2845. OpSource GLSL 450
  2846. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  2847. OpName %main "main"
  2848. OpName %b "b"
  2849. OpName %bname "bname"
  2850. OpMemberName %bname 0 "a"
  2851. OpName %storageBuffer "storageBuffer"
  2852. OpName %nu_ii "nu_ii"
  2853. OpDecorate %b Location 0
  2854. OpMemberDecorate %bname 0 Offset 0
  2855. OpDecorate %bname BufferBlock
  2856. OpDecorate %storageBuffer DescriptorSet 0
  2857. OpDecorate %storageBuffer Binding 3
  2858. OpDecorate %nu_ii Flat
  2859. OpDecorate %nu_ii Location 0
  2860. OpDecorate %nu_ii NonUniform
  2861. OpDecorate %16 NonUniform
  2862. OpDecorate %20 NonUniform
  2863. %void = OpTypeVoid
  2864. %3 = OpTypeFunction %void
  2865. %float = OpTypeFloat 32
  2866. %_ptr_Output_float = OpTypePointer Output %float
  2867. %b = OpVariable %_ptr_Output_float Output
  2868. %bname = OpTypeStruct %float
  2869. %_runtimearr_bname = OpTypeRuntimeArray %bname
  2870. %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
  2871. %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
  2872. %int = OpTypeInt 32 1
  2873. %_ptr_Input_int = OpTypePointer Input %int
  2874. %nu_ii = OpVariable %_ptr_Input_int Input
  2875. %int_0 = OpConstant %int 0
  2876. %_ptr_Uniform_float = OpTypePointer Uniform %float
  2877. )";
  2878. const std::string defs_after =
  2879. R"(OpCapability Shader
  2880. OpCapability ShaderNonUniform
  2881. OpCapability RuntimeDescriptorArray
  2882. OpCapability UniformBufferArrayNonUniformIndexing
  2883. OpExtension "SPV_EXT_descriptor_indexing"
  2884. OpExtension "SPV_KHR_storage_buffer_storage_class"
  2885. %1 = OpExtInstImport "GLSL.std.450"
  2886. OpMemoryModel Logical GLSL450
  2887. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  2888. OpExecutionMode %main OriginUpperLeft
  2889. OpSource GLSL 450
  2890. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  2891. OpName %main "main"
  2892. OpName %b "b"
  2893. OpName %bname "bname"
  2894. OpMemberName %bname 0 "a"
  2895. OpName %storageBuffer "storageBuffer"
  2896. OpName %nu_ii "nu_ii"
  2897. OpDecorate %b Location 0
  2898. OpMemberDecorate %bname 0 Offset 0
  2899. OpDecorate %bname BufferBlock
  2900. OpDecorate %storageBuffer DescriptorSet 0
  2901. OpDecorate %storageBuffer Binding 3
  2902. OpDecorate %nu_ii Flat
  2903. OpDecorate %nu_ii Location 0
  2904. OpDecorate %nu_ii NonUniform
  2905. OpDecorate %7 NonUniform
  2906. OpDecorate %102 NonUniform
  2907. OpDecorate %_runtimearr_uint ArrayStride 4
  2908. OpDecorate %_struct_31 Block
  2909. OpMemberDecorate %_struct_31 0 Offset 0
  2910. OpDecorate %33 DescriptorSet 7
  2911. OpDecorate %33 Binding 1
  2912. OpDecorate %130 NonUniform
  2913. OpDecorate %_struct_55 Block
  2914. OpMemberDecorate %_struct_55 0 Offset 0
  2915. OpMemberDecorate %_struct_55 1 Offset 4
  2916. OpDecorate %57 DescriptorSet 7
  2917. OpDecorate %57 Binding 0
  2918. OpDecorate %gl_FragCoord BuiltIn FragCoord
  2919. OpDecorate %127 NonUniform
  2920. %void = OpTypeVoid
  2921. %10 = OpTypeFunction %void
  2922. %float = OpTypeFloat 32
  2923. %_ptr_Output_float = OpTypePointer Output %float
  2924. %b = OpVariable %_ptr_Output_float Output
  2925. %bname = OpTypeStruct %float
  2926. %_runtimearr_bname = OpTypeRuntimeArray %bname
  2927. %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
  2928. %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
  2929. %int = OpTypeInt 32 1
  2930. %_ptr_Input_int = OpTypePointer Input %int
  2931. %nu_ii = OpVariable %_ptr_Input_int Input
  2932. %int_0 = OpConstant %int 0
  2933. %_ptr_Uniform_float = OpTypePointer Uniform %float
  2934. %uint = OpTypeInt 32 0
  2935. %uint_0 = OpConstant %uint 0
  2936. %uint_1 = OpConstant %uint 1
  2937. %uint_3 = OpConstant %uint 3
  2938. %26 = OpTypeFunction %uint %uint %uint
  2939. %_runtimearr_uint = OpTypeRuntimeArray %uint
  2940. %_struct_31 = OpTypeStruct %_runtimearr_uint
  2941. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  2942. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  2943. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  2944. %bool = OpTypeBool
  2945. %49 = OpTypeFunction %void %uint %uint %uint %uint
  2946. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  2947. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  2948. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  2949. %uint_9 = OpConstant %uint 9
  2950. %uint_4 = OpConstant %uint 4
  2951. %uint_23 = OpConstant %uint 23
  2952. %uint_2 = OpConstant %uint 2
  2953. %v4float = OpTypeVector %float 4
  2954. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2955. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  2956. %v4uint = OpTypeVector %uint 4
  2957. %uint_5 = OpConstant %uint 5
  2958. %uint_6 = OpConstant %uint 6
  2959. %uint_7 = OpConstant %uint 7
  2960. %uint_8 = OpConstant %uint 8
  2961. %uint_45 = OpConstant %uint 45
  2962. %101 = OpConstantNull %float
  2963. %105 = OpTypeFunction %uint %uint %uint %uint %uint
  2964. )";
  2965. const std::string func_before =
  2966. R"(%main = OpFunction %void None %3
  2967. %5 = OpLabel
  2968. %16 = OpLoad %int %nu_ii
  2969. %19 = OpAccessChain %_ptr_Uniform_float %storageBuffer %16 %int_0
  2970. %20 = OpLoad %float %19
  2971. OpStore %b %20
  2972. OpReturn
  2973. OpFunctionEnd
  2974. )";
  2975. const std::string func_after =
  2976. R"(%main = OpFunction %void None %10
  2977. %19 = OpLabel
  2978. %7 = OpLoad %int %nu_ii
  2979. %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %7 %int_0
  2980. %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
  2981. %42 = OpULessThan %bool %7 %40
  2982. OpSelectionMerge %43 None
  2983. OpBranchConditional %42 %44 %45
  2984. %44 = OpLabel
  2985. %103 = OpBitcast %uint %7
  2986. %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
  2987. %123 = OpINotEqual %bool %122 %uint_0
  2988. OpSelectionMerge %124 None
  2989. OpBranchConditional %123 %125 %126
  2990. %125 = OpLabel
  2991. %127 = OpLoad %float %20
  2992. OpBranch %124
  2993. %126 = OpLabel
  2994. %128 = OpBitcast %uint %7
  2995. %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
  2996. OpBranch %124
  2997. %124 = OpLabel
  2998. %130 = OpPhi %float %127 %125 %101 %126
  2999. OpBranch %43
  3000. %45 = OpLabel
  3001. %47 = OpBitcast %uint %7
  3002. %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
  3003. OpBranch %43
  3004. %43 = OpLabel
  3005. %102 = OpPhi %float %130 %124 %101 %45
  3006. OpStore %b %102
  3007. OpReturn
  3008. OpFunctionEnd
  3009. )";
  3010. const std::string new_funcs =
  3011. R"(%25 = OpFunction %uint None %26
  3012. %27 = OpFunctionParameter %uint
  3013. %28 = OpFunctionParameter %uint
  3014. %29 = OpLabel
  3015. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  3016. %36 = OpLoad %uint %35
  3017. %37 = OpIAdd %uint %36 %28
  3018. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  3019. %39 = OpLoad %uint %38
  3020. OpReturnValue %39
  3021. OpFunctionEnd
  3022. %48 = OpFunction %void None %49
  3023. %50 = OpFunctionParameter %uint
  3024. %51 = OpFunctionParameter %uint
  3025. %52 = OpFunctionParameter %uint
  3026. %53 = OpFunctionParameter %uint
  3027. %54 = OpLabel
  3028. %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  3029. %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_9
  3030. %62 = OpIAdd %uint %61 %uint_9
  3031. %63 = OpArrayLength %uint %57 1
  3032. %64 = OpULessThanEqual %bool %62 %63
  3033. OpSelectionMerge %65 None
  3034. OpBranchConditional %64 %66 %65
  3035. %66 = OpLabel
  3036. %67 = OpIAdd %uint %61 %uint_0
  3037. %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
  3038. OpStore %68 %uint_9
  3039. %70 = OpIAdd %uint %61 %uint_1
  3040. %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
  3041. OpStore %71 %uint_23
  3042. %73 = OpIAdd %uint %61 %uint_2
  3043. %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
  3044. OpStore %74 %50
  3045. %75 = OpIAdd %uint %61 %uint_3
  3046. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  3047. OpStore %76 %uint_4
  3048. %80 = OpLoad %v4float %gl_FragCoord
  3049. %82 = OpBitcast %v4uint %80
  3050. %83 = OpCompositeExtract %uint %82 0
  3051. %84 = OpIAdd %uint %61 %uint_4
  3052. %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
  3053. OpStore %85 %83
  3054. %86 = OpCompositeExtract %uint %82 1
  3055. %88 = OpIAdd %uint %61 %uint_5
  3056. %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
  3057. OpStore %89 %86
  3058. %91 = OpIAdd %uint %61 %uint_6
  3059. %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
  3060. OpStore %92 %51
  3061. %94 = OpIAdd %uint %61 %uint_7
  3062. %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
  3063. OpStore %95 %52
  3064. %97 = OpIAdd %uint %61 %uint_8
  3065. %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
  3066. OpStore %98 %53
  3067. OpBranch %65
  3068. %65 = OpLabel
  3069. OpReturn
  3070. OpFunctionEnd
  3071. %104 = OpFunction %uint None %105
  3072. %106 = OpFunctionParameter %uint
  3073. %107 = OpFunctionParameter %uint
  3074. %108 = OpFunctionParameter %uint
  3075. %109 = OpFunctionParameter %uint
  3076. %110 = OpLabel
  3077. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
  3078. %112 = OpLoad %uint %111
  3079. %113 = OpIAdd %uint %112 %107
  3080. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  3081. %115 = OpLoad %uint %114
  3082. %116 = OpIAdd %uint %115 %108
  3083. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  3084. %118 = OpLoad %uint %117
  3085. %119 = OpIAdd %uint %118 %109
  3086. %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
  3087. %121 = OpLoad %uint %120
  3088. OpReturnValue %121
  3089. OpFunctionEnd
  3090. )";
  3091. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  3092. SinglePassRunAndCheck<InstBindlessCheckPass>(
  3093. defs_before + func_before, defs_after + func_after + new_funcs, true,
  3094. true);
  3095. }
  3096. TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArray) {
  3097. // Same as Deprecated but declaring as StorageBuffer Block
  3098. const std::string defs_before =
  3099. R"(OpCapability Shader
  3100. OpCapability ShaderNonUniform
  3101. OpCapability RuntimeDescriptorArray
  3102. OpCapability StorageBufferArrayNonUniformIndexing
  3103. OpExtension "SPV_EXT_descriptor_indexing"
  3104. %1 = OpExtInstImport "GLSL.std.450"
  3105. OpMemoryModel Logical GLSL450
  3106. OpEntryPoint Fragment %main "main" %b %nu_ii
  3107. OpExecutionMode %main OriginUpperLeft
  3108. OpSource GLSL 450
  3109. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3110. OpName %main "main"
  3111. OpName %b "b"
  3112. OpName %bname "bname"
  3113. OpMemberName %bname 0 "a"
  3114. OpName %storageBuffer "storageBuffer"
  3115. OpName %nu_ii "nu_ii"
  3116. OpDecorate %b Location 0
  3117. OpMemberDecorate %bname 0 Offset 0
  3118. OpDecorate %bname Block
  3119. OpDecorate %storageBuffer DescriptorSet 0
  3120. OpDecorate %storageBuffer Binding 3
  3121. OpDecorate %nu_ii Flat
  3122. OpDecorate %nu_ii Location 0
  3123. OpDecorate %nu_ii NonUniform
  3124. OpDecorate %16 NonUniform
  3125. OpDecorate %20 NonUniform
  3126. %void = OpTypeVoid
  3127. %3 = OpTypeFunction %void
  3128. %float = OpTypeFloat 32
  3129. %_ptr_Output_float = OpTypePointer Output %float
  3130. %b = OpVariable %_ptr_Output_float Output
  3131. %bname = OpTypeStruct %float
  3132. %_runtimearr_bname = OpTypeRuntimeArray %bname
  3133. %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
  3134. %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
  3135. %int = OpTypeInt 32 1
  3136. %_ptr_Input_int = OpTypePointer Input %int
  3137. %nu_ii = OpVariable %_ptr_Input_int Input
  3138. %int_0 = OpConstant %int 0
  3139. %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
  3140. )";
  3141. const std::string defs_after =
  3142. R"(OpCapability Shader
  3143. OpCapability ShaderNonUniform
  3144. OpCapability RuntimeDescriptorArray
  3145. OpCapability StorageBufferArrayNonUniformIndexing
  3146. OpExtension "SPV_EXT_descriptor_indexing"
  3147. OpExtension "SPV_KHR_storage_buffer_storage_class"
  3148. %1 = OpExtInstImport "GLSL.std.450"
  3149. OpMemoryModel Logical GLSL450
  3150. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  3151. OpExecutionMode %main OriginUpperLeft
  3152. OpSource GLSL 450
  3153. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3154. OpName %main "main"
  3155. OpName %b "b"
  3156. OpName %bname "bname"
  3157. OpMemberName %bname 0 "a"
  3158. OpName %storageBuffer "storageBuffer"
  3159. OpName %nu_ii "nu_ii"
  3160. OpDecorate %b Location 0
  3161. OpMemberDecorate %bname 0 Offset 0
  3162. OpDecorate %bname Block
  3163. OpDecorate %storageBuffer DescriptorSet 0
  3164. OpDecorate %storageBuffer Binding 3
  3165. OpDecorate %nu_ii Flat
  3166. OpDecorate %nu_ii Location 0
  3167. OpDecorate %nu_ii NonUniform
  3168. OpDecorate %7 NonUniform
  3169. OpDecorate %102 NonUniform
  3170. OpDecorate %_runtimearr_uint ArrayStride 4
  3171. OpDecorate %_struct_31 Block
  3172. OpMemberDecorate %_struct_31 0 Offset 0
  3173. OpDecorate %33 DescriptorSet 7
  3174. OpDecorate %33 Binding 1
  3175. OpDecorate %130 NonUniform
  3176. OpDecorate %_struct_55 Block
  3177. OpMemberDecorate %_struct_55 0 Offset 0
  3178. OpMemberDecorate %_struct_55 1 Offset 4
  3179. OpDecorate %57 DescriptorSet 7
  3180. OpDecorate %57 Binding 0
  3181. OpDecorate %gl_FragCoord BuiltIn FragCoord
  3182. OpDecorate %127 NonUniform
  3183. %void = OpTypeVoid
  3184. %10 = OpTypeFunction %void
  3185. %float = OpTypeFloat 32
  3186. %_ptr_Output_float = OpTypePointer Output %float
  3187. %b = OpVariable %_ptr_Output_float Output
  3188. %bname = OpTypeStruct %float
  3189. %_runtimearr_bname = OpTypeRuntimeArray %bname
  3190. %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
  3191. %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
  3192. %int = OpTypeInt 32 1
  3193. %_ptr_Input_int = OpTypePointer Input %int
  3194. %nu_ii = OpVariable %_ptr_Input_int Input
  3195. %int_0 = OpConstant %int 0
  3196. %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
  3197. %uint = OpTypeInt 32 0
  3198. %uint_0 = OpConstant %uint 0
  3199. %uint_1 = OpConstant %uint 1
  3200. %uint_3 = OpConstant %uint 3
  3201. %26 = OpTypeFunction %uint %uint %uint
  3202. %_runtimearr_uint = OpTypeRuntimeArray %uint
  3203. %_struct_31 = OpTypeStruct %_runtimearr_uint
  3204. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  3205. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  3206. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  3207. %bool = OpTypeBool
  3208. %49 = OpTypeFunction %void %uint %uint %uint %uint
  3209. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  3210. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  3211. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  3212. %uint_9 = OpConstant %uint 9
  3213. %uint_4 = OpConstant %uint 4
  3214. %uint_23 = OpConstant %uint 23
  3215. %uint_2 = OpConstant %uint 2
  3216. %v4float = OpTypeVector %float 4
  3217. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3218. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  3219. %v4uint = OpTypeVector %uint 4
  3220. %uint_5 = OpConstant %uint 5
  3221. %uint_6 = OpConstant %uint 6
  3222. %uint_7 = OpConstant %uint 7
  3223. %uint_8 = OpConstant %uint 8
  3224. %uint_45 = OpConstant %uint 45
  3225. %101 = OpConstantNull %float
  3226. %105 = OpTypeFunction %uint %uint %uint %uint %uint
  3227. )";
  3228. const std::string func_before =
  3229. R"(%main = OpFunction %void None %3
  3230. %5 = OpLabel
  3231. %16 = OpLoad %int %nu_ii
  3232. %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
  3233. %20 = OpLoad %float %19
  3234. OpStore %b %20
  3235. OpReturn
  3236. OpFunctionEnd
  3237. )";
  3238. const std::string func_after =
  3239. R"(%main = OpFunction %void None %10
  3240. %19 = OpLabel
  3241. %7 = OpLoad %int %nu_ii
  3242. %20 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %7 %int_0
  3243. %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
  3244. %42 = OpULessThan %bool %7 %40
  3245. OpSelectionMerge %43 None
  3246. OpBranchConditional %42 %44 %45
  3247. %44 = OpLabel
  3248. %103 = OpBitcast %uint %7
  3249. %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
  3250. %123 = OpINotEqual %bool %122 %uint_0
  3251. OpSelectionMerge %124 None
  3252. OpBranchConditional %123 %125 %126
  3253. %125 = OpLabel
  3254. %127 = OpLoad %float %20
  3255. OpBranch %124
  3256. %126 = OpLabel
  3257. %128 = OpBitcast %uint %7
  3258. %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
  3259. OpBranch %124
  3260. %124 = OpLabel
  3261. %130 = OpPhi %float %127 %125 %101 %126
  3262. OpBranch %43
  3263. %45 = OpLabel
  3264. %47 = OpBitcast %uint %7
  3265. %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
  3266. OpBranch %43
  3267. %43 = OpLabel
  3268. %102 = OpPhi %float %130 %124 %101 %45
  3269. OpStore %b %102
  3270. OpReturn
  3271. OpFunctionEnd
  3272. )";
  3273. const std::string new_funcs =
  3274. R"(%25 = OpFunction %uint None %26
  3275. %27 = OpFunctionParameter %uint
  3276. %28 = OpFunctionParameter %uint
  3277. %29 = OpLabel
  3278. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  3279. %36 = OpLoad %uint %35
  3280. %37 = OpIAdd %uint %36 %28
  3281. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  3282. %39 = OpLoad %uint %38
  3283. OpReturnValue %39
  3284. OpFunctionEnd
  3285. %48 = OpFunction %void None %49
  3286. %50 = OpFunctionParameter %uint
  3287. %51 = OpFunctionParameter %uint
  3288. %52 = OpFunctionParameter %uint
  3289. %53 = OpFunctionParameter %uint
  3290. %54 = OpLabel
  3291. %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  3292. %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_9
  3293. %62 = OpIAdd %uint %61 %uint_9
  3294. %63 = OpArrayLength %uint %57 1
  3295. %64 = OpULessThanEqual %bool %62 %63
  3296. OpSelectionMerge %65 None
  3297. OpBranchConditional %64 %66 %65
  3298. %66 = OpLabel
  3299. %67 = OpIAdd %uint %61 %uint_0
  3300. %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
  3301. OpStore %68 %uint_9
  3302. %70 = OpIAdd %uint %61 %uint_1
  3303. %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
  3304. OpStore %71 %uint_23
  3305. %73 = OpIAdd %uint %61 %uint_2
  3306. %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
  3307. OpStore %74 %50
  3308. %75 = OpIAdd %uint %61 %uint_3
  3309. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  3310. OpStore %76 %uint_4
  3311. %80 = OpLoad %v4float %gl_FragCoord
  3312. %82 = OpBitcast %v4uint %80
  3313. %83 = OpCompositeExtract %uint %82 0
  3314. %84 = OpIAdd %uint %61 %uint_4
  3315. %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
  3316. OpStore %85 %83
  3317. %86 = OpCompositeExtract %uint %82 1
  3318. %88 = OpIAdd %uint %61 %uint_5
  3319. %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
  3320. OpStore %89 %86
  3321. %91 = OpIAdd %uint %61 %uint_6
  3322. %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
  3323. OpStore %92 %51
  3324. %94 = OpIAdd %uint %61 %uint_7
  3325. %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
  3326. OpStore %95 %52
  3327. %97 = OpIAdd %uint %61 %uint_8
  3328. %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
  3329. OpStore %98 %53
  3330. OpBranch %65
  3331. %65 = OpLabel
  3332. OpReturn
  3333. OpFunctionEnd
  3334. %104 = OpFunction %uint None %105
  3335. %106 = OpFunctionParameter %uint
  3336. %107 = OpFunctionParameter %uint
  3337. %108 = OpFunctionParameter %uint
  3338. %109 = OpFunctionParameter %uint
  3339. %110 = OpLabel
  3340. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
  3341. %112 = OpLoad %uint %111
  3342. %113 = OpIAdd %uint %112 %107
  3343. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  3344. %115 = OpLoad %uint %114
  3345. %116 = OpIAdd %uint %115 %108
  3346. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  3347. %118 = OpLoad %uint %117
  3348. %119 = OpIAdd %uint %118 %109
  3349. %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
  3350. %121 = OpLoad %uint %120
  3351. OpReturnValue %121
  3352. OpFunctionEnd
  3353. )";
  3354. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  3355. SinglePassRunAndCheck<InstBindlessCheckPass>(
  3356. defs_before + func_before, defs_after + func_after + new_funcs, true,
  3357. true);
  3358. }
  3359. TEST_F(InstBindlessTest, InstInitLoadUBOScalar) {
  3360. // #version 450
  3361. // #extension GL_EXT_nonuniform_qualifier : enable
  3362. //
  3363. // layout(location=0) out float b;
  3364. // layout(binding=3) uniform uname { float a; } uniformBuffer;
  3365. //
  3366. // void main()
  3367. // {
  3368. // b = uniformBuffer.a;
  3369. // }
  3370. const std::string defs_before =
  3371. R"(OpCapability Shader
  3372. OpExtension "SPV_EXT_descriptor_indexing"
  3373. %1 = OpExtInstImport "GLSL.std.450"
  3374. OpMemoryModel Logical GLSL450
  3375. OpEntryPoint Fragment %main "main" %b
  3376. OpExecutionMode %main OriginUpperLeft
  3377. OpSource GLSL 450
  3378. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3379. OpName %main "main"
  3380. OpName %b "b"
  3381. OpName %uname "uname"
  3382. OpMemberName %uname 0 "a"
  3383. OpName %uniformBuffer "uniformBuffer"
  3384. OpDecorate %b Location 0
  3385. OpMemberDecorate %uname 0 Offset 0
  3386. OpDecorate %uname Block
  3387. OpDecorate %uniformBuffer DescriptorSet 0
  3388. OpDecorate %uniformBuffer Binding 3
  3389. %void = OpTypeVoid
  3390. %3 = OpTypeFunction %void
  3391. %float = OpTypeFloat 32
  3392. %_ptr_Output_float = OpTypePointer Output %float
  3393. %b = OpVariable %_ptr_Output_float Output
  3394. %uname = OpTypeStruct %float
  3395. %_ptr_Uniform_uname = OpTypePointer Uniform %uname
  3396. %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
  3397. %int = OpTypeInt 32 1
  3398. %int_0 = OpConstant %int 0
  3399. %_ptr_Uniform_float = OpTypePointer Uniform %float
  3400. )";
  3401. const std::string defs_after =
  3402. R"(OpCapability Shader
  3403. OpExtension "SPV_EXT_descriptor_indexing"
  3404. OpExtension "SPV_KHR_storage_buffer_storage_class"
  3405. %1 = OpExtInstImport "GLSL.std.450"
  3406. OpMemoryModel Logical GLSL450
  3407. OpEntryPoint Fragment %main "main" %b %gl_FragCoord
  3408. OpExecutionMode %main OriginUpperLeft
  3409. OpSource GLSL 450
  3410. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3411. OpName %main "main"
  3412. OpName %b "b"
  3413. OpName %uname "uname"
  3414. OpMemberName %uname 0 "a"
  3415. OpName %uniformBuffer "uniformBuffer"
  3416. OpDecorate %b Location 0
  3417. OpMemberDecorate %uname 0 Offset 0
  3418. OpDecorate %uname Block
  3419. OpDecorate %uniformBuffer DescriptorSet 0
  3420. OpDecorate %uniformBuffer Binding 3
  3421. OpDecorate %_runtimearr_uint ArrayStride 4
  3422. OpDecorate %_struct_28 Block
  3423. OpMemberDecorate %_struct_28 0 Offset 0
  3424. OpDecorate %30 DescriptorSet 7
  3425. OpDecorate %30 Binding 1
  3426. OpDecorate %_struct_58 Block
  3427. OpMemberDecorate %_struct_58 0 Offset 0
  3428. OpMemberDecorate %_struct_58 1 Offset 4
  3429. OpDecorate %60 DescriptorSet 7
  3430. OpDecorate %60 Binding 0
  3431. OpDecorate %gl_FragCoord BuiltIn FragCoord
  3432. %void = OpTypeVoid
  3433. %7 = OpTypeFunction %void
  3434. %float = OpTypeFloat 32
  3435. %_ptr_Output_float = OpTypePointer Output %float
  3436. %b = OpVariable %_ptr_Output_float Output
  3437. %uname = OpTypeStruct %float
  3438. %_ptr_Uniform_uname = OpTypePointer Uniform %uname
  3439. %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
  3440. %int = OpTypeInt 32 1
  3441. %int_0 = OpConstant %int 0
  3442. %_ptr_Uniform_float = OpTypePointer Uniform %float
  3443. %uint = OpTypeInt 32 0
  3444. %uint_0 = OpConstant %uint 0
  3445. %uint_3 = OpConstant %uint 3
  3446. %21 = OpTypeFunction %uint %uint %uint %uint %uint
  3447. %_runtimearr_uint = OpTypeRuntimeArray %uint
  3448. %_struct_28 = OpTypeStruct %_runtimearr_uint
  3449. %_ptr_StorageBuffer__struct_28 = OpTypePointer StorageBuffer %_struct_28
  3450. %30 = OpVariable %_ptr_StorageBuffer__struct_28 StorageBuffer
  3451. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  3452. %bool = OpTypeBool
  3453. %uint_1 = OpConstant %uint 1
  3454. %52 = OpTypeFunction %void %uint %uint %uint %uint
  3455. %_struct_58 = OpTypeStruct %uint %_runtimearr_uint
  3456. %_ptr_StorageBuffer__struct_58 = OpTypePointer StorageBuffer %_struct_58
  3457. %60 = OpVariable %_ptr_StorageBuffer__struct_58 StorageBuffer
  3458. %uint_9 = OpConstant %uint 9
  3459. %uint_4 = OpConstant %uint 4
  3460. %uint_23 = OpConstant %uint 23
  3461. %uint_2 = OpConstant %uint 2
  3462. %v4float = OpTypeVector %float 4
  3463. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3464. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  3465. %v4uint = OpTypeVector %uint 4
  3466. %uint_5 = OpConstant %uint 5
  3467. %uint_6 = OpConstant %uint 6
  3468. %uint_7 = OpConstant %uint 7
  3469. %uint_8 = OpConstant %uint 8
  3470. %uint_32 = OpConstant %uint 32
  3471. %104 = OpConstantNull %float
  3472. )";
  3473. const std::string func_before =
  3474. R"(%main = OpFunction %void None %3
  3475. %5 = OpLabel
  3476. %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
  3477. %16 = OpLoad %float %15
  3478. OpStore %b %16
  3479. OpReturn
  3480. OpFunctionEnd
  3481. )";
  3482. const std::string func_after =
  3483. R"(%main = OpFunction %void None %7
  3484. %14 = OpLabel
  3485. %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
  3486. %43 = OpFunctionCall %uint %20 %uint_0 %uint_0 %uint_3 %uint_0
  3487. %45 = OpINotEqual %bool %43 %uint_0
  3488. OpSelectionMerge %47 None
  3489. OpBranchConditional %45 %48 %49
  3490. %48 = OpLabel
  3491. %50 = OpLoad %float %15
  3492. OpBranch %47
  3493. %49 = OpLabel
  3494. %103 = OpFunctionCall %void %51 %uint_32 %uint_1 %uint_0 %uint_0
  3495. OpBranch %47
  3496. %47 = OpLabel
  3497. %105 = OpPhi %float %50 %48 %104 %49
  3498. OpStore %b %105
  3499. OpReturn
  3500. OpFunctionEnd
  3501. )";
  3502. const std::string new_funcs =
  3503. R"(%20 = OpFunction %uint None %21
  3504. %22 = OpFunctionParameter %uint
  3505. %23 = OpFunctionParameter %uint
  3506. %24 = OpFunctionParameter %uint
  3507. %25 = OpFunctionParameter %uint
  3508. %26 = OpLabel
  3509. %32 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %22
  3510. %33 = OpLoad %uint %32
  3511. %34 = OpIAdd %uint %33 %23
  3512. %35 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %34
  3513. %36 = OpLoad %uint %35
  3514. %37 = OpIAdd %uint %36 %24
  3515. %38 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %37
  3516. %39 = OpLoad %uint %38
  3517. %40 = OpIAdd %uint %39 %25
  3518. %41 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %40
  3519. %42 = OpLoad %uint %41
  3520. OpReturnValue %42
  3521. OpFunctionEnd
  3522. %51 = OpFunction %void None %52
  3523. %53 = OpFunctionParameter %uint
  3524. %54 = OpFunctionParameter %uint
  3525. %55 = OpFunctionParameter %uint
  3526. %56 = OpFunctionParameter %uint
  3527. %57 = OpLabel
  3528. %61 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_0
  3529. %64 = OpAtomicIAdd %uint %61 %uint_4 %uint_0 %uint_9
  3530. %65 = OpIAdd %uint %64 %uint_9
  3531. %66 = OpArrayLength %uint %60 1
  3532. %67 = OpULessThanEqual %bool %65 %66
  3533. OpSelectionMerge %68 None
  3534. OpBranchConditional %67 %69 %68
  3535. %69 = OpLabel
  3536. %70 = OpIAdd %uint %64 %uint_0
  3537. %71 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %70
  3538. OpStore %71 %uint_9
  3539. %73 = OpIAdd %uint %64 %uint_1
  3540. %74 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %73
  3541. OpStore %74 %uint_23
  3542. %76 = OpIAdd %uint %64 %uint_2
  3543. %77 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %76
  3544. OpStore %77 %53
  3545. %78 = OpIAdd %uint %64 %uint_3
  3546. %79 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %78
  3547. OpStore %79 %uint_4
  3548. %83 = OpLoad %v4float %gl_FragCoord
  3549. %85 = OpBitcast %v4uint %83
  3550. %86 = OpCompositeExtract %uint %85 0
  3551. %87 = OpIAdd %uint %64 %uint_4
  3552. %88 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %87
  3553. OpStore %88 %86
  3554. %89 = OpCompositeExtract %uint %85 1
  3555. %91 = OpIAdd %uint %64 %uint_5
  3556. %92 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %91
  3557. OpStore %92 %89
  3558. %94 = OpIAdd %uint %64 %uint_6
  3559. %95 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %94
  3560. OpStore %95 %54
  3561. %97 = OpIAdd %uint %64 %uint_7
  3562. %98 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %97
  3563. OpStore %98 %55
  3564. %100 = OpIAdd %uint %64 %uint_8
  3565. %101 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %100
  3566. OpStore %101 %56
  3567. OpBranch %68
  3568. %68 = OpLabel
  3569. OpReturn
  3570. OpFunctionEnd
  3571. )";
  3572. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  3573. SinglePassRunAndCheck<InstBindlessCheckPass>(
  3574. defs_before + func_before, defs_after + func_after + new_funcs, true,
  3575. true);
  3576. }
  3577. TEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArray) {
  3578. // #version 450
  3579. // #extension GL_EXT_nonuniform_qualifier : enable
  3580. //
  3581. // layout(location=0) in nonuniformEXT flat int nu_ii;
  3582. // layout(location=1) in float b;
  3583. //
  3584. // layout(binding=4) buffer bname { float b; } storageBuffer[];
  3585. //
  3586. // void main()
  3587. // {
  3588. // storageBuffer[nu_ii].b = b;
  3589. // }
  3590. const std::string defs_before =
  3591. R"(OpCapability Shader
  3592. OpCapability ShaderNonUniform
  3593. OpCapability RuntimeDescriptorArray
  3594. OpCapability StorageBufferArrayNonUniformIndexing
  3595. OpExtension "SPV_EXT_descriptor_indexing"
  3596. %1 = OpExtInstImport "GLSL.std.450"
  3597. OpMemoryModel Logical GLSL450
  3598. OpEntryPoint Fragment %main "main" %nu_ii %b
  3599. OpExecutionMode %main OriginUpperLeft
  3600. OpSource GLSL 450
  3601. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3602. OpName %main "main"
  3603. OpName %bname "bname"
  3604. OpMemberName %bname 0 "b"
  3605. OpName %storageBuffer "storageBuffer"
  3606. OpName %nu_ii "nu_ii"
  3607. OpName %b "b"
  3608. OpMemberDecorate %bname 0 Offset 0
  3609. OpDecorate %bname BufferBlock
  3610. OpDecorate %storageBuffer DescriptorSet 0
  3611. OpDecorate %storageBuffer Binding 4
  3612. OpDecorate %nu_ii Flat
  3613. OpDecorate %nu_ii Location 0
  3614. OpDecorate %nu_ii NonUniform
  3615. OpDecorate %14 NonUniform
  3616. OpDecorate %b Location 1
  3617. %void = OpTypeVoid
  3618. %3 = OpTypeFunction %void
  3619. %float = OpTypeFloat 32
  3620. %bname = OpTypeStruct %float
  3621. %_runtimearr_bname = OpTypeRuntimeArray %bname
  3622. %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
  3623. %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
  3624. %int = OpTypeInt 32 1
  3625. %_ptr_Input_int = OpTypePointer Input %int
  3626. %nu_ii = OpVariable %_ptr_Input_int Input
  3627. %int_0 = OpConstant %int 0
  3628. %_ptr_Input_float = OpTypePointer Input %float
  3629. %b = OpVariable %_ptr_Input_float Input
  3630. %_ptr_Uniform_float = OpTypePointer Uniform %float
  3631. )";
  3632. const std::string defs_after =
  3633. R"(OpCapability Shader
  3634. OpCapability ShaderNonUniform
  3635. OpCapability RuntimeDescriptorArray
  3636. OpCapability StorageBufferArrayNonUniformIndexing
  3637. OpExtension "SPV_EXT_descriptor_indexing"
  3638. OpExtension "SPV_KHR_storage_buffer_storage_class"
  3639. %1 = OpExtInstImport "GLSL.std.450"
  3640. OpMemoryModel Logical GLSL450
  3641. OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord
  3642. OpExecutionMode %main OriginUpperLeft
  3643. OpSource GLSL 450
  3644. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3645. OpName %main "main"
  3646. OpName %bname "bname"
  3647. OpMemberName %bname 0 "b"
  3648. OpName %storageBuffer "storageBuffer"
  3649. OpName %nu_ii "nu_ii"
  3650. OpName %b "b"
  3651. OpMemberDecorate %bname 0 Offset 0
  3652. OpDecorate %bname BufferBlock
  3653. OpDecorate %storageBuffer DescriptorSet 0
  3654. OpDecorate %storageBuffer Binding 4
  3655. OpDecorate %nu_ii Flat
  3656. OpDecorate %nu_ii Location 0
  3657. OpDecorate %nu_ii NonUniform
  3658. OpDecorate %7 NonUniform
  3659. OpDecorate %b Location 1
  3660. OpDecorate %_runtimearr_uint ArrayStride 4
  3661. OpDecorate %_struct_31 Block
  3662. OpMemberDecorate %_struct_31 0 Offset 0
  3663. OpDecorate %33 DescriptorSet 7
  3664. OpDecorate %33 Binding 1
  3665. OpDecorate %_struct_54 Block
  3666. OpMemberDecorate %_struct_54 0 Offset 0
  3667. OpMemberDecorate %_struct_54 1 Offset 4
  3668. OpDecorate %56 DescriptorSet 7
  3669. OpDecorate %56 Binding 0
  3670. OpDecorate %gl_FragCoord BuiltIn FragCoord
  3671. %void = OpTypeVoid
  3672. %9 = OpTypeFunction %void
  3673. %float = OpTypeFloat 32
  3674. %bname = OpTypeStruct %float
  3675. %_runtimearr_bname = OpTypeRuntimeArray %bname
  3676. %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
  3677. %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
  3678. %int = OpTypeInt 32 1
  3679. %_ptr_Input_int = OpTypePointer Input %int
  3680. %nu_ii = OpVariable %_ptr_Input_int Input
  3681. %int_0 = OpConstant %int 0
  3682. %_ptr_Input_float = OpTypePointer Input %float
  3683. %b = OpVariable %_ptr_Input_float Input
  3684. %_ptr_Uniform_float = OpTypePointer Uniform %float
  3685. %uint = OpTypeInt 32 0
  3686. %uint_0 = OpConstant %uint 0
  3687. %uint_1 = OpConstant %uint 1
  3688. %uint_4 = OpConstant %uint 4
  3689. %26 = OpTypeFunction %uint %uint %uint
  3690. %_runtimearr_uint = OpTypeRuntimeArray %uint
  3691. %_struct_31 = OpTypeStruct %_runtimearr_uint
  3692. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  3693. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  3694. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  3695. %bool = OpTypeBool
  3696. %48 = OpTypeFunction %void %uint %uint %uint %uint
  3697. %_struct_54 = OpTypeStruct %uint %_runtimearr_uint
  3698. %_ptr_StorageBuffer__struct_54 = OpTypePointer StorageBuffer %_struct_54
  3699. %56 = OpVariable %_ptr_StorageBuffer__struct_54 StorageBuffer
  3700. %uint_9 = OpConstant %uint 9
  3701. %uint_23 = OpConstant %uint 23
  3702. %uint_2 = OpConstant %uint 2
  3703. %uint_3 = OpConstant %uint 3
  3704. %v4float = OpTypeVector %float 4
  3705. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3706. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  3707. %v4uint = OpTypeVector %uint 4
  3708. %uint_5 = OpConstant %uint 5
  3709. %uint_6 = OpConstant %uint 6
  3710. %uint_7 = OpConstant %uint 7
  3711. %uint_8 = OpConstant %uint 8
  3712. %uint_45 = OpConstant %uint 45
  3713. %102 = OpTypeFunction %uint %uint %uint %uint %uint
  3714. )";
  3715. const std::string func_before =
  3716. R"(%main = OpFunction %void None %3
  3717. %5 = OpLabel
  3718. %14 = OpLoad %int %nu_ii
  3719. %18 = OpLoad %float %b
  3720. %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %14 %int_0
  3721. OpStore %20 %18
  3722. OpReturn
  3723. OpFunctionEnd
  3724. )";
  3725. const std::string func_after =
  3726. R"(%main = OpFunction %void None %9
  3727. %18 = OpLabel
  3728. %7 = OpLoad %int %nu_ii
  3729. %19 = OpLoad %float %b
  3730. %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %7 %int_0
  3731. %40 = OpFunctionCall %uint %25 %uint_1 %uint_4
  3732. %42 = OpULessThan %bool %7 %40
  3733. OpSelectionMerge %43 None
  3734. OpBranchConditional %42 %44 %45
  3735. %44 = OpLabel
  3736. %100 = OpBitcast %uint %7
  3737. %119 = OpFunctionCall %uint %101 %uint_0 %uint_0 %uint_4 %100
  3738. %120 = OpINotEqual %bool %119 %uint_0
  3739. OpSelectionMerge %121 None
  3740. OpBranchConditional %120 %122 %123
  3741. %122 = OpLabel
  3742. OpStore %20 %19
  3743. OpBranch %121
  3744. %123 = OpLabel
  3745. %124 = OpBitcast %uint %7
  3746. %125 = OpFunctionCall %void %47 %uint_45 %uint_1 %124 %uint_0
  3747. OpBranch %121
  3748. %121 = OpLabel
  3749. OpBranch %43
  3750. %45 = OpLabel
  3751. %46 = OpBitcast %uint %7
  3752. %99 = OpFunctionCall %void %47 %uint_45 %uint_0 %46 %40
  3753. OpBranch %43
  3754. %43 = OpLabel
  3755. OpReturn
  3756. OpFunctionEnd
  3757. )";
  3758. const std::string new_funcs =
  3759. R"(%25 = OpFunction %uint None %26
  3760. %27 = OpFunctionParameter %uint
  3761. %28 = OpFunctionParameter %uint
  3762. %29 = OpLabel
  3763. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  3764. %36 = OpLoad %uint %35
  3765. %37 = OpIAdd %uint %36 %28
  3766. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  3767. %39 = OpLoad %uint %38
  3768. OpReturnValue %39
  3769. OpFunctionEnd
  3770. %47 = OpFunction %void None %48
  3771. %49 = OpFunctionParameter %uint
  3772. %50 = OpFunctionParameter %uint
  3773. %51 = OpFunctionParameter %uint
  3774. %52 = OpFunctionParameter %uint
  3775. %53 = OpLabel
  3776. %57 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_0
  3777. %59 = OpAtomicIAdd %uint %57 %uint_4 %uint_0 %uint_9
  3778. %60 = OpIAdd %uint %59 %uint_9
  3779. %61 = OpArrayLength %uint %56 1
  3780. %62 = OpULessThanEqual %bool %60 %61
  3781. OpSelectionMerge %63 None
  3782. OpBranchConditional %62 %64 %63
  3783. %64 = OpLabel
  3784. %65 = OpIAdd %uint %59 %uint_0
  3785. %66 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %65
  3786. OpStore %66 %uint_9
  3787. %68 = OpIAdd %uint %59 %uint_1
  3788. %69 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %68
  3789. OpStore %69 %uint_23
  3790. %71 = OpIAdd %uint %59 %uint_2
  3791. %72 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %71
  3792. OpStore %72 %49
  3793. %74 = OpIAdd %uint %59 %uint_3
  3794. %75 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %74
  3795. OpStore %75 %uint_4
  3796. %79 = OpLoad %v4float %gl_FragCoord
  3797. %81 = OpBitcast %v4uint %79
  3798. %82 = OpCompositeExtract %uint %81 0
  3799. %83 = OpIAdd %uint %59 %uint_4
  3800. %84 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %83
  3801. OpStore %84 %82
  3802. %85 = OpCompositeExtract %uint %81 1
  3803. %87 = OpIAdd %uint %59 %uint_5
  3804. %88 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %87
  3805. OpStore %88 %85
  3806. %90 = OpIAdd %uint %59 %uint_6
  3807. %91 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %90
  3808. OpStore %91 %50
  3809. %93 = OpIAdd %uint %59 %uint_7
  3810. %94 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %93
  3811. OpStore %94 %51
  3812. %96 = OpIAdd %uint %59 %uint_8
  3813. %97 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %96
  3814. OpStore %97 %52
  3815. OpBranch %63
  3816. %63 = OpLabel
  3817. OpReturn
  3818. OpFunctionEnd
  3819. %101 = OpFunction %uint None %102
  3820. %103 = OpFunctionParameter %uint
  3821. %104 = OpFunctionParameter %uint
  3822. %105 = OpFunctionParameter %uint
  3823. %106 = OpFunctionParameter %uint
  3824. %107 = OpLabel
  3825. %108 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %103
  3826. %109 = OpLoad %uint %108
  3827. %110 = OpIAdd %uint %109 %104
  3828. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %110
  3829. %112 = OpLoad %uint %111
  3830. %113 = OpIAdd %uint %112 %105
  3831. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  3832. %115 = OpLoad %uint %114
  3833. %116 = OpIAdd %uint %115 %106
  3834. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  3835. %118 = OpLoad %uint %117
  3836. OpReturnValue %118
  3837. OpFunctionEnd
  3838. )";
  3839. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  3840. SinglePassRunAndCheck<InstBindlessCheckPass>(
  3841. defs_before + func_before, defs_after + func_after + new_funcs, true,
  3842. true);
  3843. }
  3844. TEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArray) {
  3845. // #version 450
  3846. // #extension GL_EXT_nonuniform_qualifier : enable
  3847. //
  3848. // layout(location=0) in nonuniformEXT flat int nu_ii;
  3849. // layout(location=0) out float b;
  3850. //
  3851. // layout(binding=3) uniform uname { float a; } uniformBuffer[128];
  3852. //
  3853. // void main()
  3854. // {
  3855. // b = uniformBuffer[nu_ii].a;
  3856. // }
  3857. const std::string defs_before =
  3858. R"(OpCapability Shader
  3859. OpCapability ShaderNonUniform
  3860. OpCapability UniformBufferArrayNonUniformIndexing
  3861. OpExtension "SPV_EXT_descriptor_indexing"
  3862. %1 = OpExtInstImport "GLSL.std.450"
  3863. OpMemoryModel Logical GLSL450
  3864. OpEntryPoint Fragment %main "main" %b %nu_ii
  3865. OpExecutionMode %main OriginUpperLeft
  3866. OpSource GLSL 450
  3867. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3868. OpName %main "main"
  3869. OpName %b "b"
  3870. OpName %uname "uname"
  3871. OpMemberName %uname 0 "a"
  3872. OpName %uniformBuffer "uniformBuffer"
  3873. OpName %nu_ii "nu_ii"
  3874. OpDecorate %b Location 0
  3875. OpMemberDecorate %uname 0 Offset 0
  3876. OpDecorate %uname Block
  3877. OpDecorate %uniformBuffer DescriptorSet 0
  3878. OpDecorate %uniformBuffer Binding 3
  3879. OpDecorate %nu_ii Flat
  3880. OpDecorate %nu_ii Location 0
  3881. OpDecorate %nu_ii NonUniform
  3882. OpDecorate %18 NonUniform
  3883. OpDecorate %22 NonUniform
  3884. %void = OpTypeVoid
  3885. %3 = OpTypeFunction %void
  3886. %float = OpTypeFloat 32
  3887. %_ptr_Output_float = OpTypePointer Output %float
  3888. %b = OpVariable %_ptr_Output_float Output
  3889. %uname = OpTypeStruct %float
  3890. %uint = OpTypeInt 32 0
  3891. %uint_128 = OpConstant %uint 128
  3892. %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
  3893. %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
  3894. %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
  3895. %int = OpTypeInt 32 1
  3896. %_ptr_Input_int = OpTypePointer Input %int
  3897. %nu_ii = OpVariable %_ptr_Input_int Input
  3898. %int_0 = OpConstant %int 0
  3899. %_ptr_Uniform_float = OpTypePointer Uniform %float
  3900. )";
  3901. const std::string defs_after =
  3902. R"(OpCapability Shader
  3903. OpCapability ShaderNonUniform
  3904. OpCapability UniformBufferArrayNonUniformIndexing
  3905. OpExtension "SPV_EXT_descriptor_indexing"
  3906. OpExtension "SPV_KHR_storage_buffer_storage_class"
  3907. %1 = OpExtInstImport "GLSL.std.450"
  3908. OpMemoryModel Logical GLSL450
  3909. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  3910. OpExecutionMode %main OriginUpperLeft
  3911. OpSource GLSL 450
  3912. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  3913. OpName %main "main"
  3914. OpName %b "b"
  3915. OpName %uname "uname"
  3916. OpMemberName %uname 0 "a"
  3917. OpName %uniformBuffer "uniformBuffer"
  3918. OpName %nu_ii "nu_ii"
  3919. OpDecorate %b Location 0
  3920. OpMemberDecorate %uname 0 Offset 0
  3921. OpDecorate %uname Block
  3922. OpDecorate %uniformBuffer DescriptorSet 0
  3923. OpDecorate %uniformBuffer Binding 3
  3924. OpDecorate %nu_ii Flat
  3925. OpDecorate %nu_ii Location 0
  3926. OpDecorate %nu_ii NonUniform
  3927. OpDecorate %7 NonUniform
  3928. OpDecorate %89 NonUniform
  3929. OpDecorate %120 NonUniform
  3930. OpDecorate %_runtimearr_uint ArrayStride 4
  3931. OpDecorate %_struct_39 Block
  3932. OpMemberDecorate %_struct_39 0 Offset 0
  3933. OpMemberDecorate %_struct_39 1 Offset 4
  3934. OpDecorate %41 DescriptorSet 7
  3935. OpDecorate %41 Binding 0
  3936. OpDecorate %gl_FragCoord BuiltIn FragCoord
  3937. OpDecorate %_struct_98 Block
  3938. OpMemberDecorate %_struct_98 0 Offset 0
  3939. OpDecorate %100 DescriptorSet 7
  3940. OpDecorate %100 Binding 1
  3941. OpDecorate %117 NonUniform
  3942. %void = OpTypeVoid
  3943. %10 = OpTypeFunction %void
  3944. %float = OpTypeFloat 32
  3945. %_ptr_Output_float = OpTypePointer Output %float
  3946. %b = OpVariable %_ptr_Output_float Output
  3947. %uname = OpTypeStruct %float
  3948. %uint = OpTypeInt 32 0
  3949. %uint_128 = OpConstant %uint 128
  3950. %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
  3951. %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
  3952. %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
  3953. %int = OpTypeInt 32 1
  3954. %_ptr_Input_int = OpTypePointer Input %int
  3955. %nu_ii = OpVariable %_ptr_Input_int Input
  3956. %int_0 = OpConstant %int 0
  3957. %_ptr_Uniform_float = OpTypePointer Uniform %float
  3958. %uint_0 = OpConstant %uint 0
  3959. %bool = OpTypeBool
  3960. %32 = OpTypeFunction %void %uint %uint %uint %uint
  3961. %_runtimearr_uint = OpTypeRuntimeArray %uint
  3962. %_struct_39 = OpTypeStruct %uint %_runtimearr_uint
  3963. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  3964. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  3965. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  3966. %uint_9 = OpConstant %uint 9
  3967. %uint_4 = OpConstant %uint 4
  3968. %uint_1 = OpConstant %uint 1
  3969. %uint_23 = OpConstant %uint 23
  3970. %uint_2 = OpConstant %uint 2
  3971. %uint_3 = OpConstant %uint 3
  3972. %v4float = OpTypeVector %float 4
  3973. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3974. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  3975. %v4uint = OpTypeVector %uint 4
  3976. %uint_5 = OpConstant %uint 5
  3977. %uint_6 = OpConstant %uint 6
  3978. %uint_7 = OpConstant %uint 7
  3979. %uint_8 = OpConstant %uint 8
  3980. %uint_46 = OpConstant %uint 46
  3981. %88 = OpConstantNull %float
  3982. %92 = OpTypeFunction %uint %uint %uint %uint %uint
  3983. %_struct_98 = OpTypeStruct %_runtimearr_uint
  3984. %_ptr_StorageBuffer__struct_98 = OpTypePointer StorageBuffer %_struct_98
  3985. %100 = OpVariable %_ptr_StorageBuffer__struct_98 StorageBuffer
  3986. )";
  3987. const std::string func_before =
  3988. R"(%main = OpFunction %void None %3
  3989. %5 = OpLabel
  3990. %18 = OpLoad %int %nu_ii
  3991. %21 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %18 %int_0
  3992. %22 = OpLoad %float %21
  3993. OpStore %b %22
  3994. OpReturn
  3995. OpFunctionEnd
  3996. )";
  3997. const std::string func_after =
  3998. R"(%main = OpFunction %void None %10
  3999. %21 = OpLabel
  4000. %7 = OpLoad %int %nu_ii
  4001. %22 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
  4002. %25 = OpULessThan %bool %7 %uint_128
  4003. OpSelectionMerge %26 None
  4004. OpBranchConditional %25 %27 %28
  4005. %27 = OpLabel
  4006. %90 = OpBitcast %uint %7
  4007. %112 = OpFunctionCall %uint %91 %uint_0 %uint_0 %uint_3 %90
  4008. %113 = OpINotEqual %bool %112 %uint_0
  4009. OpSelectionMerge %114 None
  4010. OpBranchConditional %113 %115 %116
  4011. %115 = OpLabel
  4012. %117 = OpLoad %float %22
  4013. OpBranch %114
  4014. %116 = OpLabel
  4015. %118 = OpBitcast %uint %7
  4016. %119 = OpFunctionCall %void %31 %uint_46 %uint_1 %118 %uint_0
  4017. OpBranch %114
  4018. %114 = OpLabel
  4019. %120 = OpPhi %float %117 %115 %88 %116
  4020. OpBranch %26
  4021. %28 = OpLabel
  4022. %30 = OpBitcast %uint %7
  4023. %87 = OpFunctionCall %void %31 %uint_46 %uint_0 %30 %uint_128
  4024. OpBranch %26
  4025. %26 = OpLabel
  4026. %89 = OpPhi %float %120 %114 %88 %28
  4027. OpStore %b %89
  4028. OpReturn
  4029. OpFunctionEnd
  4030. )";
  4031. const std::string new_funcs =
  4032. R"(%31 = OpFunction %void None %32
  4033. %33 = OpFunctionParameter %uint
  4034. %34 = OpFunctionParameter %uint
  4035. %35 = OpFunctionParameter %uint
  4036. %36 = OpFunctionParameter %uint
  4037. %37 = OpLabel
  4038. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0
  4039. %46 = OpAtomicIAdd %uint %43 %uint_4 %uint_0 %uint_9
  4040. %47 = OpIAdd %uint %46 %uint_9
  4041. %48 = OpArrayLength %uint %41 1
  4042. %49 = OpULessThanEqual %bool %47 %48
  4043. OpSelectionMerge %50 None
  4044. OpBranchConditional %49 %51 %50
  4045. %51 = OpLabel
  4046. %52 = OpIAdd %uint %46 %uint_0
  4047. %54 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %52
  4048. OpStore %54 %uint_9
  4049. %56 = OpIAdd %uint %46 %uint_1
  4050. %57 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %56
  4051. OpStore %57 %uint_23
  4052. %59 = OpIAdd %uint %46 %uint_2
  4053. %60 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %59
  4054. OpStore %60 %33
  4055. %62 = OpIAdd %uint %46 %uint_3
  4056. %63 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %62
  4057. OpStore %63 %uint_4
  4058. %67 = OpLoad %v4float %gl_FragCoord
  4059. %69 = OpBitcast %v4uint %67
  4060. %70 = OpCompositeExtract %uint %69 0
  4061. %71 = OpIAdd %uint %46 %uint_4
  4062. %72 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %71
  4063. OpStore %72 %70
  4064. %73 = OpCompositeExtract %uint %69 1
  4065. %75 = OpIAdd %uint %46 %uint_5
  4066. %76 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %75
  4067. OpStore %76 %73
  4068. %78 = OpIAdd %uint %46 %uint_6
  4069. %79 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %78
  4070. OpStore %79 %34
  4071. %81 = OpIAdd %uint %46 %uint_7
  4072. %82 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %81
  4073. OpStore %82 %35
  4074. %84 = OpIAdd %uint %46 %uint_8
  4075. %85 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %84
  4076. OpStore %85 %36
  4077. OpBranch %50
  4078. %50 = OpLabel
  4079. OpReturn
  4080. OpFunctionEnd
  4081. %91 = OpFunction %uint None %92
  4082. %93 = OpFunctionParameter %uint
  4083. %94 = OpFunctionParameter %uint
  4084. %95 = OpFunctionParameter %uint
  4085. %96 = OpFunctionParameter %uint
  4086. %97 = OpLabel
  4087. %101 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %93
  4088. %102 = OpLoad %uint %101
  4089. %103 = OpIAdd %uint %102 %94
  4090. %104 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %103
  4091. %105 = OpLoad %uint %104
  4092. %106 = OpIAdd %uint %105 %95
  4093. %107 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %106
  4094. %108 = OpLoad %uint %107
  4095. %109 = OpIAdd %uint %108 %96
  4096. %110 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %109
  4097. %111 = OpLoad %uint %110
  4098. OpReturnValue %111
  4099. OpFunctionEnd
  4100. )";
  4101. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  4102. SinglePassRunAndCheck<InstBindlessCheckPass>(
  4103. defs_before + func_before, defs_after + func_after + new_funcs, true,
  4104. true);
  4105. }
  4106. TEST_F(InstBindlessTest, SimpleV2) {
  4107. // Texture2D g_tColor[128];
  4108. //
  4109. // layout(push_constant) cbuffer PerViewConstantBuffer_t
  4110. // {
  4111. // uint g_nDataIdx;
  4112. // };
  4113. //
  4114. // SamplerState g_sAniso;
  4115. //
  4116. // struct PS_INPUT
  4117. // {
  4118. // float2 vTextureCoords : TEXCOORD2;
  4119. // };
  4120. //
  4121. // struct PS_OUTPUT
  4122. // {
  4123. // float4 vColor : SV_Target0;
  4124. // };
  4125. //
  4126. // PS_OUTPUT MainPs(PS_INPUT i)
  4127. // {
  4128. // PS_OUTPUT ps_output;
  4129. // ps_output.vColor =
  4130. // g_tColor[ g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
  4131. // return ps_output;
  4132. // }
  4133. const std::string entry_before =
  4134. R"(OpCapability Shader
  4135. %1 = OpExtInstImport "GLSL.std.450"
  4136. OpMemoryModel Logical GLSL450
  4137. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  4138. OpExecutionMode %MainPs OriginUpperLeft
  4139. OpSource HLSL 500
  4140. )";
  4141. const std::string entry_after =
  4142. R"(OpCapability Shader
  4143. OpExtension "SPV_KHR_storage_buffer_storage_class"
  4144. %1 = OpExtInstImport "GLSL.std.450"
  4145. OpMemoryModel Logical GLSL450
  4146. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  4147. OpExecutionMode %MainPs OriginUpperLeft
  4148. OpSource HLSL 500
  4149. )";
  4150. const std::string names_annots =
  4151. R"(OpName %MainPs "MainPs"
  4152. OpName %g_tColor "g_tColor"
  4153. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  4154. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  4155. OpName %_ ""
  4156. OpName %g_sAniso "g_sAniso"
  4157. OpName %i_vTextureCoords "i.vTextureCoords"
  4158. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  4159. OpDecorate %g_tColor DescriptorSet 3
  4160. OpDecorate %g_tColor Binding 0
  4161. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  4162. OpDecorate %PerViewConstantBuffer_t Block
  4163. OpDecorate %g_sAniso DescriptorSet 0
  4164. OpDecorate %i_vTextureCoords Location 0
  4165. OpDecorate %_entryPointOutput_vColor Location 0
  4166. )";
  4167. const std::string new_annots =
  4168. R"(OpDecorate %_runtimearr_uint ArrayStride 4
  4169. OpDecorate %_struct_55 Block
  4170. OpMemberDecorate %_struct_55 0 Offset 0
  4171. OpMemberDecorate %_struct_55 1 Offset 4
  4172. OpDecorate %57 DescriptorSet 7
  4173. OpDecorate %57 Binding 0
  4174. OpDecorate %gl_FragCoord BuiltIn FragCoord
  4175. )";
  4176. const std::string consts_types_vars =
  4177. R"(%void = OpTypeVoid
  4178. %10 = OpTypeFunction %void
  4179. %float = OpTypeFloat 32
  4180. %v2float = OpTypeVector %float 2
  4181. %v4float = OpTypeVector %float 4
  4182. %int = OpTypeInt 32 1
  4183. %int_0 = OpConstant %int 0
  4184. %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
  4185. %uint = OpTypeInt 32 0
  4186. %uint_128 = OpConstant %uint 128
  4187. %_arr_16_uint_128 = OpTypeArray %16 %uint_128
  4188. %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
  4189. %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
  4190. %PerViewConstantBuffer_t = OpTypeStruct %uint
  4191. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  4192. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  4193. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  4194. %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
  4195. %24 = OpTypeSampler
  4196. %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
  4197. %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
  4198. %26 = OpTypeSampledImage %16
  4199. %_ptr_Input_v2float = OpTypePointer Input %v2float
  4200. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  4201. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4202. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  4203. )";
  4204. const std::string new_consts_types_vars =
  4205. R"(%uint_0 = OpConstant %uint 0
  4206. %bool = OpTypeBool
  4207. %48 = OpTypeFunction %void %uint %uint %uint %uint
  4208. %_runtimearr_uint = OpTypeRuntimeArray %uint
  4209. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  4210. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  4211. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  4212. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  4213. %uint_10 = OpConstant %uint 10
  4214. %uint_4 = OpConstant %uint 4
  4215. %uint_1 = OpConstant %uint 1
  4216. %uint_23 = OpConstant %uint 23
  4217. %uint_2 = OpConstant %uint 2
  4218. %uint_3 = OpConstant %uint 3
  4219. %_ptr_Input_v4float = OpTypePointer Input %v4float
  4220. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  4221. %v4uint = OpTypeVector %uint 4
  4222. %uint_5 = OpConstant %uint 5
  4223. %uint_7 = OpConstant %uint 7
  4224. %uint_8 = OpConstant %uint 8
  4225. %uint_9 = OpConstant %uint 9
  4226. %uint_56 = OpConstant %uint 56
  4227. %103 = OpConstantNull %v4float
  4228. )";
  4229. const std::string func_pt1 =
  4230. R"(%MainPs = OpFunction %void None %10
  4231. %29 = OpLabel
  4232. %30 = OpLoad %v2float %i_vTextureCoords
  4233. %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  4234. %32 = OpLoad %uint %31
  4235. %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
  4236. %34 = OpLoad %16 %33
  4237. %35 = OpLoad %24 %g_sAniso
  4238. %36 = OpSampledImage %26 %34 %35
  4239. )";
  4240. const std::string func_pt2_before =
  4241. R"(%37 = OpImageSampleImplicitLod %v4float %36 %30
  4242. OpStore %_entryPointOutput_vColor %37
  4243. OpReturn
  4244. OpFunctionEnd
  4245. )";
  4246. const std::string func_pt2_after =
  4247. R"(%40 = OpULessThan %bool %32 %uint_128
  4248. OpSelectionMerge %41 None
  4249. OpBranchConditional %40 %42 %43
  4250. %42 = OpLabel
  4251. %44 = OpLoad %16 %33
  4252. %45 = OpSampledImage %26 %44 %35
  4253. %46 = OpImageSampleImplicitLod %v4float %45 %30
  4254. OpBranch %41
  4255. %43 = OpLabel
  4256. %102 = OpFunctionCall %void %47 %uint_56 %uint_0 %32 %uint_128
  4257. OpBranch %41
  4258. %41 = OpLabel
  4259. %104 = OpPhi %v4float %46 %42 %103 %43
  4260. OpStore %_entryPointOutput_vColor %104
  4261. OpReturn
  4262. OpFunctionEnd
  4263. )";
  4264. const std::string output_func =
  4265. R"(%47 = OpFunction %void None %48
  4266. %49 = OpFunctionParameter %uint
  4267. %50 = OpFunctionParameter %uint
  4268. %51 = OpFunctionParameter %uint
  4269. %52 = OpFunctionParameter %uint
  4270. %53 = OpLabel
  4271. %59 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  4272. %62 = OpAtomicIAdd %uint %59 %uint_4 %uint_0 %uint_10
  4273. %63 = OpIAdd %uint %62 %uint_10
  4274. %64 = OpArrayLength %uint %57 1
  4275. %65 = OpULessThanEqual %bool %63 %64
  4276. OpSelectionMerge %66 None
  4277. OpBranchConditional %65 %67 %66
  4278. %67 = OpLabel
  4279. %68 = OpIAdd %uint %62 %uint_0
  4280. %70 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %68
  4281. OpStore %70 %uint_10
  4282. %72 = OpIAdd %uint %62 %uint_1
  4283. %73 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %72
  4284. OpStore %73 %uint_23
  4285. %75 = OpIAdd %uint %62 %uint_2
  4286. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  4287. OpStore %76 %49
  4288. %78 = OpIAdd %uint %62 %uint_3
  4289. %79 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %78
  4290. OpStore %79 %uint_4
  4291. %82 = OpLoad %v4float %gl_FragCoord
  4292. %84 = OpBitcast %v4uint %82
  4293. %85 = OpCompositeExtract %uint %84 0
  4294. %86 = OpIAdd %uint %62 %uint_4
  4295. %87 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %86
  4296. OpStore %87 %85
  4297. %88 = OpCompositeExtract %uint %84 1
  4298. %90 = OpIAdd %uint %62 %uint_5
  4299. %91 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %90
  4300. OpStore %91 %88
  4301. %93 = OpIAdd %uint %62 %uint_7
  4302. %94 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %93
  4303. OpStore %94 %50
  4304. %96 = OpIAdd %uint %62 %uint_8
  4305. %97 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %96
  4306. OpStore %97 %51
  4307. %99 = OpIAdd %uint %62 %uint_9
  4308. %100 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %99
  4309. OpStore %100 %52
  4310. OpBranch %66
  4311. %66 = OpLabel
  4312. OpReturn
  4313. OpFunctionEnd
  4314. )";
  4315. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  4316. SinglePassRunAndCheck<InstBindlessCheckPass, uint32_t, uint32_t, bool, bool,
  4317. uint32_t>(
  4318. entry_before + names_annots + consts_types_vars + func_pt1 +
  4319. func_pt2_before,
  4320. entry_after + names_annots + new_annots + consts_types_vars +
  4321. new_consts_types_vars + func_pt1 + func_pt2_after + output_func,
  4322. true, true, 7u, 23u, false, false, 2u);
  4323. }
  4324. TEST_F(InstBindlessTest, InstrumentMultipleInstructionsV2) {
  4325. // Texture2D g_tColor[128];
  4326. //
  4327. // layout(push_constant) cbuffer PerViewConstantBuffer_t
  4328. // {
  4329. // uint g_nDataIdx;
  4330. // uint g_nDataIdx2;
  4331. // };
  4332. //
  4333. // SamplerState g_sAniso;
  4334. //
  4335. // struct PS_INPUT
  4336. // {
  4337. // float2 vTextureCoords : TEXCOORD2;
  4338. // };
  4339. //
  4340. // struct PS_OUTPUT
  4341. // {
  4342. // float4 vColor : SV_Target0;
  4343. // };
  4344. //
  4345. // PS_OUTPUT MainPs(PS_INPUT i)
  4346. // {
  4347. // PS_OUTPUT ps_output;
  4348. //
  4349. // float t = g_tColor[g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
  4350. // float t2 = g_tColor[g_nDataIdx2].Sample(g_sAniso, i.vTextureCoords.xy);
  4351. // ps_output.vColor = t + t2;
  4352. // return ps_output;
  4353. // }
  4354. const std::string defs_before =
  4355. R"(OpCapability Shader
  4356. %1 = OpExtInstImport "GLSL.std.450"
  4357. OpMemoryModel Logical GLSL450
  4358. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  4359. OpExecutionMode %MainPs OriginUpperLeft
  4360. OpSource HLSL 500
  4361. OpName %MainPs "MainPs"
  4362. OpName %g_tColor "g_tColor"
  4363. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  4364. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  4365. OpName %_ ""
  4366. OpName %g_sAniso "g_sAniso"
  4367. OpName %i_vTextureCoords "i.vTextureCoords"
  4368. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  4369. OpDecorate %g_tColor DescriptorSet 3
  4370. OpDecorate %g_tColor Binding 0
  4371. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  4372. OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
  4373. OpDecorate %PerViewConstantBuffer_t Block
  4374. OpDecorate %g_sAniso DescriptorSet 0
  4375. OpDecorate %i_vTextureCoords Location 0
  4376. OpDecorate %_entryPointOutput_vColor Location 0
  4377. %void = OpTypeVoid
  4378. %10 = OpTypeFunction %void
  4379. %float = OpTypeFloat 32
  4380. %v2float = OpTypeVector %float 2
  4381. %v4float = OpTypeVector %float 4
  4382. %int = OpTypeInt 32 1
  4383. %int_0 = OpConstant %int 0
  4384. %int_1 = OpConstant %int 1
  4385. %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
  4386. %uint = OpTypeInt 32 0
  4387. %uint_128 = OpConstant %uint 128
  4388. %_arr_17_uint_128 = OpTypeArray %17 %uint_128
  4389. %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
  4390. %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
  4391. %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
  4392. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  4393. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  4394. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  4395. %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
  4396. %25 = OpTypeSampler
  4397. %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
  4398. %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
  4399. %27 = OpTypeSampledImage %17
  4400. %_ptr_Input_v2float = OpTypePointer Input %v2float
  4401. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  4402. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4403. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  4404. )";
  4405. const std::string defs_after =
  4406. R"(OpCapability Shader
  4407. OpExtension "SPV_KHR_storage_buffer_storage_class"
  4408. %1 = OpExtInstImport "GLSL.std.450"
  4409. OpMemoryModel Logical GLSL450
  4410. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  4411. OpExecutionMode %MainPs OriginUpperLeft
  4412. OpSource HLSL 500
  4413. OpName %MainPs "MainPs"
  4414. OpName %g_tColor "g_tColor"
  4415. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  4416. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  4417. OpName %_ ""
  4418. OpName %g_sAniso "g_sAniso"
  4419. OpName %i_vTextureCoords "i.vTextureCoords"
  4420. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  4421. OpDecorate %g_tColor DescriptorSet 3
  4422. OpDecorate %g_tColor Binding 0
  4423. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  4424. OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
  4425. OpDecorate %PerViewConstantBuffer_t Block
  4426. OpDecorate %g_sAniso DescriptorSet 0
  4427. OpDecorate %i_vTextureCoords Location 0
  4428. OpDecorate %_entryPointOutput_vColor Location 0
  4429. OpDecorate %_runtimearr_uint ArrayStride 4
  4430. OpDecorate %_struct_63 Block
  4431. OpMemberDecorate %_struct_63 0 Offset 0
  4432. OpMemberDecorate %_struct_63 1 Offset 4
  4433. OpDecorate %65 DescriptorSet 7
  4434. OpDecorate %65 Binding 0
  4435. OpDecorate %gl_FragCoord BuiltIn FragCoord
  4436. %void = OpTypeVoid
  4437. %10 = OpTypeFunction %void
  4438. %float = OpTypeFloat 32
  4439. %v2float = OpTypeVector %float 2
  4440. %v4float = OpTypeVector %float 4
  4441. %int = OpTypeInt 32 1
  4442. %int_0 = OpConstant %int 0
  4443. %int_1 = OpConstant %int 1
  4444. %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
  4445. %uint = OpTypeInt 32 0
  4446. %uint_128 = OpConstant %uint 128
  4447. %_arr_17_uint_128 = OpTypeArray %17 %uint_128
  4448. %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
  4449. %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
  4450. %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
  4451. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  4452. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  4453. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  4454. %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
  4455. %25 = OpTypeSampler
  4456. %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
  4457. %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
  4458. %27 = OpTypeSampledImage %17
  4459. %_ptr_Input_v2float = OpTypePointer Input %v2float
  4460. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  4461. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4462. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  4463. %uint_0 = OpConstant %uint 0
  4464. %bool = OpTypeBool
  4465. %56 = OpTypeFunction %void %uint %uint %uint %uint
  4466. %_runtimearr_uint = OpTypeRuntimeArray %uint
  4467. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  4468. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  4469. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  4470. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  4471. %uint_10 = OpConstant %uint 10
  4472. %uint_4 = OpConstant %uint 4
  4473. %uint_1 = OpConstant %uint 1
  4474. %uint_23 = OpConstant %uint 23
  4475. %uint_2 = OpConstant %uint 2
  4476. %uint_3 = OpConstant %uint 3
  4477. %_ptr_Input_v4float = OpTypePointer Input %v4float
  4478. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  4479. %v4uint = OpTypeVector %uint 4
  4480. %uint_5 = OpConstant %uint 5
  4481. %uint_7 = OpConstant %uint 7
  4482. %uint_8 = OpConstant %uint 8
  4483. %uint_9 = OpConstant %uint 9
  4484. %uint_58 = OpConstant %uint 58
  4485. %111 = OpConstantNull %v4float
  4486. %uint_64 = OpConstant %uint 64
  4487. )";
  4488. const std::string func_before =
  4489. R"(%MainPs = OpFunction %void None %10
  4490. %30 = OpLabel
  4491. %31 = OpLoad %v2float %i_vTextureCoords
  4492. %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  4493. %33 = OpLoad %uint %32
  4494. %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
  4495. %35 = OpLoad %17 %34
  4496. %36 = OpLoad %25 %g_sAniso
  4497. %37 = OpSampledImage %27 %35 %36
  4498. %38 = OpImageSampleImplicitLod %v4float %37 %31
  4499. %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
  4500. %40 = OpLoad %uint %39
  4501. %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
  4502. %42 = OpLoad %17 %41
  4503. %43 = OpSampledImage %27 %42 %36
  4504. %44 = OpImageSampleImplicitLod %v4float %43 %31
  4505. %45 = OpFAdd %v4float %38 %44
  4506. OpStore %_entryPointOutput_vColor %45
  4507. OpReturn
  4508. OpFunctionEnd
  4509. )";
  4510. const std::string func_after =
  4511. R"(%MainPs = OpFunction %void None %10
  4512. %30 = OpLabel
  4513. %31 = OpLoad %v2float %i_vTextureCoords
  4514. %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  4515. %33 = OpLoad %uint %32
  4516. %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
  4517. %35 = OpLoad %17 %34
  4518. %36 = OpLoad %25 %g_sAniso
  4519. %37 = OpSampledImage %27 %35 %36
  4520. %48 = OpULessThan %bool %33 %uint_128
  4521. OpSelectionMerge %49 None
  4522. OpBranchConditional %48 %50 %51
  4523. %50 = OpLabel
  4524. %52 = OpLoad %17 %34
  4525. %53 = OpSampledImage %27 %52 %36
  4526. %54 = OpImageSampleImplicitLod %v4float %53 %31
  4527. OpBranch %49
  4528. %51 = OpLabel
  4529. %110 = OpFunctionCall %void %55 %uint_58 %uint_0 %33 %uint_128
  4530. OpBranch %49
  4531. %49 = OpLabel
  4532. %112 = OpPhi %v4float %54 %50 %111 %51
  4533. %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
  4534. %40 = OpLoad %uint %39
  4535. %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
  4536. %42 = OpLoad %17 %41
  4537. %43 = OpSampledImage %27 %42 %36
  4538. %113 = OpULessThan %bool %40 %uint_128
  4539. OpSelectionMerge %114 None
  4540. OpBranchConditional %113 %115 %116
  4541. %115 = OpLabel
  4542. %117 = OpLoad %17 %41
  4543. %118 = OpSampledImage %27 %117 %36
  4544. %119 = OpImageSampleImplicitLod %v4float %118 %31
  4545. OpBranch %114
  4546. %116 = OpLabel
  4547. %121 = OpFunctionCall %void %55 %uint_64 %uint_0 %40 %uint_128
  4548. OpBranch %114
  4549. %114 = OpLabel
  4550. %122 = OpPhi %v4float %119 %115 %111 %116
  4551. %45 = OpFAdd %v4float %112 %122
  4552. OpStore %_entryPointOutput_vColor %45
  4553. OpReturn
  4554. OpFunctionEnd
  4555. )";
  4556. const std::string output_func =
  4557. R"(%55 = OpFunction %void None %56
  4558. %57 = OpFunctionParameter %uint
  4559. %58 = OpFunctionParameter %uint
  4560. %59 = OpFunctionParameter %uint
  4561. %60 = OpFunctionParameter %uint
  4562. %61 = OpLabel
  4563. %67 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  4564. %70 = OpAtomicIAdd %uint %67 %uint_4 %uint_0 %uint_10
  4565. %71 = OpIAdd %uint %70 %uint_10
  4566. %72 = OpArrayLength %uint %65 1
  4567. %73 = OpULessThanEqual %bool %71 %72
  4568. OpSelectionMerge %74 None
  4569. OpBranchConditional %73 %75 %74
  4570. %75 = OpLabel
  4571. %76 = OpIAdd %uint %70 %uint_0
  4572. %78 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %76
  4573. OpStore %78 %uint_10
  4574. %80 = OpIAdd %uint %70 %uint_1
  4575. %81 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %80
  4576. OpStore %81 %uint_23
  4577. %83 = OpIAdd %uint %70 %uint_2
  4578. %84 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %83
  4579. OpStore %84 %57
  4580. %86 = OpIAdd %uint %70 %uint_3
  4581. %87 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %86
  4582. OpStore %87 %uint_4
  4583. %90 = OpLoad %v4float %gl_FragCoord
  4584. %92 = OpBitcast %v4uint %90
  4585. %93 = OpCompositeExtract %uint %92 0
  4586. %94 = OpIAdd %uint %70 %uint_4
  4587. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  4588. OpStore %95 %93
  4589. %96 = OpCompositeExtract %uint %92 1
  4590. %98 = OpIAdd %uint %70 %uint_5
  4591. %99 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %98
  4592. OpStore %99 %96
  4593. %101 = OpIAdd %uint %70 %uint_7
  4594. %102 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %101
  4595. OpStore %102 %58
  4596. %104 = OpIAdd %uint %70 %uint_8
  4597. %105 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %104
  4598. OpStore %105 %59
  4599. %107 = OpIAdd %uint %70 %uint_9
  4600. %108 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %107
  4601. OpStore %108 %60
  4602. OpBranch %74
  4603. %74 = OpLabel
  4604. OpReturn
  4605. OpFunctionEnd
  4606. )";
  4607. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  4608. SinglePassRunAndCheck<InstBindlessCheckPass>(
  4609. defs_before + func_before, defs_after + func_after + output_func, true,
  4610. true, 7u, 23u, false, false, 2u);
  4611. }
  4612. TEST_F(InstBindlessTest, InstrumentOpImageV2) {
  4613. // This test verifies that the pass will correctly instrument shader
  4614. // using OpImage. This test was created by editing the SPIR-V
  4615. // from the Simple test.
  4616. const std::string defs_before =
  4617. R"(OpCapability Shader
  4618. OpCapability StorageImageReadWithoutFormat
  4619. %1 = OpExtInstImport "GLSL.std.450"
  4620. OpMemoryModel Logical GLSL450
  4621. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  4622. OpExecutionMode %MainPs OriginUpperLeft
  4623. OpSource HLSL 500
  4624. OpName %MainPs "MainPs"
  4625. OpName %g_tColor "g_tColor"
  4626. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  4627. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  4628. OpName %_ ""
  4629. OpName %i_vTextureCoords "i.vTextureCoords"
  4630. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  4631. OpDecorate %g_tColor DescriptorSet 3
  4632. OpDecorate %g_tColor Binding 0
  4633. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  4634. OpDecorate %PerViewConstantBuffer_t Block
  4635. OpDecorate %i_vTextureCoords Location 0
  4636. OpDecorate %_entryPointOutput_vColor Location 0
  4637. %void = OpTypeVoid
  4638. %3 = OpTypeFunction %void
  4639. %float = OpTypeFloat 32
  4640. %v4float = OpTypeVector %float 4
  4641. %int = OpTypeInt 32 1
  4642. %v2int = OpTypeVector %int 2
  4643. %int_0 = OpConstant %int 0
  4644. %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
  4645. %uint = OpTypeInt 32 0
  4646. %uint_128 = OpConstant %uint 128
  4647. %39 = OpTypeSampledImage %20
  4648. %_arr_39_uint_128 = OpTypeArray %39 %uint_128
  4649. %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
  4650. %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
  4651. %PerViewConstantBuffer_t = OpTypeStruct %uint
  4652. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  4653. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  4654. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  4655. %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
  4656. %_ptr_Input_v2int = OpTypePointer Input %v2int
  4657. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  4658. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4659. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  4660. )";
  4661. const std::string defs_after =
  4662. R"(OpCapability Shader
  4663. OpCapability StorageImageReadWithoutFormat
  4664. OpExtension "SPV_KHR_storage_buffer_storage_class"
  4665. %1 = OpExtInstImport "GLSL.std.450"
  4666. OpMemoryModel Logical GLSL450
  4667. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  4668. OpExecutionMode %MainPs OriginUpperLeft
  4669. OpSource HLSL 500
  4670. OpName %MainPs "MainPs"
  4671. OpName %g_tColor "g_tColor"
  4672. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  4673. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  4674. OpName %_ ""
  4675. OpName %i_vTextureCoords "i.vTextureCoords"
  4676. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  4677. OpDecorate %g_tColor DescriptorSet 3
  4678. OpDecorate %g_tColor Binding 0
  4679. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  4680. OpDecorate %PerViewConstantBuffer_t Block
  4681. OpDecorate %i_vTextureCoords Location 0
  4682. OpDecorate %_entryPointOutput_vColor Location 0
  4683. OpDecorate %_runtimearr_uint ArrayStride 4
  4684. OpDecorate %_struct_51 Block
  4685. OpMemberDecorate %_struct_51 0 Offset 0
  4686. OpMemberDecorate %_struct_51 1 Offset 4
  4687. OpDecorate %53 DescriptorSet 7
  4688. OpDecorate %53 Binding 0
  4689. OpDecorate %gl_FragCoord BuiltIn FragCoord
  4690. %void = OpTypeVoid
  4691. %9 = OpTypeFunction %void
  4692. %float = OpTypeFloat 32
  4693. %v4float = OpTypeVector %float 4
  4694. %int = OpTypeInt 32 1
  4695. %v2int = OpTypeVector %int 2
  4696. %int_0 = OpConstant %int 0
  4697. %15 = OpTypeImage %float 2D 0 0 0 0 Unknown
  4698. %uint = OpTypeInt 32 0
  4699. %uint_128 = OpConstant %uint 128
  4700. %18 = OpTypeSampledImage %15
  4701. %_arr_18_uint_128 = OpTypeArray %18 %uint_128
  4702. %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
  4703. %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
  4704. %PerViewConstantBuffer_t = OpTypeStruct %uint
  4705. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  4706. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  4707. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  4708. %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
  4709. %_ptr_Input_v2int = OpTypePointer Input %v2int
  4710. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  4711. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4712. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  4713. %uint_0 = OpConstant %uint 0
  4714. %bool = OpTypeBool
  4715. %44 = OpTypeFunction %void %uint %uint %uint %uint
  4716. %_runtimearr_uint = OpTypeRuntimeArray %uint
  4717. %_struct_51 = OpTypeStruct %uint %_runtimearr_uint
  4718. %_ptr_StorageBuffer__struct_51 = OpTypePointer StorageBuffer %_struct_51
  4719. %53 = OpVariable %_ptr_StorageBuffer__struct_51 StorageBuffer
  4720. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  4721. %uint_10 = OpConstant %uint 10
  4722. %uint_4 = OpConstant %uint 4
  4723. %uint_1 = OpConstant %uint 1
  4724. %uint_23 = OpConstant %uint 23
  4725. %uint_2 = OpConstant %uint 2
  4726. %uint_3 = OpConstant %uint 3
  4727. %_ptr_Input_v4float = OpTypePointer Input %v4float
  4728. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  4729. %v4uint = OpTypeVector %uint 4
  4730. %uint_5 = OpConstant %uint 5
  4731. %uint_7 = OpConstant %uint 7
  4732. %uint_8 = OpConstant %uint 8
  4733. %uint_9 = OpConstant %uint 9
  4734. %uint_51 = OpConstant %uint 51
  4735. %99 = OpConstantNull %v4float
  4736. )";
  4737. const std::string func_before =
  4738. R"(%MainPs = OpFunction %void None %3
  4739. %5 = OpLabel
  4740. %53 = OpLoad %v2int %i_vTextureCoords
  4741. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  4742. %64 = OpLoad %uint %63
  4743. %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
  4744. %66 = OpLoad %39 %65
  4745. %75 = OpImage %20 %66
  4746. %71 = OpImageRead %v4float %75 %53
  4747. OpStore %_entryPointOutput_vColor %71
  4748. OpReturn
  4749. OpFunctionEnd
  4750. )";
  4751. const std::string func_after =
  4752. R"(%MainPs = OpFunction %void None %9
  4753. %26 = OpLabel
  4754. %27 = OpLoad %v2int %i_vTextureCoords
  4755. %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  4756. %29 = OpLoad %uint %28
  4757. %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
  4758. %31 = OpLoad %18 %30
  4759. %32 = OpImage %15 %31
  4760. %36 = OpULessThan %bool %29 %uint_128
  4761. OpSelectionMerge %37 None
  4762. OpBranchConditional %36 %38 %39
  4763. %38 = OpLabel
  4764. %40 = OpLoad %18 %30
  4765. %41 = OpImage %15 %40
  4766. %42 = OpImageRead %v4float %41 %27
  4767. OpBranch %37
  4768. %39 = OpLabel
  4769. %98 = OpFunctionCall %void %43 %uint_51 %uint_0 %29 %uint_128
  4770. OpBranch %37
  4771. %37 = OpLabel
  4772. %100 = OpPhi %v4float %42 %38 %99 %39
  4773. OpStore %_entryPointOutput_vColor %100
  4774. OpReturn
  4775. OpFunctionEnd
  4776. )";
  4777. const std::string output_func =
  4778. R"(%43 = OpFunction %void None %44
  4779. %45 = OpFunctionParameter %uint
  4780. %46 = OpFunctionParameter %uint
  4781. %47 = OpFunctionParameter %uint
  4782. %48 = OpFunctionParameter %uint
  4783. %49 = OpLabel
  4784. %55 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_0
  4785. %58 = OpAtomicIAdd %uint %55 %uint_4 %uint_0 %uint_10
  4786. %59 = OpIAdd %uint %58 %uint_10
  4787. %60 = OpArrayLength %uint %53 1
  4788. %61 = OpULessThanEqual %bool %59 %60
  4789. OpSelectionMerge %62 None
  4790. OpBranchConditional %61 %63 %62
  4791. %63 = OpLabel
  4792. %64 = OpIAdd %uint %58 %uint_0
  4793. %66 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %64
  4794. OpStore %66 %uint_10
  4795. %68 = OpIAdd %uint %58 %uint_1
  4796. %69 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %68
  4797. OpStore %69 %uint_23
  4798. %71 = OpIAdd %uint %58 %uint_2
  4799. %72 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %71
  4800. OpStore %72 %45
  4801. %74 = OpIAdd %uint %58 %uint_3
  4802. %75 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %74
  4803. OpStore %75 %uint_4
  4804. %78 = OpLoad %v4float %gl_FragCoord
  4805. %80 = OpBitcast %v4uint %78
  4806. %81 = OpCompositeExtract %uint %80 0
  4807. %82 = OpIAdd %uint %58 %uint_4
  4808. %83 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %82
  4809. OpStore %83 %81
  4810. %84 = OpCompositeExtract %uint %80 1
  4811. %86 = OpIAdd %uint %58 %uint_5
  4812. %87 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %86
  4813. OpStore %87 %84
  4814. %89 = OpIAdd %uint %58 %uint_7
  4815. %90 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %89
  4816. OpStore %90 %46
  4817. %92 = OpIAdd %uint %58 %uint_8
  4818. %93 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %92
  4819. OpStore %93 %47
  4820. %95 = OpIAdd %uint %58 %uint_9
  4821. %96 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %95
  4822. OpStore %96 %48
  4823. OpBranch %62
  4824. %62 = OpLabel
  4825. OpReturn
  4826. OpFunctionEnd
  4827. )";
  4828. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  4829. SinglePassRunAndCheck<InstBindlessCheckPass>(
  4830. defs_before + func_before, defs_after + func_after + output_func, true,
  4831. true, 7u, 23u, false, false, 2u);
  4832. }
  4833. TEST_F(InstBindlessTest, InstrumentSampledImageV2) {
  4834. // This test verifies that the pass will correctly instrument shader
  4835. // using sampled image. This test was created by editing the SPIR-V
  4836. // from the Simple test.
  4837. const std::string defs_before =
  4838. R"(OpCapability Shader
  4839. %1 = OpExtInstImport "GLSL.std.450"
  4840. OpMemoryModel Logical GLSL450
  4841. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  4842. OpExecutionMode %MainPs OriginUpperLeft
  4843. OpSource HLSL 500
  4844. OpName %MainPs "MainPs"
  4845. OpName %g_tColor "g_tColor"
  4846. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  4847. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  4848. OpName %_ ""
  4849. OpName %i_vTextureCoords "i.vTextureCoords"
  4850. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  4851. OpDecorate %g_tColor DescriptorSet 3
  4852. OpDecorate %g_tColor Binding 0
  4853. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  4854. OpDecorate %PerViewConstantBuffer_t Block
  4855. OpDecorate %i_vTextureCoords Location 0
  4856. OpDecorate %_entryPointOutput_vColor Location 0
  4857. %void = OpTypeVoid
  4858. %3 = OpTypeFunction %void
  4859. %float = OpTypeFloat 32
  4860. %v2float = OpTypeVector %float 2
  4861. %v4float = OpTypeVector %float 4
  4862. %int = OpTypeInt 32 1
  4863. %int_0 = OpConstant %int 0
  4864. %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
  4865. %uint = OpTypeInt 32 0
  4866. %uint_128 = OpConstant %uint 128
  4867. %39 = OpTypeSampledImage %20
  4868. %_arr_39_uint_128 = OpTypeArray %39 %uint_128
  4869. %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
  4870. %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
  4871. %PerViewConstantBuffer_t = OpTypeStruct %uint
  4872. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  4873. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  4874. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  4875. %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
  4876. %_ptr_Input_v2float = OpTypePointer Input %v2float
  4877. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  4878. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4879. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  4880. )";
  4881. const std::string defs_after =
  4882. R"(OpCapability Shader
  4883. OpExtension "SPV_KHR_storage_buffer_storage_class"
  4884. %1 = OpExtInstImport "GLSL.std.450"
  4885. OpMemoryModel Logical GLSL450
  4886. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  4887. OpExecutionMode %MainPs OriginUpperLeft
  4888. OpSource HLSL 500
  4889. OpName %MainPs "MainPs"
  4890. OpName %g_tColor "g_tColor"
  4891. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  4892. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  4893. OpName %_ ""
  4894. OpName %i_vTextureCoords "i.vTextureCoords"
  4895. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  4896. OpDecorate %g_tColor DescriptorSet 3
  4897. OpDecorate %g_tColor Binding 0
  4898. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  4899. OpDecorate %PerViewConstantBuffer_t Block
  4900. OpDecorate %i_vTextureCoords Location 0
  4901. OpDecorate %_entryPointOutput_vColor Location 0
  4902. OpDecorate %_runtimearr_uint ArrayStride 4
  4903. OpDecorate %_struct_49 Block
  4904. OpMemberDecorate %_struct_49 0 Offset 0
  4905. OpMemberDecorate %_struct_49 1 Offset 4
  4906. OpDecorate %51 DescriptorSet 7
  4907. OpDecorate %51 Binding 0
  4908. OpDecorate %gl_FragCoord BuiltIn FragCoord
  4909. %void = OpTypeVoid
  4910. %9 = OpTypeFunction %void
  4911. %float = OpTypeFloat 32
  4912. %v2float = OpTypeVector %float 2
  4913. %v4float = OpTypeVector %float 4
  4914. %int = OpTypeInt 32 1
  4915. %int_0 = OpConstant %int 0
  4916. %15 = OpTypeImage %float 2D 0 0 0 1 Unknown
  4917. %uint = OpTypeInt 32 0
  4918. %uint_128 = OpConstant %uint 128
  4919. %18 = OpTypeSampledImage %15
  4920. %_arr_18_uint_128 = OpTypeArray %18 %uint_128
  4921. %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
  4922. %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
  4923. %PerViewConstantBuffer_t = OpTypeStruct %uint
  4924. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  4925. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  4926. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  4927. %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
  4928. %_ptr_Input_v2float = OpTypePointer Input %v2float
  4929. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  4930. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4931. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  4932. %uint_0 = OpConstant %uint 0
  4933. %bool = OpTypeBool
  4934. %42 = OpTypeFunction %void %uint %uint %uint %uint
  4935. %_runtimearr_uint = OpTypeRuntimeArray %uint
  4936. %_struct_49 = OpTypeStruct %uint %_runtimearr_uint
  4937. %_ptr_StorageBuffer__struct_49 = OpTypePointer StorageBuffer %_struct_49
  4938. %51 = OpVariable %_ptr_StorageBuffer__struct_49 StorageBuffer
  4939. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  4940. %uint_10 = OpConstant %uint 10
  4941. %uint_4 = OpConstant %uint 4
  4942. %uint_1 = OpConstant %uint 1
  4943. %uint_23 = OpConstant %uint 23
  4944. %uint_2 = OpConstant %uint 2
  4945. %uint_3 = OpConstant %uint 3
  4946. %_ptr_Input_v4float = OpTypePointer Input %v4float
  4947. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  4948. %v4uint = OpTypeVector %uint 4
  4949. %uint_5 = OpConstant %uint 5
  4950. %uint_7 = OpConstant %uint 7
  4951. %uint_8 = OpConstant %uint 8
  4952. %uint_9 = OpConstant %uint 9
  4953. %uint_49 = OpConstant %uint 49
  4954. %97 = OpConstantNull %v4float
  4955. )";
  4956. const std::string func_before =
  4957. R"(%MainPs = OpFunction %void None %3
  4958. %5 = OpLabel
  4959. %53 = OpLoad %v2float %i_vTextureCoords
  4960. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  4961. %64 = OpLoad %uint %63
  4962. %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
  4963. %66 = OpLoad %39 %65
  4964. %71 = OpImageSampleImplicitLod %v4float %66 %53
  4965. OpStore %_entryPointOutput_vColor %71
  4966. OpReturn
  4967. OpFunctionEnd
  4968. )";
  4969. const std::string func_after =
  4970. R"(%MainPs = OpFunction %void None %9
  4971. %26 = OpLabel
  4972. %27 = OpLoad %v2float %i_vTextureCoords
  4973. %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  4974. %29 = OpLoad %uint %28
  4975. %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
  4976. %31 = OpLoad %18 %30
  4977. %35 = OpULessThan %bool %29 %uint_128
  4978. OpSelectionMerge %36 None
  4979. OpBranchConditional %35 %37 %38
  4980. %37 = OpLabel
  4981. %39 = OpLoad %18 %30
  4982. %40 = OpImageSampleImplicitLod %v4float %39 %27
  4983. OpBranch %36
  4984. %38 = OpLabel
  4985. %96 = OpFunctionCall %void %41 %uint_49 %uint_0 %29 %uint_128
  4986. OpBranch %36
  4987. %36 = OpLabel
  4988. %98 = OpPhi %v4float %40 %37 %97 %38
  4989. OpStore %_entryPointOutput_vColor %98
  4990. OpReturn
  4991. OpFunctionEnd
  4992. )";
  4993. const std::string output_func =
  4994. R"(%41 = OpFunction %void None %42
  4995. %43 = OpFunctionParameter %uint
  4996. %44 = OpFunctionParameter %uint
  4997. %45 = OpFunctionParameter %uint
  4998. %46 = OpFunctionParameter %uint
  4999. %47 = OpLabel
  5000. %53 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_0
  5001. %56 = OpAtomicIAdd %uint %53 %uint_4 %uint_0 %uint_10
  5002. %57 = OpIAdd %uint %56 %uint_10
  5003. %58 = OpArrayLength %uint %51 1
  5004. %59 = OpULessThanEqual %bool %57 %58
  5005. OpSelectionMerge %60 None
  5006. OpBranchConditional %59 %61 %60
  5007. %61 = OpLabel
  5008. %62 = OpIAdd %uint %56 %uint_0
  5009. %64 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %62
  5010. OpStore %64 %uint_10
  5011. %66 = OpIAdd %uint %56 %uint_1
  5012. %67 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %66
  5013. OpStore %67 %uint_23
  5014. %69 = OpIAdd %uint %56 %uint_2
  5015. %70 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %69
  5016. OpStore %70 %43
  5017. %72 = OpIAdd %uint %56 %uint_3
  5018. %73 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %72
  5019. OpStore %73 %uint_4
  5020. %76 = OpLoad %v4float %gl_FragCoord
  5021. %78 = OpBitcast %v4uint %76
  5022. %79 = OpCompositeExtract %uint %78 0
  5023. %80 = OpIAdd %uint %56 %uint_4
  5024. %81 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %80
  5025. OpStore %81 %79
  5026. %82 = OpCompositeExtract %uint %78 1
  5027. %84 = OpIAdd %uint %56 %uint_5
  5028. %85 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %84
  5029. OpStore %85 %82
  5030. %87 = OpIAdd %uint %56 %uint_7
  5031. %88 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %87
  5032. OpStore %88 %44
  5033. %90 = OpIAdd %uint %56 %uint_8
  5034. %91 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %90
  5035. OpStore %91 %45
  5036. %93 = OpIAdd %uint %56 %uint_9
  5037. %94 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %93
  5038. OpStore %94 %46
  5039. OpBranch %60
  5040. %60 = OpLabel
  5041. OpReturn
  5042. OpFunctionEnd
  5043. )";
  5044. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  5045. SinglePassRunAndCheck<InstBindlessCheckPass>(
  5046. defs_before + func_before, defs_after + func_after + output_func, true,
  5047. true, 7u, 23u, false, false, 2u);
  5048. }
  5049. TEST_F(InstBindlessTest, InstrumentImageWriteV2) {
  5050. // This test verifies that the pass will correctly instrument shader
  5051. // doing bindless image write. This test was created by editing the SPIR-V
  5052. // from the Simple test.
  5053. const std::string defs_before =
  5054. R"(OpCapability Shader
  5055. OpCapability StorageImageWriteWithoutFormat
  5056. %1 = OpExtInstImport "GLSL.std.450"
  5057. OpMemoryModel Logical GLSL450
  5058. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  5059. OpExecutionMode %MainPs OriginUpperLeft
  5060. OpSource HLSL 500
  5061. OpName %MainPs "MainPs"
  5062. OpName %g_tColor "g_tColor"
  5063. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  5064. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  5065. OpName %_ ""
  5066. OpName %i_vTextureCoords "i.vTextureCoords"
  5067. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  5068. OpDecorate %g_tColor DescriptorSet 3
  5069. OpDecorate %g_tColor Binding 0
  5070. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  5071. OpDecorate %PerViewConstantBuffer_t Block
  5072. OpDecorate %i_vTextureCoords Location 0
  5073. OpDecorate %_entryPointOutput_vColor Location 0
  5074. %void = OpTypeVoid
  5075. %3 = OpTypeFunction %void
  5076. %float = OpTypeFloat 32
  5077. %v2float = OpTypeVector %float 2
  5078. %v4float = OpTypeVector %float 4
  5079. %int = OpTypeInt 32 1
  5080. %v2int = OpTypeVector %int 2
  5081. %int_0 = OpConstant %int 0
  5082. %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
  5083. %uint = OpTypeInt 32 0
  5084. %uint_128 = OpConstant %uint 128
  5085. %80 = OpConstantNull %v4float
  5086. %_arr_20_uint_128 = OpTypeArray %20 %uint_128
  5087. %_ptr_UniformConstant__arr_20_uint_128 = OpTypePointer UniformConstant %_arr_20_uint_128
  5088. %g_tColor = OpVariable %_ptr_UniformConstant__arr_20_uint_128 UniformConstant
  5089. %PerViewConstantBuffer_t = OpTypeStruct %uint
  5090. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  5091. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  5092. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  5093. %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
  5094. %_ptr_Input_v2int = OpTypePointer Input %v2int
  5095. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  5096. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5097. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  5098. )";
  5099. const std::string defs_after =
  5100. R"(OpCapability Shader
  5101. OpCapability StorageImageWriteWithoutFormat
  5102. OpExtension "SPV_KHR_storage_buffer_storage_class"
  5103. %1 = OpExtInstImport "GLSL.std.450"
  5104. OpMemoryModel Logical GLSL450
  5105. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  5106. OpExecutionMode %MainPs OriginUpperLeft
  5107. OpSource HLSL 500
  5108. OpName %MainPs "MainPs"
  5109. OpName %g_tColor "g_tColor"
  5110. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  5111. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  5112. OpName %_ ""
  5113. OpName %i_vTextureCoords "i.vTextureCoords"
  5114. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  5115. OpDecorate %g_tColor DescriptorSet 3
  5116. OpDecorate %g_tColor Binding 0
  5117. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  5118. OpDecorate %PerViewConstantBuffer_t Block
  5119. OpDecorate %i_vTextureCoords Location 0
  5120. OpDecorate %_entryPointOutput_vColor Location 0
  5121. OpDecorate %_runtimearr_uint ArrayStride 4
  5122. OpDecorate %_struct_48 Block
  5123. OpMemberDecorate %_struct_48 0 Offset 0
  5124. OpMemberDecorate %_struct_48 1 Offset 4
  5125. OpDecorate %50 DescriptorSet 7
  5126. OpDecorate %50 Binding 0
  5127. OpDecorate %gl_FragCoord BuiltIn FragCoord
  5128. %void = OpTypeVoid
  5129. %9 = OpTypeFunction %void
  5130. %float = OpTypeFloat 32
  5131. %v2float = OpTypeVector %float 2
  5132. %v4float = OpTypeVector %float 4
  5133. %int = OpTypeInt 32 1
  5134. %v2int = OpTypeVector %int 2
  5135. %int_0 = OpConstant %int 0
  5136. %16 = OpTypeImage %float 2D 0 0 0 0 Unknown
  5137. %uint = OpTypeInt 32 0
  5138. %uint_128 = OpConstant %uint 128
  5139. %19 = OpConstantNull %v4float
  5140. %_arr_16_uint_128 = OpTypeArray %16 %uint_128
  5141. %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
  5142. %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
  5143. %PerViewConstantBuffer_t = OpTypeStruct %uint
  5144. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  5145. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  5146. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  5147. %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
  5148. %_ptr_Input_v2int = OpTypePointer Input %v2int
  5149. %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
  5150. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5151. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  5152. %uint_0 = OpConstant %uint 0
  5153. %bool = OpTypeBool
  5154. %41 = OpTypeFunction %void %uint %uint %uint %uint
  5155. %_runtimearr_uint = OpTypeRuntimeArray %uint
  5156. %_struct_48 = OpTypeStruct %uint %_runtimearr_uint
  5157. %_ptr_StorageBuffer__struct_48 = OpTypePointer StorageBuffer %_struct_48
  5158. %50 = OpVariable %_ptr_StorageBuffer__struct_48 StorageBuffer
  5159. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  5160. %uint_10 = OpConstant %uint 10
  5161. %uint_4 = OpConstant %uint 4
  5162. %uint_1 = OpConstant %uint 1
  5163. %uint_23 = OpConstant %uint 23
  5164. %uint_2 = OpConstant %uint 2
  5165. %uint_3 = OpConstant %uint 3
  5166. %_ptr_Input_v4float = OpTypePointer Input %v4float
  5167. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  5168. %v4uint = OpTypeVector %uint 4
  5169. %uint_5 = OpConstant %uint 5
  5170. %uint_7 = OpConstant %uint 7
  5171. %uint_8 = OpConstant %uint 8
  5172. %uint_9 = OpConstant %uint 9
  5173. %uint_51 = OpConstant %uint 51
  5174. )";
  5175. const std::string func_before =
  5176. R"(%MainPs = OpFunction %void None %3
  5177. %5 = OpLabel
  5178. %53 = OpLoad %v2int %i_vTextureCoords
  5179. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  5180. %64 = OpLoad %uint %63
  5181. %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
  5182. %66 = OpLoad %20 %65
  5183. OpImageWrite %66 %53 %80
  5184. OpStore %_entryPointOutput_vColor %80
  5185. OpReturn
  5186. OpFunctionEnd
  5187. )";
  5188. const std::string func_after =
  5189. R"(%MainPs = OpFunction %void None %9
  5190. %27 = OpLabel
  5191. %28 = OpLoad %v2int %i_vTextureCoords
  5192. %29 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  5193. %30 = OpLoad %uint %29
  5194. %31 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %30
  5195. %32 = OpLoad %16 %31
  5196. %35 = OpULessThan %bool %30 %uint_128
  5197. OpSelectionMerge %36 None
  5198. OpBranchConditional %35 %37 %38
  5199. %37 = OpLabel
  5200. %39 = OpLoad %16 %31
  5201. OpImageWrite %39 %28 %19
  5202. OpBranch %36
  5203. %38 = OpLabel
  5204. %95 = OpFunctionCall %void %40 %uint_51 %uint_0 %30 %uint_128
  5205. OpBranch %36
  5206. %36 = OpLabel
  5207. OpStore %_entryPointOutput_vColor %19
  5208. OpReturn
  5209. OpFunctionEnd
  5210. )";
  5211. const std::string output_func =
  5212. R"(%40 = OpFunction %void None %41
  5213. %42 = OpFunctionParameter %uint
  5214. %43 = OpFunctionParameter %uint
  5215. %44 = OpFunctionParameter %uint
  5216. %45 = OpFunctionParameter %uint
  5217. %46 = OpLabel
  5218. %52 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_0
  5219. %55 = OpAtomicIAdd %uint %52 %uint_4 %uint_0 %uint_10
  5220. %56 = OpIAdd %uint %55 %uint_10
  5221. %57 = OpArrayLength %uint %50 1
  5222. %58 = OpULessThanEqual %bool %56 %57
  5223. OpSelectionMerge %59 None
  5224. OpBranchConditional %58 %60 %59
  5225. %60 = OpLabel
  5226. %61 = OpIAdd %uint %55 %uint_0
  5227. %63 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %61
  5228. OpStore %63 %uint_10
  5229. %65 = OpIAdd %uint %55 %uint_1
  5230. %66 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %65
  5231. OpStore %66 %uint_23
  5232. %68 = OpIAdd %uint %55 %uint_2
  5233. %69 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %68
  5234. OpStore %69 %42
  5235. %71 = OpIAdd %uint %55 %uint_3
  5236. %72 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %71
  5237. OpStore %72 %uint_4
  5238. %75 = OpLoad %v4float %gl_FragCoord
  5239. %77 = OpBitcast %v4uint %75
  5240. %78 = OpCompositeExtract %uint %77 0
  5241. %79 = OpIAdd %uint %55 %uint_4
  5242. %80 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %79
  5243. OpStore %80 %78
  5244. %81 = OpCompositeExtract %uint %77 1
  5245. %83 = OpIAdd %uint %55 %uint_5
  5246. %84 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %83
  5247. OpStore %84 %81
  5248. %86 = OpIAdd %uint %55 %uint_7
  5249. %87 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %86
  5250. OpStore %87 %43
  5251. %89 = OpIAdd %uint %55 %uint_8
  5252. %90 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %89
  5253. OpStore %90 %44
  5254. %92 = OpIAdd %uint %55 %uint_9
  5255. %93 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %92
  5256. OpStore %93 %45
  5257. OpBranch %59
  5258. %59 = OpLabel
  5259. OpReturn
  5260. OpFunctionEnd
  5261. )";
  5262. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  5263. SinglePassRunAndCheck<InstBindlessCheckPass>(
  5264. defs_before + func_before, defs_after + func_after + output_func, true,
  5265. true, 7u, 23u, false, false, 2u);
  5266. }
  5267. TEST_F(InstBindlessTest, InstrumentVertexSimpleV2) {
  5268. // This test verifies that the pass will correctly instrument shader
  5269. // doing bindless image write. This test was created by editing the SPIR-V
  5270. // from the Simple test.
  5271. const std::string defs_before =
  5272. R"(OpCapability Shader
  5273. OpCapability Sampled1D
  5274. %1 = OpExtInstImport "GLSL.std.450"
  5275. OpMemoryModel Logical GLSL450
  5276. OpEntryPoint Vertex %main "main" %_ %coords2D
  5277. OpSource GLSL 450
  5278. OpName %main "main"
  5279. OpName %lod "lod"
  5280. OpName %coords1D "coords1D"
  5281. OpName %gl_PerVertex "gl_PerVertex"
  5282. OpMemberName %gl_PerVertex 0 "gl_Position"
  5283. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  5284. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  5285. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  5286. OpName %_ ""
  5287. OpName %texSampler1D "texSampler1D"
  5288. OpName %foo "foo"
  5289. OpMemberName %foo 0 "g_idx"
  5290. OpName %__0 ""
  5291. OpName %coords2D "coords2D"
  5292. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  5293. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  5294. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  5295. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  5296. OpDecorate %gl_PerVertex Block
  5297. OpDecorate %texSampler1D DescriptorSet 0
  5298. OpDecorate %texSampler1D Binding 3
  5299. OpMemberDecorate %foo 0 Offset 0
  5300. OpDecorate %foo Block
  5301. OpDecorate %__0 DescriptorSet 0
  5302. OpDecorate %__0 Binding 5
  5303. OpDecorate %coords2D Location 0
  5304. %void = OpTypeVoid
  5305. %3 = OpTypeFunction %void
  5306. %float = OpTypeFloat 32
  5307. %_ptr_Function_float = OpTypePointer Function %float
  5308. %float_3 = OpConstant %float 3
  5309. %float_1_78900003 = OpConstant %float 1.78900003
  5310. %v4float = OpTypeVector %float 4
  5311. %uint = OpTypeInt 32 0
  5312. %uint_1 = OpConstant %uint 1
  5313. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  5314. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  5315. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  5316. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  5317. %int = OpTypeInt 32 1
  5318. %int_0 = OpConstant %int 0
  5319. %21 = OpTypeImage %float 1D 0 0 0 1 Unknown
  5320. %22 = OpTypeSampledImage %21
  5321. %uint_128 = OpConstant %uint 128
  5322. %_arr_22_uint_128 = OpTypeArray %22 %uint_128
  5323. %_ptr_UniformConstant__arr_22_uint_128 = OpTypePointer UniformConstant %_arr_22_uint_128
  5324. %texSampler1D = OpVariable %_ptr_UniformConstant__arr_22_uint_128 UniformConstant
  5325. %foo = OpTypeStruct %int
  5326. %_ptr_Uniform_foo = OpTypePointer Uniform %foo
  5327. %__0 = OpVariable %_ptr_Uniform_foo Uniform
  5328. %_ptr_Uniform_int = OpTypePointer Uniform %int
  5329. %_ptr_UniformConstant_22 = OpTypePointer UniformConstant %22
  5330. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5331. %v2float = OpTypeVector %float 2
  5332. %_ptr_Input_v2float = OpTypePointer Input %v2float
  5333. %coords2D = OpVariable %_ptr_Input_v2float Input
  5334. )";
  5335. const std::string defs_after =
  5336. R"(OpCapability Shader
  5337. OpCapability Sampled1D
  5338. OpExtension "SPV_KHR_storage_buffer_storage_class"
  5339. %1 = OpExtInstImport "GLSL.std.450"
  5340. OpMemoryModel Logical GLSL450
  5341. OpEntryPoint Vertex %main "main" %_ %coords2D %gl_VertexIndex %gl_InstanceIndex
  5342. OpSource GLSL 450
  5343. OpName %main "main"
  5344. OpName %lod "lod"
  5345. OpName %coords1D "coords1D"
  5346. OpName %gl_PerVertex "gl_PerVertex"
  5347. OpMemberName %gl_PerVertex 0 "gl_Position"
  5348. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  5349. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  5350. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  5351. OpName %_ ""
  5352. OpName %texSampler1D "texSampler1D"
  5353. OpName %foo "foo"
  5354. OpMemberName %foo 0 "g_idx"
  5355. OpName %__0 ""
  5356. OpName %coords2D "coords2D"
  5357. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  5358. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  5359. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  5360. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  5361. OpDecorate %gl_PerVertex Block
  5362. OpDecorate %texSampler1D DescriptorSet 0
  5363. OpDecorate %texSampler1D Binding 3
  5364. OpMemberDecorate %foo 0 Offset 0
  5365. OpDecorate %foo Block
  5366. OpDecorate %__0 DescriptorSet 0
  5367. OpDecorate %__0 Binding 5
  5368. OpDecorate %coords2D Location 0
  5369. OpDecorate %_runtimearr_uint ArrayStride 4
  5370. OpDecorate %_struct_61 Block
  5371. OpMemberDecorate %_struct_61 0 Offset 0
  5372. OpMemberDecorate %_struct_61 1 Offset 4
  5373. OpDecorate %63 DescriptorSet 7
  5374. OpDecorate %63 Binding 0
  5375. OpDecorate %gl_VertexIndex BuiltIn VertexIndex
  5376. OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
  5377. %void = OpTypeVoid
  5378. %12 = OpTypeFunction %void
  5379. %float = OpTypeFloat 32
  5380. %_ptr_Function_float = OpTypePointer Function %float
  5381. %float_3 = OpConstant %float 3
  5382. %float_1_78900003 = OpConstant %float 1.78900003
  5383. %v4float = OpTypeVector %float 4
  5384. %uint = OpTypeInt 32 0
  5385. %uint_1 = OpConstant %uint 1
  5386. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  5387. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  5388. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  5389. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  5390. %int = OpTypeInt 32 1
  5391. %int_0 = OpConstant %int 0
  5392. %24 = OpTypeImage %float 1D 0 0 0 1 Unknown
  5393. %25 = OpTypeSampledImage %24
  5394. %uint_128 = OpConstant %uint 128
  5395. %_arr_25_uint_128 = OpTypeArray %25 %uint_128
  5396. %_ptr_UniformConstant__arr_25_uint_128 = OpTypePointer UniformConstant %_arr_25_uint_128
  5397. %texSampler1D = OpVariable %_ptr_UniformConstant__arr_25_uint_128 UniformConstant
  5398. %foo = OpTypeStruct %int
  5399. %_ptr_Uniform_foo = OpTypePointer Uniform %foo
  5400. %__0 = OpVariable %_ptr_Uniform_foo Uniform
  5401. %_ptr_Uniform_int = OpTypePointer Uniform %int
  5402. %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
  5403. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5404. %v2float = OpTypeVector %float 2
  5405. %_ptr_Input_v2float = OpTypePointer Input %v2float
  5406. %coords2D = OpVariable %_ptr_Input_v2float Input
  5407. %uint_0 = OpConstant %uint 0
  5408. %bool = OpTypeBool
  5409. %54 = OpTypeFunction %void %uint %uint %uint %uint
  5410. %_runtimearr_uint = OpTypeRuntimeArray %uint
  5411. %_struct_61 = OpTypeStruct %uint %_runtimearr_uint
  5412. %_ptr_StorageBuffer__struct_61 = OpTypePointer StorageBuffer %_struct_61
  5413. %63 = OpVariable %_ptr_StorageBuffer__struct_61 StorageBuffer
  5414. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  5415. %uint_10 = OpConstant %uint 10
  5416. %uint_4 = OpConstant %uint 4
  5417. %uint_23 = OpConstant %uint 23
  5418. %uint_2 = OpConstant %uint 2
  5419. %uint_3 = OpConstant %uint 3
  5420. %_ptr_Input_uint = OpTypePointer Input %uint
  5421. %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
  5422. %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
  5423. %uint_5 = OpConstant %uint 5
  5424. %uint_7 = OpConstant %uint 7
  5425. %uint_8 = OpConstant %uint 8
  5426. %uint_9 = OpConstant %uint 9
  5427. %uint_74 = OpConstant %uint 74
  5428. %106 = OpConstantNull %v4float
  5429. )";
  5430. const std::string func_before =
  5431. R"(%main = OpFunction %void None %3
  5432. %5 = OpLabel
  5433. %lod = OpVariable %_ptr_Function_float Function
  5434. %coords1D = OpVariable %_ptr_Function_float Function
  5435. OpStore %lod %float_3
  5436. OpStore %coords1D %float_1_78900003
  5437. %31 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
  5438. %32 = OpLoad %int %31
  5439. %34 = OpAccessChain %_ptr_UniformConstant_22 %texSampler1D %32
  5440. %35 = OpLoad %22 %34
  5441. %36 = OpLoad %float %coords1D
  5442. %37 = OpLoad %float %lod
  5443. %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
  5444. %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  5445. OpStore %40 %38
  5446. OpReturn
  5447. OpFunctionEnd
  5448. )";
  5449. const std::string func_after =
  5450. R"(%main = OpFunction %void None %12
  5451. %35 = OpLabel
  5452. %lod = OpVariable %_ptr_Function_float Function
  5453. %coords1D = OpVariable %_ptr_Function_float Function
  5454. OpStore %lod %float_3
  5455. OpStore %coords1D %float_1_78900003
  5456. %36 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
  5457. %37 = OpLoad %int %36
  5458. %38 = OpAccessChain %_ptr_UniformConstant_25 %texSampler1D %37
  5459. %39 = OpLoad %25 %38
  5460. %40 = OpLoad %float %coords1D
  5461. %41 = OpLoad %float %lod
  5462. %46 = OpULessThan %bool %37 %uint_128
  5463. OpSelectionMerge %47 None
  5464. OpBranchConditional %46 %48 %49
  5465. %48 = OpLabel
  5466. %50 = OpLoad %25 %38
  5467. %51 = OpImageSampleExplicitLod %v4float %50 %40 Lod %41
  5468. OpBranch %47
  5469. %49 = OpLabel
  5470. %52 = OpBitcast %uint %37
  5471. %105 = OpFunctionCall %void %53 %uint_74 %uint_0 %52 %uint_128
  5472. OpBranch %47
  5473. %47 = OpLabel
  5474. %107 = OpPhi %v4float %51 %48 %106 %49
  5475. %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  5476. OpStore %43 %107
  5477. OpReturn
  5478. OpFunctionEnd
  5479. )";
  5480. const std::string output_func =
  5481. R"(%53 = OpFunction %void None %54
  5482. %55 = OpFunctionParameter %uint
  5483. %56 = OpFunctionParameter %uint
  5484. %57 = OpFunctionParameter %uint
  5485. %58 = OpFunctionParameter %uint
  5486. %59 = OpLabel
  5487. %65 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_0
  5488. %68 = OpAtomicIAdd %uint %65 %uint_4 %uint_0 %uint_10
  5489. %69 = OpIAdd %uint %68 %uint_10
  5490. %70 = OpArrayLength %uint %63 1
  5491. %71 = OpULessThanEqual %bool %69 %70
  5492. OpSelectionMerge %72 None
  5493. OpBranchConditional %71 %73 %72
  5494. %73 = OpLabel
  5495. %74 = OpIAdd %uint %68 %uint_0
  5496. %75 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %74
  5497. OpStore %75 %uint_10
  5498. %77 = OpIAdd %uint %68 %uint_1
  5499. %78 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %77
  5500. OpStore %78 %uint_23
  5501. %80 = OpIAdd %uint %68 %uint_2
  5502. %81 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %80
  5503. OpStore %81 %55
  5504. %83 = OpIAdd %uint %68 %uint_3
  5505. %84 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %83
  5506. OpStore %84 %uint_0
  5507. %87 = OpLoad %uint %gl_VertexIndex
  5508. %88 = OpIAdd %uint %68 %uint_4
  5509. %89 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %88
  5510. OpStore %89 %87
  5511. %91 = OpLoad %uint %gl_InstanceIndex
  5512. %93 = OpIAdd %uint %68 %uint_5
  5513. %94 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %93
  5514. OpStore %94 %91
  5515. %96 = OpIAdd %uint %68 %uint_7
  5516. %97 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %96
  5517. OpStore %97 %56
  5518. %99 = OpIAdd %uint %68 %uint_8
  5519. %100 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %99
  5520. OpStore %100 %57
  5521. %102 = OpIAdd %uint %68 %uint_9
  5522. %103 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %102
  5523. OpStore %103 %58
  5524. OpBranch %72
  5525. %72 = OpLabel
  5526. OpReturn
  5527. OpFunctionEnd
  5528. )";
  5529. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  5530. SinglePassRunAndCheck<InstBindlessCheckPass>(
  5531. defs_before + func_before, defs_after + func_after + output_func, true,
  5532. true, 7u, 23u, false, false, 2u);
  5533. }
  5534. TEST_F(InstBindlessTest, InstrumentTeseSimpleV2) {
  5535. // This test verifies that the pass will correctly instrument tessellation
  5536. // evaluation shader doing bindless buffer load.
  5537. //
  5538. // clang-format off
  5539. //
  5540. // #version 450
  5541. // #extension GL_EXT_nonuniform_qualifier : enable
  5542. //
  5543. // layout(std140, set = 0, binding = 0) uniform ufoo { uint index; } uniform_index_buffer;
  5544. //
  5545. // layout(set = 0, binding = 1) buffer bfoo { vec4 val; } adds[11];
  5546. //
  5547. // layout(triangles, equal_spacing, cw) in;
  5548. //
  5549. // void main() {
  5550. // gl_Position = adds[uniform_index_buffer.index].val;
  5551. // }
  5552. //
  5553. // clang-format on
  5554. const std::string defs_before =
  5555. R"(OpCapability Tessellation
  5556. %1 = OpExtInstImport "GLSL.std.450"
  5557. OpMemoryModel Logical GLSL450
  5558. OpEntryPoint TessellationEvaluation %main "main" %_
  5559. OpExecutionMode %main Triangles
  5560. OpExecutionMode %main SpacingEqual
  5561. OpExecutionMode %main VertexOrderCw
  5562. OpSource GLSL 450
  5563. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  5564. OpName %main "main"
  5565. OpName %gl_PerVertex "gl_PerVertex"
  5566. OpMemberName %gl_PerVertex 0 "gl_Position"
  5567. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  5568. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  5569. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  5570. OpName %_ ""
  5571. OpName %bfoo "bfoo"
  5572. OpMemberName %bfoo 0 "val"
  5573. OpName %adds "adds"
  5574. OpName %ufoo "ufoo"
  5575. OpMemberName %ufoo 0 "index"
  5576. OpName %uniform_index_buffer "uniform_index_buffer"
  5577. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  5578. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  5579. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  5580. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  5581. OpDecorate %gl_PerVertex Block
  5582. OpMemberDecorate %bfoo 0 Offset 0
  5583. OpDecorate %bfoo Block
  5584. OpDecorate %adds DescriptorSet 0
  5585. OpDecorate %adds Binding 1
  5586. OpMemberDecorate %ufoo 0 Offset 0
  5587. OpDecorate %ufoo Block
  5588. OpDecorate %uniform_index_buffer DescriptorSet 0
  5589. OpDecorate %uniform_index_buffer Binding 0
  5590. %void = OpTypeVoid
  5591. %3 = OpTypeFunction %void
  5592. %float = OpTypeFloat 32
  5593. %v4float = OpTypeVector %float 4
  5594. %uint = OpTypeInt 32 0
  5595. %uint_1 = OpConstant %uint 1
  5596. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  5597. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  5598. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  5599. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  5600. %int = OpTypeInt 32 1
  5601. %int_0 = OpConstant %int 0
  5602. %bfoo = OpTypeStruct %v4float
  5603. %uint_11 = OpConstant %uint 11
  5604. %_arr_bfoo_uint_11 = OpTypeArray %bfoo %uint_11
  5605. %_ptr_StorageBuffer__arr_bfoo_uint_11 = OpTypePointer StorageBuffer %_arr_bfoo_uint_11
  5606. %adds = OpVariable %_ptr_StorageBuffer__arr_bfoo_uint_11 StorageBuffer
  5607. %ufoo = OpTypeStruct %uint
  5608. %_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
  5609. %uniform_index_buffer = OpVariable %_ptr_Uniform_ufoo Uniform
  5610. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  5611. %_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float
  5612. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5613. )";
  5614. const std::string defs_after =
  5615. R"(OpCapability Tessellation
  5616. OpExtension "SPV_KHR_storage_buffer_storage_class"
  5617. %1 = OpExtInstImport "GLSL.std.450"
  5618. OpMemoryModel Logical GLSL450
  5619. OpEntryPoint TessellationEvaluation %main "main" %_ %gl_PrimitiveID %gl_TessCoord
  5620. OpExecutionMode %main Triangles
  5621. OpExecutionMode %main SpacingEqual
  5622. OpExecutionMode %main VertexOrderCw
  5623. OpSource GLSL 450
  5624. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  5625. OpName %main "main"
  5626. OpName %gl_PerVertex "gl_PerVertex"
  5627. OpMemberName %gl_PerVertex 0 "gl_Position"
  5628. OpMemberName %gl_PerVertex 1 "gl_PointSize"
  5629. OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
  5630. OpMemberName %gl_PerVertex 3 "gl_CullDistance"
  5631. OpName %_ ""
  5632. OpName %bfoo "bfoo"
  5633. OpMemberName %bfoo 0 "val"
  5634. OpName %adds "adds"
  5635. OpName %ufoo "ufoo"
  5636. OpMemberName %ufoo 0 "index"
  5637. OpName %uniform_index_buffer "uniform_index_buffer"
  5638. OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
  5639. OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
  5640. OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
  5641. OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
  5642. OpDecorate %gl_PerVertex Block
  5643. OpMemberDecorate %bfoo 0 Offset 0
  5644. OpDecorate %bfoo Block
  5645. OpDecorate %adds DescriptorSet 0
  5646. OpDecorate %adds Binding 1
  5647. OpMemberDecorate %ufoo 0 Offset 0
  5648. OpDecorate %ufoo Block
  5649. OpDecorate %uniform_index_buffer DescriptorSet 0
  5650. OpDecorate %uniform_index_buffer Binding 0
  5651. OpDecorate %_runtimearr_uint ArrayStride 4
  5652. OpDecorate %_struct_47 Block
  5653. OpMemberDecorate %_struct_47 0 Offset 0
  5654. OpMemberDecorate %_struct_47 1 Offset 4
  5655. OpDecorate %49 DescriptorSet 7
  5656. OpDecorate %49 Binding 0
  5657. OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId
  5658. OpDecorate %gl_TessCoord BuiltIn TessCoord
  5659. %void = OpTypeVoid
  5660. %10 = OpTypeFunction %void
  5661. %float = OpTypeFloat 32
  5662. %v4float = OpTypeVector %float 4
  5663. %uint = OpTypeInt 32 0
  5664. %uint_1 = OpConstant %uint 1
  5665. %_arr_float_uint_1 = OpTypeArray %float %uint_1
  5666. %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
  5667. %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
  5668. %_ = OpVariable %_ptr_Output_gl_PerVertex Output
  5669. %int = OpTypeInt 32 1
  5670. %int_0 = OpConstant %int 0
  5671. %bfoo = OpTypeStruct %v4float
  5672. %uint_11 = OpConstant %uint 11
  5673. %_arr_bfoo_uint_11 = OpTypeArray %bfoo %uint_11
  5674. %_ptr_StorageBuffer__arr_bfoo_uint_11 = OpTypePointer StorageBuffer %_arr_bfoo_uint_11
  5675. %adds = OpVariable %_ptr_StorageBuffer__arr_bfoo_uint_11 StorageBuffer
  5676. %ufoo = OpTypeStruct %uint
  5677. %_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
  5678. %uniform_index_buffer = OpVariable %_ptr_Uniform_ufoo Uniform
  5679. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  5680. %_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float
  5681. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5682. %uint_0 = OpConstant %uint 0
  5683. %bool = OpTypeBool
  5684. %40 = OpTypeFunction %void %uint %uint %uint %uint
  5685. %_runtimearr_uint = OpTypeRuntimeArray %uint
  5686. %_struct_47 = OpTypeStruct %uint %_runtimearr_uint
  5687. %_ptr_StorageBuffer__struct_47 = OpTypePointer StorageBuffer %_struct_47
  5688. %49 = OpVariable %_ptr_StorageBuffer__struct_47 StorageBuffer
  5689. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  5690. %uint_10 = OpConstant %uint 10
  5691. %uint_4 = OpConstant %uint 4
  5692. %uint_23 = OpConstant %uint 23
  5693. %uint_2 = OpConstant %uint 2
  5694. %uint_3 = OpConstant %uint 3
  5695. %_ptr_Input_uint = OpTypePointer Input %uint
  5696. %gl_PrimitiveID = OpVariable %_ptr_Input_uint Input
  5697. %v3float = OpTypeVector %float 3
  5698. %_ptr_Input_v3float = OpTypePointer Input %v3float
  5699. %gl_TessCoord = OpVariable %_ptr_Input_v3float Input
  5700. %v3uint = OpTypeVector %uint 3
  5701. %uint_5 = OpConstant %uint 5
  5702. %uint_6 = OpConstant %uint 6
  5703. %uint_7 = OpConstant %uint 7
  5704. %uint_8 = OpConstant %uint 8
  5705. %uint_9 = OpConstant %uint 9
  5706. %uint_63 = OpConstant %uint 63
  5707. %101 = OpConstantNull %v4float
  5708. )";
  5709. const std::string func_before =
  5710. R"(%main = OpFunction %void None %3
  5711. %5 = OpLabel
  5712. %25 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0
  5713. %26 = OpLoad %uint %25
  5714. %28 = OpAccessChain %_ptr_StorageBuffer_v4float %adds %26 %int_0
  5715. %29 = OpLoad %v4float %28
  5716. %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  5717. OpStore %31 %29
  5718. OpReturn
  5719. OpFunctionEnd
  5720. )";
  5721. const std::string func_after =
  5722. R"(%main = OpFunction %void None %10
  5723. %26 = OpLabel
  5724. %27 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0
  5725. %28 = OpLoad %uint %27
  5726. %29 = OpAccessChain %_ptr_StorageBuffer_v4float %adds %28 %int_0
  5727. %34 = OpULessThan %bool %28 %uint_11
  5728. OpSelectionMerge %35 None
  5729. OpBranchConditional %34 %36 %37
  5730. %36 = OpLabel
  5731. %38 = OpLoad %v4float %29
  5732. OpBranch %35
  5733. %37 = OpLabel
  5734. %100 = OpFunctionCall %void %39 %uint_63 %uint_0 %28 %uint_11
  5735. OpBranch %35
  5736. %35 = OpLabel
  5737. %102 = OpPhi %v4float %38 %36 %101 %37
  5738. %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0
  5739. OpStore %31 %102
  5740. OpReturn
  5741. OpFunctionEnd
  5742. )";
  5743. const std::string output_func =
  5744. R"(%39 = OpFunction %void None %40
  5745. %41 = OpFunctionParameter %uint
  5746. %42 = OpFunctionParameter %uint
  5747. %43 = OpFunctionParameter %uint
  5748. %44 = OpFunctionParameter %uint
  5749. %45 = OpLabel
  5750. %51 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_0
  5751. %54 = OpAtomicIAdd %uint %51 %uint_4 %uint_0 %uint_10
  5752. %55 = OpIAdd %uint %54 %uint_10
  5753. %56 = OpArrayLength %uint %49 1
  5754. %57 = OpULessThanEqual %bool %55 %56
  5755. OpSelectionMerge %58 None
  5756. OpBranchConditional %57 %59 %58
  5757. %59 = OpLabel
  5758. %60 = OpIAdd %uint %54 %uint_0
  5759. %61 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %60
  5760. OpStore %61 %uint_10
  5761. %63 = OpIAdd %uint %54 %uint_1
  5762. %64 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %63
  5763. OpStore %64 %uint_23
  5764. %66 = OpIAdd %uint %54 %uint_2
  5765. %67 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %66
  5766. OpStore %67 %41
  5767. %69 = OpIAdd %uint %54 %uint_3
  5768. %70 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %69
  5769. OpStore %70 %uint_2
  5770. %73 = OpLoad %uint %gl_PrimitiveID
  5771. %74 = OpIAdd %uint %54 %uint_4
  5772. %75 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %74
  5773. OpStore %75 %73
  5774. %79 = OpLoad %v3float %gl_TessCoord
  5775. %81 = OpBitcast %v3uint %79
  5776. %82 = OpCompositeExtract %uint %81 0
  5777. %83 = OpCompositeExtract %uint %81 1
  5778. %85 = OpIAdd %uint %54 %uint_5
  5779. %86 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %85
  5780. OpStore %86 %82
  5781. %88 = OpIAdd %uint %54 %uint_6
  5782. %89 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %88
  5783. OpStore %89 %83
  5784. %91 = OpIAdd %uint %54 %uint_7
  5785. %92 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %91
  5786. OpStore %92 %42
  5787. %94 = OpIAdd %uint %54 %uint_8
  5788. %95 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %94
  5789. OpStore %95 %43
  5790. %97 = OpIAdd %uint %54 %uint_9
  5791. %98 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %97
  5792. OpStore %98 %44
  5793. OpBranch %58
  5794. %58 = OpLabel
  5795. OpReturn
  5796. OpFunctionEnd
  5797. )";
  5798. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  5799. SinglePassRunAndCheck<InstBindlessCheckPass>(
  5800. defs_before + func_before, defs_after + func_after + output_func, true,
  5801. true, 7u, 23u, false, false, 2u);
  5802. }
  5803. TEST_F(InstBindlessTest, MultipleDebugFunctionsV2) {
  5804. // Same source as Simple, but compiled -g and not optimized, especially not
  5805. // inlined. The OpSource has had the source extracted for the sake of brevity.
  5806. const std::string defs_before =
  5807. R"(OpCapability Shader
  5808. %2 = OpExtInstImport "GLSL.std.450"
  5809. OpMemoryModel Logical GLSL450
  5810. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  5811. OpExecutionMode %MainPs OriginUpperLeft
  5812. %1 = OpString "foo5.frag"
  5813. OpSource HLSL 500 %1
  5814. OpName %MainPs "MainPs"
  5815. OpName %PS_INPUT "PS_INPUT"
  5816. OpMemberName %PS_INPUT 0 "vTextureCoords"
  5817. OpName %PS_OUTPUT "PS_OUTPUT"
  5818. OpMemberName %PS_OUTPUT 0 "vColor"
  5819. OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
  5820. OpName %i "i"
  5821. OpName %ps_output "ps_output"
  5822. OpName %g_tColor "g_tColor"
  5823. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  5824. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  5825. OpName %_ ""
  5826. OpName %g_sAniso "g_sAniso"
  5827. OpName %i_0 "i"
  5828. OpName %i_vTextureCoords "i.vTextureCoords"
  5829. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  5830. OpName %param "param"
  5831. OpDecorate %g_tColor DescriptorSet 0
  5832. OpDecorate %g_tColor Binding 0
  5833. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  5834. OpDecorate %PerViewConstantBuffer_t Block
  5835. OpDecorate %g_sAniso DescriptorSet 0
  5836. OpDecorate %g_sAniso Binding 1
  5837. OpDecorate %i_vTextureCoords Location 0
  5838. OpDecorate %_entryPointOutput_vColor Location 0
  5839. %void = OpTypeVoid
  5840. %4 = OpTypeFunction %void
  5841. %float = OpTypeFloat 32
  5842. %v2float = OpTypeVector %float 2
  5843. %PS_INPUT = OpTypeStruct %v2float
  5844. %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
  5845. %v4float = OpTypeVector %float 4
  5846. %PS_OUTPUT = OpTypeStruct %v4float
  5847. %13 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
  5848. %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
  5849. %int = OpTypeInt 32 1
  5850. %int_0 = OpConstant %int 0
  5851. %21 = OpTypeImage %float 2D 0 0 0 1 Unknown
  5852. %uint = OpTypeInt 32 0
  5853. %uint_128 = OpConstant %uint 128
  5854. %_arr_21_uint_128 = OpTypeArray %21 %uint_128
  5855. %_ptr_UniformConstant__arr_21_uint_128 = OpTypePointer UniformConstant %_arr_21_uint_128
  5856. %g_tColor = OpVariable %_ptr_UniformConstant__arr_21_uint_128 UniformConstant
  5857. %PerViewConstantBuffer_t = OpTypeStruct %uint
  5858. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  5859. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  5860. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  5861. %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
  5862. %36 = OpTypeSampler
  5863. %_ptr_UniformConstant_36 = OpTypePointer UniformConstant %36
  5864. %g_sAniso = OpVariable %_ptr_UniformConstant_36 UniformConstant
  5865. %40 = OpTypeSampledImage %21
  5866. %_ptr_Function_v2float = OpTypePointer Function %v2float
  5867. %_ptr_Function_v4float = OpTypePointer Function %v4float
  5868. %_ptr_Input_v2float = OpTypePointer Input %v2float
  5869. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  5870. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5871. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  5872. )";
  5873. const std::string defs_after =
  5874. R"(OpCapability Shader
  5875. OpExtension "SPV_KHR_storage_buffer_storage_class"
  5876. %1 = OpExtInstImport "GLSL.std.450"
  5877. OpMemoryModel Logical GLSL450
  5878. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  5879. OpExecutionMode %MainPs OriginUpperLeft
  5880. %5 = OpString "foo5.frag"
  5881. OpSource HLSL 500 %5
  5882. OpName %MainPs "MainPs"
  5883. OpName %PS_INPUT "PS_INPUT"
  5884. OpMemberName %PS_INPUT 0 "vTextureCoords"
  5885. OpName %PS_OUTPUT "PS_OUTPUT"
  5886. OpMemberName %PS_OUTPUT 0 "vColor"
  5887. OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
  5888. OpName %i "i"
  5889. OpName %ps_output "ps_output"
  5890. OpName %g_tColor "g_tColor"
  5891. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  5892. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  5893. OpName %_ ""
  5894. OpName %g_sAniso "g_sAniso"
  5895. OpName %i_0 "i"
  5896. OpName %i_vTextureCoords "i.vTextureCoords"
  5897. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  5898. OpName %param "param"
  5899. OpDecorate %g_tColor DescriptorSet 0
  5900. OpDecorate %g_tColor Binding 0
  5901. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  5902. OpDecorate %PerViewConstantBuffer_t Block
  5903. OpDecorate %g_sAniso DescriptorSet 0
  5904. OpDecorate %g_sAniso Binding 1
  5905. OpDecorate %i_vTextureCoords Location 0
  5906. OpDecorate %_entryPointOutput_vColor Location 0
  5907. OpDecorate %_runtimearr_uint ArrayStride 4
  5908. OpDecorate %_struct_77 Block
  5909. OpMemberDecorate %_struct_77 0 Offset 0
  5910. OpMemberDecorate %_struct_77 1 Offset 4
  5911. OpDecorate %79 DescriptorSet 7
  5912. OpDecorate %79 Binding 0
  5913. OpDecorate %gl_FragCoord BuiltIn FragCoord
  5914. %void = OpTypeVoid
  5915. %18 = OpTypeFunction %void
  5916. %float = OpTypeFloat 32
  5917. %v2float = OpTypeVector %float 2
  5918. %PS_INPUT = OpTypeStruct %v2float
  5919. %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
  5920. %v4float = OpTypeVector %float 4
  5921. %PS_OUTPUT = OpTypeStruct %v4float
  5922. %23 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
  5923. %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
  5924. %int = OpTypeInt 32 1
  5925. %int_0 = OpConstant %int 0
  5926. %27 = OpTypeImage %float 2D 0 0 0 1 Unknown
  5927. %uint = OpTypeInt 32 0
  5928. %uint_128 = OpConstant %uint 128
  5929. %_arr_27_uint_128 = OpTypeArray %27 %uint_128
  5930. %_ptr_UniformConstant__arr_27_uint_128 = OpTypePointer UniformConstant %_arr_27_uint_128
  5931. %g_tColor = OpVariable %_ptr_UniformConstant__arr_27_uint_128 UniformConstant
  5932. %PerViewConstantBuffer_t = OpTypeStruct %uint
  5933. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  5934. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  5935. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  5936. %_ptr_UniformConstant_27 = OpTypePointer UniformConstant %27
  5937. %35 = OpTypeSampler
  5938. %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
  5939. %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
  5940. %37 = OpTypeSampledImage %27
  5941. %_ptr_Function_v2float = OpTypePointer Function %v2float
  5942. %_ptr_Function_v4float = OpTypePointer Function %v4float
  5943. %_ptr_Input_v2float = OpTypePointer Input %v2float
  5944. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  5945. %_ptr_Output_v4float = OpTypePointer Output %v4float
  5946. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  5947. %uint_0 = OpConstant %uint 0
  5948. %bool = OpTypeBool
  5949. %70 = OpTypeFunction %void %uint %uint %uint %uint
  5950. %_runtimearr_uint = OpTypeRuntimeArray %uint
  5951. %_struct_77 = OpTypeStruct %uint %_runtimearr_uint
  5952. %_ptr_StorageBuffer__struct_77 = OpTypePointer StorageBuffer %_struct_77
  5953. %79 = OpVariable %_ptr_StorageBuffer__struct_77 StorageBuffer
  5954. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  5955. %uint_10 = OpConstant %uint 10
  5956. %uint_4 = OpConstant %uint 4
  5957. %uint_1 = OpConstant %uint 1
  5958. %uint_23 = OpConstant %uint 23
  5959. %uint_2 = OpConstant %uint 2
  5960. %uint_3 = OpConstant %uint 3
  5961. %_ptr_Input_v4float = OpTypePointer Input %v4float
  5962. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  5963. %v4uint = OpTypeVector %uint 4
  5964. %uint_5 = OpConstant %uint 5
  5965. %uint_7 = OpConstant %uint 7
  5966. %uint_8 = OpConstant %uint 8
  5967. %uint_9 = OpConstant %uint 9
  5968. %uint_93 = OpConstant %uint 93
  5969. %125 = OpConstantNull %v4float
  5970. )";
  5971. const std::string func1_before =
  5972. R"(%MainPs = OpFunction %void None %4
  5973. %6 = OpLabel
  5974. %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
  5975. %param = OpVariable %_ptr_Function_PS_INPUT Function
  5976. OpLine %1 21 0
  5977. %54 = OpLoad %v2float %i_vTextureCoords
  5978. %55 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
  5979. OpStore %55 %54
  5980. %59 = OpLoad %PS_INPUT %i_0
  5981. OpStore %param %59
  5982. %60 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
  5983. %61 = OpCompositeExtract %v4float %60 0
  5984. OpStore %_entryPointOutput_vColor %61
  5985. OpReturn
  5986. OpFunctionEnd
  5987. )";
  5988. const std::string func1_after =
  5989. R"(%MainPs = OpFunction %void None %18
  5990. %42 = OpLabel
  5991. %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
  5992. %param = OpVariable %_ptr_Function_PS_INPUT Function
  5993. OpLine %5 21 0
  5994. %43 = OpLoad %v2float %i_vTextureCoords
  5995. %44 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
  5996. OpStore %44 %43
  5997. %45 = OpLoad %PS_INPUT %i_0
  5998. OpStore %param %45
  5999. %46 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
  6000. %47 = OpCompositeExtract %v4float %46 0
  6001. OpStore %_entryPointOutput_vColor %47
  6002. OpReturn
  6003. OpFunctionEnd
  6004. )";
  6005. const std::string func2_before =
  6006. R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %13
  6007. %i = OpFunctionParameter %_ptr_Function_PS_INPUT
  6008. %16 = OpLabel
  6009. %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
  6010. OpLine %1 24 0
  6011. %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  6012. %32 = OpLoad %uint %31
  6013. %34 = OpAccessChain %_ptr_UniformConstant_21 %g_tColor %32
  6014. %35 = OpLoad %21 %34
  6015. %39 = OpLoad %36 %g_sAniso
  6016. %41 = OpSampledImage %40 %35 %39
  6017. %43 = OpAccessChain %_ptr_Function_v2float %i %int_0
  6018. %44 = OpLoad %v2float %43
  6019. %45 = OpImageSampleImplicitLod %v4float %41 %44
  6020. %47 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
  6021. OpStore %47 %45
  6022. OpLine %1 25 0
  6023. %48 = OpLoad %PS_OUTPUT %ps_output
  6024. OpReturnValue %48
  6025. OpFunctionEnd
  6026. )";
  6027. const std::string func2_after =
  6028. R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %23
  6029. %i = OpFunctionParameter %_ptr_Function_PS_INPUT
  6030. %48 = OpLabel
  6031. %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
  6032. OpLine %5 24 0
  6033. %49 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  6034. %50 = OpLoad %uint %49
  6035. %51 = OpAccessChain %_ptr_UniformConstant_27 %g_tColor %50
  6036. %52 = OpLoad %27 %51
  6037. %53 = OpLoad %35 %g_sAniso
  6038. %54 = OpSampledImage %37 %52 %53
  6039. %55 = OpAccessChain %_ptr_Function_v2float %i %int_0
  6040. %56 = OpLoad %v2float %55
  6041. %62 = OpULessThan %bool %50 %uint_128
  6042. OpSelectionMerge %63 None
  6043. OpBranchConditional %62 %64 %65
  6044. %64 = OpLabel
  6045. %66 = OpLoad %27 %51
  6046. %67 = OpSampledImage %37 %66 %53
  6047. %68 = OpImageSampleImplicitLod %v4float %67 %56
  6048. OpBranch %63
  6049. %65 = OpLabel
  6050. %124 = OpFunctionCall %void %69 %uint_93 %uint_0 %50 %uint_128
  6051. OpBranch %63
  6052. %63 = OpLabel
  6053. %126 = OpPhi %v4float %68 %64 %125 %65
  6054. %58 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
  6055. OpStore %58 %126
  6056. OpLine %5 25 0
  6057. %59 = OpLoad %PS_OUTPUT %ps_output
  6058. OpReturnValue %59
  6059. OpFunctionEnd
  6060. )";
  6061. const std::string output_func =
  6062. R"(%69 = OpFunction %void None %70
  6063. %71 = OpFunctionParameter %uint
  6064. %72 = OpFunctionParameter %uint
  6065. %73 = OpFunctionParameter %uint
  6066. %74 = OpFunctionParameter %uint
  6067. %75 = OpLabel
  6068. %81 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_0
  6069. %84 = OpAtomicIAdd %uint %81 %uint_4 %uint_0 %uint_10
  6070. %85 = OpIAdd %uint %84 %uint_10
  6071. %86 = OpArrayLength %uint %79 1
  6072. %87 = OpULessThanEqual %bool %85 %86
  6073. OpSelectionMerge %88 None
  6074. OpBranchConditional %87 %89 %88
  6075. %89 = OpLabel
  6076. %90 = OpIAdd %uint %84 %uint_0
  6077. %92 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %90
  6078. OpStore %92 %uint_10
  6079. %94 = OpIAdd %uint %84 %uint_1
  6080. %95 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %94
  6081. OpStore %95 %uint_23
  6082. %97 = OpIAdd %uint %84 %uint_2
  6083. %98 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %97
  6084. OpStore %98 %71
  6085. %100 = OpIAdd %uint %84 %uint_3
  6086. %101 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %100
  6087. OpStore %101 %uint_4
  6088. %104 = OpLoad %v4float %gl_FragCoord
  6089. %106 = OpBitcast %v4uint %104
  6090. %107 = OpCompositeExtract %uint %106 0
  6091. %108 = OpIAdd %uint %84 %uint_4
  6092. %109 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %108
  6093. OpStore %109 %107
  6094. %110 = OpCompositeExtract %uint %106 1
  6095. %112 = OpIAdd %uint %84 %uint_5
  6096. %113 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %112
  6097. OpStore %113 %110
  6098. %115 = OpIAdd %uint %84 %uint_7
  6099. %116 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %115
  6100. OpStore %116 %72
  6101. %118 = OpIAdd %uint %84 %uint_8
  6102. %119 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %118
  6103. OpStore %119 %73
  6104. %121 = OpIAdd %uint %84 %uint_9
  6105. %122 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %121
  6106. OpStore %122 %74
  6107. OpBranch %88
  6108. %88 = OpLabel
  6109. OpReturn
  6110. OpFunctionEnd
  6111. )";
  6112. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  6113. SinglePassRunAndCheck<InstBindlessCheckPass>(
  6114. defs_before + func1_before + func2_before,
  6115. defs_after + func1_after + func2_after + output_func, true, true, 7u, 23u,
  6116. false, false, 2u);
  6117. }
  6118. TEST_F(InstBindlessTest, RuntimeArrayV2) {
  6119. // This test verifies that the pass will correctly instrument shader
  6120. // with runtime descriptor array. This test was created by editing the
  6121. // SPIR-V from the Simple test.
  6122. const std::string defs_before =
  6123. R"(OpCapability Shader
  6124. OpCapability RuntimeDescriptorArray
  6125. OpExtension "SPV_EXT_descriptor_indexing"
  6126. %1 = OpExtInstImport "GLSL.std.450"
  6127. OpMemoryModel Logical GLSL450
  6128. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  6129. OpExecutionMode %MainPs OriginUpperLeft
  6130. OpSource HLSL 500
  6131. OpName %MainPs "MainPs"
  6132. OpName %g_tColor "g_tColor"
  6133. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  6134. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  6135. OpName %_ ""
  6136. OpName %g_sAniso "g_sAniso"
  6137. OpName %i_vTextureCoords "i.vTextureCoords"
  6138. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  6139. OpDecorate %g_tColor DescriptorSet 1
  6140. OpDecorate %g_tColor Binding 2
  6141. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  6142. OpDecorate %PerViewConstantBuffer_t Block
  6143. OpDecorate %g_sAniso DescriptorSet 1
  6144. OpDecorate %g_sAniso Binding 0
  6145. OpDecorate %i_vTextureCoords Location 0
  6146. OpDecorate %_entryPointOutput_vColor Location 0
  6147. %void = OpTypeVoid
  6148. %3 = OpTypeFunction %void
  6149. %float = OpTypeFloat 32
  6150. %v2float = OpTypeVector %float 2
  6151. %v4float = OpTypeVector %float 4
  6152. %int = OpTypeInt 32 1
  6153. %int_0 = OpConstant %int 0
  6154. %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
  6155. %uint = OpTypeInt 32 0
  6156. %uint_1 = OpConstant %uint 1
  6157. %_rarr_20 = OpTypeRuntimeArray %20
  6158. %_ptr_UniformConstant__arr_20 = OpTypePointer UniformConstant %_rarr_20
  6159. %g_tColor = OpVariable %_ptr_UniformConstant__arr_20 UniformConstant
  6160. %PerViewConstantBuffer_t = OpTypeStruct %uint
  6161. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  6162. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  6163. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  6164. %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
  6165. %35 = OpTypeSampler
  6166. %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
  6167. %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
  6168. %39 = OpTypeSampledImage %20
  6169. %_ptr_Input_v2float = OpTypePointer Input %v2float
  6170. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  6171. %_ptr_Output_v4float = OpTypePointer Output %v4float
  6172. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  6173. )";
  6174. const std::string defs_after =
  6175. R"(OpCapability Shader
  6176. OpCapability RuntimeDescriptorArray
  6177. OpExtension "SPV_EXT_descriptor_indexing"
  6178. OpExtension "SPV_KHR_storage_buffer_storage_class"
  6179. %1 = OpExtInstImport "GLSL.std.450"
  6180. OpMemoryModel Logical GLSL450
  6181. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  6182. OpExecutionMode %MainPs OriginUpperLeft
  6183. OpSource HLSL 500
  6184. OpName %MainPs "MainPs"
  6185. OpName %g_tColor "g_tColor"
  6186. OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
  6187. OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
  6188. OpName %_ ""
  6189. OpName %g_sAniso "g_sAniso"
  6190. OpName %i_vTextureCoords "i.vTextureCoords"
  6191. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  6192. OpDecorate %g_tColor DescriptorSet 1
  6193. OpDecorate %g_tColor Binding 2
  6194. OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
  6195. OpDecorate %PerViewConstantBuffer_t Block
  6196. OpDecorate %g_sAniso DescriptorSet 1
  6197. OpDecorate %g_sAniso Binding 0
  6198. OpDecorate %i_vTextureCoords Location 0
  6199. OpDecorate %_entryPointOutput_vColor Location 0
  6200. OpDecorate %_runtimearr_uint ArrayStride 4
  6201. OpDecorate %_struct_46 Block
  6202. OpMemberDecorate %_struct_46 0 Offset 0
  6203. OpDecorate %48 DescriptorSet 7
  6204. OpDecorate %48 Binding 1
  6205. OpDecorate %_struct_71 Block
  6206. OpMemberDecorate %_struct_71 0 Offset 0
  6207. OpMemberDecorate %_struct_71 1 Offset 4
  6208. OpDecorate %73 DescriptorSet 7
  6209. OpDecorate %73 Binding 0
  6210. OpDecorate %gl_FragCoord BuiltIn FragCoord
  6211. %void = OpTypeVoid
  6212. %10 = OpTypeFunction %void
  6213. %float = OpTypeFloat 32
  6214. %v2float = OpTypeVector %float 2
  6215. %v4float = OpTypeVector %float 4
  6216. %int = OpTypeInt 32 1
  6217. %int_0 = OpConstant %int 0
  6218. %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
  6219. %uint = OpTypeInt 32 0
  6220. %uint_1 = OpConstant %uint 1
  6221. %_runtimearr_16 = OpTypeRuntimeArray %16
  6222. %_ptr_UniformConstant__runtimearr_16 = OpTypePointer UniformConstant %_runtimearr_16
  6223. %g_tColor = OpVariable %_ptr_UniformConstant__runtimearr_16 UniformConstant
  6224. %PerViewConstantBuffer_t = OpTypeStruct %uint
  6225. %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
  6226. %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
  6227. %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
  6228. %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
  6229. %24 = OpTypeSampler
  6230. %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
  6231. %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
  6232. %26 = OpTypeSampledImage %16
  6233. %_ptr_Input_v2float = OpTypePointer Input %v2float
  6234. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  6235. %_ptr_Output_v4float = OpTypePointer Output %v4float
  6236. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  6237. %uint_0 = OpConstant %uint 0
  6238. %uint_2 = OpConstant %uint 2
  6239. %41 = OpTypeFunction %uint %uint %uint
  6240. %_runtimearr_uint = OpTypeRuntimeArray %uint
  6241. %_struct_46 = OpTypeStruct %_runtimearr_uint
  6242. %_ptr_StorageBuffer__struct_46 = OpTypePointer StorageBuffer %_struct_46
  6243. %48 = OpVariable %_ptr_StorageBuffer__struct_46 StorageBuffer
  6244. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  6245. %bool = OpTypeBool
  6246. %65 = OpTypeFunction %void %uint %uint %uint %uint
  6247. %_struct_71 = OpTypeStruct %uint %_runtimearr_uint
  6248. %_ptr_StorageBuffer__struct_71 = OpTypePointer StorageBuffer %_struct_71
  6249. %73 = OpVariable %_ptr_StorageBuffer__struct_71 StorageBuffer
  6250. %uint_10 = OpConstant %uint 10
  6251. %uint_4 = OpConstant %uint 4
  6252. %uint_23 = OpConstant %uint 23
  6253. %uint_3 = OpConstant %uint 3
  6254. %_ptr_Input_v4float = OpTypePointer Input %v4float
  6255. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  6256. %v4uint = OpTypeVector %uint 4
  6257. %uint_5 = OpConstant %uint 5
  6258. %uint_7 = OpConstant %uint 7
  6259. %uint_8 = OpConstant %uint 8
  6260. %uint_9 = OpConstant %uint 9
  6261. %uint_59 = OpConstant %uint 59
  6262. %116 = OpConstantNull %v4float
  6263. %119 = OpTypeFunction %uint %uint %uint %uint %uint
  6264. )";
  6265. const std::string func_before =
  6266. R"(%MainPs = OpFunction %void None %3
  6267. %5 = OpLabel
  6268. %53 = OpLoad %v2float %i_vTextureCoords
  6269. %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  6270. %64 = OpLoad %uint %63
  6271. %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
  6272. %66 = OpLoad %20 %65
  6273. %67 = OpLoad %35 %g_sAniso
  6274. %68 = OpSampledImage %39 %66 %67
  6275. %71 = OpImageSampleImplicitLod %v4float %68 %53
  6276. OpStore %_entryPointOutput_vColor %71
  6277. OpReturn
  6278. OpFunctionEnd
  6279. )";
  6280. const std::string func_after =
  6281. R"(%MainPs = OpFunction %void None %10
  6282. %29 = OpLabel
  6283. %30 = OpLoad %v2float %i_vTextureCoords
  6284. %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
  6285. %32 = OpLoad %uint %31
  6286. %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
  6287. %34 = OpLoad %16 %33
  6288. %35 = OpLoad %24 %g_sAniso
  6289. %36 = OpSampledImage %26 %34 %35
  6290. %55 = OpFunctionCall %uint %40 %uint_2 %uint_2
  6291. %57 = OpULessThan %bool %32 %55
  6292. OpSelectionMerge %58 None
  6293. OpBranchConditional %57 %59 %60
  6294. %59 = OpLabel
  6295. %61 = OpLoad %16 %33
  6296. %62 = OpSampledImage %26 %61 %35
  6297. %136 = OpFunctionCall %uint %118 %uint_0 %uint_1 %uint_2 %32
  6298. %137 = OpINotEqual %bool %136 %uint_0
  6299. OpSelectionMerge %138 None
  6300. OpBranchConditional %137 %139 %140
  6301. %139 = OpLabel
  6302. %141 = OpLoad %16 %33
  6303. %142 = OpSampledImage %26 %141 %35
  6304. %143 = OpImageSampleImplicitLod %v4float %142 %30
  6305. OpBranch %138
  6306. %140 = OpLabel
  6307. %144 = OpFunctionCall %void %64 %uint_59 %uint_1 %32 %uint_0
  6308. OpBranch %138
  6309. %138 = OpLabel
  6310. %145 = OpPhi %v4float %143 %139 %116 %140
  6311. OpBranch %58
  6312. %60 = OpLabel
  6313. %115 = OpFunctionCall %void %64 %uint_59 %uint_0 %32 %55
  6314. OpBranch %58
  6315. %58 = OpLabel
  6316. %117 = OpPhi %v4float %145 %138 %116 %60
  6317. OpStore %_entryPointOutput_vColor %117
  6318. OpReturn
  6319. OpFunctionEnd
  6320. )";
  6321. const std::string new_funcs =
  6322. R"(%40 = OpFunction %uint None %41
  6323. %42 = OpFunctionParameter %uint
  6324. %43 = OpFunctionParameter %uint
  6325. %44 = OpLabel
  6326. %50 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %42
  6327. %51 = OpLoad %uint %50
  6328. %52 = OpIAdd %uint %51 %43
  6329. %53 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %52
  6330. %54 = OpLoad %uint %53
  6331. OpReturnValue %54
  6332. OpFunctionEnd
  6333. %64 = OpFunction %void None %65
  6334. %66 = OpFunctionParameter %uint
  6335. %67 = OpFunctionParameter %uint
  6336. %68 = OpFunctionParameter %uint
  6337. %69 = OpFunctionParameter %uint
  6338. %70 = OpLabel
  6339. %74 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_0
  6340. %77 = OpAtomicIAdd %uint %74 %uint_4 %uint_0 %uint_10
  6341. %78 = OpIAdd %uint %77 %uint_10
  6342. %79 = OpArrayLength %uint %73 1
  6343. %80 = OpULessThanEqual %bool %78 %79
  6344. OpSelectionMerge %81 None
  6345. OpBranchConditional %80 %82 %81
  6346. %82 = OpLabel
  6347. %83 = OpIAdd %uint %77 %uint_0
  6348. %84 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %83
  6349. OpStore %84 %uint_10
  6350. %86 = OpIAdd %uint %77 %uint_1
  6351. %87 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %86
  6352. OpStore %87 %uint_23
  6353. %88 = OpIAdd %uint %77 %uint_2
  6354. %89 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %88
  6355. OpStore %89 %66
  6356. %91 = OpIAdd %uint %77 %uint_3
  6357. %92 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %91
  6358. OpStore %92 %uint_4
  6359. %95 = OpLoad %v4float %gl_FragCoord
  6360. %97 = OpBitcast %v4uint %95
  6361. %98 = OpCompositeExtract %uint %97 0
  6362. %99 = OpIAdd %uint %77 %uint_4
  6363. %100 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %99
  6364. OpStore %100 %98
  6365. %101 = OpCompositeExtract %uint %97 1
  6366. %103 = OpIAdd %uint %77 %uint_5
  6367. %104 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %103
  6368. OpStore %104 %101
  6369. %106 = OpIAdd %uint %77 %uint_7
  6370. %107 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %106
  6371. OpStore %107 %67
  6372. %109 = OpIAdd %uint %77 %uint_8
  6373. %110 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %109
  6374. OpStore %110 %68
  6375. %112 = OpIAdd %uint %77 %uint_9
  6376. %113 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %112
  6377. OpStore %113 %69
  6378. OpBranch %81
  6379. %81 = OpLabel
  6380. OpReturn
  6381. OpFunctionEnd
  6382. %118 = OpFunction %uint None %119
  6383. %120 = OpFunctionParameter %uint
  6384. %121 = OpFunctionParameter %uint
  6385. %122 = OpFunctionParameter %uint
  6386. %123 = OpFunctionParameter %uint
  6387. %124 = OpLabel
  6388. %125 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %120
  6389. %126 = OpLoad %uint %125
  6390. %127 = OpIAdd %uint %126 %121
  6391. %128 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %127
  6392. %129 = OpLoad %uint %128
  6393. %130 = OpIAdd %uint %129 %122
  6394. %131 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %130
  6395. %132 = OpLoad %uint %131
  6396. %133 = OpIAdd %uint %132 %123
  6397. %134 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %133
  6398. %135 = OpLoad %uint %134
  6399. OpReturnValue %135
  6400. OpFunctionEnd
  6401. )";
  6402. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  6403. SinglePassRunAndCheck<InstBindlessCheckPass>(
  6404. defs_before + func_before, defs_after + func_after + new_funcs, true,
  6405. true, 7u, 23u, true, true, 2u);
  6406. }
  6407. TEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptorV2) {
  6408. // This test verifies that the pass will correctly instrument vanilla
  6409. // texture sample on a scalar descriptor with an initialization check if the
  6410. // input_init_enable argument is set to true. This can happen when the
  6411. // descriptor indexing extension is enabled in the API but the SPIR-V
  6412. // does not have the extension enabled because it does not contain a
  6413. // runtime array. This is the same shader as NoInstrumentNonBindless.
  6414. const std::string defs_before =
  6415. R"(OpCapability Shader
  6416. %1 = OpExtInstImport "GLSL.std.450"
  6417. OpMemoryModel Logical GLSL450
  6418. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
  6419. OpExecutionMode %MainPs OriginUpperLeft
  6420. OpSource HLSL 500
  6421. OpName %MainPs "MainPs"
  6422. OpName %g_tColor "g_tColor"
  6423. OpName %g_sAniso "g_sAniso"
  6424. OpName %i_vTextureCoords "i.vTextureCoords"
  6425. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  6426. OpDecorate %g_tColor DescriptorSet 0
  6427. OpDecorate %g_tColor Binding 0
  6428. OpDecorate %g_sAniso DescriptorSet 0
  6429. OpDecorate %g_sAniso Binding 0
  6430. OpDecorate %i_vTextureCoords Location 0
  6431. OpDecorate %_entryPointOutput_vColor Location 0
  6432. %void = OpTypeVoid
  6433. %8 = OpTypeFunction %void
  6434. %float = OpTypeFloat 32
  6435. %v2float = OpTypeVector %float 2
  6436. %v4float = OpTypeVector %float 4
  6437. %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
  6438. %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
  6439. %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
  6440. %14 = OpTypeSampler
  6441. %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
  6442. %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
  6443. %16 = OpTypeSampledImage %12
  6444. %_ptr_Input_v2float = OpTypePointer Input %v2float
  6445. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  6446. %_ptr_Output_v4float = OpTypePointer Output %v4float
  6447. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  6448. )";
  6449. const std::string defs_after =
  6450. R"(OpCapability Shader
  6451. OpExtension "SPV_KHR_storage_buffer_storage_class"
  6452. %1 = OpExtInstImport "GLSL.std.450"
  6453. OpMemoryModel Logical GLSL450
  6454. OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
  6455. OpExecutionMode %MainPs OriginUpperLeft
  6456. OpSource HLSL 500
  6457. OpName %MainPs "MainPs"
  6458. OpName %g_tColor "g_tColor"
  6459. OpName %g_sAniso "g_sAniso"
  6460. OpName %i_vTextureCoords "i.vTextureCoords"
  6461. OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
  6462. OpDecorate %g_tColor DescriptorSet 0
  6463. OpDecorate %g_tColor Binding 0
  6464. OpDecorate %g_sAniso DescriptorSet 0
  6465. OpDecorate %g_sAniso Binding 0
  6466. OpDecorate %i_vTextureCoords Location 0
  6467. OpDecorate %_entryPointOutput_vColor Location 0
  6468. OpDecorate %_runtimearr_uint ArrayStride 4
  6469. OpDecorate %_struct_35 Block
  6470. OpMemberDecorate %_struct_35 0 Offset 0
  6471. OpDecorate %37 DescriptorSet 7
  6472. OpDecorate %37 Binding 1
  6473. OpDecorate %_struct_67 Block
  6474. OpMemberDecorate %_struct_67 0 Offset 0
  6475. OpMemberDecorate %_struct_67 1 Offset 4
  6476. OpDecorate %69 DescriptorSet 7
  6477. OpDecorate %69 Binding 0
  6478. OpDecorate %gl_FragCoord BuiltIn FragCoord
  6479. %void = OpTypeVoid
  6480. %8 = OpTypeFunction %void
  6481. %float = OpTypeFloat 32
  6482. %v2float = OpTypeVector %float 2
  6483. %v4float = OpTypeVector %float 4
  6484. %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
  6485. %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
  6486. %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
  6487. %14 = OpTypeSampler
  6488. %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
  6489. %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
  6490. %16 = OpTypeSampledImage %12
  6491. %_ptr_Input_v2float = OpTypePointer Input %v2float
  6492. %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
  6493. %_ptr_Output_v4float = OpTypePointer Output %v4float
  6494. %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
  6495. %uint = OpTypeInt 32 0
  6496. %uint_0 = OpConstant %uint 0
  6497. %28 = OpTypeFunction %uint %uint %uint %uint %uint
  6498. %_runtimearr_uint = OpTypeRuntimeArray %uint
  6499. %_struct_35 = OpTypeStruct %_runtimearr_uint
  6500. %_ptr_StorageBuffer__struct_35 = OpTypePointer StorageBuffer %_struct_35
  6501. %37 = OpVariable %_ptr_StorageBuffer__struct_35 StorageBuffer
  6502. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  6503. %bool = OpTypeBool
  6504. %uint_1 = OpConstant %uint 1
  6505. %61 = OpTypeFunction %void %uint %uint %uint %uint
  6506. %_struct_67 = OpTypeStruct %uint %_runtimearr_uint
  6507. %_ptr_StorageBuffer__struct_67 = OpTypePointer StorageBuffer %_struct_67
  6508. %69 = OpVariable %_ptr_StorageBuffer__struct_67 StorageBuffer
  6509. %uint_10 = OpConstant %uint 10
  6510. %uint_4 = OpConstant %uint 4
  6511. %uint_23 = OpConstant %uint 23
  6512. %uint_2 = OpConstant %uint 2
  6513. %uint_3 = OpConstant %uint 3
  6514. %_ptr_Input_v4float = OpTypePointer Input %v4float
  6515. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  6516. %v4uint = OpTypeVector %uint 4
  6517. %uint_5 = OpConstant %uint 5
  6518. %uint_7 = OpConstant %uint 7
  6519. %uint_8 = OpConstant %uint 8
  6520. %uint_9 = OpConstant %uint 9
  6521. %uint_39 = OpConstant %uint 39
  6522. %113 = OpConstantNull %v4float
  6523. )";
  6524. const std::string func_before =
  6525. R"(%MainPs = OpFunction %void None %8
  6526. %19 = OpLabel
  6527. %20 = OpLoad %v2float %i_vTextureCoords
  6528. %21 = OpLoad %12 %g_tColor
  6529. %22 = OpLoad %14 %g_sAniso
  6530. %23 = OpSampledImage %16 %21 %22
  6531. %24 = OpImageSampleImplicitLod %v4float %23 %20
  6532. OpStore %_entryPointOutput_vColor %24
  6533. OpReturn
  6534. OpFunctionEnd
  6535. )";
  6536. const std::string func_after =
  6537. R"(%MainPs = OpFunction %void None %8
  6538. %19 = OpLabel
  6539. %20 = OpLoad %v2float %i_vTextureCoords
  6540. %21 = OpLoad %12 %g_tColor
  6541. %22 = OpLoad %14 %g_sAniso
  6542. %23 = OpSampledImage %16 %21 %22
  6543. %50 = OpFunctionCall %uint %27 %uint_0 %uint_0 %uint_0 %uint_0
  6544. %52 = OpINotEqual %bool %50 %uint_0
  6545. OpSelectionMerge %54 None
  6546. OpBranchConditional %52 %55 %56
  6547. %55 = OpLabel
  6548. %57 = OpLoad %12 %g_tColor
  6549. %58 = OpSampledImage %16 %57 %22
  6550. %59 = OpImageSampleImplicitLod %v4float %58 %20
  6551. OpBranch %54
  6552. %56 = OpLabel
  6553. %112 = OpFunctionCall %void %60 %uint_39 %uint_1 %uint_0 %uint_0
  6554. OpBranch %54
  6555. %54 = OpLabel
  6556. %114 = OpPhi %v4float %59 %55 %113 %56
  6557. OpStore %_entryPointOutput_vColor %114
  6558. OpReturn
  6559. OpFunctionEnd
  6560. )";
  6561. const std::string new_funcs =
  6562. R"(%27 = OpFunction %uint None %28
  6563. %29 = OpFunctionParameter %uint
  6564. %30 = OpFunctionParameter %uint
  6565. %31 = OpFunctionParameter %uint
  6566. %32 = OpFunctionParameter %uint
  6567. %33 = OpLabel
  6568. %39 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %29
  6569. %40 = OpLoad %uint %39
  6570. %41 = OpIAdd %uint %40 %30
  6571. %42 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %41
  6572. %43 = OpLoad %uint %42
  6573. %44 = OpIAdd %uint %43 %31
  6574. %45 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %44
  6575. %46 = OpLoad %uint %45
  6576. %47 = OpIAdd %uint %46 %32
  6577. %48 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %47
  6578. %49 = OpLoad %uint %48
  6579. OpReturnValue %49
  6580. OpFunctionEnd
  6581. %60 = OpFunction %void None %61
  6582. %62 = OpFunctionParameter %uint
  6583. %63 = OpFunctionParameter %uint
  6584. %64 = OpFunctionParameter %uint
  6585. %65 = OpFunctionParameter %uint
  6586. %66 = OpLabel
  6587. %70 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_0
  6588. %73 = OpAtomicIAdd %uint %70 %uint_4 %uint_0 %uint_10
  6589. %74 = OpIAdd %uint %73 %uint_10
  6590. %75 = OpArrayLength %uint %69 1
  6591. %76 = OpULessThanEqual %bool %74 %75
  6592. OpSelectionMerge %77 None
  6593. OpBranchConditional %76 %78 %77
  6594. %78 = OpLabel
  6595. %79 = OpIAdd %uint %73 %uint_0
  6596. %80 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %79
  6597. OpStore %80 %uint_10
  6598. %82 = OpIAdd %uint %73 %uint_1
  6599. %83 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %82
  6600. OpStore %83 %uint_23
  6601. %85 = OpIAdd %uint %73 %uint_2
  6602. %86 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %85
  6603. OpStore %86 %62
  6604. %88 = OpIAdd %uint %73 %uint_3
  6605. %89 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %88
  6606. OpStore %89 %uint_4
  6607. %92 = OpLoad %v4float %gl_FragCoord
  6608. %94 = OpBitcast %v4uint %92
  6609. %95 = OpCompositeExtract %uint %94 0
  6610. %96 = OpIAdd %uint %73 %uint_4
  6611. %97 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %96
  6612. OpStore %97 %95
  6613. %98 = OpCompositeExtract %uint %94 1
  6614. %100 = OpIAdd %uint %73 %uint_5
  6615. %101 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %100
  6616. OpStore %101 %98
  6617. %103 = OpIAdd %uint %73 %uint_7
  6618. %104 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %103
  6619. OpStore %104 %63
  6620. %106 = OpIAdd %uint %73 %uint_8
  6621. %107 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %106
  6622. OpStore %107 %64
  6623. %109 = OpIAdd %uint %73 %uint_9
  6624. %110 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %109
  6625. OpStore %110 %65
  6626. OpBranch %77
  6627. %77 = OpLabel
  6628. OpReturn
  6629. OpFunctionEnd
  6630. )";
  6631. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  6632. SinglePassRunAndCheck<InstBindlessCheckPass>(
  6633. defs_before + func_before, defs_after + func_after + new_funcs, true,
  6634. true, 7u, 23u, true, true, 2u);
  6635. }
  6636. TEST_F(InstBindlessTest, SPV14AddToEntryPointV2) {
  6637. const std::string text = R"(
  6638. ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
  6639. ; CHECK: OpDecorate [[v1]] DescriptorSet 7
  6640. ; CHECK: OpDecorate [[v2]] DescriptorSet 7
  6641. ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
  6642. ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
  6643. OpCapability Shader
  6644. OpExtension "SPV_EXT_descriptor_indexing"
  6645. OpMemoryModel Logical GLSL450
  6646. OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
  6647. OpExecutionMode %foo OriginUpperLeft
  6648. OpDecorate %image_var DescriptorSet 0
  6649. OpDecorate %image_var Binding 0
  6650. OpDecorate %sampler_var DescriptorSet 0
  6651. OpDecorate %sampler_var Binding 1
  6652. OpDecorate %gid DescriptorSet 0
  6653. OpDecorate %gid Binding 2
  6654. OpDecorate %struct Block
  6655. OpMemberDecorate %struct 0 Offset 0
  6656. %void = OpTypeVoid
  6657. %int = OpTypeInt 32 0
  6658. %int_0 = OpConstant %int 0
  6659. %v3int = OpTypeVector %int 3
  6660. %float = OpTypeFloat 32
  6661. %v3float = OpTypeVector %float 3
  6662. %v4float = OpTypeVector %float 4
  6663. %struct = OpTypeStruct %v3int
  6664. %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
  6665. %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
  6666. %gid = OpVariable %ptr_ssbo_struct StorageBuffer
  6667. %image = OpTypeImage %float 3D 0 0 0 1 Unknown
  6668. %ptr_uc_image = OpTypePointer UniformConstant %image
  6669. %sampler = OpTypeSampler
  6670. %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
  6671. %image_var = OpVariable %ptr_uc_image UniformConstant
  6672. %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
  6673. %sampled = OpTypeSampledImage %image
  6674. %void_fn = OpTypeFunction %void
  6675. %foo = OpFunction %void None %void_fn
  6676. %entry = OpLabel
  6677. %ld_image = OpLoad %image %image_var
  6678. %ld_sampler = OpLoad %sampler %sampler_var
  6679. %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
  6680. %ld_gid = OpLoad %v3int %gep
  6681. %convert = OpConvertUToF %v3float %ld_gid
  6682. %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
  6683. %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
  6684. OpReturn
  6685. OpFunctionEnd
  6686. )";
  6687. SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
  6688. SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
  6689. 2u);
  6690. }
  6691. TEST_F(InstBindlessTest, SPV14AddToEntryPointsV2) {
  6692. const std::string text = R"(
  6693. ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
  6694. ; CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
  6695. ; CHECK: OpDecorate [[v1]] DescriptorSet 7
  6696. ; CHECK: OpDecorate [[v2]] DescriptorSet 7
  6697. ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
  6698. ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
  6699. OpCapability Shader
  6700. OpExtension "SPV_EXT_descriptor_indexing"
  6701. OpMemoryModel Logical GLSL450
  6702. OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
  6703. OpEntryPoint Fragment %foo "bar" %gid %image_var %sampler_var
  6704. OpExecutionMode %foo OriginUpperLeft
  6705. OpDecorate %image_var DescriptorSet 0
  6706. OpDecorate %image_var Binding 0
  6707. OpDecorate %sampler_var DescriptorSet 0
  6708. OpDecorate %sampler_var Binding 1
  6709. OpDecorate %gid DescriptorSet 0
  6710. OpDecorate %gid Binding 2
  6711. OpDecorate %struct Block
  6712. OpMemberDecorate %struct 0 Offset 0
  6713. %void = OpTypeVoid
  6714. %int = OpTypeInt 32 0
  6715. %int_0 = OpConstant %int 0
  6716. %v3int = OpTypeVector %int 3
  6717. %float = OpTypeFloat 32
  6718. %v3float = OpTypeVector %float 3
  6719. %v4float = OpTypeVector %float 4
  6720. %struct = OpTypeStruct %v3int
  6721. %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
  6722. %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
  6723. %gid = OpVariable %ptr_ssbo_struct StorageBuffer
  6724. %image = OpTypeImage %float 3D 0 0 0 1 Unknown
  6725. %ptr_uc_image = OpTypePointer UniformConstant %image
  6726. %sampler = OpTypeSampler
  6727. %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
  6728. %image_var = OpVariable %ptr_uc_image UniformConstant
  6729. %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
  6730. %sampled = OpTypeSampledImage %image
  6731. %void_fn = OpTypeFunction %void
  6732. %foo = OpFunction %void None %void_fn
  6733. %entry = OpLabel
  6734. %ld_image = OpLoad %image %image_var
  6735. %ld_sampler = OpLoad %sampler %sampler_var
  6736. %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
  6737. %ld_gid = OpLoad %v3int %gep
  6738. %convert = OpConvertUToF %v3float %ld_gid
  6739. %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
  6740. %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
  6741. OpReturn
  6742. OpFunctionEnd
  6743. )";
  6744. SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
  6745. SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
  6746. 2u);
  6747. }
  6748. TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedUBOArrayV2) {
  6749. // #version 450
  6750. // #extension GL_EXT_nonuniform_qualifier : enable
  6751. //
  6752. // layout(location=0) in nonuniformEXT flat int nu_ii;
  6753. // layout(location=0) out float b;
  6754. //
  6755. // layout(binding=3) uniform uname { float a; } uniformBuffer[];
  6756. //
  6757. // void main()
  6758. // {
  6759. // b = uniformBuffer[nu_ii].a;
  6760. // }
  6761. const std::string defs_before =
  6762. R"(OpCapability Shader
  6763. OpCapability ShaderNonUniform
  6764. OpCapability RuntimeDescriptorArray
  6765. OpCapability UniformBufferArrayNonUniformIndexing
  6766. OpExtension "SPV_EXT_descriptor_indexing"
  6767. %1 = OpExtInstImport "GLSL.std.450"
  6768. OpMemoryModel Logical GLSL450
  6769. OpEntryPoint Fragment %main "main" %b %nu_ii
  6770. OpExecutionMode %main OriginUpperLeft
  6771. OpSource GLSL 450
  6772. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  6773. OpName %main "main"
  6774. OpName %b "b"
  6775. OpName %uname "uname"
  6776. OpMemberName %uname 0 "a"
  6777. OpName %uniformBuffer "uniformBuffer"
  6778. OpName %nu_ii "nu_ii"
  6779. OpDecorate %b Location 0
  6780. OpMemberDecorate %uname 0 Offset 0
  6781. OpDecorate %uname Block
  6782. OpDecorate %uniformBuffer DescriptorSet 0
  6783. OpDecorate %uniformBuffer Binding 3
  6784. OpDecorate %nu_ii Flat
  6785. OpDecorate %nu_ii Location 0
  6786. OpDecorate %nu_ii NonUniform
  6787. OpDecorate %16 NonUniform
  6788. OpDecorate %20 NonUniform
  6789. %void = OpTypeVoid
  6790. %3 = OpTypeFunction %void
  6791. %float = OpTypeFloat 32
  6792. %_ptr_Output_float = OpTypePointer Output %float
  6793. %b = OpVariable %_ptr_Output_float Output
  6794. %uname = OpTypeStruct %float
  6795. %_runtimearr_uname = OpTypeRuntimeArray %uname
  6796. %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
  6797. %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
  6798. %int = OpTypeInt 32 1
  6799. %_ptr_Input_int = OpTypePointer Input %int
  6800. %nu_ii = OpVariable %_ptr_Input_int Input
  6801. %int_0 = OpConstant %int 0
  6802. %_ptr_Uniform_float = OpTypePointer Uniform %float
  6803. )";
  6804. const std::string defs_after =
  6805. R"(OpCapability Shader
  6806. OpCapability ShaderNonUniform
  6807. OpCapability RuntimeDescriptorArray
  6808. OpCapability UniformBufferArrayNonUniformIndexing
  6809. OpExtension "SPV_EXT_descriptor_indexing"
  6810. OpExtension "SPV_KHR_storage_buffer_storage_class"
  6811. %1 = OpExtInstImport "GLSL.std.450"
  6812. OpMemoryModel Logical GLSL450
  6813. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  6814. OpExecutionMode %main OriginUpperLeft
  6815. OpSource GLSL 450
  6816. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  6817. OpName %main "main"
  6818. OpName %b "b"
  6819. OpName %uname "uname"
  6820. OpMemberName %uname 0 "a"
  6821. OpName %uniformBuffer "uniformBuffer"
  6822. OpName %nu_ii "nu_ii"
  6823. OpDecorate %b Location 0
  6824. OpMemberDecorate %uname 0 Offset 0
  6825. OpDecorate %uname Block
  6826. OpDecorate %uniformBuffer DescriptorSet 0
  6827. OpDecorate %uniformBuffer Binding 3
  6828. OpDecorate %nu_ii Flat
  6829. OpDecorate %nu_ii Location 0
  6830. OpDecorate %nu_ii NonUniform
  6831. OpDecorate %7 NonUniform
  6832. OpDecorate %102 NonUniform
  6833. OpDecorate %_runtimearr_uint ArrayStride 4
  6834. OpDecorate %_struct_31 Block
  6835. OpMemberDecorate %_struct_31 0 Offset 0
  6836. OpDecorate %33 DescriptorSet 7
  6837. OpDecorate %33 Binding 1
  6838. OpDecorate %130 NonUniform
  6839. OpDecorate %_struct_55 Block
  6840. OpMemberDecorate %_struct_55 0 Offset 0
  6841. OpMemberDecorate %_struct_55 1 Offset 4
  6842. OpDecorate %57 DescriptorSet 7
  6843. OpDecorate %57 Binding 0
  6844. OpDecorate %gl_FragCoord BuiltIn FragCoord
  6845. OpDecorate %127 NonUniform
  6846. %void = OpTypeVoid
  6847. %10 = OpTypeFunction %void
  6848. %float = OpTypeFloat 32
  6849. %_ptr_Output_float = OpTypePointer Output %float
  6850. %b = OpVariable %_ptr_Output_float Output
  6851. %uname = OpTypeStruct %float
  6852. %_runtimearr_uname = OpTypeRuntimeArray %uname
  6853. %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
  6854. %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
  6855. %int = OpTypeInt 32 1
  6856. %_ptr_Input_int = OpTypePointer Input %int
  6857. %nu_ii = OpVariable %_ptr_Input_int Input
  6858. %int_0 = OpConstant %int 0
  6859. %_ptr_Uniform_float = OpTypePointer Uniform %float
  6860. %uint = OpTypeInt 32 0
  6861. %uint_0 = OpConstant %uint 0
  6862. %uint_1 = OpConstant %uint 1
  6863. %uint_3 = OpConstant %uint 3
  6864. %26 = OpTypeFunction %uint %uint %uint
  6865. %_runtimearr_uint = OpTypeRuntimeArray %uint
  6866. %_struct_31 = OpTypeStruct %_runtimearr_uint
  6867. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  6868. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  6869. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  6870. %bool = OpTypeBool
  6871. %49 = OpTypeFunction %void %uint %uint %uint %uint
  6872. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  6873. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  6874. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  6875. %uint_10 = OpConstant %uint 10
  6876. %uint_4 = OpConstant %uint 4
  6877. %uint_23 = OpConstant %uint 23
  6878. %uint_2 = OpConstant %uint 2
  6879. %v4float = OpTypeVector %float 4
  6880. %_ptr_Input_v4float = OpTypePointer Input %v4float
  6881. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  6882. %v4uint = OpTypeVector %uint 4
  6883. %uint_5 = OpConstant %uint 5
  6884. %uint_7 = OpConstant %uint 7
  6885. %uint_8 = OpConstant %uint 8
  6886. %uint_9 = OpConstant %uint 9
  6887. %uint_45 = OpConstant %uint 45
  6888. %101 = OpConstantNull %float
  6889. %105 = OpTypeFunction %uint %uint %uint %uint %uint
  6890. )";
  6891. const std::string func_before =
  6892. R"(%main = OpFunction %void None %3
  6893. %5 = OpLabel
  6894. %16 = OpLoad %int %nu_ii
  6895. %19 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %16 %int_0
  6896. %20 = OpLoad %float %19
  6897. OpStore %b %20
  6898. OpReturn
  6899. OpFunctionEnd
  6900. )";
  6901. const std::string func_after =
  6902. R"(%main = OpFunction %void None %10
  6903. %19 = OpLabel
  6904. %7 = OpLoad %int %nu_ii
  6905. %20 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
  6906. %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
  6907. %42 = OpULessThan %bool %7 %40
  6908. OpSelectionMerge %43 None
  6909. OpBranchConditional %42 %44 %45
  6910. %44 = OpLabel
  6911. %103 = OpBitcast %uint %7
  6912. %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
  6913. %123 = OpINotEqual %bool %122 %uint_0
  6914. OpSelectionMerge %124 None
  6915. OpBranchConditional %123 %125 %126
  6916. %125 = OpLabel
  6917. %127 = OpLoad %float %20
  6918. OpBranch %124
  6919. %126 = OpLabel
  6920. %128 = OpBitcast %uint %7
  6921. %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
  6922. OpBranch %124
  6923. %124 = OpLabel
  6924. %130 = OpPhi %float %127 %125 %101 %126
  6925. OpBranch %43
  6926. %45 = OpLabel
  6927. %47 = OpBitcast %uint %7
  6928. %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
  6929. OpBranch %43
  6930. %43 = OpLabel
  6931. %102 = OpPhi %float %130 %124 %101 %45
  6932. OpStore %b %102
  6933. OpReturn
  6934. OpFunctionEnd
  6935. )";
  6936. const std::string new_funcs =
  6937. R"(%25 = OpFunction %uint None %26
  6938. %27 = OpFunctionParameter %uint
  6939. %28 = OpFunctionParameter %uint
  6940. %29 = OpLabel
  6941. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  6942. %36 = OpLoad %uint %35
  6943. %37 = OpIAdd %uint %36 %28
  6944. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  6945. %39 = OpLoad %uint %38
  6946. OpReturnValue %39
  6947. OpFunctionEnd
  6948. %48 = OpFunction %void None %49
  6949. %50 = OpFunctionParameter %uint
  6950. %51 = OpFunctionParameter %uint
  6951. %52 = OpFunctionParameter %uint
  6952. %53 = OpFunctionParameter %uint
  6953. %54 = OpLabel
  6954. %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  6955. %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_10
  6956. %62 = OpIAdd %uint %61 %uint_10
  6957. %63 = OpArrayLength %uint %57 1
  6958. %64 = OpULessThanEqual %bool %62 %63
  6959. OpSelectionMerge %65 None
  6960. OpBranchConditional %64 %66 %65
  6961. %66 = OpLabel
  6962. %67 = OpIAdd %uint %61 %uint_0
  6963. %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
  6964. OpStore %68 %uint_10
  6965. %70 = OpIAdd %uint %61 %uint_1
  6966. %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
  6967. OpStore %71 %uint_23
  6968. %73 = OpIAdd %uint %61 %uint_2
  6969. %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
  6970. OpStore %74 %50
  6971. %75 = OpIAdd %uint %61 %uint_3
  6972. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  6973. OpStore %76 %uint_4
  6974. %80 = OpLoad %v4float %gl_FragCoord
  6975. %82 = OpBitcast %v4uint %80
  6976. %83 = OpCompositeExtract %uint %82 0
  6977. %84 = OpIAdd %uint %61 %uint_4
  6978. %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
  6979. OpStore %85 %83
  6980. %86 = OpCompositeExtract %uint %82 1
  6981. %88 = OpIAdd %uint %61 %uint_5
  6982. %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
  6983. OpStore %89 %86
  6984. %91 = OpIAdd %uint %61 %uint_7
  6985. %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
  6986. OpStore %92 %51
  6987. %94 = OpIAdd %uint %61 %uint_8
  6988. %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
  6989. OpStore %95 %52
  6990. %97 = OpIAdd %uint %61 %uint_9
  6991. %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
  6992. OpStore %98 %53
  6993. OpBranch %65
  6994. %65 = OpLabel
  6995. OpReturn
  6996. OpFunctionEnd
  6997. %104 = OpFunction %uint None %105
  6998. %106 = OpFunctionParameter %uint
  6999. %107 = OpFunctionParameter %uint
  7000. %108 = OpFunctionParameter %uint
  7001. %109 = OpFunctionParameter %uint
  7002. %110 = OpLabel
  7003. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
  7004. %112 = OpLoad %uint %111
  7005. %113 = OpIAdd %uint %112 %107
  7006. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  7007. %115 = OpLoad %uint %114
  7008. %116 = OpIAdd %uint %115 %108
  7009. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  7010. %118 = OpLoad %uint %117
  7011. %119 = OpIAdd %uint %118 %109
  7012. %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
  7013. %121 = OpLoad %uint %120
  7014. OpReturnValue %121
  7015. OpFunctionEnd
  7016. )";
  7017. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  7018. SinglePassRunAndCheck<InstBindlessCheckPass>(
  7019. defs_before + func_before, defs_after + func_after + new_funcs, true,
  7020. true, 7u, 23u, true, true, 2u);
  7021. }
  7022. TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayDeprecatedV2) {
  7023. // #version 450
  7024. // #extension GL_EXT_nonuniform_qualifier : enable
  7025. //
  7026. // layout(location=0) in nonuniformEXT flat int nu_ii;
  7027. // layout(location=0) out float b;
  7028. //
  7029. // layout(binding=3) buffer bname { float b; } storageBuffer[];
  7030. //
  7031. // void main()
  7032. // {
  7033. // b = storageBuffer[nu_ii].b;
  7034. // }
  7035. const std::string defs_before =
  7036. R"(OpCapability Shader
  7037. OpCapability ShaderNonUniform
  7038. OpCapability RuntimeDescriptorArray
  7039. OpCapability StorageBufferArrayNonUniformIndexing
  7040. OpExtension "SPV_EXT_descriptor_indexing"
  7041. %1 = OpExtInstImport "GLSL.std.450"
  7042. OpMemoryModel Logical GLSL450
  7043. OpEntryPoint Fragment %main "main" %b %nu_ii
  7044. OpExecutionMode %main OriginUpperLeft
  7045. OpSource GLSL 450
  7046. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7047. OpName %main "main"
  7048. OpName %b "b"
  7049. OpName %bname "bname"
  7050. OpMemberName %bname 0 "a"
  7051. OpName %storageBuffer "storageBuffer"
  7052. OpName %nu_ii "nu_ii"
  7053. OpDecorate %b Location 0
  7054. OpMemberDecorate %bname 0 Offset 0
  7055. OpDecorate %bname Block
  7056. OpDecorate %storageBuffer DescriptorSet 0
  7057. OpDecorate %storageBuffer Binding 3
  7058. OpDecorate %nu_ii Flat
  7059. OpDecorate %nu_ii Location 0
  7060. OpDecorate %nu_ii NonUniform
  7061. OpDecorate %16 NonUniform
  7062. OpDecorate %20 NonUniform
  7063. %void = OpTypeVoid
  7064. %3 = OpTypeFunction %void
  7065. %float = OpTypeFloat 32
  7066. %_ptr_Output_float = OpTypePointer Output %float
  7067. %b = OpVariable %_ptr_Output_float Output
  7068. %bname = OpTypeStruct %float
  7069. %_runtimearr_bname = OpTypeRuntimeArray %bname
  7070. %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
  7071. %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
  7072. %int = OpTypeInt 32 1
  7073. %_ptr_Input_int = OpTypePointer Input %int
  7074. %nu_ii = OpVariable %_ptr_Input_int Input
  7075. %int_0 = OpConstant %int 0
  7076. %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
  7077. )";
  7078. const std::string defs_after =
  7079. R"(OpCapability Shader
  7080. OpCapability ShaderNonUniform
  7081. OpCapability RuntimeDescriptorArray
  7082. OpCapability StorageBufferArrayNonUniformIndexing
  7083. OpExtension "SPV_EXT_descriptor_indexing"
  7084. OpExtension "SPV_KHR_storage_buffer_storage_class"
  7085. %1 = OpExtInstImport "GLSL.std.450"
  7086. OpMemoryModel Logical GLSL450
  7087. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  7088. OpExecutionMode %main OriginUpperLeft
  7089. OpSource GLSL 450
  7090. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7091. OpName %main "main"
  7092. OpName %b "b"
  7093. OpName %bname "bname"
  7094. OpMemberName %bname 0 "a"
  7095. OpName %storageBuffer "storageBuffer"
  7096. OpName %nu_ii "nu_ii"
  7097. OpDecorate %b Location 0
  7098. OpMemberDecorate %bname 0 Offset 0
  7099. OpDecorate %bname Block
  7100. OpDecorate %storageBuffer DescriptorSet 0
  7101. OpDecorate %storageBuffer Binding 3
  7102. OpDecorate %nu_ii Flat
  7103. OpDecorate %nu_ii Location 0
  7104. OpDecorate %nu_ii NonUniform
  7105. OpDecorate %7 NonUniform
  7106. OpDecorate %102 NonUniform
  7107. OpDecorate %_runtimearr_uint ArrayStride 4
  7108. OpDecorate %_struct_31 Block
  7109. OpMemberDecorate %_struct_31 0 Offset 0
  7110. OpDecorate %33 DescriptorSet 7
  7111. OpDecorate %33 Binding 1
  7112. OpDecorate %130 NonUniform
  7113. OpDecorate %_struct_55 Block
  7114. OpMemberDecorate %_struct_55 0 Offset 0
  7115. OpMemberDecorate %_struct_55 1 Offset 4
  7116. OpDecorate %57 DescriptorSet 7
  7117. OpDecorate %57 Binding 0
  7118. OpDecorate %gl_FragCoord BuiltIn FragCoord
  7119. OpDecorate %127 NonUniform
  7120. %void = OpTypeVoid
  7121. %10 = OpTypeFunction %void
  7122. %float = OpTypeFloat 32
  7123. %_ptr_Output_float = OpTypePointer Output %float
  7124. %b = OpVariable %_ptr_Output_float Output
  7125. %bname = OpTypeStruct %float
  7126. %_runtimearr_bname = OpTypeRuntimeArray %bname
  7127. %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
  7128. %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
  7129. %int = OpTypeInt 32 1
  7130. %_ptr_Input_int = OpTypePointer Input %int
  7131. %nu_ii = OpVariable %_ptr_Input_int Input
  7132. %int_0 = OpConstant %int 0
  7133. %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
  7134. %uint = OpTypeInt 32 0
  7135. %uint_0 = OpConstant %uint 0
  7136. %uint_1 = OpConstant %uint 1
  7137. %uint_3 = OpConstant %uint 3
  7138. %26 = OpTypeFunction %uint %uint %uint
  7139. %_runtimearr_uint = OpTypeRuntimeArray %uint
  7140. %_struct_31 = OpTypeStruct %_runtimearr_uint
  7141. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  7142. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  7143. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  7144. %bool = OpTypeBool
  7145. %49 = OpTypeFunction %void %uint %uint %uint %uint
  7146. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  7147. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  7148. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  7149. %uint_10 = OpConstant %uint 10
  7150. %uint_4 = OpConstant %uint 4
  7151. %uint_23 = OpConstant %uint 23
  7152. %uint_2 = OpConstant %uint 2
  7153. %v4float = OpTypeVector %float 4
  7154. %_ptr_Input_v4float = OpTypePointer Input %v4float
  7155. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  7156. %v4uint = OpTypeVector %uint 4
  7157. %uint_5 = OpConstant %uint 5
  7158. %uint_7 = OpConstant %uint 7
  7159. %uint_8 = OpConstant %uint 8
  7160. %uint_9 = OpConstant %uint 9
  7161. %uint_45 = OpConstant %uint 45
  7162. %101 = OpConstantNull %float
  7163. %105 = OpTypeFunction %uint %uint %uint %uint %uint
  7164. )";
  7165. const std::string func_before =
  7166. R"(%main = OpFunction %void None %3
  7167. %5 = OpLabel
  7168. %16 = OpLoad %int %nu_ii
  7169. %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
  7170. %20 = OpLoad %float %19
  7171. OpStore %b %20
  7172. OpReturn
  7173. OpFunctionEnd
  7174. )";
  7175. const std::string func_after =
  7176. R"(%main = OpFunction %void None %10
  7177. %19 = OpLabel
  7178. %7 = OpLoad %int %nu_ii
  7179. %20 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %7 %int_0
  7180. %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
  7181. %42 = OpULessThan %bool %7 %40
  7182. OpSelectionMerge %43 None
  7183. OpBranchConditional %42 %44 %45
  7184. %44 = OpLabel
  7185. %103 = OpBitcast %uint %7
  7186. %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
  7187. %123 = OpINotEqual %bool %122 %uint_0
  7188. OpSelectionMerge %124 None
  7189. OpBranchConditional %123 %125 %126
  7190. %125 = OpLabel
  7191. %127 = OpLoad %float %20
  7192. OpBranch %124
  7193. %126 = OpLabel
  7194. %128 = OpBitcast %uint %7
  7195. %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
  7196. OpBranch %124
  7197. %124 = OpLabel
  7198. %130 = OpPhi %float %127 %125 %101 %126
  7199. OpBranch %43
  7200. %45 = OpLabel
  7201. %47 = OpBitcast %uint %7
  7202. %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
  7203. OpBranch %43
  7204. %43 = OpLabel
  7205. %102 = OpPhi %float %130 %124 %101 %45
  7206. OpStore %b %102
  7207. OpReturn
  7208. OpFunctionEnd
  7209. )";
  7210. const std::string new_funcs =
  7211. R"(%25 = OpFunction %uint None %26
  7212. %27 = OpFunctionParameter %uint
  7213. %28 = OpFunctionParameter %uint
  7214. %29 = OpLabel
  7215. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  7216. %36 = OpLoad %uint %35
  7217. %37 = OpIAdd %uint %36 %28
  7218. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  7219. %39 = OpLoad %uint %38
  7220. OpReturnValue %39
  7221. OpFunctionEnd
  7222. %48 = OpFunction %void None %49
  7223. %50 = OpFunctionParameter %uint
  7224. %51 = OpFunctionParameter %uint
  7225. %52 = OpFunctionParameter %uint
  7226. %53 = OpFunctionParameter %uint
  7227. %54 = OpLabel
  7228. %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  7229. %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_10
  7230. %62 = OpIAdd %uint %61 %uint_10
  7231. %63 = OpArrayLength %uint %57 1
  7232. %64 = OpULessThanEqual %bool %62 %63
  7233. OpSelectionMerge %65 None
  7234. OpBranchConditional %64 %66 %65
  7235. %66 = OpLabel
  7236. %67 = OpIAdd %uint %61 %uint_0
  7237. %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
  7238. OpStore %68 %uint_10
  7239. %70 = OpIAdd %uint %61 %uint_1
  7240. %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
  7241. OpStore %71 %uint_23
  7242. %73 = OpIAdd %uint %61 %uint_2
  7243. %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
  7244. OpStore %74 %50
  7245. %75 = OpIAdd %uint %61 %uint_3
  7246. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  7247. OpStore %76 %uint_4
  7248. %80 = OpLoad %v4float %gl_FragCoord
  7249. %82 = OpBitcast %v4uint %80
  7250. %83 = OpCompositeExtract %uint %82 0
  7251. %84 = OpIAdd %uint %61 %uint_4
  7252. %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
  7253. OpStore %85 %83
  7254. %86 = OpCompositeExtract %uint %82 1
  7255. %88 = OpIAdd %uint %61 %uint_5
  7256. %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
  7257. OpStore %89 %86
  7258. %91 = OpIAdd %uint %61 %uint_7
  7259. %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
  7260. OpStore %92 %51
  7261. %94 = OpIAdd %uint %61 %uint_8
  7262. %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
  7263. OpStore %95 %52
  7264. %97 = OpIAdd %uint %61 %uint_9
  7265. %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
  7266. OpStore %98 %53
  7267. OpBranch %65
  7268. %65 = OpLabel
  7269. OpReturn
  7270. OpFunctionEnd
  7271. %104 = OpFunction %uint None %105
  7272. %106 = OpFunctionParameter %uint
  7273. %107 = OpFunctionParameter %uint
  7274. %108 = OpFunctionParameter %uint
  7275. %109 = OpFunctionParameter %uint
  7276. %110 = OpLabel
  7277. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
  7278. %112 = OpLoad %uint %111
  7279. %113 = OpIAdd %uint %112 %107
  7280. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  7281. %115 = OpLoad %uint %114
  7282. %116 = OpIAdd %uint %115 %108
  7283. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  7284. %118 = OpLoad %uint %117
  7285. %119 = OpIAdd %uint %118 %109
  7286. %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
  7287. %121 = OpLoad %uint %120
  7288. OpReturnValue %121
  7289. OpFunctionEnd
  7290. )";
  7291. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  7292. SinglePassRunAndCheck<InstBindlessCheckPass>(
  7293. defs_before + func_before, defs_after + func_after + new_funcs, true,
  7294. true, 7u, 23u, true, true, 2u);
  7295. }
  7296. TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayV2) {
  7297. // Same as Deprecated but declaring as StorageBuffer Block
  7298. const std::string defs_before =
  7299. R"(OpCapability Shader
  7300. OpCapability ShaderNonUniform
  7301. OpCapability RuntimeDescriptorArray
  7302. OpCapability StorageBufferArrayNonUniformIndexing
  7303. OpExtension "SPV_EXT_descriptor_indexing"
  7304. %1 = OpExtInstImport "GLSL.std.450"
  7305. OpMemoryModel Logical GLSL450
  7306. OpEntryPoint Fragment %main "main" %b %nu_ii
  7307. OpExecutionMode %main OriginUpperLeft
  7308. OpSource GLSL 450
  7309. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7310. OpName %main "main"
  7311. OpName %b "b"
  7312. OpName %bname "bname"
  7313. OpMemberName %bname 0 "a"
  7314. OpName %storageBuffer "storageBuffer"
  7315. OpName %nu_ii "nu_ii"
  7316. OpDecorate %b Location 0
  7317. OpMemberDecorate %bname 0 Offset 0
  7318. OpDecorate %bname Block
  7319. OpDecorate %storageBuffer DescriptorSet 0
  7320. OpDecorate %storageBuffer Binding 3
  7321. OpDecorate %nu_ii Flat
  7322. OpDecorate %nu_ii Location 0
  7323. OpDecorate %nu_ii NonUniform
  7324. OpDecorate %16 NonUniform
  7325. OpDecorate %20 NonUniform
  7326. %void = OpTypeVoid
  7327. %3 = OpTypeFunction %void
  7328. %float = OpTypeFloat 32
  7329. %_ptr_Output_float = OpTypePointer Output %float
  7330. %b = OpVariable %_ptr_Output_float Output
  7331. %bname = OpTypeStruct %float
  7332. %_runtimearr_bname = OpTypeRuntimeArray %bname
  7333. %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
  7334. %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
  7335. %int = OpTypeInt 32 1
  7336. %_ptr_Input_int = OpTypePointer Input %int
  7337. %nu_ii = OpVariable %_ptr_Input_int Input
  7338. %int_0 = OpConstant %int 0
  7339. %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
  7340. )";
  7341. const std::string defs_after =
  7342. R"(OpCapability Shader
  7343. OpCapability ShaderNonUniform
  7344. OpCapability RuntimeDescriptorArray
  7345. OpCapability StorageBufferArrayNonUniformIndexing
  7346. OpExtension "SPV_EXT_descriptor_indexing"
  7347. OpExtension "SPV_KHR_storage_buffer_storage_class"
  7348. %1 = OpExtInstImport "GLSL.std.450"
  7349. OpMemoryModel Logical GLSL450
  7350. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  7351. OpExecutionMode %main OriginUpperLeft
  7352. OpSource GLSL 450
  7353. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7354. OpName %main "main"
  7355. OpName %b "b"
  7356. OpName %bname "bname"
  7357. OpMemberName %bname 0 "a"
  7358. OpName %storageBuffer "storageBuffer"
  7359. OpName %nu_ii "nu_ii"
  7360. OpDecorate %b Location 0
  7361. OpMemberDecorate %bname 0 Offset 0
  7362. OpDecorate %bname Block
  7363. OpDecorate %storageBuffer DescriptorSet 0
  7364. OpDecorate %storageBuffer Binding 3
  7365. OpDecorate %nu_ii Flat
  7366. OpDecorate %nu_ii Location 0
  7367. OpDecorate %nu_ii NonUniform
  7368. OpDecorate %7 NonUniform
  7369. OpDecorate %102 NonUniform
  7370. OpDecorate %_runtimearr_uint ArrayStride 4
  7371. OpDecorate %_struct_31 Block
  7372. OpMemberDecorate %_struct_31 0 Offset 0
  7373. OpDecorate %33 DescriptorSet 7
  7374. OpDecorate %33 Binding 1
  7375. OpDecorate %130 NonUniform
  7376. OpDecorate %_struct_55 Block
  7377. OpMemberDecorate %_struct_55 0 Offset 0
  7378. OpMemberDecorate %_struct_55 1 Offset 4
  7379. OpDecorate %57 DescriptorSet 7
  7380. OpDecorate %57 Binding 0
  7381. OpDecorate %gl_FragCoord BuiltIn FragCoord
  7382. OpDecorate %127 NonUniform
  7383. %void = OpTypeVoid
  7384. %10 = OpTypeFunction %void
  7385. %float = OpTypeFloat 32
  7386. %_ptr_Output_float = OpTypePointer Output %float
  7387. %b = OpVariable %_ptr_Output_float Output
  7388. %bname = OpTypeStruct %float
  7389. %_runtimearr_bname = OpTypeRuntimeArray %bname
  7390. %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
  7391. %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
  7392. %int = OpTypeInt 32 1
  7393. %_ptr_Input_int = OpTypePointer Input %int
  7394. %nu_ii = OpVariable %_ptr_Input_int Input
  7395. %int_0 = OpConstant %int 0
  7396. %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
  7397. %uint = OpTypeInt 32 0
  7398. %uint_0 = OpConstant %uint 0
  7399. %uint_1 = OpConstant %uint 1
  7400. %uint_3 = OpConstant %uint 3
  7401. %26 = OpTypeFunction %uint %uint %uint
  7402. %_runtimearr_uint = OpTypeRuntimeArray %uint
  7403. %_struct_31 = OpTypeStruct %_runtimearr_uint
  7404. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  7405. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  7406. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  7407. %bool = OpTypeBool
  7408. %49 = OpTypeFunction %void %uint %uint %uint %uint
  7409. %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
  7410. %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
  7411. %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
  7412. %uint_10 = OpConstant %uint 10
  7413. %uint_4 = OpConstant %uint 4
  7414. %uint_23 = OpConstant %uint 23
  7415. %uint_2 = OpConstant %uint 2
  7416. %v4float = OpTypeVector %float 4
  7417. %_ptr_Input_v4float = OpTypePointer Input %v4float
  7418. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  7419. %v4uint = OpTypeVector %uint 4
  7420. %uint_5 = OpConstant %uint 5
  7421. %uint_7 = OpConstant %uint 7
  7422. %uint_8 = OpConstant %uint 8
  7423. %uint_9 = OpConstant %uint 9
  7424. %uint_45 = OpConstant %uint 45
  7425. %101 = OpConstantNull %float
  7426. %105 = OpTypeFunction %uint %uint %uint %uint %uint
  7427. )";
  7428. const std::string func_before =
  7429. R"(%main = OpFunction %void None %3
  7430. %5 = OpLabel
  7431. %16 = OpLoad %int %nu_ii
  7432. %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
  7433. %20 = OpLoad %float %19
  7434. OpStore %b %20
  7435. OpReturn
  7436. OpFunctionEnd
  7437. )";
  7438. const std::string func_after =
  7439. R"(%main = OpFunction %void None %10
  7440. %19 = OpLabel
  7441. %7 = OpLoad %int %nu_ii
  7442. %20 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %7 %int_0
  7443. %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
  7444. %42 = OpULessThan %bool %7 %40
  7445. OpSelectionMerge %43 None
  7446. OpBranchConditional %42 %44 %45
  7447. %44 = OpLabel
  7448. %103 = OpBitcast %uint %7
  7449. %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
  7450. %123 = OpINotEqual %bool %122 %uint_0
  7451. OpSelectionMerge %124 None
  7452. OpBranchConditional %123 %125 %126
  7453. %125 = OpLabel
  7454. %127 = OpLoad %float %20
  7455. OpBranch %124
  7456. %126 = OpLabel
  7457. %128 = OpBitcast %uint %7
  7458. %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
  7459. OpBranch %124
  7460. %124 = OpLabel
  7461. %130 = OpPhi %float %127 %125 %101 %126
  7462. OpBranch %43
  7463. %45 = OpLabel
  7464. %47 = OpBitcast %uint %7
  7465. %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
  7466. OpBranch %43
  7467. %43 = OpLabel
  7468. %102 = OpPhi %float %130 %124 %101 %45
  7469. OpStore %b %102
  7470. OpReturn
  7471. OpFunctionEnd
  7472. )";
  7473. const std::string new_funcs =
  7474. R"(%25 = OpFunction %uint None %26
  7475. %27 = OpFunctionParameter %uint
  7476. %28 = OpFunctionParameter %uint
  7477. %29 = OpLabel
  7478. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  7479. %36 = OpLoad %uint %35
  7480. %37 = OpIAdd %uint %36 %28
  7481. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  7482. %39 = OpLoad %uint %38
  7483. OpReturnValue %39
  7484. OpFunctionEnd
  7485. %48 = OpFunction %void None %49
  7486. %50 = OpFunctionParameter %uint
  7487. %51 = OpFunctionParameter %uint
  7488. %52 = OpFunctionParameter %uint
  7489. %53 = OpFunctionParameter %uint
  7490. %54 = OpLabel
  7491. %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
  7492. %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_10
  7493. %62 = OpIAdd %uint %61 %uint_10
  7494. %63 = OpArrayLength %uint %57 1
  7495. %64 = OpULessThanEqual %bool %62 %63
  7496. OpSelectionMerge %65 None
  7497. OpBranchConditional %64 %66 %65
  7498. %66 = OpLabel
  7499. %67 = OpIAdd %uint %61 %uint_0
  7500. %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
  7501. OpStore %68 %uint_10
  7502. %70 = OpIAdd %uint %61 %uint_1
  7503. %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
  7504. OpStore %71 %uint_23
  7505. %73 = OpIAdd %uint %61 %uint_2
  7506. %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
  7507. OpStore %74 %50
  7508. %75 = OpIAdd %uint %61 %uint_3
  7509. %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
  7510. OpStore %76 %uint_4
  7511. %80 = OpLoad %v4float %gl_FragCoord
  7512. %82 = OpBitcast %v4uint %80
  7513. %83 = OpCompositeExtract %uint %82 0
  7514. %84 = OpIAdd %uint %61 %uint_4
  7515. %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
  7516. OpStore %85 %83
  7517. %86 = OpCompositeExtract %uint %82 1
  7518. %88 = OpIAdd %uint %61 %uint_5
  7519. %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
  7520. OpStore %89 %86
  7521. %91 = OpIAdd %uint %61 %uint_7
  7522. %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
  7523. OpStore %92 %51
  7524. %94 = OpIAdd %uint %61 %uint_8
  7525. %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
  7526. OpStore %95 %52
  7527. %97 = OpIAdd %uint %61 %uint_9
  7528. %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
  7529. OpStore %98 %53
  7530. OpBranch %65
  7531. %65 = OpLabel
  7532. OpReturn
  7533. OpFunctionEnd
  7534. %104 = OpFunction %uint None %105
  7535. %106 = OpFunctionParameter %uint
  7536. %107 = OpFunctionParameter %uint
  7537. %108 = OpFunctionParameter %uint
  7538. %109 = OpFunctionParameter %uint
  7539. %110 = OpLabel
  7540. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
  7541. %112 = OpLoad %uint %111
  7542. %113 = OpIAdd %uint %112 %107
  7543. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  7544. %115 = OpLoad %uint %114
  7545. %116 = OpIAdd %uint %115 %108
  7546. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  7547. %118 = OpLoad %uint %117
  7548. %119 = OpIAdd %uint %118 %109
  7549. %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
  7550. %121 = OpLoad %uint %120
  7551. OpReturnValue %121
  7552. OpFunctionEnd
  7553. )";
  7554. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  7555. SinglePassRunAndCheck<InstBindlessCheckPass>(
  7556. defs_before + func_before, defs_after + func_after + new_funcs, true,
  7557. true, 7u, 23u, true, true, 2u);
  7558. }
  7559. TEST_F(InstBindlessTest, InstInitLoadUBOScalarV2) {
  7560. // #version 450
  7561. // #extension GL_EXT_nonuniform_qualifier : enable
  7562. //
  7563. // layout(location=0) out float b;
  7564. // layout(binding=3) uniform uname { float a; } uniformBuffer;
  7565. //
  7566. // void main()
  7567. // {
  7568. // b = uniformBuffer.a;
  7569. // }
  7570. const std::string defs_before =
  7571. R"(OpCapability Shader
  7572. OpExtension "SPV_EXT_descriptor_indexing"
  7573. %1 = OpExtInstImport "GLSL.std.450"
  7574. OpMemoryModel Logical GLSL450
  7575. OpEntryPoint Fragment %main "main" %b
  7576. OpExecutionMode %main OriginUpperLeft
  7577. OpSource GLSL 450
  7578. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7579. OpName %main "main"
  7580. OpName %b "b"
  7581. OpName %uname "uname"
  7582. OpMemberName %uname 0 "a"
  7583. OpName %uniformBuffer "uniformBuffer"
  7584. OpDecorate %b Location 0
  7585. OpMemberDecorate %uname 0 Offset 0
  7586. OpDecorate %uname Block
  7587. OpDecorate %uniformBuffer DescriptorSet 0
  7588. OpDecorate %uniformBuffer Binding 3
  7589. %void = OpTypeVoid
  7590. %3 = OpTypeFunction %void
  7591. %float = OpTypeFloat 32
  7592. %_ptr_Output_float = OpTypePointer Output %float
  7593. %b = OpVariable %_ptr_Output_float Output
  7594. %uname = OpTypeStruct %float
  7595. %_ptr_Uniform_uname = OpTypePointer Uniform %uname
  7596. %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
  7597. %int = OpTypeInt 32 1
  7598. %int_0 = OpConstant %int 0
  7599. %_ptr_Uniform_float = OpTypePointer Uniform %float
  7600. )";
  7601. const std::string defs_after =
  7602. R"(OpCapability Shader
  7603. OpExtension "SPV_EXT_descriptor_indexing"
  7604. OpExtension "SPV_KHR_storage_buffer_storage_class"
  7605. %1 = OpExtInstImport "GLSL.std.450"
  7606. OpMemoryModel Logical GLSL450
  7607. OpEntryPoint Fragment %main "main" %b %gl_FragCoord
  7608. OpExecutionMode %main OriginUpperLeft
  7609. OpSource GLSL 450
  7610. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7611. OpName %main "main"
  7612. OpName %b "b"
  7613. OpName %uname "uname"
  7614. OpMemberName %uname 0 "a"
  7615. OpName %uniformBuffer "uniformBuffer"
  7616. OpDecorate %b Location 0
  7617. OpMemberDecorate %uname 0 Offset 0
  7618. OpDecorate %uname Block
  7619. OpDecorate %uniformBuffer DescriptorSet 0
  7620. OpDecorate %uniformBuffer Binding 3
  7621. OpDecorate %_runtimearr_uint ArrayStride 4
  7622. OpDecorate %_struct_28 Block
  7623. OpMemberDecorate %_struct_28 0 Offset 0
  7624. OpDecorate %30 DescriptorSet 7
  7625. OpDecorate %30 Binding 1
  7626. OpDecorate %_struct_58 Block
  7627. OpMemberDecorate %_struct_58 0 Offset 0
  7628. OpMemberDecorate %_struct_58 1 Offset 4
  7629. OpDecorate %60 DescriptorSet 7
  7630. OpDecorate %60 Binding 0
  7631. OpDecorate %gl_FragCoord BuiltIn FragCoord
  7632. %void = OpTypeVoid
  7633. %7 = OpTypeFunction %void
  7634. %float = OpTypeFloat 32
  7635. %_ptr_Output_float = OpTypePointer Output %float
  7636. %b = OpVariable %_ptr_Output_float Output
  7637. %uname = OpTypeStruct %float
  7638. %_ptr_Uniform_uname = OpTypePointer Uniform %uname
  7639. %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
  7640. %int = OpTypeInt 32 1
  7641. %int_0 = OpConstant %int 0
  7642. %_ptr_Uniform_float = OpTypePointer Uniform %float
  7643. %uint = OpTypeInt 32 0
  7644. %uint_0 = OpConstant %uint 0
  7645. %uint_3 = OpConstant %uint 3
  7646. %21 = OpTypeFunction %uint %uint %uint %uint %uint
  7647. %_runtimearr_uint = OpTypeRuntimeArray %uint
  7648. %_struct_28 = OpTypeStruct %_runtimearr_uint
  7649. %_ptr_StorageBuffer__struct_28 = OpTypePointer StorageBuffer %_struct_28
  7650. %30 = OpVariable %_ptr_StorageBuffer__struct_28 StorageBuffer
  7651. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  7652. %bool = OpTypeBool
  7653. %uint_1 = OpConstant %uint 1
  7654. %52 = OpTypeFunction %void %uint %uint %uint %uint
  7655. %_struct_58 = OpTypeStruct %uint %_runtimearr_uint
  7656. %_ptr_StorageBuffer__struct_58 = OpTypePointer StorageBuffer %_struct_58
  7657. %60 = OpVariable %_ptr_StorageBuffer__struct_58 StorageBuffer
  7658. %uint_10 = OpConstant %uint 10
  7659. %uint_4 = OpConstant %uint 4
  7660. %uint_23 = OpConstant %uint 23
  7661. %uint_2 = OpConstant %uint 2
  7662. %v4float = OpTypeVector %float 4
  7663. %_ptr_Input_v4float = OpTypePointer Input %v4float
  7664. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  7665. %v4uint = OpTypeVector %uint 4
  7666. %uint_5 = OpConstant %uint 5
  7667. %uint_7 = OpConstant %uint 7
  7668. %uint_8 = OpConstant %uint 8
  7669. %uint_9 = OpConstant %uint 9
  7670. %uint_32 = OpConstant %uint 32
  7671. %104 = OpConstantNull %float
  7672. )";
  7673. const std::string func_before =
  7674. R"(%main = OpFunction %void None %3
  7675. %5 = OpLabel
  7676. %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
  7677. %16 = OpLoad %float %15
  7678. OpStore %b %16
  7679. OpReturn
  7680. OpFunctionEnd
  7681. )";
  7682. const std::string func_after =
  7683. R"(%main = OpFunction %void None %7
  7684. %14 = OpLabel
  7685. %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
  7686. %43 = OpFunctionCall %uint %20 %uint_0 %uint_0 %uint_3 %uint_0
  7687. %45 = OpINotEqual %bool %43 %uint_0
  7688. OpSelectionMerge %47 None
  7689. OpBranchConditional %45 %48 %49
  7690. %48 = OpLabel
  7691. %50 = OpLoad %float %15
  7692. OpBranch %47
  7693. %49 = OpLabel
  7694. %103 = OpFunctionCall %void %51 %uint_32 %uint_1 %uint_0 %uint_0
  7695. OpBranch %47
  7696. %47 = OpLabel
  7697. %105 = OpPhi %float %50 %48 %104 %49
  7698. OpStore %b %105
  7699. OpReturn
  7700. OpFunctionEnd
  7701. )";
  7702. const std::string new_funcs =
  7703. R"(%20 = OpFunction %uint None %21
  7704. %22 = OpFunctionParameter %uint
  7705. %23 = OpFunctionParameter %uint
  7706. %24 = OpFunctionParameter %uint
  7707. %25 = OpFunctionParameter %uint
  7708. %26 = OpLabel
  7709. %32 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %22
  7710. %33 = OpLoad %uint %32
  7711. %34 = OpIAdd %uint %33 %23
  7712. %35 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %34
  7713. %36 = OpLoad %uint %35
  7714. %37 = OpIAdd %uint %36 %24
  7715. %38 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %37
  7716. %39 = OpLoad %uint %38
  7717. %40 = OpIAdd %uint %39 %25
  7718. %41 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %40
  7719. %42 = OpLoad %uint %41
  7720. OpReturnValue %42
  7721. OpFunctionEnd
  7722. %51 = OpFunction %void None %52
  7723. %53 = OpFunctionParameter %uint
  7724. %54 = OpFunctionParameter %uint
  7725. %55 = OpFunctionParameter %uint
  7726. %56 = OpFunctionParameter %uint
  7727. %57 = OpLabel
  7728. %61 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_0
  7729. %64 = OpAtomicIAdd %uint %61 %uint_4 %uint_0 %uint_10
  7730. %65 = OpIAdd %uint %64 %uint_10
  7731. %66 = OpArrayLength %uint %60 1
  7732. %67 = OpULessThanEqual %bool %65 %66
  7733. OpSelectionMerge %68 None
  7734. OpBranchConditional %67 %69 %68
  7735. %69 = OpLabel
  7736. %70 = OpIAdd %uint %64 %uint_0
  7737. %71 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %70
  7738. OpStore %71 %uint_10
  7739. %73 = OpIAdd %uint %64 %uint_1
  7740. %74 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %73
  7741. OpStore %74 %uint_23
  7742. %76 = OpIAdd %uint %64 %uint_2
  7743. %77 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %76
  7744. OpStore %77 %53
  7745. %78 = OpIAdd %uint %64 %uint_3
  7746. %79 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %78
  7747. OpStore %79 %uint_4
  7748. %83 = OpLoad %v4float %gl_FragCoord
  7749. %85 = OpBitcast %v4uint %83
  7750. %86 = OpCompositeExtract %uint %85 0
  7751. %87 = OpIAdd %uint %64 %uint_4
  7752. %88 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %87
  7753. OpStore %88 %86
  7754. %89 = OpCompositeExtract %uint %85 1
  7755. %91 = OpIAdd %uint %64 %uint_5
  7756. %92 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %91
  7757. OpStore %92 %89
  7758. %94 = OpIAdd %uint %64 %uint_7
  7759. %95 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %94
  7760. OpStore %95 %54
  7761. %97 = OpIAdd %uint %64 %uint_8
  7762. %98 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %97
  7763. OpStore %98 %55
  7764. %100 = OpIAdd %uint %64 %uint_9
  7765. %101 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %100
  7766. OpStore %101 %56
  7767. OpBranch %68
  7768. %68 = OpLabel
  7769. OpReturn
  7770. OpFunctionEnd
  7771. )";
  7772. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  7773. SinglePassRunAndCheck<InstBindlessCheckPass>(
  7774. defs_before + func_before, defs_after + func_after + new_funcs, true,
  7775. true, 7u, 23u, true, true, 2u);
  7776. }
  7777. TEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArrayV2) {
  7778. // #version 450
  7779. // #extension GL_EXT_nonuniform_qualifier : enable
  7780. //
  7781. // layout(location=0) in nonuniformEXT flat int nu_ii;
  7782. // layout(location=1) in float b;
  7783. //
  7784. // layout(binding=4) buffer bname { float b; } storageBuffer[];
  7785. //
  7786. // void main()
  7787. // {
  7788. // storageBuffer[nu_ii].b = b;
  7789. // }
  7790. const std::string defs_before =
  7791. R"(OpCapability Shader
  7792. OpCapability ShaderNonUniform
  7793. OpCapability RuntimeDescriptorArray
  7794. OpCapability StorageBufferArrayNonUniformIndexing
  7795. OpExtension "SPV_EXT_descriptor_indexing"
  7796. %1 = OpExtInstImport "GLSL.std.450"
  7797. OpMemoryModel Logical GLSL450
  7798. OpEntryPoint Fragment %main "main" %nu_ii %b
  7799. OpExecutionMode %main OriginUpperLeft
  7800. OpSource GLSL 450
  7801. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7802. OpName %main "main"
  7803. OpName %bname "bname"
  7804. OpMemberName %bname 0 "b"
  7805. OpName %storageBuffer "storageBuffer"
  7806. OpName %nu_ii "nu_ii"
  7807. OpName %b "b"
  7808. OpMemberDecorate %bname 0 Offset 0
  7809. OpDecorate %bname BufferBlock
  7810. OpDecorate %storageBuffer DescriptorSet 0
  7811. OpDecorate %storageBuffer Binding 4
  7812. OpDecorate %nu_ii Flat
  7813. OpDecorate %nu_ii Location 0
  7814. OpDecorate %nu_ii NonUniform
  7815. OpDecorate %14 NonUniform
  7816. OpDecorate %b Location 1
  7817. %void = OpTypeVoid
  7818. %3 = OpTypeFunction %void
  7819. %float = OpTypeFloat 32
  7820. %bname = OpTypeStruct %float
  7821. %_runtimearr_bname = OpTypeRuntimeArray %bname
  7822. %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
  7823. %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
  7824. %int = OpTypeInt 32 1
  7825. %_ptr_Input_int = OpTypePointer Input %int
  7826. %nu_ii = OpVariable %_ptr_Input_int Input
  7827. %int_0 = OpConstant %int 0
  7828. %_ptr_Input_float = OpTypePointer Input %float
  7829. %b = OpVariable %_ptr_Input_float Input
  7830. %_ptr_Uniform_float = OpTypePointer Uniform %float
  7831. )";
  7832. const std::string defs_after =
  7833. R"(OpCapability Shader
  7834. OpCapability ShaderNonUniform
  7835. OpCapability RuntimeDescriptorArray
  7836. OpCapability StorageBufferArrayNonUniformIndexing
  7837. OpExtension "SPV_EXT_descriptor_indexing"
  7838. OpExtension "SPV_KHR_storage_buffer_storage_class"
  7839. %1 = OpExtInstImport "GLSL.std.450"
  7840. OpMemoryModel Logical GLSL450
  7841. OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord
  7842. OpExecutionMode %main OriginUpperLeft
  7843. OpSource GLSL 450
  7844. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  7845. OpName %main "main"
  7846. OpName %bname "bname"
  7847. OpMemberName %bname 0 "b"
  7848. OpName %storageBuffer "storageBuffer"
  7849. OpName %nu_ii "nu_ii"
  7850. OpName %b "b"
  7851. OpMemberDecorate %bname 0 Offset 0
  7852. OpDecorate %bname BufferBlock
  7853. OpDecorate %storageBuffer DescriptorSet 0
  7854. OpDecorate %storageBuffer Binding 4
  7855. OpDecorate %nu_ii Flat
  7856. OpDecorate %nu_ii Location 0
  7857. OpDecorate %nu_ii NonUniform
  7858. OpDecorate %7 NonUniform
  7859. OpDecorate %b Location 1
  7860. OpDecorate %_runtimearr_uint ArrayStride 4
  7861. OpDecorate %_struct_31 Block
  7862. OpMemberDecorate %_struct_31 0 Offset 0
  7863. OpDecorate %33 DescriptorSet 7
  7864. OpDecorate %33 Binding 1
  7865. OpDecorate %_struct_54 Block
  7866. OpMemberDecorate %_struct_54 0 Offset 0
  7867. OpMemberDecorate %_struct_54 1 Offset 4
  7868. OpDecorate %56 DescriptorSet 7
  7869. OpDecorate %56 Binding 0
  7870. OpDecorate %gl_FragCoord BuiltIn FragCoord
  7871. %void = OpTypeVoid
  7872. %9 = OpTypeFunction %void
  7873. %float = OpTypeFloat 32
  7874. %bname = OpTypeStruct %float
  7875. %_runtimearr_bname = OpTypeRuntimeArray %bname
  7876. %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
  7877. %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
  7878. %int = OpTypeInt 32 1
  7879. %_ptr_Input_int = OpTypePointer Input %int
  7880. %nu_ii = OpVariable %_ptr_Input_int Input
  7881. %int_0 = OpConstant %int 0
  7882. %_ptr_Input_float = OpTypePointer Input %float
  7883. %b = OpVariable %_ptr_Input_float Input
  7884. %_ptr_Uniform_float = OpTypePointer Uniform %float
  7885. %uint = OpTypeInt 32 0
  7886. %uint_0 = OpConstant %uint 0
  7887. %uint_1 = OpConstant %uint 1
  7888. %uint_4 = OpConstant %uint 4
  7889. %26 = OpTypeFunction %uint %uint %uint
  7890. %_runtimearr_uint = OpTypeRuntimeArray %uint
  7891. %_struct_31 = OpTypeStruct %_runtimearr_uint
  7892. %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
  7893. %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
  7894. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  7895. %bool = OpTypeBool
  7896. %48 = OpTypeFunction %void %uint %uint %uint %uint
  7897. %_struct_54 = OpTypeStruct %uint %_runtimearr_uint
  7898. %_ptr_StorageBuffer__struct_54 = OpTypePointer StorageBuffer %_struct_54
  7899. %56 = OpVariable %_ptr_StorageBuffer__struct_54 StorageBuffer
  7900. %uint_10 = OpConstant %uint 10
  7901. %uint_23 = OpConstant %uint 23
  7902. %uint_2 = OpConstant %uint 2
  7903. %uint_3 = OpConstant %uint 3
  7904. %v4float = OpTypeVector %float 4
  7905. %_ptr_Input_v4float = OpTypePointer Input %v4float
  7906. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  7907. %v4uint = OpTypeVector %uint 4
  7908. %uint_5 = OpConstant %uint 5
  7909. %uint_7 = OpConstant %uint 7
  7910. %uint_8 = OpConstant %uint 8
  7911. %uint_9 = OpConstant %uint 9
  7912. %uint_45 = OpConstant %uint 45
  7913. %102 = OpTypeFunction %uint %uint %uint %uint %uint
  7914. )";
  7915. const std::string func_before =
  7916. R"(%main = OpFunction %void None %3
  7917. %5 = OpLabel
  7918. %14 = OpLoad %int %nu_ii
  7919. %18 = OpLoad %float %b
  7920. %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %14 %int_0
  7921. OpStore %20 %18
  7922. OpReturn
  7923. OpFunctionEnd
  7924. )";
  7925. const std::string func_after =
  7926. R"(%main = OpFunction %void None %9
  7927. %18 = OpLabel
  7928. %7 = OpLoad %int %nu_ii
  7929. %19 = OpLoad %float %b
  7930. %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %7 %int_0
  7931. %40 = OpFunctionCall %uint %25 %uint_1 %uint_4
  7932. %42 = OpULessThan %bool %7 %40
  7933. OpSelectionMerge %43 None
  7934. OpBranchConditional %42 %44 %45
  7935. %44 = OpLabel
  7936. %100 = OpBitcast %uint %7
  7937. %119 = OpFunctionCall %uint %101 %uint_0 %uint_0 %uint_4 %100
  7938. %120 = OpINotEqual %bool %119 %uint_0
  7939. OpSelectionMerge %121 None
  7940. OpBranchConditional %120 %122 %123
  7941. %122 = OpLabel
  7942. OpStore %20 %19
  7943. OpBranch %121
  7944. %123 = OpLabel
  7945. %124 = OpBitcast %uint %7
  7946. %125 = OpFunctionCall %void %47 %uint_45 %uint_1 %124 %uint_0
  7947. OpBranch %121
  7948. %121 = OpLabel
  7949. OpBranch %43
  7950. %45 = OpLabel
  7951. %46 = OpBitcast %uint %7
  7952. %99 = OpFunctionCall %void %47 %uint_45 %uint_0 %46 %40
  7953. OpBranch %43
  7954. %43 = OpLabel
  7955. OpReturn
  7956. OpFunctionEnd
  7957. )";
  7958. const std::string new_funcs =
  7959. R"(%25 = OpFunction %uint None %26
  7960. %27 = OpFunctionParameter %uint
  7961. %28 = OpFunctionParameter %uint
  7962. %29 = OpLabel
  7963. %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
  7964. %36 = OpLoad %uint %35
  7965. %37 = OpIAdd %uint %36 %28
  7966. %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
  7967. %39 = OpLoad %uint %38
  7968. OpReturnValue %39
  7969. OpFunctionEnd
  7970. %47 = OpFunction %void None %48
  7971. %49 = OpFunctionParameter %uint
  7972. %50 = OpFunctionParameter %uint
  7973. %51 = OpFunctionParameter %uint
  7974. %52 = OpFunctionParameter %uint
  7975. %53 = OpLabel
  7976. %57 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_0
  7977. %59 = OpAtomicIAdd %uint %57 %uint_4 %uint_0 %uint_10
  7978. %60 = OpIAdd %uint %59 %uint_10
  7979. %61 = OpArrayLength %uint %56 1
  7980. %62 = OpULessThanEqual %bool %60 %61
  7981. OpSelectionMerge %63 None
  7982. OpBranchConditional %62 %64 %63
  7983. %64 = OpLabel
  7984. %65 = OpIAdd %uint %59 %uint_0
  7985. %66 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %65
  7986. OpStore %66 %uint_10
  7987. %68 = OpIAdd %uint %59 %uint_1
  7988. %69 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %68
  7989. OpStore %69 %uint_23
  7990. %71 = OpIAdd %uint %59 %uint_2
  7991. %72 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %71
  7992. OpStore %72 %49
  7993. %74 = OpIAdd %uint %59 %uint_3
  7994. %75 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %74
  7995. OpStore %75 %uint_4
  7996. %79 = OpLoad %v4float %gl_FragCoord
  7997. %81 = OpBitcast %v4uint %79
  7998. %82 = OpCompositeExtract %uint %81 0
  7999. %83 = OpIAdd %uint %59 %uint_4
  8000. %84 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %83
  8001. OpStore %84 %82
  8002. %85 = OpCompositeExtract %uint %81 1
  8003. %87 = OpIAdd %uint %59 %uint_5
  8004. %88 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %87
  8005. OpStore %88 %85
  8006. %90 = OpIAdd %uint %59 %uint_7
  8007. %91 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %90
  8008. OpStore %91 %50
  8009. %93 = OpIAdd %uint %59 %uint_8
  8010. %94 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %93
  8011. OpStore %94 %51
  8012. %96 = OpIAdd %uint %59 %uint_9
  8013. %97 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %96
  8014. OpStore %97 %52
  8015. OpBranch %63
  8016. %63 = OpLabel
  8017. OpReturn
  8018. OpFunctionEnd
  8019. %101 = OpFunction %uint None %102
  8020. %103 = OpFunctionParameter %uint
  8021. %104 = OpFunctionParameter %uint
  8022. %105 = OpFunctionParameter %uint
  8023. %106 = OpFunctionParameter %uint
  8024. %107 = OpLabel
  8025. %108 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %103
  8026. %109 = OpLoad %uint %108
  8027. %110 = OpIAdd %uint %109 %104
  8028. %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %110
  8029. %112 = OpLoad %uint %111
  8030. %113 = OpIAdd %uint %112 %105
  8031. %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
  8032. %115 = OpLoad %uint %114
  8033. %116 = OpIAdd %uint %115 %106
  8034. %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
  8035. %118 = OpLoad %uint %117
  8036. OpReturnValue %118
  8037. OpFunctionEnd
  8038. )";
  8039. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  8040. SinglePassRunAndCheck<InstBindlessCheckPass>(
  8041. defs_before + func_before, defs_after + func_after + new_funcs, true,
  8042. true, 7u, 23u, true, true, 2u);
  8043. }
  8044. TEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArrayV2) {
  8045. // #version 450
  8046. // #extension GL_EXT_nonuniform_qualifier : enable
  8047. //
  8048. // layout(location=0) in nonuniformEXT flat int nu_ii;
  8049. // layout(location=0) out float b;
  8050. //
  8051. // layout(binding=3) uniform uname { float a; } uniformBuffer[128];
  8052. //
  8053. // void main()
  8054. // {
  8055. // b = uniformBuffer[nu_ii].a;
  8056. // }
  8057. const std::string defs_before =
  8058. R"(OpCapability Shader
  8059. OpCapability ShaderNonUniform
  8060. OpCapability UniformBufferArrayNonUniformIndexing
  8061. OpExtension "SPV_EXT_descriptor_indexing"
  8062. %1 = OpExtInstImport "GLSL.std.450"
  8063. OpMemoryModel Logical GLSL450
  8064. OpEntryPoint Fragment %main "main" %b %nu_ii
  8065. OpExecutionMode %main OriginUpperLeft
  8066. OpSource GLSL 450
  8067. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8068. OpName %main "main"
  8069. OpName %b "b"
  8070. OpName %uname "uname"
  8071. OpMemberName %uname 0 "a"
  8072. OpName %uniformBuffer "uniformBuffer"
  8073. OpName %nu_ii "nu_ii"
  8074. OpDecorate %b Location 0
  8075. OpMemberDecorate %uname 0 Offset 0
  8076. OpDecorate %uname Block
  8077. OpDecorate %uniformBuffer DescriptorSet 0
  8078. OpDecorate %uniformBuffer Binding 3
  8079. OpDecorate %nu_ii Flat
  8080. OpDecorate %nu_ii Location 0
  8081. OpDecorate %nu_ii NonUniform
  8082. OpDecorate %18 NonUniform
  8083. OpDecorate %22 NonUniform
  8084. %void = OpTypeVoid
  8085. %3 = OpTypeFunction %void
  8086. %float = OpTypeFloat 32
  8087. %_ptr_Output_float = OpTypePointer Output %float
  8088. %b = OpVariable %_ptr_Output_float Output
  8089. %uname = OpTypeStruct %float
  8090. %uint = OpTypeInt 32 0
  8091. %uint_128 = OpConstant %uint 128
  8092. %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
  8093. %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
  8094. %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
  8095. %int = OpTypeInt 32 1
  8096. %_ptr_Input_int = OpTypePointer Input %int
  8097. %nu_ii = OpVariable %_ptr_Input_int Input
  8098. %int_0 = OpConstant %int 0
  8099. %_ptr_Uniform_float = OpTypePointer Uniform %float
  8100. )";
  8101. const std::string defs_after =
  8102. R"(OpCapability Shader
  8103. OpCapability ShaderNonUniform
  8104. OpCapability UniformBufferArrayNonUniformIndexing
  8105. OpExtension "SPV_EXT_descriptor_indexing"
  8106. OpExtension "SPV_KHR_storage_buffer_storage_class"
  8107. %1 = OpExtInstImport "GLSL.std.450"
  8108. OpMemoryModel Logical GLSL450
  8109. OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
  8110. OpExecutionMode %main OriginUpperLeft
  8111. OpSource GLSL 450
  8112. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8113. OpName %main "main"
  8114. OpName %b "b"
  8115. OpName %uname "uname"
  8116. OpMemberName %uname 0 "a"
  8117. OpName %uniformBuffer "uniformBuffer"
  8118. OpName %nu_ii "nu_ii"
  8119. OpDecorate %b Location 0
  8120. OpMemberDecorate %uname 0 Offset 0
  8121. OpDecorate %uname Block
  8122. OpDecorate %uniformBuffer DescriptorSet 0
  8123. OpDecorate %uniformBuffer Binding 3
  8124. OpDecorate %nu_ii Flat
  8125. OpDecorate %nu_ii Location 0
  8126. OpDecorate %nu_ii NonUniform
  8127. OpDecorate %7 NonUniform
  8128. OpDecorate %89 NonUniform
  8129. OpDecorate %120 NonUniform
  8130. OpDecorate %_runtimearr_uint ArrayStride 4
  8131. OpDecorate %_struct_39 Block
  8132. OpMemberDecorate %_struct_39 0 Offset 0
  8133. OpMemberDecorate %_struct_39 1 Offset 4
  8134. OpDecorate %41 DescriptorSet 7
  8135. OpDecorate %41 Binding 0
  8136. OpDecorate %gl_FragCoord BuiltIn FragCoord
  8137. OpDecorate %_struct_98 Block
  8138. OpMemberDecorate %_struct_98 0 Offset 0
  8139. OpDecorate %100 DescriptorSet 7
  8140. OpDecorate %100 Binding 1
  8141. OpDecorate %117 NonUniform
  8142. %void = OpTypeVoid
  8143. %10 = OpTypeFunction %void
  8144. %float = OpTypeFloat 32
  8145. %_ptr_Output_float = OpTypePointer Output %float
  8146. %b = OpVariable %_ptr_Output_float Output
  8147. %uname = OpTypeStruct %float
  8148. %uint = OpTypeInt 32 0
  8149. %uint_128 = OpConstant %uint 128
  8150. %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
  8151. %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
  8152. %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
  8153. %int = OpTypeInt 32 1
  8154. %_ptr_Input_int = OpTypePointer Input %int
  8155. %nu_ii = OpVariable %_ptr_Input_int Input
  8156. %int_0 = OpConstant %int 0
  8157. %_ptr_Uniform_float = OpTypePointer Uniform %float
  8158. %uint_0 = OpConstant %uint 0
  8159. %bool = OpTypeBool
  8160. %32 = OpTypeFunction %void %uint %uint %uint %uint
  8161. %_runtimearr_uint = OpTypeRuntimeArray %uint
  8162. %_struct_39 = OpTypeStruct %uint %_runtimearr_uint
  8163. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  8164. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  8165. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  8166. %uint_10 = OpConstant %uint 10
  8167. %uint_4 = OpConstant %uint 4
  8168. %uint_1 = OpConstant %uint 1
  8169. %uint_23 = OpConstant %uint 23
  8170. %uint_2 = OpConstant %uint 2
  8171. %uint_3 = OpConstant %uint 3
  8172. %v4float = OpTypeVector %float 4
  8173. %_ptr_Input_v4float = OpTypePointer Input %v4float
  8174. %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
  8175. %v4uint = OpTypeVector %uint 4
  8176. %uint_5 = OpConstant %uint 5
  8177. %uint_7 = OpConstant %uint 7
  8178. %uint_8 = OpConstant %uint 8
  8179. %uint_9 = OpConstant %uint 9
  8180. %uint_46 = OpConstant %uint 46
  8181. %88 = OpConstantNull %float
  8182. %92 = OpTypeFunction %uint %uint %uint %uint %uint
  8183. %_struct_98 = OpTypeStruct %_runtimearr_uint
  8184. %_ptr_StorageBuffer__struct_98 = OpTypePointer StorageBuffer %_struct_98
  8185. %100 = OpVariable %_ptr_StorageBuffer__struct_98 StorageBuffer
  8186. )";
  8187. const std::string func_before =
  8188. R"(%main = OpFunction %void None %3
  8189. %5 = OpLabel
  8190. %18 = OpLoad %int %nu_ii
  8191. %21 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %18 %int_0
  8192. %22 = OpLoad %float %21
  8193. OpStore %b %22
  8194. OpReturn
  8195. OpFunctionEnd
  8196. )";
  8197. const std::string func_after =
  8198. R"(%main = OpFunction %void None %10
  8199. %21 = OpLabel
  8200. %7 = OpLoad %int %nu_ii
  8201. %22 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
  8202. %25 = OpULessThan %bool %7 %uint_128
  8203. OpSelectionMerge %26 None
  8204. OpBranchConditional %25 %27 %28
  8205. %27 = OpLabel
  8206. %90 = OpBitcast %uint %7
  8207. %112 = OpFunctionCall %uint %91 %uint_0 %uint_0 %uint_3 %90
  8208. %113 = OpINotEqual %bool %112 %uint_0
  8209. OpSelectionMerge %114 None
  8210. OpBranchConditional %113 %115 %116
  8211. %115 = OpLabel
  8212. %117 = OpLoad %float %22
  8213. OpBranch %114
  8214. %116 = OpLabel
  8215. %118 = OpBitcast %uint %7
  8216. %119 = OpFunctionCall %void %31 %uint_46 %uint_1 %118 %uint_0
  8217. OpBranch %114
  8218. %114 = OpLabel
  8219. %120 = OpPhi %float %117 %115 %88 %116
  8220. OpBranch %26
  8221. %28 = OpLabel
  8222. %30 = OpBitcast %uint %7
  8223. %87 = OpFunctionCall %void %31 %uint_46 %uint_0 %30 %uint_128
  8224. OpBranch %26
  8225. %26 = OpLabel
  8226. %89 = OpPhi %float %120 %114 %88 %28
  8227. OpStore %b %89
  8228. OpReturn
  8229. OpFunctionEnd
  8230. )";
  8231. const std::string new_funcs =
  8232. R"(%31 = OpFunction %void None %32
  8233. %33 = OpFunctionParameter %uint
  8234. %34 = OpFunctionParameter %uint
  8235. %35 = OpFunctionParameter %uint
  8236. %36 = OpFunctionParameter %uint
  8237. %37 = OpLabel
  8238. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0
  8239. %46 = OpAtomicIAdd %uint %43 %uint_4 %uint_0 %uint_10
  8240. %47 = OpIAdd %uint %46 %uint_10
  8241. %48 = OpArrayLength %uint %41 1
  8242. %49 = OpULessThanEqual %bool %47 %48
  8243. OpSelectionMerge %50 None
  8244. OpBranchConditional %49 %51 %50
  8245. %51 = OpLabel
  8246. %52 = OpIAdd %uint %46 %uint_0
  8247. %54 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %52
  8248. OpStore %54 %uint_10
  8249. %56 = OpIAdd %uint %46 %uint_1
  8250. %57 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %56
  8251. OpStore %57 %uint_23
  8252. %59 = OpIAdd %uint %46 %uint_2
  8253. %60 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %59
  8254. OpStore %60 %33
  8255. %62 = OpIAdd %uint %46 %uint_3
  8256. %63 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %62
  8257. OpStore %63 %uint_4
  8258. %67 = OpLoad %v4float %gl_FragCoord
  8259. %69 = OpBitcast %v4uint %67
  8260. %70 = OpCompositeExtract %uint %69 0
  8261. %71 = OpIAdd %uint %46 %uint_4
  8262. %72 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %71
  8263. OpStore %72 %70
  8264. %73 = OpCompositeExtract %uint %69 1
  8265. %75 = OpIAdd %uint %46 %uint_5
  8266. %76 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %75
  8267. OpStore %76 %73
  8268. %78 = OpIAdd %uint %46 %uint_7
  8269. %79 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %78
  8270. OpStore %79 %34
  8271. %81 = OpIAdd %uint %46 %uint_8
  8272. %82 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %81
  8273. OpStore %82 %35
  8274. %84 = OpIAdd %uint %46 %uint_9
  8275. %85 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %84
  8276. OpStore %85 %36
  8277. OpBranch %50
  8278. %50 = OpLabel
  8279. OpReturn
  8280. OpFunctionEnd
  8281. %91 = OpFunction %uint None %92
  8282. %93 = OpFunctionParameter %uint
  8283. %94 = OpFunctionParameter %uint
  8284. %95 = OpFunctionParameter %uint
  8285. %96 = OpFunctionParameter %uint
  8286. %97 = OpLabel
  8287. %101 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %93
  8288. %102 = OpLoad %uint %101
  8289. %103 = OpIAdd %uint %102 %94
  8290. %104 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %103
  8291. %105 = OpLoad %uint %104
  8292. %106 = OpIAdd %uint %105 %95
  8293. %107 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %106
  8294. %108 = OpLoad %uint %107
  8295. %109 = OpIAdd %uint %108 %96
  8296. %110 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %109
  8297. %111 = OpLoad %uint %110
  8298. OpReturnValue %111
  8299. OpFunctionEnd
  8300. )";
  8301. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  8302. SinglePassRunAndCheck<InstBindlessCheckPass>(
  8303. defs_before + func_before, defs_after + func_after + new_funcs, true,
  8304. true, 7u, 23u, true, true, 2u);
  8305. }
  8306. TEST_F(InstBindlessTest,
  8307. InstBoundsComputeShaderInitLoadVariableSizedSampledImagesArray) {
  8308. // #version 450
  8309. // #extension GL_EXT_nonuniform_qualifier : enable
  8310. //
  8311. // layout (local_size_x = 1, local_size_y = 1) in;
  8312. //
  8313. // layout(set = 0, binding = 0, std140) buffer Input {
  8314. // uint index;
  8315. // float red;
  8316. // } sbo;
  8317. //
  8318. // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
  8319. //
  8320. // void main()
  8321. // {
  8322. // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
  8323. // }
  8324. const std::string defs_before =
  8325. R"(OpCapability Shader
  8326. OpCapability RuntimeDescriptorArray
  8327. OpExtension "SPV_EXT_descriptor_indexing"
  8328. %1 = OpExtInstImport "GLSL.std.450"
  8329. OpMemoryModel Logical GLSL450
  8330. OpEntryPoint GLCompute %main "main"
  8331. OpExecutionMode %main LocalSize 1 1 1
  8332. OpSource GLSL 450
  8333. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8334. OpName %main "main"
  8335. OpName %Input "Input"
  8336. OpMemberName %Input 0 "index"
  8337. OpMemberName %Input 1 "red"
  8338. OpName %sbo "sbo"
  8339. OpName %images "images"
  8340. OpMemberDecorate %Input 0 Offset 0
  8341. OpMemberDecorate %Input 1 Offset 4
  8342. OpDecorate %Input BufferBlock
  8343. OpDecorate %sbo DescriptorSet 0
  8344. OpDecorate %sbo Binding 0
  8345. OpDecorate %images DescriptorSet 0
  8346. OpDecorate %images Binding 1
  8347. OpDecorate %images NonWritable
  8348. %void = OpTypeVoid
  8349. %3 = OpTypeFunction %void
  8350. %uint = OpTypeInt 32 0
  8351. %float = OpTypeFloat 32
  8352. %Input = OpTypeStruct %uint %float
  8353. %_ptr_Uniform_Input = OpTypePointer Uniform %Input
  8354. %sbo = OpVariable %_ptr_Uniform_Input Uniform
  8355. %int = OpTypeInt 32 1
  8356. %int_1 = OpConstant %int 1
  8357. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  8358. %_runtimearr_13 = OpTypeRuntimeArray %13
  8359. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  8360. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  8361. %int_0 = OpConstant %int 0
  8362. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  8363. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  8364. %v2int = OpTypeVector %int 2
  8365. %25 = OpConstantComposite %v2int %int_0 %int_0
  8366. %v4float = OpTypeVector %float 4
  8367. %uint_0 = OpConstant %uint 0
  8368. %_ptr_Uniform_float = OpTypePointer Uniform %float
  8369. )";
  8370. const std::string defs_after =
  8371. R"(OpCapability Shader
  8372. OpCapability RuntimeDescriptorArray
  8373. OpExtension "SPV_EXT_descriptor_indexing"
  8374. OpExtension "SPV_KHR_storage_buffer_storage_class"
  8375. %1 = OpExtInstImport "GLSL.std.450"
  8376. OpMemoryModel Logical GLSL450
  8377. OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
  8378. OpExecutionMode %main LocalSize 1 1 1
  8379. OpSource GLSL 450
  8380. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8381. OpName %main "main"
  8382. OpName %Input "Input"
  8383. OpMemberName %Input 0 "index"
  8384. OpMemberName %Input 1 "red"
  8385. OpName %sbo "sbo"
  8386. OpName %images "images"
  8387. OpMemberDecorate %Input 0 Offset 0
  8388. OpMemberDecorate %Input 1 Offset 4
  8389. OpDecorate %Input BufferBlock
  8390. OpDecorate %sbo DescriptorSet 0
  8391. OpDecorate %sbo Binding 0
  8392. OpDecorate %images DescriptorSet 0
  8393. OpDecorate %images Binding 1
  8394. OpDecorate %images NonWritable
  8395. OpDecorate %_runtimearr_uint ArrayStride 4
  8396. OpDecorate %_struct_39 Block
  8397. OpMemberDecorate %_struct_39 0 Offset 0
  8398. OpDecorate %41 DescriptorSet 7
  8399. OpDecorate %41 Binding 1
  8400. OpDecorate %_struct_63 Block
  8401. OpMemberDecorate %_struct_63 0 Offset 0
  8402. OpMemberDecorate %_struct_63 1 Offset 4
  8403. OpDecorate %65 DescriptorSet 7
  8404. OpDecorate %65 Binding 0
  8405. OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
  8406. %void = OpTypeVoid
  8407. %7 = OpTypeFunction %void
  8408. %uint = OpTypeInt 32 0
  8409. %float = OpTypeFloat 32
  8410. %Input = OpTypeStruct %uint %float
  8411. %_ptr_Uniform_Input = OpTypePointer Uniform %Input
  8412. %sbo = OpVariable %_ptr_Uniform_Input Uniform
  8413. %int = OpTypeInt 32 1
  8414. %int_1 = OpConstant %int 1
  8415. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  8416. %_runtimearr_13 = OpTypeRuntimeArray %13
  8417. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  8418. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  8419. %int_0 = OpConstant %int 0
  8420. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  8421. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  8422. %v2int = OpTypeVector %int 2
  8423. %20 = OpConstantComposite %v2int %int_0 %int_0
  8424. %v4float = OpTypeVector %float 4
  8425. %uint_0 = OpConstant %uint 0
  8426. %_ptr_Uniform_float = OpTypePointer Uniform %float
  8427. %uint_1 = OpConstant %uint 1
  8428. %34 = OpTypeFunction %uint %uint %uint
  8429. %_runtimearr_uint = OpTypeRuntimeArray %uint
  8430. %_struct_39 = OpTypeStruct %_runtimearr_uint
  8431. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  8432. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  8433. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  8434. %bool = OpTypeBool
  8435. %57 = OpTypeFunction %void %uint %uint %uint %uint
  8436. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  8437. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  8438. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  8439. %uint_10 = OpConstant %uint 10
  8440. %uint_4 = OpConstant %uint 4
  8441. %uint_23 = OpConstant %uint 23
  8442. %uint_2 = OpConstant %uint 2
  8443. %uint_5 = OpConstant %uint 5
  8444. %uint_3 = OpConstant %uint 3
  8445. %v3uint = OpTypeVector %uint 3
  8446. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  8447. %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
  8448. %uint_6 = OpConstant %uint 6
  8449. %uint_7 = OpConstant %uint 7
  8450. %uint_8 = OpConstant %uint 8
  8451. %uint_9 = OpConstant %uint 9
  8452. %uint_50 = OpConstant %uint 50
  8453. %112 = OpConstantNull %v4float
  8454. %115 = OpTypeFunction %uint %uint %uint %uint %uint
  8455. %uint_47 = OpConstant %uint 47
  8456. %140 = OpConstantNull %uint
  8457. %uint_53 = OpConstant %uint 53
  8458. )";
  8459. const std::string func_before =
  8460. R"(%main = OpFunction %void None %3
  8461. %5 = OpLabel
  8462. %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  8463. %20 = OpLoad %uint %19
  8464. %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
  8465. %23 = OpLoad %13 %22
  8466. %27 = OpImageRead %v4float %23 %25
  8467. %29 = OpCompositeExtract %float %27 0
  8468. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  8469. OpStore %31 %29
  8470. OpReturn
  8471. OpFunctionEnd
  8472. )";
  8473. const std::string func_after =
  8474. R"(%main = OpFunction %void None %7
  8475. %24 = OpLabel
  8476. %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  8477. %132 = OpFunctionCall %uint %114 %uint_0 %uint_0 %uint_0 %uint_0
  8478. %133 = OpINotEqual %bool %132 %uint_0
  8479. OpSelectionMerge %134 None
  8480. OpBranchConditional %133 %135 %136
  8481. %135 = OpLabel
  8482. %137 = OpLoad %uint %25
  8483. OpBranch %134
  8484. %136 = OpLabel
  8485. %139 = OpFunctionCall %void %56 %uint_47 %uint_1 %uint_0 %uint_0
  8486. OpBranch %134
  8487. %134 = OpLabel
  8488. %141 = OpPhi %uint %137 %135 %140 %136
  8489. %27 = OpAccessChain %_ptr_UniformConstant_13 %images %141
  8490. %28 = OpLoad %13 %27
  8491. %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
  8492. %50 = OpULessThan %bool %141 %48
  8493. OpSelectionMerge %51 None
  8494. OpBranchConditional %50 %52 %53
  8495. %52 = OpLabel
  8496. %54 = OpLoad %13 %27
  8497. %142 = OpFunctionCall %uint %114 %uint_0 %uint_0 %uint_1 %141
  8498. %143 = OpINotEqual %bool %142 %uint_0
  8499. OpSelectionMerge %144 None
  8500. OpBranchConditional %143 %145 %146
  8501. %145 = OpLabel
  8502. %147 = OpLoad %13 %27
  8503. %148 = OpImageRead %v4float %147 %20
  8504. OpBranch %144
  8505. %146 = OpLabel
  8506. %149 = OpFunctionCall %void %56 %uint_50 %uint_1 %141 %uint_0
  8507. OpBranch %144
  8508. %144 = OpLabel
  8509. %150 = OpPhi %v4float %148 %145 %112 %146
  8510. OpBranch %51
  8511. %53 = OpLabel
  8512. %111 = OpFunctionCall %void %56 %uint_50 %uint_0 %141 %48
  8513. OpBranch %51
  8514. %51 = OpLabel
  8515. %113 = OpPhi %v4float %150 %144 %112 %53
  8516. %30 = OpCompositeExtract %float %113 0
  8517. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  8518. %151 = OpFunctionCall %uint %114 %uint_0 %uint_0 %uint_0 %uint_0
  8519. %152 = OpINotEqual %bool %151 %uint_0
  8520. OpSelectionMerge %153 None
  8521. OpBranchConditional %152 %154 %155
  8522. %154 = OpLabel
  8523. OpStore %31 %30
  8524. OpBranch %153
  8525. %155 = OpLabel
  8526. %157 = OpFunctionCall %void %56 %uint_53 %uint_1 %uint_0 %uint_0
  8527. OpBranch %153
  8528. %153 = OpLabel
  8529. OpReturn
  8530. OpFunctionEnd
  8531. )";
  8532. const std::string new_funcs =
  8533. R"(%33 = OpFunction %uint None %34
  8534. %35 = OpFunctionParameter %uint
  8535. %36 = OpFunctionParameter %uint
  8536. %37 = OpLabel
  8537. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
  8538. %44 = OpLoad %uint %43
  8539. %45 = OpIAdd %uint %44 %36
  8540. %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
  8541. %47 = OpLoad %uint %46
  8542. OpReturnValue %47
  8543. OpFunctionEnd
  8544. %56 = OpFunction %void None %57
  8545. %58 = OpFunctionParameter %uint
  8546. %59 = OpFunctionParameter %uint
  8547. %60 = OpFunctionParameter %uint
  8548. %61 = OpFunctionParameter %uint
  8549. %62 = OpLabel
  8550. %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  8551. %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
  8552. %70 = OpIAdd %uint %69 %uint_10
  8553. %71 = OpArrayLength %uint %65 1
  8554. %72 = OpULessThanEqual %bool %70 %71
  8555. OpSelectionMerge %73 None
  8556. OpBranchConditional %72 %74 %73
  8557. %74 = OpLabel
  8558. %75 = OpIAdd %uint %69 %uint_0
  8559. %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
  8560. OpStore %76 %uint_10
  8561. %78 = OpIAdd %uint %69 %uint_1
  8562. %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
  8563. OpStore %79 %uint_23
  8564. %81 = OpIAdd %uint %69 %uint_2
  8565. %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
  8566. OpStore %82 %58
  8567. %85 = OpIAdd %uint %69 %uint_3
  8568. %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
  8569. OpStore %86 %uint_5
  8570. %90 = OpLoad %v3uint %gl_GlobalInvocationID
  8571. %91 = OpCompositeExtract %uint %90 0
  8572. %92 = OpCompositeExtract %uint %90 1
  8573. %93 = OpCompositeExtract %uint %90 2
  8574. %94 = OpIAdd %uint %69 %uint_4
  8575. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  8576. OpStore %95 %91
  8577. %96 = OpIAdd %uint %69 %uint_5
  8578. %97 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %96
  8579. OpStore %97 %92
  8580. %99 = OpIAdd %uint %69 %uint_6
  8581. %100 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %99
  8582. OpStore %100 %93
  8583. %102 = OpIAdd %uint %69 %uint_7
  8584. %103 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %102
  8585. OpStore %103 %59
  8586. %105 = OpIAdd %uint %69 %uint_8
  8587. %106 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %105
  8588. OpStore %106 %60
  8589. %108 = OpIAdd %uint %69 %uint_9
  8590. %109 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %108
  8591. OpStore %109 %61
  8592. OpBranch %73
  8593. %73 = OpLabel
  8594. OpReturn
  8595. OpFunctionEnd
  8596. %114 = OpFunction %uint None %115
  8597. %116 = OpFunctionParameter %uint
  8598. %117 = OpFunctionParameter %uint
  8599. %118 = OpFunctionParameter %uint
  8600. %119 = OpFunctionParameter %uint
  8601. %120 = OpLabel
  8602. %121 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %116
  8603. %122 = OpLoad %uint %121
  8604. %123 = OpIAdd %uint %122 %117
  8605. %124 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %123
  8606. %125 = OpLoad %uint %124
  8607. %126 = OpIAdd %uint %125 %118
  8608. %127 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %126
  8609. %128 = OpLoad %uint %127
  8610. %129 = OpIAdd %uint %128 %119
  8611. %130 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %129
  8612. %131 = OpLoad %uint %130
  8613. OpReturnValue %131
  8614. OpFunctionEnd
  8615. )";
  8616. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  8617. SinglePassRunAndCheck<InstBindlessCheckPass>(
  8618. defs_before + func_before, defs_after + func_after + new_funcs, true,
  8619. true, 7u, 23u, true, true, 2u);
  8620. }
  8621. TEST_F(InstBindlessTest,
  8622. InstBoundsRayGenerationInitLoadVariableSizedSampledImagesArray) {
  8623. // #version 460
  8624. // #extension GL_EXT_nonuniform_qualifier : require
  8625. // #extension GL_NV_ray_tracing : require
  8626. //
  8627. // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
  8628. // uint index;
  8629. // float red;
  8630. // } sbo;
  8631. //
  8632. // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
  8633. //
  8634. // void main()
  8635. // {
  8636. // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
  8637. // }
  8638. const std::string defs_before =
  8639. R"(OpCapability RuntimeDescriptorArray
  8640. OpCapability RayTracingNV
  8641. OpExtension "SPV_EXT_descriptor_indexing"
  8642. OpExtension "SPV_NV_ray_tracing"
  8643. %1 = OpExtInstImport "GLSL.std.450"
  8644. OpMemoryModel Logical GLSL450
  8645. OpEntryPoint RayGenerationNV %main "main"
  8646. OpSource GLSL 460
  8647. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8648. OpSourceExtension "GL_NV_ray_tracing"
  8649. OpName %main "main"
  8650. OpName %StorageBuffer "StorageBuffer"
  8651. OpMemberName %StorageBuffer 0 "index"
  8652. OpMemberName %StorageBuffer 1 "red"
  8653. OpName %sbo "sbo"
  8654. OpName %images "images"
  8655. OpMemberDecorate %StorageBuffer 0 Offset 0
  8656. OpMemberDecorate %StorageBuffer 1 Offset 4
  8657. OpDecorate %StorageBuffer BufferBlock
  8658. OpDecorate %sbo DescriptorSet 0
  8659. OpDecorate %sbo Binding 0
  8660. OpDecorate %images DescriptorSet 0
  8661. OpDecorate %images Binding 1
  8662. OpDecorate %images NonWritable
  8663. %void = OpTypeVoid
  8664. )";
  8665. const std::string defs_after =
  8666. R"(OpCapability RuntimeDescriptorArray
  8667. OpCapability RayTracingNV
  8668. OpExtension "SPV_EXT_descriptor_indexing"
  8669. OpExtension "SPV_NV_ray_tracing"
  8670. OpExtension "SPV_KHR_storage_buffer_storage_class"
  8671. %1 = OpExtInstImport "GLSL.std.450"
  8672. OpMemoryModel Logical GLSL450
  8673. OpEntryPoint RayGenerationNV %main "main" %89
  8674. OpSource GLSL 460
  8675. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8676. OpSourceExtension "GL_NV_ray_tracing"
  8677. OpName %main "main"
  8678. OpName %StorageBuffer "StorageBuffer"
  8679. OpMemberName %StorageBuffer 0 "index"
  8680. OpMemberName %StorageBuffer 1 "red"
  8681. OpName %sbo "sbo"
  8682. OpName %images "images"
  8683. OpMemberDecorate %StorageBuffer 0 Offset 0
  8684. OpMemberDecorate %StorageBuffer 1 Offset 4
  8685. OpDecorate %StorageBuffer BufferBlock
  8686. OpDecorate %sbo DescriptorSet 0
  8687. OpDecorate %sbo Binding 0
  8688. OpDecorate %images DescriptorSet 0
  8689. OpDecorate %images Binding 1
  8690. OpDecorate %images NonWritable
  8691. OpDecorate %_runtimearr_uint ArrayStride 4
  8692. OpDecorate %_struct_39 Block
  8693. OpMemberDecorate %_struct_39 0 Offset 0
  8694. OpDecorate %41 DescriptorSet 7
  8695. OpDecorate %41 Binding 1
  8696. OpDecorate %_struct_63 Block
  8697. OpMemberDecorate %_struct_63 0 Offset 0
  8698. OpMemberDecorate %_struct_63 1 Offset 4
  8699. OpDecorate %65 DescriptorSet 7
  8700. OpDecorate %65 Binding 0
  8701. OpDecorate %89 BuiltIn LaunchIdNV
  8702. %void = OpTypeVoid
  8703. )";
  8704. const std::string func_before =
  8705. R"(%3 = OpTypeFunction %void
  8706. %uint = OpTypeInt 32 0
  8707. %float = OpTypeFloat 32
  8708. %StorageBuffer = OpTypeStruct %uint %float
  8709. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  8710. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  8711. %int = OpTypeInt 32 1
  8712. %int_1 = OpConstant %int 1
  8713. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  8714. %_runtimearr_13 = OpTypeRuntimeArray %13
  8715. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  8716. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  8717. %int_0 = OpConstant %int 0
  8718. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  8719. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  8720. %v2int = OpTypeVector %int 2
  8721. %25 = OpConstantComposite %v2int %int_0 %int_0
  8722. %v4float = OpTypeVector %float 4
  8723. %uint_0 = OpConstant %uint 0
  8724. %_ptr_Uniform_float = OpTypePointer Uniform %float
  8725. %main = OpFunction %void None %3
  8726. %5 = OpLabel
  8727. %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  8728. %20 = OpLoad %uint %19
  8729. %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
  8730. %23 = OpLoad %13 %22
  8731. %27 = OpImageRead %v4float %23 %25
  8732. %29 = OpCompositeExtract %float %27 0
  8733. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  8734. OpStore %31 %29
  8735. OpReturn
  8736. OpFunctionEnd
  8737. )";
  8738. const std::string func_after =
  8739. R"(%7 = OpTypeFunction %void
  8740. %uint = OpTypeInt 32 0
  8741. %float = OpTypeFloat 32
  8742. %StorageBuffer = OpTypeStruct %uint %float
  8743. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  8744. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  8745. %int = OpTypeInt 32 1
  8746. %int_1 = OpConstant %int 1
  8747. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  8748. %_runtimearr_13 = OpTypeRuntimeArray %13
  8749. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  8750. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  8751. %int_0 = OpConstant %int 0
  8752. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  8753. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  8754. %v2int = OpTypeVector %int 2
  8755. %20 = OpConstantComposite %v2int %int_0 %int_0
  8756. %v4float = OpTypeVector %float 4
  8757. %uint_0 = OpConstant %uint 0
  8758. %_ptr_Uniform_float = OpTypePointer Uniform %float
  8759. %uint_1 = OpConstant %uint 1
  8760. %34 = OpTypeFunction %uint %uint %uint
  8761. %_runtimearr_uint = OpTypeRuntimeArray %uint
  8762. %_struct_39 = OpTypeStruct %_runtimearr_uint
  8763. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  8764. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  8765. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  8766. %bool = OpTypeBool
  8767. %57 = OpTypeFunction %void %uint %uint %uint %uint
  8768. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  8769. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  8770. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  8771. %uint_10 = OpConstant %uint 10
  8772. %uint_4 = OpConstant %uint 4
  8773. %uint_23 = OpConstant %uint 23
  8774. %uint_2 = OpConstant %uint 2
  8775. %uint_5313 = OpConstant %uint 5313
  8776. %uint_3 = OpConstant %uint 3
  8777. %v3uint = OpTypeVector %uint 3
  8778. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  8779. %89 = OpVariable %_ptr_Input_v3uint Input
  8780. %uint_5 = OpConstant %uint 5
  8781. %uint_6 = OpConstant %uint 6
  8782. %uint_7 = OpConstant %uint 7
  8783. %uint_8 = OpConstant %uint 8
  8784. %uint_9 = OpConstant %uint 9
  8785. %uint_51 = OpConstant %uint 51
  8786. %113 = OpConstantNull %v4float
  8787. %116 = OpTypeFunction %uint %uint %uint %uint %uint
  8788. %uint_48 = OpConstant %uint 48
  8789. %141 = OpConstantNull %uint
  8790. %uint_54 = OpConstant %uint 54
  8791. %main = OpFunction %void None %7
  8792. %24 = OpLabel
  8793. %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  8794. %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  8795. %134 = OpINotEqual %bool %133 %uint_0
  8796. OpSelectionMerge %135 None
  8797. OpBranchConditional %134 %136 %137
  8798. %136 = OpLabel
  8799. %138 = OpLoad %uint %25
  8800. OpBranch %135
  8801. %137 = OpLabel
  8802. %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
  8803. OpBranch %135
  8804. %135 = OpLabel
  8805. %142 = OpPhi %uint %138 %136 %141 %137
  8806. %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
  8807. %28 = OpLoad %13 %27
  8808. %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
  8809. %50 = OpULessThan %bool %142 %48
  8810. OpSelectionMerge %51 None
  8811. OpBranchConditional %50 %52 %53
  8812. %52 = OpLabel
  8813. %54 = OpLoad %13 %27
  8814. %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
  8815. %144 = OpINotEqual %bool %143 %uint_0
  8816. OpSelectionMerge %145 None
  8817. OpBranchConditional %144 %146 %147
  8818. %146 = OpLabel
  8819. %148 = OpLoad %13 %27
  8820. %149 = OpImageRead %v4float %148 %20
  8821. OpBranch %145
  8822. %147 = OpLabel
  8823. %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
  8824. OpBranch %145
  8825. %145 = OpLabel
  8826. %151 = OpPhi %v4float %149 %146 %113 %147
  8827. OpBranch %51
  8828. %53 = OpLabel
  8829. %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
  8830. OpBranch %51
  8831. %51 = OpLabel
  8832. %114 = OpPhi %v4float %151 %145 %113 %53
  8833. %30 = OpCompositeExtract %float %114 0
  8834. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  8835. %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  8836. %153 = OpINotEqual %bool %152 %uint_0
  8837. OpSelectionMerge %154 None
  8838. OpBranchConditional %153 %155 %156
  8839. %155 = OpLabel
  8840. OpStore %31 %30
  8841. OpBranch %154
  8842. %156 = OpLabel
  8843. %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
  8844. OpBranch %154
  8845. %154 = OpLabel
  8846. OpReturn
  8847. OpFunctionEnd
  8848. )";
  8849. const std::string new_funcs =
  8850. R"(%33 = OpFunction %uint None %34
  8851. %35 = OpFunctionParameter %uint
  8852. %36 = OpFunctionParameter %uint
  8853. %37 = OpLabel
  8854. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
  8855. %44 = OpLoad %uint %43
  8856. %45 = OpIAdd %uint %44 %36
  8857. %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
  8858. %47 = OpLoad %uint %46
  8859. OpReturnValue %47
  8860. OpFunctionEnd
  8861. %56 = OpFunction %void None %57
  8862. %58 = OpFunctionParameter %uint
  8863. %59 = OpFunctionParameter %uint
  8864. %60 = OpFunctionParameter %uint
  8865. %61 = OpFunctionParameter %uint
  8866. %62 = OpLabel
  8867. %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  8868. %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
  8869. %70 = OpIAdd %uint %69 %uint_10
  8870. %71 = OpArrayLength %uint %65 1
  8871. %72 = OpULessThanEqual %bool %70 %71
  8872. OpSelectionMerge %73 None
  8873. OpBranchConditional %72 %74 %73
  8874. %74 = OpLabel
  8875. %75 = OpIAdd %uint %69 %uint_0
  8876. %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
  8877. OpStore %76 %uint_10
  8878. %78 = OpIAdd %uint %69 %uint_1
  8879. %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
  8880. OpStore %79 %uint_23
  8881. %81 = OpIAdd %uint %69 %uint_2
  8882. %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
  8883. OpStore %82 %58
  8884. %85 = OpIAdd %uint %69 %uint_3
  8885. %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
  8886. OpStore %86 %uint_5313
  8887. %90 = OpLoad %v3uint %89
  8888. %91 = OpCompositeExtract %uint %90 0
  8889. %92 = OpCompositeExtract %uint %90 1
  8890. %93 = OpCompositeExtract %uint %90 2
  8891. %94 = OpIAdd %uint %69 %uint_4
  8892. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  8893. OpStore %95 %91
  8894. %97 = OpIAdd %uint %69 %uint_5
  8895. %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
  8896. OpStore %98 %92
  8897. %100 = OpIAdd %uint %69 %uint_6
  8898. %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
  8899. OpStore %101 %93
  8900. %103 = OpIAdd %uint %69 %uint_7
  8901. %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
  8902. OpStore %104 %59
  8903. %106 = OpIAdd %uint %69 %uint_8
  8904. %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
  8905. OpStore %107 %60
  8906. %109 = OpIAdd %uint %69 %uint_9
  8907. %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
  8908. OpStore %110 %61
  8909. OpBranch %73
  8910. %73 = OpLabel
  8911. OpReturn
  8912. OpFunctionEnd
  8913. %115 = OpFunction %uint None %116
  8914. %117 = OpFunctionParameter %uint
  8915. %118 = OpFunctionParameter %uint
  8916. %119 = OpFunctionParameter %uint
  8917. %120 = OpFunctionParameter %uint
  8918. %121 = OpLabel
  8919. %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
  8920. %123 = OpLoad %uint %122
  8921. %124 = OpIAdd %uint %123 %118
  8922. %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
  8923. %126 = OpLoad %uint %125
  8924. %127 = OpIAdd %uint %126 %119
  8925. %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
  8926. %129 = OpLoad %uint %128
  8927. %130 = OpIAdd %uint %129 %120
  8928. %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
  8929. %132 = OpLoad %uint %131
  8930. OpReturnValue %132
  8931. OpFunctionEnd
  8932. )";
  8933. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  8934. SinglePassRunAndCheck<InstBindlessCheckPass>(
  8935. defs_before + func_before, defs_after + func_after + new_funcs, true,
  8936. true, 7u, 23u, true, true, 2u);
  8937. }
  8938. TEST_F(InstBindlessTest,
  8939. InstBoundsIntersectionInitLoadVariableSizedSampledImagesArray) {
  8940. // #version 460
  8941. // #extension GL_EXT_nonuniform_qualifier : require
  8942. // #extension GL_NV_ray_tracing : require
  8943. //
  8944. // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
  8945. // uint index;
  8946. // float red;
  8947. // } sbo;
  8948. //
  8949. // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
  8950. //
  8951. // void main()
  8952. // {
  8953. // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
  8954. // }
  8955. const std::string defs_before =
  8956. R"(OpCapability RuntimeDescriptorArray
  8957. OpCapability RayTracingNV
  8958. OpExtension "SPV_EXT_descriptor_indexing"
  8959. OpExtension "SPV_NV_ray_tracing"
  8960. %1 = OpExtInstImport "GLSL.std.450"
  8961. OpMemoryModel Logical GLSL450
  8962. OpEntryPoint IntersectionNV %main "main"
  8963. OpSource GLSL 460
  8964. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8965. OpSourceExtension "GL_NV_ray_tracing"
  8966. OpName %main "main"
  8967. OpName %StorageBuffer "StorageBuffer"
  8968. OpMemberName %StorageBuffer 0 "index"
  8969. OpMemberName %StorageBuffer 1 "red"
  8970. OpName %sbo "sbo"
  8971. OpName %images "images"
  8972. OpMemberDecorate %StorageBuffer 0 Offset 0
  8973. OpMemberDecorate %StorageBuffer 1 Offset 4
  8974. OpDecorate %StorageBuffer BufferBlock
  8975. OpDecorate %sbo DescriptorSet 0
  8976. OpDecorate %sbo Binding 0
  8977. OpDecorate %images DescriptorSet 0
  8978. OpDecorate %images Binding 1
  8979. OpDecorate %images NonWritable
  8980. %void = OpTypeVoid
  8981. )";
  8982. const std::string defs_after =
  8983. R"(OpCapability RuntimeDescriptorArray
  8984. OpCapability RayTracingNV
  8985. OpExtension "SPV_EXT_descriptor_indexing"
  8986. OpExtension "SPV_NV_ray_tracing"
  8987. OpExtension "SPV_KHR_storage_buffer_storage_class"
  8988. %1 = OpExtInstImport "GLSL.std.450"
  8989. OpMemoryModel Logical GLSL450
  8990. OpEntryPoint IntersectionNV %main "main" %89
  8991. OpSource GLSL 460
  8992. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  8993. OpSourceExtension "GL_NV_ray_tracing"
  8994. OpName %main "main"
  8995. OpName %StorageBuffer "StorageBuffer"
  8996. OpMemberName %StorageBuffer 0 "index"
  8997. OpMemberName %StorageBuffer 1 "red"
  8998. OpName %sbo "sbo"
  8999. OpName %images "images"
  9000. OpMemberDecorate %StorageBuffer 0 Offset 0
  9001. OpMemberDecorate %StorageBuffer 1 Offset 4
  9002. OpDecorate %StorageBuffer BufferBlock
  9003. OpDecorate %sbo DescriptorSet 0
  9004. OpDecorate %sbo Binding 0
  9005. OpDecorate %images DescriptorSet 0
  9006. OpDecorate %images Binding 1
  9007. OpDecorate %images NonWritable
  9008. OpDecorate %_runtimearr_uint ArrayStride 4
  9009. OpDecorate %_struct_39 Block
  9010. OpMemberDecorate %_struct_39 0 Offset 0
  9011. OpDecorate %41 DescriptorSet 7
  9012. OpDecorate %41 Binding 1
  9013. OpDecorate %_struct_63 Block
  9014. OpMemberDecorate %_struct_63 0 Offset 0
  9015. OpMemberDecorate %_struct_63 1 Offset 4
  9016. OpDecorate %65 DescriptorSet 7
  9017. OpDecorate %65 Binding 0
  9018. OpDecorate %89 BuiltIn LaunchIdNV
  9019. %void = OpTypeVoid
  9020. )";
  9021. const std::string func_before =
  9022. R"(%3 = OpTypeFunction %void
  9023. %uint = OpTypeInt 32 0
  9024. %float = OpTypeFloat 32
  9025. %StorageBuffer = OpTypeStruct %uint %float
  9026. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  9027. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  9028. %int = OpTypeInt 32 1
  9029. %int_1 = OpConstant %int 1
  9030. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  9031. %_runtimearr_13 = OpTypeRuntimeArray %13
  9032. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  9033. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  9034. %int_0 = OpConstant %int 0
  9035. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  9036. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  9037. %v2int = OpTypeVector %int 2
  9038. %25 = OpConstantComposite %v2int %int_0 %int_0
  9039. %v4float = OpTypeVector %float 4
  9040. %uint_0 = OpConstant %uint 0
  9041. %_ptr_Uniform_float = OpTypePointer Uniform %float
  9042. %main = OpFunction %void None %3
  9043. %5 = OpLabel
  9044. %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  9045. %20 = OpLoad %uint %19
  9046. %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
  9047. %23 = OpLoad %13 %22
  9048. %27 = OpImageRead %v4float %23 %25
  9049. %29 = OpCompositeExtract %float %27 0
  9050. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  9051. OpStore %31 %29
  9052. OpReturn
  9053. OpFunctionEnd
  9054. )";
  9055. const std::string func_after =
  9056. R"(%7 = OpTypeFunction %void
  9057. %uint = OpTypeInt 32 0
  9058. %float = OpTypeFloat 32
  9059. %StorageBuffer = OpTypeStruct %uint %float
  9060. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  9061. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  9062. %int = OpTypeInt 32 1
  9063. %int_1 = OpConstant %int 1
  9064. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  9065. %_runtimearr_13 = OpTypeRuntimeArray %13
  9066. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  9067. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  9068. %int_0 = OpConstant %int 0
  9069. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  9070. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  9071. %v2int = OpTypeVector %int 2
  9072. %20 = OpConstantComposite %v2int %int_0 %int_0
  9073. %v4float = OpTypeVector %float 4
  9074. %uint_0 = OpConstant %uint 0
  9075. %_ptr_Uniform_float = OpTypePointer Uniform %float
  9076. %uint_1 = OpConstant %uint 1
  9077. %34 = OpTypeFunction %uint %uint %uint
  9078. %_runtimearr_uint = OpTypeRuntimeArray %uint
  9079. %_struct_39 = OpTypeStruct %_runtimearr_uint
  9080. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  9081. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  9082. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  9083. %bool = OpTypeBool
  9084. %57 = OpTypeFunction %void %uint %uint %uint %uint
  9085. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  9086. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  9087. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  9088. %uint_10 = OpConstant %uint 10
  9089. %uint_4 = OpConstant %uint 4
  9090. %uint_23 = OpConstant %uint 23
  9091. %uint_2 = OpConstant %uint 2
  9092. %uint_5314 = OpConstant %uint 5314
  9093. %uint_3 = OpConstant %uint 3
  9094. %v3uint = OpTypeVector %uint 3
  9095. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  9096. %89 = OpVariable %_ptr_Input_v3uint Input
  9097. %uint_5 = OpConstant %uint 5
  9098. %uint_6 = OpConstant %uint 6
  9099. %uint_7 = OpConstant %uint 7
  9100. %uint_8 = OpConstant %uint 8
  9101. %uint_9 = OpConstant %uint 9
  9102. %uint_51 = OpConstant %uint 51
  9103. %113 = OpConstantNull %v4float
  9104. %116 = OpTypeFunction %uint %uint %uint %uint %uint
  9105. %uint_48 = OpConstant %uint 48
  9106. %141 = OpConstantNull %uint
  9107. %uint_54 = OpConstant %uint 54
  9108. %main = OpFunction %void None %7
  9109. %24 = OpLabel
  9110. %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  9111. %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  9112. %134 = OpINotEqual %bool %133 %uint_0
  9113. OpSelectionMerge %135 None
  9114. OpBranchConditional %134 %136 %137
  9115. %136 = OpLabel
  9116. %138 = OpLoad %uint %25
  9117. OpBranch %135
  9118. %137 = OpLabel
  9119. %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
  9120. OpBranch %135
  9121. %135 = OpLabel
  9122. %142 = OpPhi %uint %138 %136 %141 %137
  9123. %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
  9124. %28 = OpLoad %13 %27
  9125. %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
  9126. %50 = OpULessThan %bool %142 %48
  9127. OpSelectionMerge %51 None
  9128. OpBranchConditional %50 %52 %53
  9129. %52 = OpLabel
  9130. %54 = OpLoad %13 %27
  9131. %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
  9132. %144 = OpINotEqual %bool %143 %uint_0
  9133. OpSelectionMerge %145 None
  9134. OpBranchConditional %144 %146 %147
  9135. %146 = OpLabel
  9136. %148 = OpLoad %13 %27
  9137. %149 = OpImageRead %v4float %148 %20
  9138. OpBranch %145
  9139. %147 = OpLabel
  9140. %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
  9141. OpBranch %145
  9142. %145 = OpLabel
  9143. %151 = OpPhi %v4float %149 %146 %113 %147
  9144. OpBranch %51
  9145. %53 = OpLabel
  9146. %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
  9147. OpBranch %51
  9148. %51 = OpLabel
  9149. %114 = OpPhi %v4float %151 %145 %113 %53
  9150. %30 = OpCompositeExtract %float %114 0
  9151. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  9152. %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  9153. %153 = OpINotEqual %bool %152 %uint_0
  9154. OpSelectionMerge %154 None
  9155. OpBranchConditional %153 %155 %156
  9156. %155 = OpLabel
  9157. OpStore %31 %30
  9158. OpBranch %154
  9159. %156 = OpLabel
  9160. %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
  9161. OpBranch %154
  9162. %154 = OpLabel
  9163. OpReturn
  9164. OpFunctionEnd
  9165. )";
  9166. const std::string new_funcs =
  9167. R"(%33 = OpFunction %uint None %34
  9168. %35 = OpFunctionParameter %uint
  9169. %36 = OpFunctionParameter %uint
  9170. %37 = OpLabel
  9171. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
  9172. %44 = OpLoad %uint %43
  9173. %45 = OpIAdd %uint %44 %36
  9174. %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
  9175. %47 = OpLoad %uint %46
  9176. OpReturnValue %47
  9177. OpFunctionEnd
  9178. %56 = OpFunction %void None %57
  9179. %58 = OpFunctionParameter %uint
  9180. %59 = OpFunctionParameter %uint
  9181. %60 = OpFunctionParameter %uint
  9182. %61 = OpFunctionParameter %uint
  9183. %62 = OpLabel
  9184. %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  9185. %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
  9186. %70 = OpIAdd %uint %69 %uint_10
  9187. %71 = OpArrayLength %uint %65 1
  9188. %72 = OpULessThanEqual %bool %70 %71
  9189. OpSelectionMerge %73 None
  9190. OpBranchConditional %72 %74 %73
  9191. %74 = OpLabel
  9192. %75 = OpIAdd %uint %69 %uint_0
  9193. %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
  9194. OpStore %76 %uint_10
  9195. %78 = OpIAdd %uint %69 %uint_1
  9196. %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
  9197. OpStore %79 %uint_23
  9198. %81 = OpIAdd %uint %69 %uint_2
  9199. %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
  9200. OpStore %82 %58
  9201. %85 = OpIAdd %uint %69 %uint_3
  9202. %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
  9203. OpStore %86 %uint_5314
  9204. %90 = OpLoad %v3uint %89
  9205. %91 = OpCompositeExtract %uint %90 0
  9206. %92 = OpCompositeExtract %uint %90 1
  9207. %93 = OpCompositeExtract %uint %90 2
  9208. %94 = OpIAdd %uint %69 %uint_4
  9209. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  9210. OpStore %95 %91
  9211. %97 = OpIAdd %uint %69 %uint_5
  9212. %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
  9213. OpStore %98 %92
  9214. %100 = OpIAdd %uint %69 %uint_6
  9215. %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
  9216. OpStore %101 %93
  9217. %103 = OpIAdd %uint %69 %uint_7
  9218. %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
  9219. OpStore %104 %59
  9220. %106 = OpIAdd %uint %69 %uint_8
  9221. %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
  9222. OpStore %107 %60
  9223. %109 = OpIAdd %uint %69 %uint_9
  9224. %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
  9225. OpStore %110 %61
  9226. OpBranch %73
  9227. %73 = OpLabel
  9228. OpReturn
  9229. OpFunctionEnd
  9230. %115 = OpFunction %uint None %116
  9231. %117 = OpFunctionParameter %uint
  9232. %118 = OpFunctionParameter %uint
  9233. %119 = OpFunctionParameter %uint
  9234. %120 = OpFunctionParameter %uint
  9235. %121 = OpLabel
  9236. %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
  9237. %123 = OpLoad %uint %122
  9238. %124 = OpIAdd %uint %123 %118
  9239. %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
  9240. %126 = OpLoad %uint %125
  9241. %127 = OpIAdd %uint %126 %119
  9242. %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
  9243. %129 = OpLoad %uint %128
  9244. %130 = OpIAdd %uint %129 %120
  9245. %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
  9246. %132 = OpLoad %uint %131
  9247. OpReturnValue %132
  9248. OpFunctionEnd
  9249. )";
  9250. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  9251. SinglePassRunAndCheck<InstBindlessCheckPass>(
  9252. defs_before + func_before, defs_after + func_after + new_funcs, true,
  9253. true, 7u, 23u, true, true, 2u);
  9254. }
  9255. TEST_F(InstBindlessTest,
  9256. InstBoundsAnyHitInitLoadVariableSizedSampledImagesArray) {
  9257. // #version 460
  9258. // #extension GL_EXT_nonuniform_qualifier : require
  9259. // #extension GL_NV_ray_tracing : require
  9260. //
  9261. // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
  9262. // uint index;
  9263. // float red;
  9264. // } sbo;
  9265. //
  9266. // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
  9267. //
  9268. // void main()
  9269. // {
  9270. // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
  9271. // }
  9272. const std::string defs_before =
  9273. R"(OpCapability RuntimeDescriptorArray
  9274. OpCapability RayTracingNV
  9275. OpExtension "SPV_EXT_descriptor_indexing"
  9276. OpExtension "SPV_NV_ray_tracing"
  9277. %1 = OpExtInstImport "GLSL.std.450"
  9278. OpMemoryModel Logical GLSL450
  9279. OpEntryPoint AnyHitNV %main "main"
  9280. OpSource GLSL 460
  9281. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  9282. OpSourceExtension "GL_NV_ray_tracing"
  9283. OpName %main "main"
  9284. OpName %StorageBuffer "StorageBuffer"
  9285. OpMemberName %StorageBuffer 0 "index"
  9286. OpMemberName %StorageBuffer 1 "red"
  9287. OpName %sbo "sbo"
  9288. OpName %images "images"
  9289. OpMemberDecorate %StorageBuffer 0 Offset 0
  9290. OpMemberDecorate %StorageBuffer 1 Offset 4
  9291. OpDecorate %StorageBuffer BufferBlock
  9292. OpDecorate %sbo DescriptorSet 0
  9293. OpDecorate %sbo Binding 0
  9294. OpDecorate %images DescriptorSet 0
  9295. OpDecorate %images Binding 1
  9296. OpDecorate %images NonWritable
  9297. %void = OpTypeVoid
  9298. )";
  9299. const std::string defs_after =
  9300. R"(OpCapability RuntimeDescriptorArray
  9301. OpCapability RayTracingNV
  9302. OpExtension "SPV_EXT_descriptor_indexing"
  9303. OpExtension "SPV_NV_ray_tracing"
  9304. OpExtension "SPV_KHR_storage_buffer_storage_class"
  9305. %1 = OpExtInstImport "GLSL.std.450"
  9306. OpMemoryModel Logical GLSL450
  9307. OpEntryPoint AnyHitNV %main "main" %89
  9308. OpSource GLSL 460
  9309. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  9310. OpSourceExtension "GL_NV_ray_tracing"
  9311. OpName %main "main"
  9312. OpName %StorageBuffer "StorageBuffer"
  9313. OpMemberName %StorageBuffer 0 "index"
  9314. OpMemberName %StorageBuffer 1 "red"
  9315. OpName %sbo "sbo"
  9316. OpName %images "images"
  9317. OpMemberDecorate %StorageBuffer 0 Offset 0
  9318. OpMemberDecorate %StorageBuffer 1 Offset 4
  9319. OpDecorate %StorageBuffer BufferBlock
  9320. OpDecorate %sbo DescriptorSet 0
  9321. OpDecorate %sbo Binding 0
  9322. OpDecorate %images DescriptorSet 0
  9323. OpDecorate %images Binding 1
  9324. OpDecorate %images NonWritable
  9325. OpDecorate %_runtimearr_uint ArrayStride 4
  9326. OpDecorate %_struct_39 Block
  9327. OpMemberDecorate %_struct_39 0 Offset 0
  9328. OpDecorate %41 DescriptorSet 7
  9329. OpDecorate %41 Binding 1
  9330. OpDecorate %_struct_63 Block
  9331. OpMemberDecorate %_struct_63 0 Offset 0
  9332. OpMemberDecorate %_struct_63 1 Offset 4
  9333. OpDecorate %65 DescriptorSet 7
  9334. OpDecorate %65 Binding 0
  9335. OpDecorate %89 BuiltIn LaunchIdNV
  9336. %void = OpTypeVoid
  9337. )";
  9338. const std::string func_before =
  9339. R"(%3 = OpTypeFunction %void
  9340. %uint = OpTypeInt 32 0
  9341. %float = OpTypeFloat 32
  9342. %StorageBuffer = OpTypeStruct %uint %float
  9343. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  9344. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  9345. %int = OpTypeInt 32 1
  9346. %int_1 = OpConstant %int 1
  9347. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  9348. %_runtimearr_13 = OpTypeRuntimeArray %13
  9349. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  9350. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  9351. %int_0 = OpConstant %int 0
  9352. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  9353. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  9354. %v2int = OpTypeVector %int 2
  9355. %25 = OpConstantComposite %v2int %int_0 %int_0
  9356. %v4float = OpTypeVector %float 4
  9357. %uint_0 = OpConstant %uint 0
  9358. %_ptr_Uniform_float = OpTypePointer Uniform %float
  9359. %main = OpFunction %void None %3
  9360. %5 = OpLabel
  9361. %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  9362. %20 = OpLoad %uint %19
  9363. %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
  9364. %23 = OpLoad %13 %22
  9365. %27 = OpImageRead %v4float %23 %25
  9366. %29 = OpCompositeExtract %float %27 0
  9367. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  9368. OpStore %31 %29
  9369. OpReturn
  9370. OpFunctionEnd
  9371. )";
  9372. const std::string func_after =
  9373. R"(%7 = OpTypeFunction %void
  9374. %uint = OpTypeInt 32 0
  9375. %float = OpTypeFloat 32
  9376. %StorageBuffer = OpTypeStruct %uint %float
  9377. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  9378. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  9379. %int = OpTypeInt 32 1
  9380. %int_1 = OpConstant %int 1
  9381. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  9382. %_runtimearr_13 = OpTypeRuntimeArray %13
  9383. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  9384. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  9385. %int_0 = OpConstant %int 0
  9386. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  9387. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  9388. %v2int = OpTypeVector %int 2
  9389. %20 = OpConstantComposite %v2int %int_0 %int_0
  9390. %v4float = OpTypeVector %float 4
  9391. %uint_0 = OpConstant %uint 0
  9392. %_ptr_Uniform_float = OpTypePointer Uniform %float
  9393. %uint_1 = OpConstant %uint 1
  9394. %34 = OpTypeFunction %uint %uint %uint
  9395. %_runtimearr_uint = OpTypeRuntimeArray %uint
  9396. %_struct_39 = OpTypeStruct %_runtimearr_uint
  9397. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  9398. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  9399. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  9400. %bool = OpTypeBool
  9401. %57 = OpTypeFunction %void %uint %uint %uint %uint
  9402. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  9403. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  9404. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  9405. %uint_10 = OpConstant %uint 10
  9406. %uint_4 = OpConstant %uint 4
  9407. %uint_23 = OpConstant %uint 23
  9408. %uint_2 = OpConstant %uint 2
  9409. %uint_5315 = OpConstant %uint 5315
  9410. %uint_3 = OpConstant %uint 3
  9411. %v3uint = OpTypeVector %uint 3
  9412. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  9413. %89 = OpVariable %_ptr_Input_v3uint Input
  9414. %uint_5 = OpConstant %uint 5
  9415. %uint_6 = OpConstant %uint 6
  9416. %uint_7 = OpConstant %uint 7
  9417. %uint_8 = OpConstant %uint 8
  9418. %uint_9 = OpConstant %uint 9
  9419. %uint_51 = OpConstant %uint 51
  9420. %113 = OpConstantNull %v4float
  9421. %116 = OpTypeFunction %uint %uint %uint %uint %uint
  9422. %uint_48 = OpConstant %uint 48
  9423. %141 = OpConstantNull %uint
  9424. %uint_54 = OpConstant %uint 54
  9425. %main = OpFunction %void None %7
  9426. %24 = OpLabel
  9427. %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  9428. %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  9429. %134 = OpINotEqual %bool %133 %uint_0
  9430. OpSelectionMerge %135 None
  9431. OpBranchConditional %134 %136 %137
  9432. %136 = OpLabel
  9433. %138 = OpLoad %uint %25
  9434. OpBranch %135
  9435. %137 = OpLabel
  9436. %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
  9437. OpBranch %135
  9438. %135 = OpLabel
  9439. %142 = OpPhi %uint %138 %136 %141 %137
  9440. %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
  9441. %28 = OpLoad %13 %27
  9442. %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
  9443. %50 = OpULessThan %bool %142 %48
  9444. OpSelectionMerge %51 None
  9445. OpBranchConditional %50 %52 %53
  9446. %52 = OpLabel
  9447. %54 = OpLoad %13 %27
  9448. %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
  9449. %144 = OpINotEqual %bool %143 %uint_0
  9450. OpSelectionMerge %145 None
  9451. OpBranchConditional %144 %146 %147
  9452. %146 = OpLabel
  9453. %148 = OpLoad %13 %27
  9454. %149 = OpImageRead %v4float %148 %20
  9455. OpBranch %145
  9456. %147 = OpLabel
  9457. %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
  9458. OpBranch %145
  9459. %145 = OpLabel
  9460. %151 = OpPhi %v4float %149 %146 %113 %147
  9461. OpBranch %51
  9462. %53 = OpLabel
  9463. %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
  9464. OpBranch %51
  9465. %51 = OpLabel
  9466. %114 = OpPhi %v4float %151 %145 %113 %53
  9467. %30 = OpCompositeExtract %float %114 0
  9468. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  9469. %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  9470. %153 = OpINotEqual %bool %152 %uint_0
  9471. OpSelectionMerge %154 None
  9472. OpBranchConditional %153 %155 %156
  9473. %155 = OpLabel
  9474. OpStore %31 %30
  9475. OpBranch %154
  9476. %156 = OpLabel
  9477. %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
  9478. OpBranch %154
  9479. %154 = OpLabel
  9480. OpReturn
  9481. OpFunctionEnd
  9482. )";
  9483. const std::string new_funcs =
  9484. R"(%33 = OpFunction %uint None %34
  9485. %35 = OpFunctionParameter %uint
  9486. %36 = OpFunctionParameter %uint
  9487. %37 = OpLabel
  9488. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
  9489. %44 = OpLoad %uint %43
  9490. %45 = OpIAdd %uint %44 %36
  9491. %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
  9492. %47 = OpLoad %uint %46
  9493. OpReturnValue %47
  9494. OpFunctionEnd
  9495. %56 = OpFunction %void None %57
  9496. %58 = OpFunctionParameter %uint
  9497. %59 = OpFunctionParameter %uint
  9498. %60 = OpFunctionParameter %uint
  9499. %61 = OpFunctionParameter %uint
  9500. %62 = OpLabel
  9501. %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  9502. %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
  9503. %70 = OpIAdd %uint %69 %uint_10
  9504. %71 = OpArrayLength %uint %65 1
  9505. %72 = OpULessThanEqual %bool %70 %71
  9506. OpSelectionMerge %73 None
  9507. OpBranchConditional %72 %74 %73
  9508. %74 = OpLabel
  9509. %75 = OpIAdd %uint %69 %uint_0
  9510. %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
  9511. OpStore %76 %uint_10
  9512. %78 = OpIAdd %uint %69 %uint_1
  9513. %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
  9514. OpStore %79 %uint_23
  9515. %81 = OpIAdd %uint %69 %uint_2
  9516. %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
  9517. OpStore %82 %58
  9518. %85 = OpIAdd %uint %69 %uint_3
  9519. %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
  9520. OpStore %86 %uint_5315
  9521. %90 = OpLoad %v3uint %89
  9522. %91 = OpCompositeExtract %uint %90 0
  9523. %92 = OpCompositeExtract %uint %90 1
  9524. %93 = OpCompositeExtract %uint %90 2
  9525. %94 = OpIAdd %uint %69 %uint_4
  9526. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  9527. OpStore %95 %91
  9528. %97 = OpIAdd %uint %69 %uint_5
  9529. %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
  9530. OpStore %98 %92
  9531. %100 = OpIAdd %uint %69 %uint_6
  9532. %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
  9533. OpStore %101 %93
  9534. %103 = OpIAdd %uint %69 %uint_7
  9535. %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
  9536. OpStore %104 %59
  9537. %106 = OpIAdd %uint %69 %uint_8
  9538. %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
  9539. OpStore %107 %60
  9540. %109 = OpIAdd %uint %69 %uint_9
  9541. %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
  9542. OpStore %110 %61
  9543. OpBranch %73
  9544. %73 = OpLabel
  9545. OpReturn
  9546. OpFunctionEnd
  9547. %115 = OpFunction %uint None %116
  9548. %117 = OpFunctionParameter %uint
  9549. %118 = OpFunctionParameter %uint
  9550. %119 = OpFunctionParameter %uint
  9551. %120 = OpFunctionParameter %uint
  9552. %121 = OpLabel
  9553. %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
  9554. %123 = OpLoad %uint %122
  9555. %124 = OpIAdd %uint %123 %118
  9556. %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
  9557. %126 = OpLoad %uint %125
  9558. %127 = OpIAdd %uint %126 %119
  9559. %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
  9560. %129 = OpLoad %uint %128
  9561. %130 = OpIAdd %uint %129 %120
  9562. %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
  9563. %132 = OpLoad %uint %131
  9564. OpReturnValue %132
  9565. OpFunctionEnd
  9566. )";
  9567. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  9568. SinglePassRunAndCheck<InstBindlessCheckPass>(
  9569. defs_before + func_before, defs_after + func_after + new_funcs, true,
  9570. true, 7u, 23u, true, true, 2u);
  9571. }
  9572. TEST_F(InstBindlessTest,
  9573. InstBoundsClosestHitInitLoadVariableSizedSampledImagesArray) {
  9574. // #version 460
  9575. // #extension GL_EXT_nonuniform_qualifier : require
  9576. // #extension GL_NV_ray_tracing : require
  9577. //
  9578. // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
  9579. // uint index;
  9580. // float red;
  9581. // } sbo;
  9582. //
  9583. // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
  9584. //
  9585. // void main()
  9586. // {
  9587. // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
  9588. // }
  9589. const std::string defs_before =
  9590. R"(OpCapability RuntimeDescriptorArray
  9591. OpCapability RayTracingNV
  9592. OpExtension "SPV_EXT_descriptor_indexing"
  9593. OpExtension "SPV_NV_ray_tracing"
  9594. %1 = OpExtInstImport "GLSL.std.450"
  9595. OpMemoryModel Logical GLSL450
  9596. OpEntryPoint ClosestHitNV %main "main"
  9597. OpSource GLSL 460
  9598. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  9599. OpSourceExtension "GL_NV_ray_tracing"
  9600. OpName %main "main"
  9601. OpName %StorageBuffer "StorageBuffer"
  9602. OpMemberName %StorageBuffer 0 "index"
  9603. OpMemberName %StorageBuffer 1 "red"
  9604. OpName %sbo "sbo"
  9605. OpName %images "images"
  9606. OpMemberDecorate %StorageBuffer 0 Offset 0
  9607. OpMemberDecorate %StorageBuffer 1 Offset 4
  9608. OpDecorate %StorageBuffer BufferBlock
  9609. OpDecorate %sbo DescriptorSet 0
  9610. OpDecorate %sbo Binding 0
  9611. OpDecorate %images DescriptorSet 0
  9612. OpDecorate %images Binding 1
  9613. OpDecorate %images NonWritable
  9614. %void = OpTypeVoid
  9615. )";
  9616. const std::string defs_after =
  9617. R"(OpCapability RuntimeDescriptorArray
  9618. OpCapability RayTracingNV
  9619. OpExtension "SPV_EXT_descriptor_indexing"
  9620. OpExtension "SPV_NV_ray_tracing"
  9621. OpExtension "SPV_KHR_storage_buffer_storage_class"
  9622. %1 = OpExtInstImport "GLSL.std.450"
  9623. OpMemoryModel Logical GLSL450
  9624. OpEntryPoint ClosestHitNV %main "main" %89
  9625. OpSource GLSL 460
  9626. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  9627. OpSourceExtension "GL_NV_ray_tracing"
  9628. OpName %main "main"
  9629. OpName %StorageBuffer "StorageBuffer"
  9630. OpMemberName %StorageBuffer 0 "index"
  9631. OpMemberName %StorageBuffer 1 "red"
  9632. OpName %sbo "sbo"
  9633. OpName %images "images"
  9634. OpMemberDecorate %StorageBuffer 0 Offset 0
  9635. OpMemberDecorate %StorageBuffer 1 Offset 4
  9636. OpDecorate %StorageBuffer BufferBlock
  9637. OpDecorate %sbo DescriptorSet 0
  9638. OpDecorate %sbo Binding 0
  9639. OpDecorate %images DescriptorSet 0
  9640. OpDecorate %images Binding 1
  9641. OpDecorate %images NonWritable
  9642. OpDecorate %_runtimearr_uint ArrayStride 4
  9643. OpDecorate %_struct_39 Block
  9644. OpMemberDecorate %_struct_39 0 Offset 0
  9645. OpDecorate %41 DescriptorSet 7
  9646. OpDecorate %41 Binding 1
  9647. OpDecorate %_struct_63 Block
  9648. OpMemberDecorate %_struct_63 0 Offset 0
  9649. OpMemberDecorate %_struct_63 1 Offset 4
  9650. OpDecorate %65 DescriptorSet 7
  9651. OpDecorate %65 Binding 0
  9652. OpDecorate %89 BuiltIn LaunchIdNV
  9653. %void = OpTypeVoid
  9654. )";
  9655. const std::string func_before =
  9656. R"(%3 = OpTypeFunction %void
  9657. %uint = OpTypeInt 32 0
  9658. %float = OpTypeFloat 32
  9659. %StorageBuffer = OpTypeStruct %uint %float
  9660. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  9661. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  9662. %int = OpTypeInt 32 1
  9663. %int_1 = OpConstant %int 1
  9664. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  9665. %_runtimearr_13 = OpTypeRuntimeArray %13
  9666. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  9667. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  9668. %int_0 = OpConstant %int 0
  9669. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  9670. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  9671. %v2int = OpTypeVector %int 2
  9672. %25 = OpConstantComposite %v2int %int_0 %int_0
  9673. %v4float = OpTypeVector %float 4
  9674. %uint_0 = OpConstant %uint 0
  9675. %_ptr_Uniform_float = OpTypePointer Uniform %float
  9676. %main = OpFunction %void None %3
  9677. %5 = OpLabel
  9678. %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  9679. %20 = OpLoad %uint %19
  9680. %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
  9681. %23 = OpLoad %13 %22
  9682. %27 = OpImageRead %v4float %23 %25
  9683. %29 = OpCompositeExtract %float %27 0
  9684. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  9685. OpStore %31 %29
  9686. OpReturn
  9687. OpFunctionEnd
  9688. )";
  9689. const std::string func_after =
  9690. R"(%7 = OpTypeFunction %void
  9691. %uint = OpTypeInt 32 0
  9692. %float = OpTypeFloat 32
  9693. %StorageBuffer = OpTypeStruct %uint %float
  9694. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  9695. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  9696. %int = OpTypeInt 32 1
  9697. %int_1 = OpConstant %int 1
  9698. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  9699. %_runtimearr_13 = OpTypeRuntimeArray %13
  9700. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  9701. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  9702. %int_0 = OpConstant %int 0
  9703. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  9704. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  9705. %v2int = OpTypeVector %int 2
  9706. %20 = OpConstantComposite %v2int %int_0 %int_0
  9707. %v4float = OpTypeVector %float 4
  9708. %uint_0 = OpConstant %uint 0
  9709. %_ptr_Uniform_float = OpTypePointer Uniform %float
  9710. %uint_1 = OpConstant %uint 1
  9711. %34 = OpTypeFunction %uint %uint %uint
  9712. %_runtimearr_uint = OpTypeRuntimeArray %uint
  9713. %_struct_39 = OpTypeStruct %_runtimearr_uint
  9714. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  9715. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  9716. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  9717. %bool = OpTypeBool
  9718. %57 = OpTypeFunction %void %uint %uint %uint %uint
  9719. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  9720. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  9721. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  9722. %uint_10 = OpConstant %uint 10
  9723. %uint_4 = OpConstant %uint 4
  9724. %uint_23 = OpConstant %uint 23
  9725. %uint_2 = OpConstant %uint 2
  9726. %uint_5316 = OpConstant %uint 5316
  9727. %uint_3 = OpConstant %uint 3
  9728. %v3uint = OpTypeVector %uint 3
  9729. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  9730. %89 = OpVariable %_ptr_Input_v3uint Input
  9731. %uint_5 = OpConstant %uint 5
  9732. %uint_6 = OpConstant %uint 6
  9733. %uint_7 = OpConstant %uint 7
  9734. %uint_8 = OpConstant %uint 8
  9735. %uint_9 = OpConstant %uint 9
  9736. %uint_51 = OpConstant %uint 51
  9737. %113 = OpConstantNull %v4float
  9738. %116 = OpTypeFunction %uint %uint %uint %uint %uint
  9739. %uint_48 = OpConstant %uint 48
  9740. %141 = OpConstantNull %uint
  9741. %uint_54 = OpConstant %uint 54
  9742. %main = OpFunction %void None %7
  9743. %24 = OpLabel
  9744. %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  9745. %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  9746. %134 = OpINotEqual %bool %133 %uint_0
  9747. OpSelectionMerge %135 None
  9748. OpBranchConditional %134 %136 %137
  9749. %136 = OpLabel
  9750. %138 = OpLoad %uint %25
  9751. OpBranch %135
  9752. %137 = OpLabel
  9753. %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
  9754. OpBranch %135
  9755. %135 = OpLabel
  9756. %142 = OpPhi %uint %138 %136 %141 %137
  9757. %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
  9758. %28 = OpLoad %13 %27
  9759. %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
  9760. %50 = OpULessThan %bool %142 %48
  9761. OpSelectionMerge %51 None
  9762. OpBranchConditional %50 %52 %53
  9763. %52 = OpLabel
  9764. %54 = OpLoad %13 %27
  9765. %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
  9766. %144 = OpINotEqual %bool %143 %uint_0
  9767. OpSelectionMerge %145 None
  9768. OpBranchConditional %144 %146 %147
  9769. %146 = OpLabel
  9770. %148 = OpLoad %13 %27
  9771. %149 = OpImageRead %v4float %148 %20
  9772. OpBranch %145
  9773. %147 = OpLabel
  9774. %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
  9775. OpBranch %145
  9776. %145 = OpLabel
  9777. %151 = OpPhi %v4float %149 %146 %113 %147
  9778. OpBranch %51
  9779. %53 = OpLabel
  9780. %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
  9781. OpBranch %51
  9782. %51 = OpLabel
  9783. %114 = OpPhi %v4float %151 %145 %113 %53
  9784. %30 = OpCompositeExtract %float %114 0
  9785. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  9786. %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  9787. %153 = OpINotEqual %bool %152 %uint_0
  9788. OpSelectionMerge %154 None
  9789. OpBranchConditional %153 %155 %156
  9790. %155 = OpLabel
  9791. OpStore %31 %30
  9792. OpBranch %154
  9793. %156 = OpLabel
  9794. %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
  9795. OpBranch %154
  9796. %154 = OpLabel
  9797. OpReturn
  9798. OpFunctionEnd
  9799. )";
  9800. const std::string new_funcs =
  9801. R"(%33 = OpFunction %uint None %34
  9802. %35 = OpFunctionParameter %uint
  9803. %36 = OpFunctionParameter %uint
  9804. %37 = OpLabel
  9805. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
  9806. %44 = OpLoad %uint %43
  9807. %45 = OpIAdd %uint %44 %36
  9808. %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
  9809. %47 = OpLoad %uint %46
  9810. OpReturnValue %47
  9811. OpFunctionEnd
  9812. %56 = OpFunction %void None %57
  9813. %58 = OpFunctionParameter %uint
  9814. %59 = OpFunctionParameter %uint
  9815. %60 = OpFunctionParameter %uint
  9816. %61 = OpFunctionParameter %uint
  9817. %62 = OpLabel
  9818. %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  9819. %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
  9820. %70 = OpIAdd %uint %69 %uint_10
  9821. %71 = OpArrayLength %uint %65 1
  9822. %72 = OpULessThanEqual %bool %70 %71
  9823. OpSelectionMerge %73 None
  9824. OpBranchConditional %72 %74 %73
  9825. %74 = OpLabel
  9826. %75 = OpIAdd %uint %69 %uint_0
  9827. %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
  9828. OpStore %76 %uint_10
  9829. %78 = OpIAdd %uint %69 %uint_1
  9830. %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
  9831. OpStore %79 %uint_23
  9832. %81 = OpIAdd %uint %69 %uint_2
  9833. %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
  9834. OpStore %82 %58
  9835. %85 = OpIAdd %uint %69 %uint_3
  9836. %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
  9837. OpStore %86 %uint_5316
  9838. %90 = OpLoad %v3uint %89
  9839. %91 = OpCompositeExtract %uint %90 0
  9840. %92 = OpCompositeExtract %uint %90 1
  9841. %93 = OpCompositeExtract %uint %90 2
  9842. %94 = OpIAdd %uint %69 %uint_4
  9843. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  9844. OpStore %95 %91
  9845. %97 = OpIAdd %uint %69 %uint_5
  9846. %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
  9847. OpStore %98 %92
  9848. %100 = OpIAdd %uint %69 %uint_6
  9849. %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
  9850. OpStore %101 %93
  9851. %103 = OpIAdd %uint %69 %uint_7
  9852. %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
  9853. OpStore %104 %59
  9854. %106 = OpIAdd %uint %69 %uint_8
  9855. %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
  9856. OpStore %107 %60
  9857. %109 = OpIAdd %uint %69 %uint_9
  9858. %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
  9859. OpStore %110 %61
  9860. OpBranch %73
  9861. %73 = OpLabel
  9862. OpReturn
  9863. OpFunctionEnd
  9864. %115 = OpFunction %uint None %116
  9865. %117 = OpFunctionParameter %uint
  9866. %118 = OpFunctionParameter %uint
  9867. %119 = OpFunctionParameter %uint
  9868. %120 = OpFunctionParameter %uint
  9869. %121 = OpLabel
  9870. %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
  9871. %123 = OpLoad %uint %122
  9872. %124 = OpIAdd %uint %123 %118
  9873. %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
  9874. %126 = OpLoad %uint %125
  9875. %127 = OpIAdd %uint %126 %119
  9876. %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
  9877. %129 = OpLoad %uint %128
  9878. %130 = OpIAdd %uint %129 %120
  9879. %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
  9880. %132 = OpLoad %uint %131
  9881. OpReturnValue %132
  9882. OpFunctionEnd
  9883. )";
  9884. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  9885. SinglePassRunAndCheck<InstBindlessCheckPass>(
  9886. defs_before + func_before, defs_after + func_after + new_funcs, true,
  9887. true, 7u, 23u, true, true, 2u);
  9888. }
  9889. TEST_F(InstBindlessTest,
  9890. InstBoundsMissInitLoadVariableSizedSampledImagesArray) {
  9891. // #version 460
  9892. // #extension GL_EXT_nonuniform_qualifier : require
  9893. // #extension GL_NV_ray_tracing : require
  9894. //
  9895. // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
  9896. // uint index;
  9897. // float red;
  9898. // } sbo;
  9899. //
  9900. // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
  9901. //
  9902. // void main()
  9903. // {
  9904. // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
  9905. // }
  9906. const std::string defs_before =
  9907. R"(OpCapability RuntimeDescriptorArray
  9908. OpCapability RayTracingNV
  9909. OpExtension "SPV_EXT_descriptor_indexing"
  9910. OpExtension "SPV_NV_ray_tracing"
  9911. %1 = OpExtInstImport "GLSL.std.450"
  9912. OpMemoryModel Logical GLSL450
  9913. OpEntryPoint MissNV %main "main"
  9914. OpSource GLSL 460
  9915. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  9916. OpSourceExtension "GL_NV_ray_tracing"
  9917. OpName %main "main"
  9918. OpName %StorageBuffer "StorageBuffer"
  9919. OpMemberName %StorageBuffer 0 "index"
  9920. OpMemberName %StorageBuffer 1 "red"
  9921. OpName %sbo "sbo"
  9922. OpName %images "images"
  9923. OpMemberDecorate %StorageBuffer 0 Offset 0
  9924. OpMemberDecorate %StorageBuffer 1 Offset 4
  9925. OpDecorate %StorageBuffer BufferBlock
  9926. OpDecorate %sbo DescriptorSet 0
  9927. OpDecorate %sbo Binding 0
  9928. OpDecorate %images DescriptorSet 0
  9929. OpDecorate %images Binding 1
  9930. OpDecorate %images NonWritable
  9931. %void = OpTypeVoid
  9932. )";
  9933. const std::string defs_after =
  9934. R"(OpCapability RuntimeDescriptorArray
  9935. OpCapability RayTracingNV
  9936. OpExtension "SPV_EXT_descriptor_indexing"
  9937. OpExtension "SPV_NV_ray_tracing"
  9938. OpExtension "SPV_KHR_storage_buffer_storage_class"
  9939. %1 = OpExtInstImport "GLSL.std.450"
  9940. OpMemoryModel Logical GLSL450
  9941. OpEntryPoint MissNV %main "main" %89
  9942. OpSource GLSL 460
  9943. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  9944. OpSourceExtension "GL_NV_ray_tracing"
  9945. OpName %main "main"
  9946. OpName %StorageBuffer "StorageBuffer"
  9947. OpMemberName %StorageBuffer 0 "index"
  9948. OpMemberName %StorageBuffer 1 "red"
  9949. OpName %sbo "sbo"
  9950. OpName %images "images"
  9951. OpMemberDecorate %StorageBuffer 0 Offset 0
  9952. OpMemberDecorate %StorageBuffer 1 Offset 4
  9953. OpDecorate %StorageBuffer BufferBlock
  9954. OpDecorate %sbo DescriptorSet 0
  9955. OpDecorate %sbo Binding 0
  9956. OpDecorate %images DescriptorSet 0
  9957. OpDecorate %images Binding 1
  9958. OpDecorate %images NonWritable
  9959. OpDecorate %_runtimearr_uint ArrayStride 4
  9960. OpDecorate %_struct_39 Block
  9961. OpMemberDecorate %_struct_39 0 Offset 0
  9962. OpDecorate %41 DescriptorSet 7
  9963. OpDecorate %41 Binding 1
  9964. OpDecorate %_struct_63 Block
  9965. OpMemberDecorate %_struct_63 0 Offset 0
  9966. OpMemberDecorate %_struct_63 1 Offset 4
  9967. OpDecorate %65 DescriptorSet 7
  9968. OpDecorate %65 Binding 0
  9969. OpDecorate %89 BuiltIn LaunchIdNV
  9970. %void = OpTypeVoid
  9971. )";
  9972. const std::string func_before =
  9973. R"(%3 = OpTypeFunction %void
  9974. %uint = OpTypeInt 32 0
  9975. %float = OpTypeFloat 32
  9976. %StorageBuffer = OpTypeStruct %uint %float
  9977. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  9978. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  9979. %int = OpTypeInt 32 1
  9980. %int_1 = OpConstant %int 1
  9981. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  9982. %_runtimearr_13 = OpTypeRuntimeArray %13
  9983. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  9984. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  9985. %int_0 = OpConstant %int 0
  9986. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  9987. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  9988. %v2int = OpTypeVector %int 2
  9989. %25 = OpConstantComposite %v2int %int_0 %int_0
  9990. %v4float = OpTypeVector %float 4
  9991. %uint_0 = OpConstant %uint 0
  9992. %_ptr_Uniform_float = OpTypePointer Uniform %float
  9993. %main = OpFunction %void None %3
  9994. %5 = OpLabel
  9995. %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  9996. %20 = OpLoad %uint %19
  9997. %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
  9998. %23 = OpLoad %13 %22
  9999. %27 = OpImageRead %v4float %23 %25
  10000. %29 = OpCompositeExtract %float %27 0
  10001. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  10002. OpStore %31 %29
  10003. OpReturn
  10004. OpFunctionEnd
  10005. )";
  10006. const std::string func_after =
  10007. R"(%7 = OpTypeFunction %void
  10008. %uint = OpTypeInt 32 0
  10009. %float = OpTypeFloat 32
  10010. %StorageBuffer = OpTypeStruct %uint %float
  10011. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  10012. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  10013. %int = OpTypeInt 32 1
  10014. %int_1 = OpConstant %int 1
  10015. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  10016. %_runtimearr_13 = OpTypeRuntimeArray %13
  10017. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  10018. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  10019. %int_0 = OpConstant %int 0
  10020. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  10021. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  10022. %v2int = OpTypeVector %int 2
  10023. %20 = OpConstantComposite %v2int %int_0 %int_0
  10024. %v4float = OpTypeVector %float 4
  10025. %uint_0 = OpConstant %uint 0
  10026. %_ptr_Uniform_float = OpTypePointer Uniform %float
  10027. %uint_1 = OpConstant %uint 1
  10028. %34 = OpTypeFunction %uint %uint %uint
  10029. %_runtimearr_uint = OpTypeRuntimeArray %uint
  10030. %_struct_39 = OpTypeStruct %_runtimearr_uint
  10031. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  10032. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  10033. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  10034. %bool = OpTypeBool
  10035. %57 = OpTypeFunction %void %uint %uint %uint %uint
  10036. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  10037. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  10038. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  10039. %uint_10 = OpConstant %uint 10
  10040. %uint_4 = OpConstant %uint 4
  10041. %uint_23 = OpConstant %uint 23
  10042. %uint_2 = OpConstant %uint 2
  10043. %uint_5317 = OpConstant %uint 5317
  10044. %uint_3 = OpConstant %uint 3
  10045. %v3uint = OpTypeVector %uint 3
  10046. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  10047. %89 = OpVariable %_ptr_Input_v3uint Input
  10048. %uint_5 = OpConstant %uint 5
  10049. %uint_6 = OpConstant %uint 6
  10050. %uint_7 = OpConstant %uint 7
  10051. %uint_8 = OpConstant %uint 8
  10052. %uint_9 = OpConstant %uint 9
  10053. %uint_51 = OpConstant %uint 51
  10054. %113 = OpConstantNull %v4float
  10055. %116 = OpTypeFunction %uint %uint %uint %uint %uint
  10056. %uint_48 = OpConstant %uint 48
  10057. %141 = OpConstantNull %uint
  10058. %uint_54 = OpConstant %uint 54
  10059. %main = OpFunction %void None %7
  10060. %24 = OpLabel
  10061. %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  10062. %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  10063. %134 = OpINotEqual %bool %133 %uint_0
  10064. OpSelectionMerge %135 None
  10065. OpBranchConditional %134 %136 %137
  10066. %136 = OpLabel
  10067. %138 = OpLoad %uint %25
  10068. OpBranch %135
  10069. %137 = OpLabel
  10070. %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
  10071. OpBranch %135
  10072. %135 = OpLabel
  10073. %142 = OpPhi %uint %138 %136 %141 %137
  10074. %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
  10075. %28 = OpLoad %13 %27
  10076. %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
  10077. %50 = OpULessThan %bool %142 %48
  10078. OpSelectionMerge %51 None
  10079. OpBranchConditional %50 %52 %53
  10080. %52 = OpLabel
  10081. %54 = OpLoad %13 %27
  10082. %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
  10083. %144 = OpINotEqual %bool %143 %uint_0
  10084. OpSelectionMerge %145 None
  10085. OpBranchConditional %144 %146 %147
  10086. %146 = OpLabel
  10087. %148 = OpLoad %13 %27
  10088. %149 = OpImageRead %v4float %148 %20
  10089. OpBranch %145
  10090. %147 = OpLabel
  10091. %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
  10092. OpBranch %145
  10093. %145 = OpLabel
  10094. %151 = OpPhi %v4float %149 %146 %113 %147
  10095. OpBranch %51
  10096. %53 = OpLabel
  10097. %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
  10098. OpBranch %51
  10099. %51 = OpLabel
  10100. %114 = OpPhi %v4float %151 %145 %113 %53
  10101. %30 = OpCompositeExtract %float %114 0
  10102. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  10103. %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  10104. %153 = OpINotEqual %bool %152 %uint_0
  10105. OpSelectionMerge %154 None
  10106. OpBranchConditional %153 %155 %156
  10107. %155 = OpLabel
  10108. OpStore %31 %30
  10109. OpBranch %154
  10110. %156 = OpLabel
  10111. %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
  10112. OpBranch %154
  10113. %154 = OpLabel
  10114. OpReturn
  10115. OpFunctionEnd
  10116. )";
  10117. const std::string new_funcs =
  10118. R"(%33 = OpFunction %uint None %34
  10119. %35 = OpFunctionParameter %uint
  10120. %36 = OpFunctionParameter %uint
  10121. %37 = OpLabel
  10122. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
  10123. %44 = OpLoad %uint %43
  10124. %45 = OpIAdd %uint %44 %36
  10125. %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
  10126. %47 = OpLoad %uint %46
  10127. OpReturnValue %47
  10128. OpFunctionEnd
  10129. %56 = OpFunction %void None %57
  10130. %58 = OpFunctionParameter %uint
  10131. %59 = OpFunctionParameter %uint
  10132. %60 = OpFunctionParameter %uint
  10133. %61 = OpFunctionParameter %uint
  10134. %62 = OpLabel
  10135. %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  10136. %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
  10137. %70 = OpIAdd %uint %69 %uint_10
  10138. %71 = OpArrayLength %uint %65 1
  10139. %72 = OpULessThanEqual %bool %70 %71
  10140. OpSelectionMerge %73 None
  10141. OpBranchConditional %72 %74 %73
  10142. %74 = OpLabel
  10143. %75 = OpIAdd %uint %69 %uint_0
  10144. %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
  10145. OpStore %76 %uint_10
  10146. %78 = OpIAdd %uint %69 %uint_1
  10147. %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
  10148. OpStore %79 %uint_23
  10149. %81 = OpIAdd %uint %69 %uint_2
  10150. %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
  10151. OpStore %82 %58
  10152. %85 = OpIAdd %uint %69 %uint_3
  10153. %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
  10154. OpStore %86 %uint_5317
  10155. %90 = OpLoad %v3uint %89
  10156. %91 = OpCompositeExtract %uint %90 0
  10157. %92 = OpCompositeExtract %uint %90 1
  10158. %93 = OpCompositeExtract %uint %90 2
  10159. %94 = OpIAdd %uint %69 %uint_4
  10160. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  10161. OpStore %95 %91
  10162. %97 = OpIAdd %uint %69 %uint_5
  10163. %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
  10164. OpStore %98 %92
  10165. %100 = OpIAdd %uint %69 %uint_6
  10166. %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
  10167. OpStore %101 %93
  10168. %103 = OpIAdd %uint %69 %uint_7
  10169. %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
  10170. OpStore %104 %59
  10171. %106 = OpIAdd %uint %69 %uint_8
  10172. %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
  10173. OpStore %107 %60
  10174. %109 = OpIAdd %uint %69 %uint_9
  10175. %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
  10176. OpStore %110 %61
  10177. OpBranch %73
  10178. %73 = OpLabel
  10179. OpReturn
  10180. OpFunctionEnd
  10181. %115 = OpFunction %uint None %116
  10182. %117 = OpFunctionParameter %uint
  10183. %118 = OpFunctionParameter %uint
  10184. %119 = OpFunctionParameter %uint
  10185. %120 = OpFunctionParameter %uint
  10186. %121 = OpLabel
  10187. %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
  10188. %123 = OpLoad %uint %122
  10189. %124 = OpIAdd %uint %123 %118
  10190. %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
  10191. %126 = OpLoad %uint %125
  10192. %127 = OpIAdd %uint %126 %119
  10193. %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
  10194. %129 = OpLoad %uint %128
  10195. %130 = OpIAdd %uint %129 %120
  10196. %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
  10197. %132 = OpLoad %uint %131
  10198. OpReturnValue %132
  10199. OpFunctionEnd
  10200. )";
  10201. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  10202. SinglePassRunAndCheck<InstBindlessCheckPass>(
  10203. defs_before + func_before, defs_after + func_after + new_funcs, true,
  10204. true, 7u, 23u, true, true, 2u);
  10205. }
  10206. TEST_F(InstBindlessTest,
  10207. InstBoundsCallableInitLoadVariableSizedSampledImagesArray) {
  10208. // #version 460
  10209. // #extension GL_EXT_nonuniform_qualifier : require
  10210. // #extension GL_NV_ray_tracing : require
  10211. //
  10212. // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
  10213. // uint index;
  10214. // float red;
  10215. // } sbo;
  10216. //
  10217. // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
  10218. //
  10219. // void main()
  10220. // {
  10221. // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
  10222. // }
  10223. const std::string defs_before =
  10224. R"(OpCapability RuntimeDescriptorArray
  10225. OpCapability RayTracingNV
  10226. OpExtension "SPV_EXT_descriptor_indexing"
  10227. OpExtension "SPV_NV_ray_tracing"
  10228. %1 = OpExtInstImport "GLSL.std.450"
  10229. OpMemoryModel Logical GLSL450
  10230. OpEntryPoint CallableNV %main "main"
  10231. OpSource GLSL 460
  10232. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  10233. OpSourceExtension "GL_NV_ray_tracing"
  10234. OpName %main "main"
  10235. OpName %StorageBuffer "StorageBuffer"
  10236. OpMemberName %StorageBuffer 0 "index"
  10237. OpMemberName %StorageBuffer 1 "red"
  10238. OpName %sbo "sbo"
  10239. OpName %images "images"
  10240. OpMemberDecorate %StorageBuffer 0 Offset 0
  10241. OpMemberDecorate %StorageBuffer 1 Offset 4
  10242. OpDecorate %StorageBuffer BufferBlock
  10243. OpDecorate %sbo DescriptorSet 0
  10244. OpDecorate %sbo Binding 0
  10245. OpDecorate %images DescriptorSet 0
  10246. OpDecorate %images Binding 1
  10247. OpDecorate %images NonWritable
  10248. %void = OpTypeVoid
  10249. )";
  10250. const std::string defs_after =
  10251. R"(OpCapability RuntimeDescriptorArray
  10252. OpCapability RayTracingNV
  10253. OpExtension "SPV_EXT_descriptor_indexing"
  10254. OpExtension "SPV_NV_ray_tracing"
  10255. OpExtension "SPV_KHR_storage_buffer_storage_class"
  10256. %1 = OpExtInstImport "GLSL.std.450"
  10257. OpMemoryModel Logical GLSL450
  10258. OpEntryPoint CallableNV %main "main" %89
  10259. OpSource GLSL 460
  10260. OpSourceExtension "GL_EXT_nonuniform_qualifier"
  10261. OpSourceExtension "GL_NV_ray_tracing"
  10262. OpName %main "main"
  10263. OpName %StorageBuffer "StorageBuffer"
  10264. OpMemberName %StorageBuffer 0 "index"
  10265. OpMemberName %StorageBuffer 1 "red"
  10266. OpName %sbo "sbo"
  10267. OpName %images "images"
  10268. OpMemberDecorate %StorageBuffer 0 Offset 0
  10269. OpMemberDecorate %StorageBuffer 1 Offset 4
  10270. OpDecorate %StorageBuffer BufferBlock
  10271. OpDecorate %sbo DescriptorSet 0
  10272. OpDecorate %sbo Binding 0
  10273. OpDecorate %images DescriptorSet 0
  10274. OpDecorate %images Binding 1
  10275. OpDecorate %images NonWritable
  10276. OpDecorate %_runtimearr_uint ArrayStride 4
  10277. OpDecorate %_struct_39 Block
  10278. OpMemberDecorate %_struct_39 0 Offset 0
  10279. OpDecorate %41 DescriptorSet 7
  10280. OpDecorate %41 Binding 1
  10281. OpDecorate %_struct_63 Block
  10282. OpMemberDecorate %_struct_63 0 Offset 0
  10283. OpMemberDecorate %_struct_63 1 Offset 4
  10284. OpDecorate %65 DescriptorSet 7
  10285. OpDecorate %65 Binding 0
  10286. OpDecorate %89 BuiltIn LaunchIdNV
  10287. %void = OpTypeVoid
  10288. )";
  10289. const std::string func_before =
  10290. R"(%3 = OpTypeFunction %void
  10291. %uint = OpTypeInt 32 0
  10292. %float = OpTypeFloat 32
  10293. %StorageBuffer = OpTypeStruct %uint %float
  10294. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  10295. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  10296. %int = OpTypeInt 32 1
  10297. %int_1 = OpConstant %int 1
  10298. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  10299. %_runtimearr_13 = OpTypeRuntimeArray %13
  10300. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  10301. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  10302. %int_0 = OpConstant %int 0
  10303. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  10304. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  10305. %v2int = OpTypeVector %int 2
  10306. %25 = OpConstantComposite %v2int %int_0 %int_0
  10307. %v4float = OpTypeVector %float 4
  10308. %uint_0 = OpConstant %uint 0
  10309. %_ptr_Uniform_float = OpTypePointer Uniform %float
  10310. %main = OpFunction %void None %3
  10311. %5 = OpLabel
  10312. %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  10313. %20 = OpLoad %uint %19
  10314. %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
  10315. %23 = OpLoad %13 %22
  10316. %27 = OpImageRead %v4float %23 %25
  10317. %29 = OpCompositeExtract %float %27 0
  10318. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  10319. OpStore %31 %29
  10320. OpReturn
  10321. OpFunctionEnd
  10322. )";
  10323. const std::string func_after =
  10324. R"(%7 = OpTypeFunction %void
  10325. %uint = OpTypeInt 32 0
  10326. %float = OpTypeFloat 32
  10327. %StorageBuffer = OpTypeStruct %uint %float
  10328. %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
  10329. %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
  10330. %int = OpTypeInt 32 1
  10331. %int_1 = OpConstant %int 1
  10332. %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
  10333. %_runtimearr_13 = OpTypeRuntimeArray %13
  10334. %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
  10335. %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
  10336. %int_0 = OpConstant %int 0
  10337. %_ptr_Uniform_uint = OpTypePointer Uniform %uint
  10338. %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
  10339. %v2int = OpTypeVector %int 2
  10340. %20 = OpConstantComposite %v2int %int_0 %int_0
  10341. %v4float = OpTypeVector %float 4
  10342. %uint_0 = OpConstant %uint 0
  10343. %_ptr_Uniform_float = OpTypePointer Uniform %float
  10344. %uint_1 = OpConstant %uint 1
  10345. %34 = OpTypeFunction %uint %uint %uint
  10346. %_runtimearr_uint = OpTypeRuntimeArray %uint
  10347. %_struct_39 = OpTypeStruct %_runtimearr_uint
  10348. %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
  10349. %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
  10350. %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
  10351. %bool = OpTypeBool
  10352. %57 = OpTypeFunction %void %uint %uint %uint %uint
  10353. %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
  10354. %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
  10355. %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
  10356. %uint_10 = OpConstant %uint 10
  10357. %uint_4 = OpConstant %uint 4
  10358. %uint_23 = OpConstant %uint 23
  10359. %uint_2 = OpConstant %uint 2
  10360. %uint_5318 = OpConstant %uint 5318
  10361. %uint_3 = OpConstant %uint 3
  10362. %v3uint = OpTypeVector %uint 3
  10363. %_ptr_Input_v3uint = OpTypePointer Input %v3uint
  10364. %89 = OpVariable %_ptr_Input_v3uint Input
  10365. %uint_5 = OpConstant %uint 5
  10366. %uint_6 = OpConstant %uint 6
  10367. %uint_7 = OpConstant %uint 7
  10368. %uint_8 = OpConstant %uint 8
  10369. %uint_9 = OpConstant %uint 9
  10370. %uint_51 = OpConstant %uint 51
  10371. %113 = OpConstantNull %v4float
  10372. %116 = OpTypeFunction %uint %uint %uint %uint %uint
  10373. %uint_48 = OpConstant %uint 48
  10374. %141 = OpConstantNull %uint
  10375. %uint_54 = OpConstant %uint 54
  10376. %main = OpFunction %void None %7
  10377. %24 = OpLabel
  10378. %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
  10379. %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  10380. %134 = OpINotEqual %bool %133 %uint_0
  10381. OpSelectionMerge %135 None
  10382. OpBranchConditional %134 %136 %137
  10383. %136 = OpLabel
  10384. %138 = OpLoad %uint %25
  10385. OpBranch %135
  10386. %137 = OpLabel
  10387. %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
  10388. OpBranch %135
  10389. %135 = OpLabel
  10390. %142 = OpPhi %uint %138 %136 %141 %137
  10391. %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
  10392. %28 = OpLoad %13 %27
  10393. %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
  10394. %50 = OpULessThan %bool %142 %48
  10395. OpSelectionMerge %51 None
  10396. OpBranchConditional %50 %52 %53
  10397. %52 = OpLabel
  10398. %54 = OpLoad %13 %27
  10399. %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
  10400. %144 = OpINotEqual %bool %143 %uint_0
  10401. OpSelectionMerge %145 None
  10402. OpBranchConditional %144 %146 %147
  10403. %146 = OpLabel
  10404. %148 = OpLoad %13 %27
  10405. %149 = OpImageRead %v4float %148 %20
  10406. OpBranch %145
  10407. %147 = OpLabel
  10408. %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
  10409. OpBranch %145
  10410. %145 = OpLabel
  10411. %151 = OpPhi %v4float %149 %146 %113 %147
  10412. OpBranch %51
  10413. %53 = OpLabel
  10414. %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
  10415. OpBranch %51
  10416. %51 = OpLabel
  10417. %114 = OpPhi %v4float %151 %145 %113 %53
  10418. %30 = OpCompositeExtract %float %114 0
  10419. %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
  10420. %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
  10421. %153 = OpINotEqual %bool %152 %uint_0
  10422. OpSelectionMerge %154 None
  10423. OpBranchConditional %153 %155 %156
  10424. %155 = OpLabel
  10425. OpStore %31 %30
  10426. OpBranch %154
  10427. %156 = OpLabel
  10428. %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
  10429. OpBranch %154
  10430. %154 = OpLabel
  10431. OpReturn
  10432. OpFunctionEnd
  10433. )";
  10434. const std::string new_funcs =
  10435. R"(%33 = OpFunction %uint None %34
  10436. %35 = OpFunctionParameter %uint
  10437. %36 = OpFunctionParameter %uint
  10438. %37 = OpLabel
  10439. %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
  10440. %44 = OpLoad %uint %43
  10441. %45 = OpIAdd %uint %44 %36
  10442. %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
  10443. %47 = OpLoad %uint %46
  10444. OpReturnValue %47
  10445. OpFunctionEnd
  10446. %56 = OpFunction %void None %57
  10447. %58 = OpFunctionParameter %uint
  10448. %59 = OpFunctionParameter %uint
  10449. %60 = OpFunctionParameter %uint
  10450. %61 = OpFunctionParameter %uint
  10451. %62 = OpLabel
  10452. %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
  10453. %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
  10454. %70 = OpIAdd %uint %69 %uint_10
  10455. %71 = OpArrayLength %uint %65 1
  10456. %72 = OpULessThanEqual %bool %70 %71
  10457. OpSelectionMerge %73 None
  10458. OpBranchConditional %72 %74 %73
  10459. %74 = OpLabel
  10460. %75 = OpIAdd %uint %69 %uint_0
  10461. %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
  10462. OpStore %76 %uint_10
  10463. %78 = OpIAdd %uint %69 %uint_1
  10464. %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
  10465. OpStore %79 %uint_23
  10466. %81 = OpIAdd %uint %69 %uint_2
  10467. %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
  10468. OpStore %82 %58
  10469. %85 = OpIAdd %uint %69 %uint_3
  10470. %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
  10471. OpStore %86 %uint_5318
  10472. %90 = OpLoad %v3uint %89
  10473. %91 = OpCompositeExtract %uint %90 0
  10474. %92 = OpCompositeExtract %uint %90 1
  10475. %93 = OpCompositeExtract %uint %90 2
  10476. %94 = OpIAdd %uint %69 %uint_4
  10477. %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
  10478. OpStore %95 %91
  10479. %97 = OpIAdd %uint %69 %uint_5
  10480. %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
  10481. OpStore %98 %92
  10482. %100 = OpIAdd %uint %69 %uint_6
  10483. %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
  10484. OpStore %101 %93
  10485. %103 = OpIAdd %uint %69 %uint_7
  10486. %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
  10487. OpStore %104 %59
  10488. %106 = OpIAdd %uint %69 %uint_8
  10489. %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
  10490. OpStore %107 %60
  10491. %109 = OpIAdd %uint %69 %uint_9
  10492. %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
  10493. OpStore %110 %61
  10494. OpBranch %73
  10495. %73 = OpLabel
  10496. OpReturn
  10497. OpFunctionEnd
  10498. %115 = OpFunction %uint None %116
  10499. %117 = OpFunctionParameter %uint
  10500. %118 = OpFunctionParameter %uint
  10501. %119 = OpFunctionParameter %uint
  10502. %120 = OpFunctionParameter %uint
  10503. %121 = OpLabel
  10504. %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
  10505. %123 = OpLoad %uint %122
  10506. %124 = OpIAdd %uint %123 %118
  10507. %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
  10508. %126 = OpLoad %uint %125
  10509. %127 = OpIAdd %uint %126 %119
  10510. %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
  10511. %129 = OpLoad %uint %128
  10512. %130 = OpIAdd %uint %129 %120
  10513. %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
  10514. %132 = OpLoad %uint %131
  10515. OpReturnValue %132
  10516. OpFunctionEnd
  10517. )";
  10518. // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  10519. SinglePassRunAndCheck<InstBindlessCheckPass>(
  10520. defs_before + func_before, defs_after + func_after + new_funcs, true,
  10521. true, 7u, 23u, true, true, 2u);
  10522. }
  10523. // TODO(greg-lunarg): Add tests to verify handling of these cases:
  10524. //
  10525. // Compute shader
  10526. // Geometry shader
  10527. // Tesselation control shader
  10528. // Tesselation eval shader
  10529. // OpImage
  10530. // SampledImage variable
  10531. } // namespace
  10532. } // namespace opt
  10533. } // namespace spvtools