inst_bindless_check_test.cpp 373 KB

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