| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834 |
- // Copyright (c) 2017 Valve Corporation
- // Copyright (c) 2017 LunarG Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // Bindless Check Instrumentation Tests.
- // Tests ending with V2 use version 2 record format.
- #include <string>
- #include <vector>
- #include "test/opt/assembly_builder.h"
- #include "test/opt/pass_fixture.h"
- #include "test/opt/pass_utils.h"
- namespace spvtools {
- namespace opt {
- namespace {
- using InstBindlessTest = PassTest<::testing::Test>;
- TEST_F(InstBindlessTest, Simple) {
- // Texture2D g_tColor[128];
- //
- // layout(push_constant) cbuffer PerViewConstantBuffer_t
- // {
- // uint g_nDataIdx;
- // };
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- // ps_output.vColor =
- // g_tColor[ g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
- // return ps_output;
- // }
- const std::string entry_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- )";
- const std::string entry_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- )";
- const std::string names_annots =
- R"(OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- )";
- const std::string new_annots =
- R"(OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- )";
- const std::string consts_types_vars =
- R"(%void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_16_uint_128 = OpTypeArray %16 %uint_128
- %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %24 = OpTypeSampler
- %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
- %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
- %26 = OpTypeSampledImage %16
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string new_consts_types_vars =
- R"(%uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %48 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_56 = OpConstant %uint 56
- %103 = OpConstantNull %v4float
- )";
- const std::string func_pt1 =
- R"(%MainPs = OpFunction %void None %10
- %29 = OpLabel
- %30 = OpLoad %v2float %i_vTextureCoords
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
- %34 = OpLoad %16 %33
- %35 = OpLoad %24 %g_sAniso
- %36 = OpSampledImage %26 %34 %35
- )";
- const std::string func_pt2_before =
- R"(%37 = OpImageSampleImplicitLod %v4float %36 %30
- OpStore %_entryPointOutput_vColor %37
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_pt2_after =
- R"(%40 = OpULessThan %bool %32 %uint_128
- OpSelectionMerge %41 None
- OpBranchConditional %40 %42 %43
- %42 = OpLabel
- %44 = OpLoad %16 %33
- %45 = OpSampledImage %26 %44 %35
- %46 = OpImageSampleImplicitLod %v4float %45 %30
- OpBranch %41
- %43 = OpLabel
- %102 = OpFunctionCall %void %47 %uint_56 %uint_0 %32 %uint_128
- OpBranch %41
- %41 = OpLabel
- %104 = OpPhi %v4float %46 %42 %103 %43
- OpStore %_entryPointOutput_vColor %104
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%47 = OpFunction %void None %48
- %49 = OpFunctionParameter %uint
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpLabel
- %59 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %62 = OpAtomicIAdd %uint %59 %uint_4 %uint_0 %uint_9
- %63 = OpIAdd %uint %62 %uint_9
- %64 = OpArrayLength %uint %57 1
- %65 = OpULessThanEqual %bool %63 %64
- OpSelectionMerge %66 None
- OpBranchConditional %65 %67 %66
- %67 = OpLabel
- %68 = OpIAdd %uint %62 %uint_0
- %70 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %68
- OpStore %70 %uint_9
- %72 = OpIAdd %uint %62 %uint_1
- %73 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %72
- OpStore %73 %uint_23
- %75 = OpIAdd %uint %62 %uint_2
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %49
- %78 = OpIAdd %uint %62 %uint_3
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %78
- OpStore %79 %uint_4
- %82 = OpLoad %v4float %gl_FragCoord
- %84 = OpBitcast %v4uint %82
- %85 = OpCompositeExtract %uint %84 0
- %86 = OpIAdd %uint %62 %uint_4
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %86
- OpStore %87 %85
- %88 = OpCompositeExtract %uint %84 1
- %90 = OpIAdd %uint %62 %uint_5
- %91 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %90
- OpStore %91 %88
- %93 = OpIAdd %uint %62 %uint_6
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %93
- OpStore %94 %50
- %96 = OpIAdd %uint %62 %uint_7
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %96
- OpStore %97 %51
- %99 = OpIAdd %uint %62 %uint_8
- %100 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %99
- OpStore %100 %52
- OpBranch %66
- %66 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- entry_before + names_annots + consts_types_vars + func_pt1 +
- func_pt2_before,
- entry_after + names_annots + new_annots + consts_types_vars +
- new_consts_types_vars + func_pt1 + func_pt2_after + output_func,
- true, true, 7u, 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, NoInstrumentConstIndexInbounds) {
- // Texture2D g_tColor[128];
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- //
- // ps_output.vColor = g_tColor[ 37 ].Sample(g_sAniso, i.vTextureCoords.xy);
- // return ps_output;
- // }
- const std::string before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_37 = OpConstant %int 37
- %15 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_15_uint_128 = OpTypeArray %15 %uint_128
- %_ptr_UniformConstant__arr_15_uint_128 = OpTypePointer UniformConstant %_arr_15_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_15_uint_128 UniformConstant
- %_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
- %21 = OpTypeSampler
- %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
- %g_sAniso = OpVariable %_ptr_UniformConstant_21 UniformConstant
- %23 = OpTypeSampledImage %15
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %MainPs = OpFunction %void None %8
- %26 = OpLabel
- %27 = OpLoad %v2float %i_vTextureCoords
- %28 = OpAccessChain %_ptr_UniformConstant_15 %g_tColor %int_37
- %29 = OpLoad %15 %28
- %30 = OpLoad %21 %g_sAniso
- %31 = OpSampledImage %23 %29 %30
- %32 = OpImageSampleImplicitLod %v4float %31 %27
- OpStore %_entryPointOutput_vColor %32
- OpReturn
- OpFunctionEnd
- )";
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(before, before, true, true, 7u,
- 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, InstrumentMultipleInstructions) {
- // Texture2D g_tColor[128];
- //
- // layout(push_constant) cbuffer PerViewConstantBuffer_t
- // {
- // uint g_nDataIdx;
- // uint g_nDataIdx2;
- // };
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- //
- // float t = g_tColor[g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
- // float t2 = g_tColor[g_nDataIdx2].Sample(g_sAniso, i.vTextureCoords.xy);
- // ps_output.vColor = t + t2;
- // return ps_output;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_1 = OpConstant %int 1
- %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_17_uint_128 = OpTypeArray %17 %uint_128
- %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
- %25 = OpTypeSampler
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
- %27 = OpTypeSampledImage %17
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_1 = OpConstant %int 1
- %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_17_uint_128 = OpTypeArray %17 %uint_128
- %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
- %25 = OpTypeSampler
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
- %27 = OpTypeSampledImage %17
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %56 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_58 = OpConstant %uint 58
- %111 = OpConstantNull %v4float
- %uint_64 = OpConstant %uint 64
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %10
- %30 = OpLabel
- %31 = OpLoad %v2float %i_vTextureCoords
- %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %33 = OpLoad %uint %32
- %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
- %35 = OpLoad %17 %34
- %36 = OpLoad %25 %g_sAniso
- %37 = OpSampledImage %27 %35 %36
- %38 = OpImageSampleImplicitLod %v4float %37 %31
- %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
- %40 = OpLoad %uint %39
- %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
- %42 = OpLoad %17 %41
- %43 = OpSampledImage %27 %42 %36
- %44 = OpImageSampleImplicitLod %v4float %43 %31
- %45 = OpFAdd %v4float %38 %44
- OpStore %_entryPointOutput_vColor %45
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %10
- %30 = OpLabel
- %31 = OpLoad %v2float %i_vTextureCoords
- %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %33 = OpLoad %uint %32
- %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
- %35 = OpLoad %17 %34
- %36 = OpLoad %25 %g_sAniso
- %37 = OpSampledImage %27 %35 %36
- %48 = OpULessThan %bool %33 %uint_128
- OpSelectionMerge %49 None
- OpBranchConditional %48 %50 %51
- %50 = OpLabel
- %52 = OpLoad %17 %34
- %53 = OpSampledImage %27 %52 %36
- %54 = OpImageSampleImplicitLod %v4float %53 %31
- OpBranch %49
- %51 = OpLabel
- %110 = OpFunctionCall %void %55 %uint_58 %uint_0 %33 %uint_128
- OpBranch %49
- %49 = OpLabel
- %112 = OpPhi %v4float %54 %50 %111 %51
- %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
- %40 = OpLoad %uint %39
- %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
- %42 = OpLoad %17 %41
- %43 = OpSampledImage %27 %42 %36
- %113 = OpULessThan %bool %40 %uint_128
- OpSelectionMerge %114 None
- OpBranchConditional %113 %115 %116
- %115 = OpLabel
- %117 = OpLoad %17 %41
- %118 = OpSampledImage %27 %117 %36
- %119 = OpImageSampleImplicitLod %v4float %118 %31
- OpBranch %114
- %116 = OpLabel
- %121 = OpFunctionCall %void %55 %uint_64 %uint_0 %40 %uint_128
- OpBranch %114
- %114 = OpLabel
- %122 = OpPhi %v4float %119 %115 %111 %116
- %45 = OpFAdd %v4float %112 %122
- OpStore %_entryPointOutput_vColor %45
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%55 = OpFunction %void None %56
- %57 = OpFunctionParameter %uint
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpLabel
- %67 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %70 = OpAtomicIAdd %uint %67 %uint_4 %uint_0 %uint_9
- %71 = OpIAdd %uint %70 %uint_9
- %72 = OpArrayLength %uint %65 1
- %73 = OpULessThanEqual %bool %71 %72
- OpSelectionMerge %74 None
- OpBranchConditional %73 %75 %74
- %75 = OpLabel
- %76 = OpIAdd %uint %70 %uint_0
- %78 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %76
- OpStore %78 %uint_9
- %80 = OpIAdd %uint %70 %uint_1
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %80
- OpStore %81 %uint_23
- %83 = OpIAdd %uint %70 %uint_2
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %83
- OpStore %84 %57
- %86 = OpIAdd %uint %70 %uint_3
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %86
- OpStore %87 %uint_4
- %90 = OpLoad %v4float %gl_FragCoord
- %92 = OpBitcast %v4uint %90
- %93 = OpCompositeExtract %uint %92 0
- %94 = OpIAdd %uint %70 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %93
- %96 = OpCompositeExtract %uint %92 1
- %98 = OpIAdd %uint %70 %uint_5
- %99 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %98
- OpStore %99 %96
- %101 = OpIAdd %uint %70 %uint_6
- %102 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %101
- OpStore %102 %58
- %104 = OpIAdd %uint %70 %uint_7
- %105 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %104
- OpStore %105 %59
- %107 = OpIAdd %uint %70 %uint_8
- %108 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %107
- OpStore %108 %60
- OpBranch %74
- %74 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, InstrumentOpImage) {
- // This test verifies that the pass will correctly instrument shader
- // using OpImage. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability StorageImageReadWithoutFormat
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %39 = OpTypeSampledImage %20
- %_arr_39_uint_128 = OpTypeArray %39 %uint_128
- %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability StorageImageReadWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_51 Block
- OpMemberDecorate %_struct_51 0 Offset 0
- OpMemberDecorate %_struct_51 1 Offset 4
- OpDecorate %53 DescriptorSet 7
- OpDecorate %53 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %15 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %18 = OpTypeSampledImage %15
- %_arr_18_uint_128 = OpTypeArray %18 %uint_128
- %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %44 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_51 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_51 = OpTypePointer StorageBuffer %_struct_51
- %53 = OpVariable %_ptr_StorageBuffer__struct_51 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_51 = OpConstant %uint 51
- %99 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2int %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
- %66 = OpLoad %39 %65
- %75 = OpImage %20 %66
- %71 = OpImageRead %v4float %75 %53
- OpStore %_entryPointOutput_vColor %71
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %9
- %26 = OpLabel
- %27 = OpLoad %v2int %i_vTextureCoords
- %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %29 = OpLoad %uint %28
- %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
- %31 = OpLoad %18 %30
- %32 = OpImage %15 %31
- %36 = OpULessThan %bool %29 %uint_128
- OpSelectionMerge %37 None
- OpBranchConditional %36 %38 %39
- %38 = OpLabel
- %40 = OpLoad %18 %30
- %41 = OpImage %15 %40
- %42 = OpImageRead %v4float %41 %27
- OpBranch %37
- %39 = OpLabel
- %98 = OpFunctionCall %void %43 %uint_51 %uint_0 %29 %uint_128
- OpBranch %37
- %37 = OpLabel
- %100 = OpPhi %v4float %42 %38 %99 %39
- OpStore %_entryPointOutput_vColor %100
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%43 = OpFunction %void None %44
- %45 = OpFunctionParameter %uint
- %46 = OpFunctionParameter %uint
- %47 = OpFunctionParameter %uint
- %48 = OpFunctionParameter %uint
- %49 = OpLabel
- %55 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_0
- %58 = OpAtomicIAdd %uint %55 %uint_4 %uint_0 %uint_9
- %59 = OpIAdd %uint %58 %uint_9
- %60 = OpArrayLength %uint %53 1
- %61 = OpULessThanEqual %bool %59 %60
- OpSelectionMerge %62 None
- OpBranchConditional %61 %63 %62
- %63 = OpLabel
- %64 = OpIAdd %uint %58 %uint_0
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %64
- OpStore %66 %uint_9
- %68 = OpIAdd %uint %58 %uint_1
- %69 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %68
- OpStore %69 %uint_23
- %71 = OpIAdd %uint %58 %uint_2
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %71
- OpStore %72 %45
- %74 = OpIAdd %uint %58 %uint_3
- %75 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %74
- OpStore %75 %uint_4
- %78 = OpLoad %v4float %gl_FragCoord
- %80 = OpBitcast %v4uint %78
- %81 = OpCompositeExtract %uint %80 0
- %82 = OpIAdd %uint %58 %uint_4
- %83 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %82
- OpStore %83 %81
- %84 = OpCompositeExtract %uint %80 1
- %86 = OpIAdd %uint %58 %uint_5
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %86
- OpStore %87 %84
- %89 = OpIAdd %uint %58 %uint_6
- %90 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %89
- OpStore %90 %46
- %92 = OpIAdd %uint %58 %uint_7
- %93 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %92
- OpStore %93 %47
- %95 = OpIAdd %uint %58 %uint_8
- %96 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %95
- OpStore %96 %48
- OpBranch %62
- %62 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, InstrumentSampledImage) {
- // This test verifies that the pass will correctly instrument shader
- // using sampled image. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %39 = OpTypeSampledImage %20
- %_arr_39_uint_128 = OpTypeArray %39 %uint_128
- %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_49 Block
- OpMemberDecorate %_struct_49 0 Offset 0
- OpMemberDecorate %_struct_49 1 Offset 4
- OpDecorate %51 DescriptorSet 7
- OpDecorate %51 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %15 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %18 = OpTypeSampledImage %15
- %_arr_18_uint_128 = OpTypeArray %18 %uint_128
- %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %42 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_49 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_49 = OpTypePointer StorageBuffer %_struct_49
- %51 = OpVariable %_ptr_StorageBuffer__struct_49 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_49 = OpConstant %uint 49
- %97 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2float %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
- %66 = OpLoad %39 %65
- %71 = OpImageSampleImplicitLod %v4float %66 %53
- OpStore %_entryPointOutput_vColor %71
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %9
- %26 = OpLabel
- %27 = OpLoad %v2float %i_vTextureCoords
- %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %29 = OpLoad %uint %28
- %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
- %31 = OpLoad %18 %30
- %35 = OpULessThan %bool %29 %uint_128
- OpSelectionMerge %36 None
- OpBranchConditional %35 %37 %38
- %37 = OpLabel
- %39 = OpLoad %18 %30
- %40 = OpImageSampleImplicitLod %v4float %39 %27
- OpBranch %36
- %38 = OpLabel
- %96 = OpFunctionCall %void %41 %uint_49 %uint_0 %29 %uint_128
- OpBranch %36
- %36 = OpLabel
- %98 = OpPhi %v4float %40 %37 %97 %38
- OpStore %_entryPointOutput_vColor %98
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%41 = OpFunction %void None %42
- %43 = OpFunctionParameter %uint
- %44 = OpFunctionParameter %uint
- %45 = OpFunctionParameter %uint
- %46 = OpFunctionParameter %uint
- %47 = OpLabel
- %53 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_0
- %56 = OpAtomicIAdd %uint %53 %uint_4 %uint_0 %uint_9
- %57 = OpIAdd %uint %56 %uint_9
- %58 = OpArrayLength %uint %51 1
- %59 = OpULessThanEqual %bool %57 %58
- OpSelectionMerge %60 None
- OpBranchConditional %59 %61 %60
- %61 = OpLabel
- %62 = OpIAdd %uint %56 %uint_0
- %64 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %62
- OpStore %64 %uint_9
- %66 = OpIAdd %uint %56 %uint_1
- %67 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %66
- OpStore %67 %uint_23
- %69 = OpIAdd %uint %56 %uint_2
- %70 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %69
- OpStore %70 %43
- %72 = OpIAdd %uint %56 %uint_3
- %73 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %72
- OpStore %73 %uint_4
- %76 = OpLoad %v4float %gl_FragCoord
- %78 = OpBitcast %v4uint %76
- %79 = OpCompositeExtract %uint %78 0
- %80 = OpIAdd %uint %56 %uint_4
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %80
- OpStore %81 %79
- %82 = OpCompositeExtract %uint %78 1
- %84 = OpIAdd %uint %56 %uint_5
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %84
- OpStore %85 %82
- %87 = OpIAdd %uint %56 %uint_6
- %88 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %87
- OpStore %88 %44
- %90 = OpIAdd %uint %56 %uint_7
- %91 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %90
- OpStore %91 %45
- %93 = OpIAdd %uint %56 %uint_8
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %93
- OpStore %94 %46
- OpBranch %60
- %60 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, InstrumentImageWrite) {
- // This test verifies that the pass will correctly instrument shader
- // doing bindless image write. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability StorageImageWriteWithoutFormat
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %80 = OpConstantNull %v4float
- %_arr_20_uint_128 = OpTypeArray %20 %uint_128
- %_ptr_UniformConstant__arr_20_uint_128 = OpTypePointer UniformConstant %_arr_20_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_20_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability StorageImageWriteWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_48 Block
- OpMemberDecorate %_struct_48 0 Offset 0
- OpMemberDecorate %_struct_48 1 Offset 4
- OpDecorate %50 DescriptorSet 7
- OpDecorate %50 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %19 = OpConstantNull %v4float
- %_arr_16_uint_128 = OpTypeArray %16 %uint_128
- %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %41 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_48 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_48 = OpTypePointer StorageBuffer %_struct_48
- %50 = OpVariable %_ptr_StorageBuffer__struct_48 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_51 = OpConstant %uint 51
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2int %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
- %66 = OpLoad %20 %65
- OpImageWrite %66 %53 %80
- OpStore %_entryPointOutput_vColor %80
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %9
- %27 = OpLabel
- %28 = OpLoad %v2int %i_vTextureCoords
- %29 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %30 = OpLoad %uint %29
- %31 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %30
- %32 = OpLoad %16 %31
- %35 = OpULessThan %bool %30 %uint_128
- OpSelectionMerge %36 None
- OpBranchConditional %35 %37 %38
- %37 = OpLabel
- %39 = OpLoad %16 %31
- OpImageWrite %39 %28 %19
- OpBranch %36
- %38 = OpLabel
- %95 = OpFunctionCall %void %40 %uint_51 %uint_0 %30 %uint_128
- OpBranch %36
- %36 = OpLabel
- OpStore %_entryPointOutput_vColor %19
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%40 = OpFunction %void None %41
- %42 = OpFunctionParameter %uint
- %43 = OpFunctionParameter %uint
- %44 = OpFunctionParameter %uint
- %45 = OpFunctionParameter %uint
- %46 = OpLabel
- %52 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_0
- %55 = OpAtomicIAdd %uint %52 %uint_4 %uint_0 %uint_9
- %56 = OpIAdd %uint %55 %uint_9
- %57 = OpArrayLength %uint %50 1
- %58 = OpULessThanEqual %bool %56 %57
- OpSelectionMerge %59 None
- OpBranchConditional %58 %60 %59
- %60 = OpLabel
- %61 = OpIAdd %uint %55 %uint_0
- %63 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %61
- OpStore %63 %uint_9
- %65 = OpIAdd %uint %55 %uint_1
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %65
- OpStore %66 %uint_23
- %68 = OpIAdd %uint %55 %uint_2
- %69 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %68
- OpStore %69 %42
- %71 = OpIAdd %uint %55 %uint_3
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %71
- OpStore %72 %uint_4
- %75 = OpLoad %v4float %gl_FragCoord
- %77 = OpBitcast %v4uint %75
- %78 = OpCompositeExtract %uint %77 0
- %79 = OpIAdd %uint %55 %uint_4
- %80 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %79
- OpStore %80 %78
- %81 = OpCompositeExtract %uint %77 1
- %83 = OpIAdd %uint %55 %uint_5
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %83
- OpStore %84 %81
- %86 = OpIAdd %uint %55 %uint_6
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %86
- OpStore %87 %43
- %89 = OpIAdd %uint %55 %uint_7
- %90 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %89
- OpStore %90 %44
- %92 = OpIAdd %uint %55 %uint_8
- %93 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %92
- OpStore %93 %45
- OpBranch %59
- %59 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, InstrumentVertexSimple) {
- // This test verifies that the pass will correctly instrument shader
- // doing bindless image write. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability Sampled1D
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %_ %coords2D
- OpSource GLSL 450
- OpName %main "main"
- OpName %lod "lod"
- OpName %coords1D "coords1D"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %texSampler1D "texSampler1D"
- OpName %foo "foo"
- OpMemberName %foo 0 "g_idx"
- OpName %__0 ""
- OpName %coords2D "coords2D"
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpDecorate %texSampler1D DescriptorSet 0
- OpDecorate %texSampler1D Binding 3
- OpMemberDecorate %foo 0 Offset 0
- OpDecorate %foo Block
- OpDecorate %__0 DescriptorSet 0
- OpDecorate %__0 Binding 5
- OpDecorate %coords2D Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Function_float = OpTypePointer Function %float
- %float_3 = OpConstant %float 3
- %float_1_78900003 = OpConstant %float 1.78900003
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %21 = OpTypeImage %float 1D 0 0 0 1 Unknown
- %22 = OpTypeSampledImage %21
- %uint_128 = OpConstant %uint 128
- %_arr_22_uint_128 = OpTypeArray %22 %uint_128
- %_ptr_UniformConstant__arr_22_uint_128 = OpTypePointer UniformConstant %_arr_22_uint_128
- %texSampler1D = OpVariable %_ptr_UniformConstant__arr_22_uint_128 UniformConstant
- %foo = OpTypeStruct %int
- %_ptr_Uniform_foo = OpTypePointer Uniform %foo
- %__0 = OpVariable %_ptr_Uniform_foo Uniform
- %_ptr_Uniform_int = OpTypePointer Uniform %int
- %_ptr_UniformConstant_22 = OpTypePointer UniformConstant %22
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %v2float = OpTypeVector %float 2
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %coords2D = OpVariable %_ptr_Input_v2float Input
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability Sampled1D
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %_ %coords2D %gl_VertexIndex %gl_InstanceIndex
- OpSource GLSL 450
- OpName %main "main"
- OpName %lod "lod"
- OpName %coords1D "coords1D"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %texSampler1D "texSampler1D"
- OpName %foo "foo"
- OpMemberName %foo 0 "g_idx"
- OpName %__0 ""
- OpName %coords2D "coords2D"
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpDecorate %texSampler1D DescriptorSet 0
- OpDecorate %texSampler1D Binding 3
- OpMemberDecorate %foo 0 Offset 0
- OpDecorate %foo Block
- OpDecorate %__0 DescriptorSet 0
- OpDecorate %__0 Binding 5
- OpDecorate %coords2D Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_61 Block
- OpMemberDecorate %_struct_61 0 Offset 0
- OpMemberDecorate %_struct_61 1 Offset 4
- OpDecorate %63 DescriptorSet 7
- OpDecorate %63 Binding 0
- OpDecorate %gl_VertexIndex BuiltIn VertexIndex
- OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
- %void = OpTypeVoid
- %12 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Function_float = OpTypePointer Function %float
- %float_3 = OpConstant %float 3
- %float_1_78900003 = OpConstant %float 1.78900003
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %24 = OpTypeImage %float 1D 0 0 0 1 Unknown
- %25 = OpTypeSampledImage %24
- %uint_128 = OpConstant %uint 128
- %_arr_25_uint_128 = OpTypeArray %25 %uint_128
- %_ptr_UniformConstant__arr_25_uint_128 = OpTypePointer UniformConstant %_arr_25_uint_128
- %texSampler1D = OpVariable %_ptr_UniformConstant__arr_25_uint_128 UniformConstant
- %foo = OpTypeStruct %int
- %_ptr_Uniform_foo = OpTypePointer Uniform %foo
- %__0 = OpVariable %_ptr_Uniform_foo Uniform
- %_ptr_Uniform_int = OpTypePointer Uniform %int
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %v2float = OpTypeVector %float 2
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %coords2D = OpVariable %_ptr_Input_v2float Input
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %54 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_61 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_61 = OpTypePointer StorageBuffer %_struct_61
- %63 = OpVariable %_ptr_StorageBuffer__struct_61 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_uint = OpTypePointer Input %uint
- %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
- %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_74 = OpConstant %uint 74
- %106 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %lod = OpVariable %_ptr_Function_float Function
- %coords1D = OpVariable %_ptr_Function_float Function
- OpStore %lod %float_3
- OpStore %coords1D %float_1_78900003
- %31 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
- %32 = OpLoad %int %31
- %34 = OpAccessChain %_ptr_UniformConstant_22 %texSampler1D %32
- %35 = OpLoad %22 %34
- %36 = OpLoad %float %coords1D
- %37 = OpLoad %float %lod
- %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
- %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %40 %38
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %12
- %35 = OpLabel
- %lod = OpVariable %_ptr_Function_float Function
- %coords1D = OpVariable %_ptr_Function_float Function
- OpStore %lod %float_3
- OpStore %coords1D %float_1_78900003
- %36 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
- %37 = OpLoad %int %36
- %38 = OpAccessChain %_ptr_UniformConstant_25 %texSampler1D %37
- %39 = OpLoad %25 %38
- %40 = OpLoad %float %coords1D
- %41 = OpLoad %float %lod
- %46 = OpULessThan %bool %37 %uint_128
- OpSelectionMerge %47 None
- OpBranchConditional %46 %48 %49
- %48 = OpLabel
- %50 = OpLoad %25 %38
- %51 = OpImageSampleExplicitLod %v4float %50 %40 Lod %41
- OpBranch %47
- %49 = OpLabel
- %52 = OpBitcast %uint %37
- %105 = OpFunctionCall %void %53 %uint_74 %uint_0 %52 %uint_128
- OpBranch %47
- %47 = OpLabel
- %107 = OpPhi %v4float %51 %48 %106 %49
- %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %43 %107
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%53 = OpFunction %void None %54
- %55 = OpFunctionParameter %uint
- %56 = OpFunctionParameter %uint
- %57 = OpFunctionParameter %uint
- %58 = OpFunctionParameter %uint
- %59 = OpLabel
- %65 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_0
- %68 = OpAtomicIAdd %uint %65 %uint_4 %uint_0 %uint_9
- %69 = OpIAdd %uint %68 %uint_9
- %70 = OpArrayLength %uint %63 1
- %71 = OpULessThanEqual %bool %69 %70
- OpSelectionMerge %72 None
- OpBranchConditional %71 %73 %72
- %73 = OpLabel
- %74 = OpIAdd %uint %68 %uint_0
- %75 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %74
- OpStore %75 %uint_9
- %77 = OpIAdd %uint %68 %uint_1
- %78 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %77
- OpStore %78 %uint_23
- %80 = OpIAdd %uint %68 %uint_2
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %80
- OpStore %81 %55
- %83 = OpIAdd %uint %68 %uint_3
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %83
- OpStore %84 %uint_0
- %87 = OpLoad %uint %gl_VertexIndex
- %88 = OpIAdd %uint %68 %uint_4
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %88
- OpStore %89 %87
- %91 = OpLoad %uint %gl_InstanceIndex
- %93 = OpIAdd %uint %68 %uint_5
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %93
- OpStore %94 %91
- %96 = OpIAdd %uint %68 %uint_6
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %96
- OpStore %97 %56
- %99 = OpIAdd %uint %68 %uint_7
- %100 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %99
- OpStore %100 %57
- %102 = OpIAdd %uint %68 %uint_8
- %103 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %102
- OpStore %103 %58
- OpBranch %72
- %72 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, MultipleDebugFunctions) {
- // Same source as Simple, but compiled -g and not optimized, especially not
- // inlined. The OpSource has had the source extracted for the sake of brevity.
- const std::string defs_before =
- R"(OpCapability Shader
- %2 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- %1 = OpString "foo5.frag"
- OpSource HLSL 500 %1
- OpName %MainPs "MainPs"
- OpName %PS_INPUT "PS_INPUT"
- OpMemberName %PS_INPUT 0 "vTextureCoords"
- OpName %PS_OUTPUT "PS_OUTPUT"
- OpMemberName %PS_OUTPUT 0 "vColor"
- OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
- OpName %i "i"
- OpName %ps_output "ps_output"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_0 "i"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpName %param "param"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 1
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %4 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %PS_INPUT = OpTypeStruct %v2float
- %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
- %v4float = OpTypeVector %float 4
- %PS_OUTPUT = OpTypeStruct %v4float
- %13 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
- %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %21 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_21_uint_128 = OpTypeArray %21 %uint_128
- %_ptr_UniformConstant__arr_21_uint_128 = OpTypePointer UniformConstant %_arr_21_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_21_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
- %36 = OpTypeSampler
- %_ptr_UniformConstant_36 = OpTypePointer UniformConstant %36
- %g_sAniso = OpVariable %_ptr_UniformConstant_36 UniformConstant
- %40 = OpTypeSampledImage %21
- %_ptr_Function_v2float = OpTypePointer Function %v2float
- %_ptr_Function_v4float = OpTypePointer Function %v4float
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- %5 = OpString "foo5.frag"
- OpSource HLSL 500 %5
- OpName %MainPs "MainPs"
- OpName %PS_INPUT "PS_INPUT"
- OpMemberName %PS_INPUT 0 "vTextureCoords"
- OpName %PS_OUTPUT "PS_OUTPUT"
- OpMemberName %PS_OUTPUT 0 "vColor"
- OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
- OpName %i "i"
- OpName %ps_output "ps_output"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_0 "i"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpName %param "param"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 1
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_77 Block
- OpMemberDecorate %_struct_77 0 Offset 0
- OpMemberDecorate %_struct_77 1 Offset 4
- OpDecorate %79 DescriptorSet 7
- OpDecorate %79 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %18 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %PS_INPUT = OpTypeStruct %v2float
- %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
- %v4float = OpTypeVector %float 4
- %PS_OUTPUT = OpTypeStruct %v4float
- %23 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
- %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %27 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_27_uint_128 = OpTypeArray %27 %uint_128
- %_ptr_UniformConstant__arr_27_uint_128 = OpTypePointer UniformConstant %_arr_27_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_27_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_27 = OpTypePointer UniformConstant %27
- %35 = OpTypeSampler
- %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
- %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
- %37 = OpTypeSampledImage %27
- %_ptr_Function_v2float = OpTypePointer Function %v2float
- %_ptr_Function_v4float = OpTypePointer Function %v4float
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %70 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_77 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_77 = OpTypePointer StorageBuffer %_struct_77
- %79 = OpVariable %_ptr_StorageBuffer__struct_77 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_93 = OpConstant %uint 93
- %125 = OpConstantNull %v4float
- )";
- const std::string func1_before =
- R"(%MainPs = OpFunction %void None %4
- %6 = OpLabel
- %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
- %param = OpVariable %_ptr_Function_PS_INPUT Function
- OpLine %1 21 0
- %54 = OpLoad %v2float %i_vTextureCoords
- %55 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
- OpStore %55 %54
- %59 = OpLoad %PS_INPUT %i_0
- OpStore %param %59
- %60 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
- %61 = OpCompositeExtract %v4float %60 0
- OpStore %_entryPointOutput_vColor %61
- OpReturn
- OpFunctionEnd
- )";
- const std::string func1_after =
- R"(%MainPs = OpFunction %void None %18
- %42 = OpLabel
- %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
- %param = OpVariable %_ptr_Function_PS_INPUT Function
- OpLine %5 21 0
- %43 = OpLoad %v2float %i_vTextureCoords
- %44 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
- OpStore %44 %43
- %45 = OpLoad %PS_INPUT %i_0
- OpStore %param %45
- %46 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
- %47 = OpCompositeExtract %v4float %46 0
- OpStore %_entryPointOutput_vColor %47
- OpReturn
- OpFunctionEnd
- )";
- const std::string func2_before =
- R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %13
- %i = OpFunctionParameter %_ptr_Function_PS_INPUT
- %16 = OpLabel
- %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
- OpLine %1 24 0
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %34 = OpAccessChain %_ptr_UniformConstant_21 %g_tColor %32
- %35 = OpLoad %21 %34
- %39 = OpLoad %36 %g_sAniso
- %41 = OpSampledImage %40 %35 %39
- %43 = OpAccessChain %_ptr_Function_v2float %i %int_0
- %44 = OpLoad %v2float %43
- %45 = OpImageSampleImplicitLod %v4float %41 %44
- %47 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
- OpStore %47 %45
- OpLine %1 25 0
- %48 = OpLoad %PS_OUTPUT %ps_output
- OpReturnValue %48
- OpFunctionEnd
- )";
- const std::string func2_after =
- R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %23
- %i = OpFunctionParameter %_ptr_Function_PS_INPUT
- %48 = OpLabel
- %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
- OpLine %5 24 0
- %49 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %50 = OpLoad %uint %49
- %51 = OpAccessChain %_ptr_UniformConstant_27 %g_tColor %50
- %52 = OpLoad %27 %51
- %53 = OpLoad %35 %g_sAniso
- %54 = OpSampledImage %37 %52 %53
- %55 = OpAccessChain %_ptr_Function_v2float %i %int_0
- %56 = OpLoad %v2float %55
- %62 = OpULessThan %bool %50 %uint_128
- OpSelectionMerge %63 None
- OpBranchConditional %62 %64 %65
- %64 = OpLabel
- %66 = OpLoad %27 %51
- %67 = OpSampledImage %37 %66 %53
- %68 = OpImageSampleImplicitLod %v4float %67 %56
- OpBranch %63
- %65 = OpLabel
- %124 = OpFunctionCall %void %69 %uint_93 %uint_0 %50 %uint_128
- OpBranch %63
- %63 = OpLabel
- %126 = OpPhi %v4float %68 %64 %125 %65
- %58 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
- OpStore %58 %126
- OpLine %5 25 0
- %59 = OpLoad %PS_OUTPUT %ps_output
- OpReturnValue %59
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%69 = OpFunction %void None %70
- %71 = OpFunctionParameter %uint
- %72 = OpFunctionParameter %uint
- %73 = OpFunctionParameter %uint
- %74 = OpFunctionParameter %uint
- %75 = OpLabel
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_0
- %84 = OpAtomicIAdd %uint %81 %uint_4 %uint_0 %uint_9
- %85 = OpIAdd %uint %84 %uint_9
- %86 = OpArrayLength %uint %79 1
- %87 = OpULessThanEqual %bool %85 %86
- OpSelectionMerge %88 None
- OpBranchConditional %87 %89 %88
- %89 = OpLabel
- %90 = OpIAdd %uint %84 %uint_0
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %90
- OpStore %92 %uint_9
- %94 = OpIAdd %uint %84 %uint_1
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %94
- OpStore %95 %uint_23
- %97 = OpIAdd %uint %84 %uint_2
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %97
- OpStore %98 %71
- %100 = OpIAdd %uint %84 %uint_3
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %100
- OpStore %101 %uint_4
- %104 = OpLoad %v4float %gl_FragCoord
- %106 = OpBitcast %v4uint %104
- %107 = OpCompositeExtract %uint %106 0
- %108 = OpIAdd %uint %84 %uint_4
- %109 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %108
- OpStore %109 %107
- %110 = OpCompositeExtract %uint %106 1
- %112 = OpIAdd %uint %84 %uint_5
- %113 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %112
- OpStore %113 %110
- %115 = OpIAdd %uint %84 %uint_6
- %116 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %115
- OpStore %116 %72
- %118 = OpIAdd %uint %84 %uint_7
- %119 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %118
- OpStore %119 %73
- %121 = OpIAdd %uint %84 %uint_8
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %121
- OpStore %122 %74
- OpBranch %88
- %88 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func1_before + func2_before,
- defs_after + func1_after + func2_after + output_func, true, true, 7u, 23u,
- false, false, 1u);
- }
- TEST_F(InstBindlessTest, RuntimeArray) {
- // This test verifies that the pass will correctly instrument shader
- // with runtime descriptor array. This test was created by editing the
- // SPIR-V from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 1
- OpDecorate %g_tColor Binding 2
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 1
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_rarr_20 = OpTypeRuntimeArray %20
- %_ptr_UniformConstant__arr_20 = OpTypePointer UniformConstant %_rarr_20
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_20 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
- %35 = OpTypeSampler
- %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
- %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
- %39 = OpTypeSampledImage %20
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 1
- OpDecorate %g_tColor Binding 2
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 1
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_46 Block
- OpMemberDecorate %_struct_46 0 Offset 0
- OpDecorate %48 DescriptorSet 7
- OpDecorate %48 Binding 1
- OpDecorate %_struct_71 Block
- OpMemberDecorate %_struct_71 0 Offset 0
- OpMemberDecorate %_struct_71 1 Offset 4
- OpDecorate %73 DescriptorSet 7
- OpDecorate %73 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_runtimearr_16 = OpTypeRuntimeArray %16
- %_ptr_UniformConstant__runtimearr_16 = OpTypePointer UniformConstant %_runtimearr_16
- %g_tColor = OpVariable %_ptr_UniformConstant__runtimearr_16 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %24 = OpTypeSampler
- %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
- %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
- %26 = OpTypeSampledImage %16
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %uint_2 = OpConstant %uint 2
- %41 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_46 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_46 = OpTypePointer StorageBuffer %_struct_46
- %48 = OpVariable %_ptr_StorageBuffer__struct_46 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %65 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_71 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_71 = OpTypePointer StorageBuffer %_struct_71
- %73 = OpVariable %_ptr_StorageBuffer__struct_71 StorageBuffer
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_59 = OpConstant %uint 59
- %116 = OpConstantNull %v4float
- %119 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2float %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
- %66 = OpLoad %20 %65
- %67 = OpLoad %35 %g_sAniso
- %68 = OpSampledImage %39 %66 %67
- %71 = OpImageSampleImplicitLod %v4float %68 %53
- OpStore %_entryPointOutput_vColor %71
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %10
- %29 = OpLabel
- %30 = OpLoad %v2float %i_vTextureCoords
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
- %34 = OpLoad %16 %33
- %35 = OpLoad %24 %g_sAniso
- %36 = OpSampledImage %26 %34 %35
- %55 = OpFunctionCall %uint %40 %uint_2 %uint_2
- %57 = OpULessThan %bool %32 %55
- OpSelectionMerge %58 None
- OpBranchConditional %57 %59 %60
- %59 = OpLabel
- %61 = OpLoad %16 %33
- %62 = OpSampledImage %26 %61 %35
- %136 = OpFunctionCall %uint %118 %uint_0 %uint_1 %uint_2 %32
- %137 = OpINotEqual %bool %136 %uint_0
- OpSelectionMerge %138 None
- OpBranchConditional %137 %139 %140
- %139 = OpLabel
- %141 = OpLoad %16 %33
- %142 = OpSampledImage %26 %141 %35
- %143 = OpImageSampleImplicitLod %v4float %142 %30
- OpBranch %138
- %140 = OpLabel
- %144 = OpFunctionCall %void %64 %uint_59 %uint_1 %32 %uint_0
- OpBranch %138
- %138 = OpLabel
- %145 = OpPhi %v4float %143 %139 %116 %140
- OpBranch %58
- %60 = OpLabel
- %115 = OpFunctionCall %void %64 %uint_59 %uint_0 %32 %55
- OpBranch %58
- %58 = OpLabel
- %117 = OpPhi %v4float %145 %138 %116 %60
- OpStore %_entryPointOutput_vColor %117
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%40 = OpFunction %uint None %41
- %42 = OpFunctionParameter %uint
- %43 = OpFunctionParameter %uint
- %44 = OpLabel
- %50 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %42
- %51 = OpLoad %uint %50
- %52 = OpIAdd %uint %51 %43
- %53 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %52
- %54 = OpLoad %uint %53
- OpReturnValue %54
- OpFunctionEnd
- %64 = OpFunction %void None %65
- %66 = OpFunctionParameter %uint
- %67 = OpFunctionParameter %uint
- %68 = OpFunctionParameter %uint
- %69 = OpFunctionParameter %uint
- %70 = OpLabel
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_0
- %77 = OpAtomicIAdd %uint %74 %uint_4 %uint_0 %uint_9
- %78 = OpIAdd %uint %77 %uint_9
- %79 = OpArrayLength %uint %73 1
- %80 = OpULessThanEqual %bool %78 %79
- OpSelectionMerge %81 None
- OpBranchConditional %80 %82 %81
- %82 = OpLabel
- %83 = OpIAdd %uint %77 %uint_0
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %83
- OpStore %84 %uint_9
- %86 = OpIAdd %uint %77 %uint_1
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %86
- OpStore %87 %uint_23
- %88 = OpIAdd %uint %77 %uint_2
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %88
- OpStore %89 %66
- %91 = OpIAdd %uint %77 %uint_3
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %91
- OpStore %92 %uint_4
- %95 = OpLoad %v4float %gl_FragCoord
- %97 = OpBitcast %v4uint %95
- %98 = OpCompositeExtract %uint %97 0
- %99 = OpIAdd %uint %77 %uint_4
- %100 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %99
- OpStore %100 %98
- %101 = OpCompositeExtract %uint %97 1
- %103 = OpIAdd %uint %77 %uint_5
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %103
- OpStore %104 %101
- %106 = OpIAdd %uint %77 %uint_6
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %106
- OpStore %107 %67
- %109 = OpIAdd %uint %77 %uint_7
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %109
- OpStore %110 %68
- %112 = OpIAdd %uint %77 %uint_8
- %113 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %112
- OpStore %113 %69
- OpBranch %81
- %81 = OpLabel
- OpReturn
- OpFunctionEnd
- %118 = OpFunction %uint None %119
- %120 = OpFunctionParameter %uint
- %121 = OpFunctionParameter %uint
- %122 = OpFunctionParameter %uint
- %123 = OpFunctionParameter %uint
- %124 = OpLabel
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %120
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %121
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %122
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %130
- %132 = OpLoad %uint %131
- %133 = OpIAdd %uint %132 %123
- %134 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %133
- %135 = OpLoad %uint %134
- OpReturnValue %135
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, NoInstrumentNonBindless) {
- // This test verifies that the pass will correctly not instrument vanilla
- // texture sample.
- //
- // Texture2D g_tColor;
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- // ps_output.vColor =
- // g_tColor.Sample(g_sAniso, i.vTextureCoords.xy);
- // return ps_output;
- // }
- const std::string whole_file =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
- %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %16 = OpTypeSampledImage %12
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %MainPs = OpFunction %void None %8
- %19 = OpLabel
- %20 = OpLoad %v2float %i_vTextureCoords
- %21 = OpLoad %12 %g_tColor
- %22 = OpLoad %14 %g_sAniso
- %23 = OpSampledImage %16 %21 %22
- %24 = OpImageSampleImplicitLod %v4float %23 %20
- OpStore %_entryPointOutput_vColor %24
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(whole_file, whole_file, true,
- true, 7u, 23u, false, false, 1u);
- }
- TEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptor) {
- // This test verifies that the pass will correctly instrument vanilla
- // texture sample on a scalar descriptor with an initialization check if the
- // input_init_enable argument is set to true. This can happen when the
- // descriptor indexing extension is enabled in the API but the SPIR-V
- // does not have the extension enabled because it does not contain a
- // runtime array. This is the same shader as NoInstrumentNonBindless.
- const std::string defs_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
- %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %16 = OpTypeSampledImage %12
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_35 Block
- OpMemberDecorate %_struct_35 0 Offset 0
- OpDecorate %37 DescriptorSet 7
- OpDecorate %37 Binding 1
- OpDecorate %_struct_67 Block
- OpMemberDecorate %_struct_67 0 Offset 0
- OpMemberDecorate %_struct_67 1 Offset 4
- OpDecorate %69 DescriptorSet 7
- OpDecorate %69 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
- %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %16 = OpTypeSampledImage %12
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %28 = OpTypeFunction %uint %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_35 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_35 = OpTypePointer StorageBuffer %_struct_35
- %37 = OpVariable %_ptr_StorageBuffer__struct_35 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %uint_1 = OpConstant %uint 1
- %61 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_67 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_67 = OpTypePointer StorageBuffer %_struct_67
- %69 = OpVariable %_ptr_StorageBuffer__struct_67 StorageBuffer
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_39 = OpConstant %uint 39
- %113 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %8
- %19 = OpLabel
- %20 = OpLoad %v2float %i_vTextureCoords
- %21 = OpLoad %12 %g_tColor
- %22 = OpLoad %14 %g_sAniso
- %23 = OpSampledImage %16 %21 %22
- %24 = OpImageSampleImplicitLod %v4float %23 %20
- OpStore %_entryPointOutput_vColor %24
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %8
- %19 = OpLabel
- %20 = OpLoad %v2float %i_vTextureCoords
- %21 = OpLoad %12 %g_tColor
- %22 = OpLoad %14 %g_sAniso
- %23 = OpSampledImage %16 %21 %22
- %50 = OpFunctionCall %uint %27 %uint_0 %uint_0 %uint_0 %uint_0
- %52 = OpINotEqual %bool %50 %uint_0
- OpSelectionMerge %54 None
- OpBranchConditional %52 %55 %56
- %55 = OpLabel
- %57 = OpLoad %12 %g_tColor
- %58 = OpSampledImage %16 %57 %22
- %59 = OpImageSampleImplicitLod %v4float %58 %20
- OpBranch %54
- %56 = OpLabel
- %112 = OpFunctionCall %void %60 %uint_39 %uint_1 %uint_0 %uint_0
- OpBranch %54
- %54 = OpLabel
- %114 = OpPhi %v4float %59 %55 %113 %56
- OpStore %_entryPointOutput_vColor %114
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%27 = OpFunction %uint None %28
- %29 = OpFunctionParameter %uint
- %30 = OpFunctionParameter %uint
- %31 = OpFunctionParameter %uint
- %32 = OpFunctionParameter %uint
- %33 = OpLabel
- %39 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %29
- %40 = OpLoad %uint %39
- %41 = OpIAdd %uint %40 %30
- %42 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %41
- %43 = OpLoad %uint %42
- %44 = OpIAdd %uint %43 %31
- %45 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %44
- %46 = OpLoad %uint %45
- %47 = OpIAdd %uint %46 %32
- %48 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %47
- %49 = OpLoad %uint %48
- OpReturnValue %49
- OpFunctionEnd
- %60 = OpFunction %void None %61
- %62 = OpFunctionParameter %uint
- %63 = OpFunctionParameter %uint
- %64 = OpFunctionParameter %uint
- %65 = OpFunctionParameter %uint
- %66 = OpLabel
- %70 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_0
- %73 = OpAtomicIAdd %uint %70 %uint_4 %uint_0 %uint_9
- %74 = OpIAdd %uint %73 %uint_9
- %75 = OpArrayLength %uint %69 1
- %76 = OpULessThanEqual %bool %74 %75
- OpSelectionMerge %77 None
- OpBranchConditional %76 %78 %77
- %78 = OpLabel
- %79 = OpIAdd %uint %73 %uint_0
- %80 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %79
- OpStore %80 %uint_9
- %82 = OpIAdd %uint %73 %uint_1
- %83 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %82
- OpStore %83 %uint_23
- %85 = OpIAdd %uint %73 %uint_2
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %85
- OpStore %86 %62
- %88 = OpIAdd %uint %73 %uint_3
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %88
- OpStore %89 %uint_4
- %92 = OpLoad %v4float %gl_FragCoord
- %94 = OpBitcast %v4uint %92
- %95 = OpCompositeExtract %uint %94 0
- %96 = OpIAdd %uint %73 %uint_4
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %96
- OpStore %97 %95
- %98 = OpCompositeExtract %uint %94 1
- %100 = OpIAdd %uint %73 %uint_5
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %100
- OpStore %101 %98
- %103 = OpIAdd %uint %73 %uint_6
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %103
- OpStore %104 %63
- %106 = OpIAdd %uint %73 %uint_7
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %106
- OpStore %107 %64
- %109 = OpIAdd %uint %73 %uint_8
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %109
- OpStore %110 %65
- OpBranch %77
- %77 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, SPV14AddToEntryPoint) {
- const std::string text = R"(
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpDecorate [[v1]] DescriptorSet 7
- ; CHECK: OpDecorate [[v2]] DescriptorSet 7
- ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
- ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
- OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
- OpExecutionMode %foo OriginUpperLeft
- OpDecorate %image_var DescriptorSet 0
- OpDecorate %image_var Binding 0
- OpDecorate %sampler_var DescriptorSet 0
- OpDecorate %sampler_var Binding 1
- OpDecorate %gid DescriptorSet 0
- OpDecorate %gid Binding 2
- OpDecorate %struct Block
- OpMemberDecorate %struct 0 Offset 0
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int_0 = OpConstant %int 0
- %v3int = OpTypeVector %int 3
- %float = OpTypeFloat 32
- %v3float = OpTypeVector %float 3
- %v4float = OpTypeVector %float 4
- %struct = OpTypeStruct %v3int
- %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
- %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
- %gid = OpVariable %ptr_ssbo_struct StorageBuffer
- %image = OpTypeImage %float 3D 0 0 0 1 Unknown
- %ptr_uc_image = OpTypePointer UniformConstant %image
- %sampler = OpTypeSampler
- %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
- %image_var = OpVariable %ptr_uc_image UniformConstant
- %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
- %sampled = OpTypeSampledImage %image
- %void_fn = OpTypeFunction %void
- %foo = OpFunction %void None %void_fn
- %entry = OpLabel
- %ld_image = OpLoad %image %image_var
- %ld_sampler = OpLoad %sampler %sampler_var
- %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
- %ld_gid = OpLoad %v3int %gep
- %convert = OpConvertUToF %v3float %ld_gid
- %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
- %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
- OpReturn
- OpFunctionEnd
- )";
- SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true);
- }
- TEST_F(InstBindlessTest, SPV14AddToEntryPoints) {
- const std::string text = R"(
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpDecorate [[v1]] DescriptorSet 7
- ; CHECK: OpDecorate [[v2]] DescriptorSet 7
- ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
- ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
- OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
- OpEntryPoint Fragment %foo "bar" %gid %image_var %sampler_var
- OpExecutionMode %foo OriginUpperLeft
- OpDecorate %image_var DescriptorSet 0
- OpDecorate %image_var Binding 0
- OpDecorate %sampler_var DescriptorSet 0
- OpDecorate %sampler_var Binding 1
- OpDecorate %gid DescriptorSet 0
- OpDecorate %gid Binding 2
- OpDecorate %struct Block
- OpMemberDecorate %struct 0 Offset 0
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int_0 = OpConstant %int 0
- %v3int = OpTypeVector %int 3
- %float = OpTypeFloat 32
- %v3float = OpTypeVector %float 3
- %v4float = OpTypeVector %float 4
- %struct = OpTypeStruct %v3int
- %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
- %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
- %gid = OpVariable %ptr_ssbo_struct StorageBuffer
- %image = OpTypeImage %float 3D 0 0 0 1 Unknown
- %ptr_uc_image = OpTypePointer UniformConstant %image
- %sampler = OpTypeSampler
- %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
- %image_var = OpVariable %ptr_uc_image UniformConstant
- %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
- %sampled = OpTypeSampledImage %image
- %void_fn = OpTypeFunction %void
- %foo = OpFunction %void None %void_fn
- %entry = OpLabel
- %ld_image = OpLoad %image %image_var
- %ld_sampler = OpLoad %sampler %sampler_var
- %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
- %ld_gid = OpLoad %v3int %gep
- %convert = OpConvertUToF %v3float %ld_gid
- %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
- %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
- OpReturn
- OpFunctionEnd
- )";
- SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedUBOArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) uniform uname { float a; } uniformBuffer[];
- //
- // void main()
- // {
- // b = uniformBuffer[nu_ii].a;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_runtimearr_uname = OpTypeRuntimeArray %uname
- %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
- %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %102 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %130 NonUniform
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_runtimearr_uname = OpTypeRuntimeArray %uname
- %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
- %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_3 = OpConstant %uint 3
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %49 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_45 = OpConstant %uint 45
- %101 = OpConstantNull %float
- %105 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %19 = OpLabel
- %7 = OpLoad %int %nu_ii
- %20 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %103 = OpBitcast %uint %7
- %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
- %123 = OpINotEqual %bool %122 %uint_0
- OpSelectionMerge %124 None
- OpBranchConditional %123 %125 %126
- %125 = OpLabel
- %127 = OpLoad %float %20
- OpBranch %124
- %126 = OpLabel
- %128 = OpBitcast %uint %7
- %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
- OpBranch %124
- %124 = OpLabel
- %130 = OpPhi %float %127 %125 %101 %126
- OpBranch %43
- %45 = OpLabel
- %47 = OpBitcast %uint %7
- %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
- OpBranch %43
- %43 = OpLabel
- %102 = OpPhi %float %130 %124 %101 %45
- OpStore %b %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %48 = OpFunction %void None %49
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpFunctionParameter %uint
- %54 = OpLabel
- %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_9
- %62 = OpIAdd %uint %61 %uint_9
- %63 = OpArrayLength %uint %57 1
- %64 = OpULessThanEqual %bool %62 %63
- OpSelectionMerge %65 None
- OpBranchConditional %64 %66 %65
- %66 = OpLabel
- %67 = OpIAdd %uint %61 %uint_0
- %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
- OpStore %68 %uint_9
- %70 = OpIAdd %uint %61 %uint_1
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
- OpStore %71 %uint_23
- %73 = OpIAdd %uint %61 %uint_2
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
- OpStore %74 %50
- %75 = OpIAdd %uint %61 %uint_3
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %uint_4
- %80 = OpLoad %v4float %gl_FragCoord
- %82 = OpBitcast %v4uint %80
- %83 = OpCompositeExtract %uint %82 0
- %84 = OpIAdd %uint %61 %uint_4
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
- OpStore %85 %83
- %86 = OpCompositeExtract %uint %82 1
- %88 = OpIAdd %uint %61 %uint_5
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
- OpStore %89 %86
- %91 = OpIAdd %uint %61 %uint_6
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
- OpStore %92 %51
- %94 = OpIAdd %uint %61 %uint_7
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
- OpStore %95 %52
- %97 = OpIAdd %uint %61 %uint_8
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
- OpStore %98 %53
- OpBranch %65
- %65 = OpLabel
- OpReturn
- OpFunctionEnd
- %104 = OpFunction %uint None %105
- %106 = OpFunctionParameter %uint
- %107 = OpFunctionParameter %uint
- %108 = OpFunctionParameter %uint
- %109 = OpFunctionParameter %uint
- %110 = OpLabel
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %107
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %108
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- %119 = OpIAdd %uint %118 %109
- %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
- %121 = OpLoad %uint %120
- OpReturnValue %121
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayDeprecated) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) buffer bname { float b; } storageBuffer[];
- //
- // void main()
- // {
- // b = storageBuffer[nu_ii].b;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname BufferBlock
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname BufferBlock
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %102 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %130 NonUniform
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_3 = OpConstant %uint 3
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %49 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_45 = OpConstant %uint 45
- %101 = OpConstantNull %float
- %105 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_Uniform_float %storageBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %19 = OpLabel
- %7 = OpLoad %int %nu_ii
- %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %103 = OpBitcast %uint %7
- %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
- %123 = OpINotEqual %bool %122 %uint_0
- OpSelectionMerge %124 None
- OpBranchConditional %123 %125 %126
- %125 = OpLabel
- %127 = OpLoad %float %20
- OpBranch %124
- %126 = OpLabel
- %128 = OpBitcast %uint %7
- %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
- OpBranch %124
- %124 = OpLabel
- %130 = OpPhi %float %127 %125 %101 %126
- OpBranch %43
- %45 = OpLabel
- %47 = OpBitcast %uint %7
- %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
- OpBranch %43
- %43 = OpLabel
- %102 = OpPhi %float %130 %124 %101 %45
- OpStore %b %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %48 = OpFunction %void None %49
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpFunctionParameter %uint
- %54 = OpLabel
- %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_9
- %62 = OpIAdd %uint %61 %uint_9
- %63 = OpArrayLength %uint %57 1
- %64 = OpULessThanEqual %bool %62 %63
- OpSelectionMerge %65 None
- OpBranchConditional %64 %66 %65
- %66 = OpLabel
- %67 = OpIAdd %uint %61 %uint_0
- %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
- OpStore %68 %uint_9
- %70 = OpIAdd %uint %61 %uint_1
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
- OpStore %71 %uint_23
- %73 = OpIAdd %uint %61 %uint_2
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
- OpStore %74 %50
- %75 = OpIAdd %uint %61 %uint_3
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %uint_4
- %80 = OpLoad %v4float %gl_FragCoord
- %82 = OpBitcast %v4uint %80
- %83 = OpCompositeExtract %uint %82 0
- %84 = OpIAdd %uint %61 %uint_4
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
- OpStore %85 %83
- %86 = OpCompositeExtract %uint %82 1
- %88 = OpIAdd %uint %61 %uint_5
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
- OpStore %89 %86
- %91 = OpIAdd %uint %61 %uint_6
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
- OpStore %92 %51
- %94 = OpIAdd %uint %61 %uint_7
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
- OpStore %95 %52
- %97 = OpIAdd %uint %61 %uint_8
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
- OpStore %98 %53
- OpBranch %65
- %65 = OpLabel
- OpReturn
- OpFunctionEnd
- %104 = OpFunction %uint None %105
- %106 = OpFunctionParameter %uint
- %107 = OpFunctionParameter %uint
- %108 = OpFunctionParameter %uint
- %109 = OpFunctionParameter %uint
- %110 = OpLabel
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %107
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %108
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- %119 = OpIAdd %uint %118 %109
- %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
- %121 = OpLoad %uint %120
- OpReturnValue %121
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArray) {
- // Same as Deprecated but declaring as StorageBuffer Block
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %102 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %130 NonUniform
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_3 = OpConstant %uint 3
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %49 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_45 = OpConstant %uint 45
- %101 = OpConstantNull %float
- %105 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %19 = OpLabel
- %7 = OpLoad %int %nu_ii
- %20 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %103 = OpBitcast %uint %7
- %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
- %123 = OpINotEqual %bool %122 %uint_0
- OpSelectionMerge %124 None
- OpBranchConditional %123 %125 %126
- %125 = OpLabel
- %127 = OpLoad %float %20
- OpBranch %124
- %126 = OpLabel
- %128 = OpBitcast %uint %7
- %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
- OpBranch %124
- %124 = OpLabel
- %130 = OpPhi %float %127 %125 %101 %126
- OpBranch %43
- %45 = OpLabel
- %47 = OpBitcast %uint %7
- %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
- OpBranch %43
- %43 = OpLabel
- %102 = OpPhi %float %130 %124 %101 %45
- OpStore %b %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %48 = OpFunction %void None %49
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpFunctionParameter %uint
- %54 = OpLabel
- %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_9
- %62 = OpIAdd %uint %61 %uint_9
- %63 = OpArrayLength %uint %57 1
- %64 = OpULessThanEqual %bool %62 %63
- OpSelectionMerge %65 None
- OpBranchConditional %64 %66 %65
- %66 = OpLabel
- %67 = OpIAdd %uint %61 %uint_0
- %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
- OpStore %68 %uint_9
- %70 = OpIAdd %uint %61 %uint_1
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
- OpStore %71 %uint_23
- %73 = OpIAdd %uint %61 %uint_2
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
- OpStore %74 %50
- %75 = OpIAdd %uint %61 %uint_3
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %uint_4
- %80 = OpLoad %v4float %gl_FragCoord
- %82 = OpBitcast %v4uint %80
- %83 = OpCompositeExtract %uint %82 0
- %84 = OpIAdd %uint %61 %uint_4
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
- OpStore %85 %83
- %86 = OpCompositeExtract %uint %82 1
- %88 = OpIAdd %uint %61 %uint_5
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
- OpStore %89 %86
- %91 = OpIAdd %uint %61 %uint_6
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
- OpStore %92 %51
- %94 = OpIAdd %uint %61 %uint_7
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
- OpStore %95 %52
- %97 = OpIAdd %uint %61 %uint_8
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
- OpStore %98 %53
- OpBranch %65
- %65 = OpLabel
- OpReturn
- OpFunctionEnd
- %104 = OpFunction %uint None %105
- %106 = OpFunctionParameter %uint
- %107 = OpFunctionParameter %uint
- %108 = OpFunctionParameter %uint
- %109 = OpFunctionParameter %uint
- %110 = OpLabel
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %107
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %108
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- %119 = OpIAdd %uint %118 %109
- %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
- %121 = OpLoad %uint %120
- OpReturnValue %121
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, InstInitLoadUBOScalar) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) out float b;
- // layout(binding=3) uniform uname { float a; } uniformBuffer;
- //
- // void main()
- // {
- // b = uniformBuffer.a;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_ptr_Uniform_uname = OpTypePointer Uniform %uname
- %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_28 Block
- OpMemberDecorate %_struct_28 0 Offset 0
- OpDecorate %30 DescriptorSet 7
- OpDecorate %30 Binding 1
- OpDecorate %_struct_58 Block
- OpMemberDecorate %_struct_58 0 Offset 0
- OpMemberDecorate %_struct_58 1 Offset 4
- OpDecorate %60 DescriptorSet 7
- OpDecorate %60 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %7 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_ptr_Uniform_uname = OpTypePointer Uniform %uname
- %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %21 = OpTypeFunction %uint %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_28 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_28 = OpTypePointer StorageBuffer %_struct_28
- %30 = OpVariable %_ptr_StorageBuffer__struct_28 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %uint_1 = OpConstant %uint 1
- %52 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_58 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_58 = OpTypePointer StorageBuffer %_struct_58
- %60 = OpVariable %_ptr_StorageBuffer__struct_58 StorageBuffer
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_32 = OpConstant %uint 32
- %104 = OpConstantNull %float
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
- %16 = OpLoad %float %15
- OpStore %b %16
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %7
- %14 = OpLabel
- %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
- %43 = OpFunctionCall %uint %20 %uint_0 %uint_0 %uint_3 %uint_0
- %45 = OpINotEqual %bool %43 %uint_0
- OpSelectionMerge %47 None
- OpBranchConditional %45 %48 %49
- %48 = OpLabel
- %50 = OpLoad %float %15
- OpBranch %47
- %49 = OpLabel
- %103 = OpFunctionCall %void %51 %uint_32 %uint_1 %uint_0 %uint_0
- OpBranch %47
- %47 = OpLabel
- %105 = OpPhi %float %50 %48 %104 %49
- OpStore %b %105
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%20 = OpFunction %uint None %21
- %22 = OpFunctionParameter %uint
- %23 = OpFunctionParameter %uint
- %24 = OpFunctionParameter %uint
- %25 = OpFunctionParameter %uint
- %26 = OpLabel
- %32 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %22
- %33 = OpLoad %uint %32
- %34 = OpIAdd %uint %33 %23
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %34
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %24
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %37
- %39 = OpLoad %uint %38
- %40 = OpIAdd %uint %39 %25
- %41 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %40
- %42 = OpLoad %uint %41
- OpReturnValue %42
- OpFunctionEnd
- %51 = OpFunction %void None %52
- %53 = OpFunctionParameter %uint
- %54 = OpFunctionParameter %uint
- %55 = OpFunctionParameter %uint
- %56 = OpFunctionParameter %uint
- %57 = OpLabel
- %61 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_0
- %64 = OpAtomicIAdd %uint %61 %uint_4 %uint_0 %uint_9
- %65 = OpIAdd %uint %64 %uint_9
- %66 = OpArrayLength %uint %60 1
- %67 = OpULessThanEqual %bool %65 %66
- OpSelectionMerge %68 None
- OpBranchConditional %67 %69 %68
- %69 = OpLabel
- %70 = OpIAdd %uint %64 %uint_0
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %70
- OpStore %71 %uint_9
- %73 = OpIAdd %uint %64 %uint_1
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %73
- OpStore %74 %uint_23
- %76 = OpIAdd %uint %64 %uint_2
- %77 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %76
- OpStore %77 %53
- %78 = OpIAdd %uint %64 %uint_3
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %78
- OpStore %79 %uint_4
- %83 = OpLoad %v4float %gl_FragCoord
- %85 = OpBitcast %v4uint %83
- %86 = OpCompositeExtract %uint %85 0
- %87 = OpIAdd %uint %64 %uint_4
- %88 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %87
- OpStore %88 %86
- %89 = OpCompositeExtract %uint %85 1
- %91 = OpIAdd %uint %64 %uint_5
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %91
- OpStore %92 %89
- %94 = OpIAdd %uint %64 %uint_6
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %94
- OpStore %95 %54
- %97 = OpIAdd %uint %64 %uint_7
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %97
- OpStore %98 %55
- %100 = OpIAdd %uint %64 %uint_8
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %100
- OpStore %101 %56
- OpBranch %68
- %68 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=1) in float b;
- //
- // layout(binding=4) buffer bname { float b; } storageBuffer[];
- //
- // void main()
- // {
- // storageBuffer[nu_ii].b = b;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %nu_ii %b
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %bname "bname"
- OpMemberName %bname 0 "b"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpName %b "b"
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname BufferBlock
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 4
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %14 NonUniform
- OpDecorate %b Location 1
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Input_float = OpTypePointer Input %float
- %b = OpVariable %_ptr_Input_float Input
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %bname "bname"
- OpMemberName %bname 0 "b"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpName %b "b"
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname BufferBlock
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 4
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %b Location 1
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %_struct_54 Block
- OpMemberDecorate %_struct_54 0 Offset 0
- OpMemberDecorate %_struct_54 1 Offset 4
- OpDecorate %56 DescriptorSet 7
- OpDecorate %56 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Input_float = OpTypePointer Input %float
- %b = OpVariable %_ptr_Input_float Input
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_4 = OpConstant %uint 4
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %48 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_54 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_54 = OpTypePointer StorageBuffer %_struct_54
- %56 = OpVariable %_ptr_StorageBuffer__struct_54 StorageBuffer
- %uint_9 = OpConstant %uint 9
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_45 = OpConstant %uint 45
- %102 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %14 = OpLoad %int %nu_ii
- %18 = OpLoad %float %b
- %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %14 %int_0
- OpStore %20 %18
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %9
- %18 = OpLabel
- %7 = OpLoad %int %nu_ii
- %19 = OpLoad %float %b
- %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_4
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %100 = OpBitcast %uint %7
- %119 = OpFunctionCall %uint %101 %uint_0 %uint_0 %uint_4 %100
- %120 = OpINotEqual %bool %119 %uint_0
- OpSelectionMerge %121 None
- OpBranchConditional %120 %122 %123
- %122 = OpLabel
- OpStore %20 %19
- OpBranch %121
- %123 = OpLabel
- %124 = OpBitcast %uint %7
- %125 = OpFunctionCall %void %47 %uint_45 %uint_1 %124 %uint_0
- OpBranch %121
- %121 = OpLabel
- OpBranch %43
- %45 = OpLabel
- %46 = OpBitcast %uint %7
- %99 = OpFunctionCall %void %47 %uint_45 %uint_0 %46 %40
- OpBranch %43
- %43 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %47 = OpFunction %void None %48
- %49 = OpFunctionParameter %uint
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpLabel
- %57 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_0
- %59 = OpAtomicIAdd %uint %57 %uint_4 %uint_0 %uint_9
- %60 = OpIAdd %uint %59 %uint_9
- %61 = OpArrayLength %uint %56 1
- %62 = OpULessThanEqual %bool %60 %61
- OpSelectionMerge %63 None
- OpBranchConditional %62 %64 %63
- %64 = OpLabel
- %65 = OpIAdd %uint %59 %uint_0
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %65
- OpStore %66 %uint_9
- %68 = OpIAdd %uint %59 %uint_1
- %69 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %68
- OpStore %69 %uint_23
- %71 = OpIAdd %uint %59 %uint_2
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %71
- OpStore %72 %49
- %74 = OpIAdd %uint %59 %uint_3
- %75 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %74
- OpStore %75 %uint_4
- %79 = OpLoad %v4float %gl_FragCoord
- %81 = OpBitcast %v4uint %79
- %82 = OpCompositeExtract %uint %81 0
- %83 = OpIAdd %uint %59 %uint_4
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %83
- OpStore %84 %82
- %85 = OpCompositeExtract %uint %81 1
- %87 = OpIAdd %uint %59 %uint_5
- %88 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %87
- OpStore %88 %85
- %90 = OpIAdd %uint %59 %uint_6
- %91 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %90
- OpStore %91 %50
- %93 = OpIAdd %uint %59 %uint_7
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %93
- OpStore %94 %51
- %96 = OpIAdd %uint %59 %uint_8
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %96
- OpStore %97 %52
- OpBranch %63
- %63 = OpLabel
- OpReturn
- OpFunctionEnd
- %101 = OpFunction %uint None %102
- %103 = OpFunctionParameter %uint
- %104 = OpFunctionParameter %uint
- %105 = OpFunctionParameter %uint
- %106 = OpFunctionParameter %uint
- %107 = OpLabel
- %108 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %103
- %109 = OpLoad %uint %108
- %110 = OpIAdd %uint %109 %104
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %110
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %105
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %106
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- OpReturnValue %118
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) uniform uname { float a; } uniformBuffer[128];
- //
- // void main()
- // {
- // b = uniformBuffer[nu_ii].a;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %18 NonUniform
- OpDecorate %22 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
- %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
- %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %89 NonUniform
- OpDecorate %120 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpMemberDecorate %_struct_39 1 Offset 4
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %_struct_98 Block
- OpMemberDecorate %_struct_98 0 Offset 0
- OpDecorate %100 DescriptorSet 7
- OpDecorate %100 Binding 1
- OpDecorate %117 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
- %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
- %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %32 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_9 = OpConstant %uint 9
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_46 = OpConstant %uint 46
- %88 = OpConstantNull %float
- %92 = OpTypeFunction %uint %uint %uint %uint %uint
- %_struct_98 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_98 = OpTypePointer StorageBuffer %_struct_98
- %100 = OpVariable %_ptr_StorageBuffer__struct_98 StorageBuffer
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %18 = OpLoad %int %nu_ii
- %21 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %18 %int_0
- %22 = OpLoad %float %21
- OpStore %b %22
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %21 = OpLabel
- %7 = OpLoad %int %nu_ii
- %22 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
- %25 = OpULessThan %bool %7 %uint_128
- OpSelectionMerge %26 None
- OpBranchConditional %25 %27 %28
- %27 = OpLabel
- %90 = OpBitcast %uint %7
- %112 = OpFunctionCall %uint %91 %uint_0 %uint_0 %uint_3 %90
- %113 = OpINotEqual %bool %112 %uint_0
- OpSelectionMerge %114 None
- OpBranchConditional %113 %115 %116
- %115 = OpLabel
- %117 = OpLoad %float %22
- OpBranch %114
- %116 = OpLabel
- %118 = OpBitcast %uint %7
- %119 = OpFunctionCall %void %31 %uint_46 %uint_1 %118 %uint_0
- OpBranch %114
- %114 = OpLabel
- %120 = OpPhi %float %117 %115 %88 %116
- OpBranch %26
- %28 = OpLabel
- %30 = OpBitcast %uint %7
- %87 = OpFunctionCall %void %31 %uint_46 %uint_0 %30 %uint_128
- OpBranch %26
- %26 = OpLabel
- %89 = OpPhi %float %120 %114 %88 %28
- OpStore %b %89
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%31 = OpFunction %void None %32
- %33 = OpFunctionParameter %uint
- %34 = OpFunctionParameter %uint
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0
- %46 = OpAtomicIAdd %uint %43 %uint_4 %uint_0 %uint_9
- %47 = OpIAdd %uint %46 %uint_9
- %48 = OpArrayLength %uint %41 1
- %49 = OpULessThanEqual %bool %47 %48
- OpSelectionMerge %50 None
- OpBranchConditional %49 %51 %50
- %51 = OpLabel
- %52 = OpIAdd %uint %46 %uint_0
- %54 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %52
- OpStore %54 %uint_9
- %56 = OpIAdd %uint %46 %uint_1
- %57 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %56
- OpStore %57 %uint_23
- %59 = OpIAdd %uint %46 %uint_2
- %60 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %59
- OpStore %60 %33
- %62 = OpIAdd %uint %46 %uint_3
- %63 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %62
- OpStore %63 %uint_4
- %67 = OpLoad %v4float %gl_FragCoord
- %69 = OpBitcast %v4uint %67
- %70 = OpCompositeExtract %uint %69 0
- %71 = OpIAdd %uint %46 %uint_4
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %71
- OpStore %72 %70
- %73 = OpCompositeExtract %uint %69 1
- %75 = OpIAdd %uint %46 %uint_5
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %75
- OpStore %76 %73
- %78 = OpIAdd %uint %46 %uint_6
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %78
- OpStore %79 %34
- %81 = OpIAdd %uint %46 %uint_7
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %81
- OpStore %82 %35
- %84 = OpIAdd %uint %46 %uint_8
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %84
- OpStore %85 %36
- OpBranch %50
- %50 = OpLabel
- OpReturn
- OpFunctionEnd
- %91 = OpFunction %uint None %92
- %93 = OpFunctionParameter %uint
- %94 = OpFunctionParameter %uint
- %95 = OpFunctionParameter %uint
- %96 = OpFunctionParameter %uint
- %97 = OpLabel
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %93
- %102 = OpLoad %uint %101
- %103 = OpIAdd %uint %102 %94
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %103
- %105 = OpLoad %uint %104
- %106 = OpIAdd %uint %105 %95
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %106
- %108 = OpLoad %uint %107
- %109 = OpIAdd %uint %108 %96
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %109
- %111 = OpLoad %uint %110
- OpReturnValue %111
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true);
- }
- TEST_F(InstBindlessTest, SimpleV2) {
- // Texture2D g_tColor[128];
- //
- // layout(push_constant) cbuffer PerViewConstantBuffer_t
- // {
- // uint g_nDataIdx;
- // };
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- // ps_output.vColor =
- // g_tColor[ g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
- // return ps_output;
- // }
- const std::string entry_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- )";
- const std::string entry_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- )";
- const std::string names_annots =
- R"(OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- )";
- const std::string new_annots =
- R"(OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- )";
- const std::string consts_types_vars =
- R"(%void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_16_uint_128 = OpTypeArray %16 %uint_128
- %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %24 = OpTypeSampler
- %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
- %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
- %26 = OpTypeSampledImage %16
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string new_consts_types_vars =
- R"(%uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %48 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_56 = OpConstant %uint 56
- %103 = OpConstantNull %v4float
- )";
- const std::string func_pt1 =
- R"(%MainPs = OpFunction %void None %10
- %29 = OpLabel
- %30 = OpLoad %v2float %i_vTextureCoords
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
- %34 = OpLoad %16 %33
- %35 = OpLoad %24 %g_sAniso
- %36 = OpSampledImage %26 %34 %35
- )";
- const std::string func_pt2_before =
- R"(%37 = OpImageSampleImplicitLod %v4float %36 %30
- OpStore %_entryPointOutput_vColor %37
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_pt2_after =
- R"(%40 = OpULessThan %bool %32 %uint_128
- OpSelectionMerge %41 None
- OpBranchConditional %40 %42 %43
- %42 = OpLabel
- %44 = OpLoad %16 %33
- %45 = OpSampledImage %26 %44 %35
- %46 = OpImageSampleImplicitLod %v4float %45 %30
- OpBranch %41
- %43 = OpLabel
- %102 = OpFunctionCall %void %47 %uint_56 %uint_0 %32 %uint_128
- OpBranch %41
- %41 = OpLabel
- %104 = OpPhi %v4float %46 %42 %103 %43
- OpStore %_entryPointOutput_vColor %104
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%47 = OpFunction %void None %48
- %49 = OpFunctionParameter %uint
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpLabel
- %59 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %62 = OpAtomicIAdd %uint %59 %uint_4 %uint_0 %uint_10
- %63 = OpIAdd %uint %62 %uint_10
- %64 = OpArrayLength %uint %57 1
- %65 = OpULessThanEqual %bool %63 %64
- OpSelectionMerge %66 None
- OpBranchConditional %65 %67 %66
- %67 = OpLabel
- %68 = OpIAdd %uint %62 %uint_0
- %70 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %68
- OpStore %70 %uint_10
- %72 = OpIAdd %uint %62 %uint_1
- %73 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %72
- OpStore %73 %uint_23
- %75 = OpIAdd %uint %62 %uint_2
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %49
- %78 = OpIAdd %uint %62 %uint_3
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %78
- OpStore %79 %uint_4
- %82 = OpLoad %v4float %gl_FragCoord
- %84 = OpBitcast %v4uint %82
- %85 = OpCompositeExtract %uint %84 0
- %86 = OpIAdd %uint %62 %uint_4
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %86
- OpStore %87 %85
- %88 = OpCompositeExtract %uint %84 1
- %90 = OpIAdd %uint %62 %uint_5
- %91 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %90
- OpStore %91 %88
- %93 = OpIAdd %uint %62 %uint_7
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %93
- OpStore %94 %50
- %96 = OpIAdd %uint %62 %uint_8
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %96
- OpStore %97 %51
- %99 = OpIAdd %uint %62 %uint_9
- %100 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %99
- OpStore %100 %52
- OpBranch %66
- %66 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass, uint32_t, uint32_t, bool, bool,
- uint32_t>(
- entry_before + names_annots + consts_types_vars + func_pt1 +
- func_pt2_before,
- entry_after + names_annots + new_annots + consts_types_vars +
- new_consts_types_vars + func_pt1 + func_pt2_after + output_func,
- true, true, 7u, 23u, false, false, 2u);
- }
- TEST_F(InstBindlessTest, InstrumentMultipleInstructionsV2) {
- // Texture2D g_tColor[128];
- //
- // layout(push_constant) cbuffer PerViewConstantBuffer_t
- // {
- // uint g_nDataIdx;
- // uint g_nDataIdx2;
- // };
- //
- // SamplerState g_sAniso;
- //
- // struct PS_INPUT
- // {
- // float2 vTextureCoords : TEXCOORD2;
- // };
- //
- // struct PS_OUTPUT
- // {
- // float4 vColor : SV_Target0;
- // };
- //
- // PS_OUTPUT MainPs(PS_INPUT i)
- // {
- // PS_OUTPUT ps_output;
- //
- // float t = g_tColor[g_nDataIdx ].Sample(g_sAniso, i.vTextureCoords.xy);
- // float t2 = g_tColor[g_nDataIdx2].Sample(g_sAniso, i.vTextureCoords.xy);
- // ps_output.vColor = t + t2;
- // return ps_output;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_1 = OpConstant %int 1
- %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_17_uint_128 = OpTypeArray %17 %uint_128
- %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
- %25 = OpTypeSampler
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
- %27 = OpTypeSampledImage %17
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpMemberDecorate %PerViewConstantBuffer_t 1 Offset 4
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %int_1 = OpConstant %int 1
- %17 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_17_uint_128 = OpTypeArray %17 %uint_128
- %_ptr_UniformConstant__arr_17_uint_128 = OpTypePointer UniformConstant %_arr_17_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_17_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_17 = OpTypePointer UniformConstant %17
- %25 = OpTypeSampler
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %g_sAniso = OpVariable %_ptr_UniformConstant_25 UniformConstant
- %27 = OpTypeSampledImage %17
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %56 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_58 = OpConstant %uint 58
- %111 = OpConstantNull %v4float
- %uint_64 = OpConstant %uint 64
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %10
- %30 = OpLabel
- %31 = OpLoad %v2float %i_vTextureCoords
- %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %33 = OpLoad %uint %32
- %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
- %35 = OpLoad %17 %34
- %36 = OpLoad %25 %g_sAniso
- %37 = OpSampledImage %27 %35 %36
- %38 = OpImageSampleImplicitLod %v4float %37 %31
- %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
- %40 = OpLoad %uint %39
- %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
- %42 = OpLoad %17 %41
- %43 = OpSampledImage %27 %42 %36
- %44 = OpImageSampleImplicitLod %v4float %43 %31
- %45 = OpFAdd %v4float %38 %44
- OpStore %_entryPointOutput_vColor %45
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %10
- %30 = OpLabel
- %31 = OpLoad %v2float %i_vTextureCoords
- %32 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %33 = OpLoad %uint %32
- %34 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %33
- %35 = OpLoad %17 %34
- %36 = OpLoad %25 %g_sAniso
- %37 = OpSampledImage %27 %35 %36
- %48 = OpULessThan %bool %33 %uint_128
- OpSelectionMerge %49 None
- OpBranchConditional %48 %50 %51
- %50 = OpLabel
- %52 = OpLoad %17 %34
- %53 = OpSampledImage %27 %52 %36
- %54 = OpImageSampleImplicitLod %v4float %53 %31
- OpBranch %49
- %51 = OpLabel
- %110 = OpFunctionCall %void %55 %uint_58 %uint_0 %33 %uint_128
- OpBranch %49
- %49 = OpLabel
- %112 = OpPhi %v4float %54 %50 %111 %51
- %39 = OpAccessChain %_ptr_PushConstant_uint %_ %int_1
- %40 = OpLoad %uint %39
- %41 = OpAccessChain %_ptr_UniformConstant_17 %g_tColor %40
- %42 = OpLoad %17 %41
- %43 = OpSampledImage %27 %42 %36
- %113 = OpULessThan %bool %40 %uint_128
- OpSelectionMerge %114 None
- OpBranchConditional %113 %115 %116
- %115 = OpLabel
- %117 = OpLoad %17 %41
- %118 = OpSampledImage %27 %117 %36
- %119 = OpImageSampleImplicitLod %v4float %118 %31
- OpBranch %114
- %116 = OpLabel
- %121 = OpFunctionCall %void %55 %uint_64 %uint_0 %40 %uint_128
- OpBranch %114
- %114 = OpLabel
- %122 = OpPhi %v4float %119 %115 %111 %116
- %45 = OpFAdd %v4float %112 %122
- OpStore %_entryPointOutput_vColor %45
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%55 = OpFunction %void None %56
- %57 = OpFunctionParameter %uint
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpLabel
- %67 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %70 = OpAtomicIAdd %uint %67 %uint_4 %uint_0 %uint_10
- %71 = OpIAdd %uint %70 %uint_10
- %72 = OpArrayLength %uint %65 1
- %73 = OpULessThanEqual %bool %71 %72
- OpSelectionMerge %74 None
- OpBranchConditional %73 %75 %74
- %75 = OpLabel
- %76 = OpIAdd %uint %70 %uint_0
- %78 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %76
- OpStore %78 %uint_10
- %80 = OpIAdd %uint %70 %uint_1
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %80
- OpStore %81 %uint_23
- %83 = OpIAdd %uint %70 %uint_2
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %83
- OpStore %84 %57
- %86 = OpIAdd %uint %70 %uint_3
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %86
- OpStore %87 %uint_4
- %90 = OpLoad %v4float %gl_FragCoord
- %92 = OpBitcast %v4uint %90
- %93 = OpCompositeExtract %uint %92 0
- %94 = OpIAdd %uint %70 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %93
- %96 = OpCompositeExtract %uint %92 1
- %98 = OpIAdd %uint %70 %uint_5
- %99 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %98
- OpStore %99 %96
- %101 = OpIAdd %uint %70 %uint_7
- %102 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %101
- OpStore %102 %58
- %104 = OpIAdd %uint %70 %uint_8
- %105 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %104
- OpStore %105 %59
- %107 = OpIAdd %uint %70 %uint_9
- %108 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %107
- OpStore %108 %60
- OpBranch %74
- %74 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 2u);
- }
- TEST_F(InstBindlessTest, InstrumentOpImageV2) {
- // This test verifies that the pass will correctly instrument shader
- // using OpImage. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability StorageImageReadWithoutFormat
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %39 = OpTypeSampledImage %20
- %_arr_39_uint_128 = OpTypeArray %39 %uint_128
- %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability StorageImageReadWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_51 Block
- OpMemberDecorate %_struct_51 0 Offset 0
- OpMemberDecorate %_struct_51 1 Offset 4
- OpDecorate %53 DescriptorSet 7
- OpDecorate %53 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %15 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %18 = OpTypeSampledImage %15
- %_arr_18_uint_128 = OpTypeArray %18 %uint_128
- %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %44 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_51 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_51 = OpTypePointer StorageBuffer %_struct_51
- %53 = OpVariable %_ptr_StorageBuffer__struct_51 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- %99 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2int %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
- %66 = OpLoad %39 %65
- %75 = OpImage %20 %66
- %71 = OpImageRead %v4float %75 %53
- OpStore %_entryPointOutput_vColor %71
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %9
- %26 = OpLabel
- %27 = OpLoad %v2int %i_vTextureCoords
- %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %29 = OpLoad %uint %28
- %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
- %31 = OpLoad %18 %30
- %32 = OpImage %15 %31
- %36 = OpULessThan %bool %29 %uint_128
- OpSelectionMerge %37 None
- OpBranchConditional %36 %38 %39
- %38 = OpLabel
- %40 = OpLoad %18 %30
- %41 = OpImage %15 %40
- %42 = OpImageRead %v4float %41 %27
- OpBranch %37
- %39 = OpLabel
- %98 = OpFunctionCall %void %43 %uint_51 %uint_0 %29 %uint_128
- OpBranch %37
- %37 = OpLabel
- %100 = OpPhi %v4float %42 %38 %99 %39
- OpStore %_entryPointOutput_vColor %100
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%43 = OpFunction %void None %44
- %45 = OpFunctionParameter %uint
- %46 = OpFunctionParameter %uint
- %47 = OpFunctionParameter %uint
- %48 = OpFunctionParameter %uint
- %49 = OpLabel
- %55 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_0
- %58 = OpAtomicIAdd %uint %55 %uint_4 %uint_0 %uint_10
- %59 = OpIAdd %uint %58 %uint_10
- %60 = OpArrayLength %uint %53 1
- %61 = OpULessThanEqual %bool %59 %60
- OpSelectionMerge %62 None
- OpBranchConditional %61 %63 %62
- %63 = OpLabel
- %64 = OpIAdd %uint %58 %uint_0
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %64
- OpStore %66 %uint_10
- %68 = OpIAdd %uint %58 %uint_1
- %69 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %68
- OpStore %69 %uint_23
- %71 = OpIAdd %uint %58 %uint_2
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %71
- OpStore %72 %45
- %74 = OpIAdd %uint %58 %uint_3
- %75 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %74
- OpStore %75 %uint_4
- %78 = OpLoad %v4float %gl_FragCoord
- %80 = OpBitcast %v4uint %78
- %81 = OpCompositeExtract %uint %80 0
- %82 = OpIAdd %uint %58 %uint_4
- %83 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %82
- OpStore %83 %81
- %84 = OpCompositeExtract %uint %80 1
- %86 = OpIAdd %uint %58 %uint_5
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %86
- OpStore %87 %84
- %89 = OpIAdd %uint %58 %uint_7
- %90 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %89
- OpStore %90 %46
- %92 = OpIAdd %uint %58 %uint_8
- %93 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %92
- OpStore %93 %47
- %95 = OpIAdd %uint %58 %uint_9
- %96 = OpAccessChain %_ptr_StorageBuffer_uint %53 %uint_1 %95
- OpStore %96 %48
- OpBranch %62
- %62 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 2u);
- }
- TEST_F(InstBindlessTest, InstrumentSampledImageV2) {
- // This test verifies that the pass will correctly instrument shader
- // using sampled image. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %39 = OpTypeSampledImage %20
- %_arr_39_uint_128 = OpTypeArray %39 %uint_128
- %_ptr_UniformConstant__arr_39_uint_128 = OpTypePointer UniformConstant %_arr_39_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_39_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_39 = OpTypePointer UniformConstant %39
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_49 Block
- OpMemberDecorate %_struct_49 0 Offset 0
- OpMemberDecorate %_struct_49 1 Offset 4
- OpDecorate %51 DescriptorSet 7
- OpDecorate %51 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %15 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %18 = OpTypeSampledImage %15
- %_arr_18_uint_128 = OpTypeArray %18 %uint_128
- %_ptr_UniformConstant__arr_18_uint_128 = OpTypePointer UniformConstant %_arr_18_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_18_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_18 = OpTypePointer UniformConstant %18
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %42 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_49 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_49 = OpTypePointer StorageBuffer %_struct_49
- %51 = OpVariable %_ptr_StorageBuffer__struct_49 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_49 = OpConstant %uint 49
- %97 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2float %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_39 %g_tColor %64
- %66 = OpLoad %39 %65
- %71 = OpImageSampleImplicitLod %v4float %66 %53
- OpStore %_entryPointOutput_vColor %71
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %9
- %26 = OpLabel
- %27 = OpLoad %v2float %i_vTextureCoords
- %28 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %29 = OpLoad %uint %28
- %30 = OpAccessChain %_ptr_UniformConstant_18 %g_tColor %29
- %31 = OpLoad %18 %30
- %35 = OpULessThan %bool %29 %uint_128
- OpSelectionMerge %36 None
- OpBranchConditional %35 %37 %38
- %37 = OpLabel
- %39 = OpLoad %18 %30
- %40 = OpImageSampleImplicitLod %v4float %39 %27
- OpBranch %36
- %38 = OpLabel
- %96 = OpFunctionCall %void %41 %uint_49 %uint_0 %29 %uint_128
- OpBranch %36
- %36 = OpLabel
- %98 = OpPhi %v4float %40 %37 %97 %38
- OpStore %_entryPointOutput_vColor %98
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%41 = OpFunction %void None %42
- %43 = OpFunctionParameter %uint
- %44 = OpFunctionParameter %uint
- %45 = OpFunctionParameter %uint
- %46 = OpFunctionParameter %uint
- %47 = OpLabel
- %53 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_0
- %56 = OpAtomicIAdd %uint %53 %uint_4 %uint_0 %uint_10
- %57 = OpIAdd %uint %56 %uint_10
- %58 = OpArrayLength %uint %51 1
- %59 = OpULessThanEqual %bool %57 %58
- OpSelectionMerge %60 None
- OpBranchConditional %59 %61 %60
- %61 = OpLabel
- %62 = OpIAdd %uint %56 %uint_0
- %64 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %62
- OpStore %64 %uint_10
- %66 = OpIAdd %uint %56 %uint_1
- %67 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %66
- OpStore %67 %uint_23
- %69 = OpIAdd %uint %56 %uint_2
- %70 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %69
- OpStore %70 %43
- %72 = OpIAdd %uint %56 %uint_3
- %73 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %72
- OpStore %73 %uint_4
- %76 = OpLoad %v4float %gl_FragCoord
- %78 = OpBitcast %v4uint %76
- %79 = OpCompositeExtract %uint %78 0
- %80 = OpIAdd %uint %56 %uint_4
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %80
- OpStore %81 %79
- %82 = OpCompositeExtract %uint %78 1
- %84 = OpIAdd %uint %56 %uint_5
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %84
- OpStore %85 %82
- %87 = OpIAdd %uint %56 %uint_7
- %88 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %87
- OpStore %88 %44
- %90 = OpIAdd %uint %56 %uint_8
- %91 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %90
- OpStore %91 %45
- %93 = OpIAdd %uint %56 %uint_9
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %51 %uint_1 %93
- OpStore %94 %46
- OpBranch %60
- %60 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 2u);
- }
- TEST_F(InstBindlessTest, InstrumentImageWriteV2) {
- // This test verifies that the pass will correctly instrument shader
- // doing bindless image write. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability StorageImageWriteWithoutFormat
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %80 = OpConstantNull %v4float
- %_arr_20_uint_128 = OpTypeArray %20 %uint_128
- %_ptr_UniformConstant__arr_20_uint_128 = OpTypePointer UniformConstant %_arr_20_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_20_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability StorageImageWriteWithoutFormat
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 3
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_48 Block
- OpMemberDecorate %_struct_48 0 Offset 0
- OpMemberDecorate %_struct_48 1 Offset 4
- OpDecorate %50 DescriptorSet 7
- OpDecorate %50 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %v2int = OpTypeVector %int 2
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 0 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %19 = OpConstantNull %v4float
- %_arr_16_uint_128 = OpTypeArray %16 %uint_128
- %_ptr_UniformConstant__arr_16_uint_128 = OpTypePointer UniformConstant %_arr_16_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_16_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %_ptr_Input_v2int = OpTypePointer Input %v2int
- %i_vTextureCoords = OpVariable %_ptr_Input_v2int Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %41 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_48 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_48 = OpTypePointer StorageBuffer %_struct_48
- %50 = OpVariable %_ptr_StorageBuffer__struct_48 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2int %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
- %66 = OpLoad %20 %65
- OpImageWrite %66 %53 %80
- OpStore %_entryPointOutput_vColor %80
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %9
- %27 = OpLabel
- %28 = OpLoad %v2int %i_vTextureCoords
- %29 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %30 = OpLoad %uint %29
- %31 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %30
- %32 = OpLoad %16 %31
- %35 = OpULessThan %bool %30 %uint_128
- OpSelectionMerge %36 None
- OpBranchConditional %35 %37 %38
- %37 = OpLabel
- %39 = OpLoad %16 %31
- OpImageWrite %39 %28 %19
- OpBranch %36
- %38 = OpLabel
- %95 = OpFunctionCall %void %40 %uint_51 %uint_0 %30 %uint_128
- OpBranch %36
- %36 = OpLabel
- OpStore %_entryPointOutput_vColor %19
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%40 = OpFunction %void None %41
- %42 = OpFunctionParameter %uint
- %43 = OpFunctionParameter %uint
- %44 = OpFunctionParameter %uint
- %45 = OpFunctionParameter %uint
- %46 = OpLabel
- %52 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_0
- %55 = OpAtomicIAdd %uint %52 %uint_4 %uint_0 %uint_10
- %56 = OpIAdd %uint %55 %uint_10
- %57 = OpArrayLength %uint %50 1
- %58 = OpULessThanEqual %bool %56 %57
- OpSelectionMerge %59 None
- OpBranchConditional %58 %60 %59
- %60 = OpLabel
- %61 = OpIAdd %uint %55 %uint_0
- %63 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %61
- OpStore %63 %uint_10
- %65 = OpIAdd %uint %55 %uint_1
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %65
- OpStore %66 %uint_23
- %68 = OpIAdd %uint %55 %uint_2
- %69 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %68
- OpStore %69 %42
- %71 = OpIAdd %uint %55 %uint_3
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %71
- OpStore %72 %uint_4
- %75 = OpLoad %v4float %gl_FragCoord
- %77 = OpBitcast %v4uint %75
- %78 = OpCompositeExtract %uint %77 0
- %79 = OpIAdd %uint %55 %uint_4
- %80 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %79
- OpStore %80 %78
- %81 = OpCompositeExtract %uint %77 1
- %83 = OpIAdd %uint %55 %uint_5
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %83
- OpStore %84 %81
- %86 = OpIAdd %uint %55 %uint_7
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %86
- OpStore %87 %43
- %89 = OpIAdd %uint %55 %uint_8
- %90 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %89
- OpStore %90 %44
- %92 = OpIAdd %uint %55 %uint_9
- %93 = OpAccessChain %_ptr_StorageBuffer_uint %50 %uint_1 %92
- OpStore %93 %45
- OpBranch %59
- %59 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 2u);
- }
- TEST_F(InstBindlessTest, InstrumentVertexSimpleV2) {
- // This test verifies that the pass will correctly instrument shader
- // doing bindless image write. This test was created by editing the SPIR-V
- // from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability Sampled1D
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %_ %coords2D
- OpSource GLSL 450
- OpName %main "main"
- OpName %lod "lod"
- OpName %coords1D "coords1D"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %texSampler1D "texSampler1D"
- OpName %foo "foo"
- OpMemberName %foo 0 "g_idx"
- OpName %__0 ""
- OpName %coords2D "coords2D"
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpDecorate %texSampler1D DescriptorSet 0
- OpDecorate %texSampler1D Binding 3
- OpMemberDecorate %foo 0 Offset 0
- OpDecorate %foo Block
- OpDecorate %__0 DescriptorSet 0
- OpDecorate %__0 Binding 5
- OpDecorate %coords2D Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Function_float = OpTypePointer Function %float
- %float_3 = OpConstant %float 3
- %float_1_78900003 = OpConstant %float 1.78900003
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %21 = OpTypeImage %float 1D 0 0 0 1 Unknown
- %22 = OpTypeSampledImage %21
- %uint_128 = OpConstant %uint 128
- %_arr_22_uint_128 = OpTypeArray %22 %uint_128
- %_ptr_UniformConstant__arr_22_uint_128 = OpTypePointer UniformConstant %_arr_22_uint_128
- %texSampler1D = OpVariable %_ptr_UniformConstant__arr_22_uint_128 UniformConstant
- %foo = OpTypeStruct %int
- %_ptr_Uniform_foo = OpTypePointer Uniform %foo
- %__0 = OpVariable %_ptr_Uniform_foo Uniform
- %_ptr_Uniform_int = OpTypePointer Uniform %int
- %_ptr_UniformConstant_22 = OpTypePointer UniformConstant %22
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %v2float = OpTypeVector %float 2
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %coords2D = OpVariable %_ptr_Input_v2float Input
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability Sampled1D
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Vertex %main "main" %_ %coords2D %gl_VertexIndex %gl_InstanceIndex
- OpSource GLSL 450
- OpName %main "main"
- OpName %lod "lod"
- OpName %coords1D "coords1D"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %texSampler1D "texSampler1D"
- OpName %foo "foo"
- OpMemberName %foo 0 "g_idx"
- OpName %__0 ""
- OpName %coords2D "coords2D"
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpDecorate %texSampler1D DescriptorSet 0
- OpDecorate %texSampler1D Binding 3
- OpMemberDecorate %foo 0 Offset 0
- OpDecorate %foo Block
- OpDecorate %__0 DescriptorSet 0
- OpDecorate %__0 Binding 5
- OpDecorate %coords2D Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_61 Block
- OpMemberDecorate %_struct_61 0 Offset 0
- OpMemberDecorate %_struct_61 1 Offset 4
- OpDecorate %63 DescriptorSet 7
- OpDecorate %63 Binding 0
- OpDecorate %gl_VertexIndex BuiltIn VertexIndex
- OpDecorate %gl_InstanceIndex BuiltIn InstanceIndex
- %void = OpTypeVoid
- %12 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Function_float = OpTypePointer Function %float
- %float_3 = OpConstant %float 3
- %float_1_78900003 = OpConstant %float 1.78900003
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %24 = OpTypeImage %float 1D 0 0 0 1 Unknown
- %25 = OpTypeSampledImage %24
- %uint_128 = OpConstant %uint 128
- %_arr_25_uint_128 = OpTypeArray %25 %uint_128
- %_ptr_UniformConstant__arr_25_uint_128 = OpTypePointer UniformConstant %_arr_25_uint_128
- %texSampler1D = OpVariable %_ptr_UniformConstant__arr_25_uint_128 UniformConstant
- %foo = OpTypeStruct %int
- %_ptr_Uniform_foo = OpTypePointer Uniform %foo
- %__0 = OpVariable %_ptr_Uniform_foo Uniform
- %_ptr_Uniform_int = OpTypePointer Uniform %int
- %_ptr_UniformConstant_25 = OpTypePointer UniformConstant %25
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %v2float = OpTypeVector %float 2
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %coords2D = OpVariable %_ptr_Input_v2float Input
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %54 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_61 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_61 = OpTypePointer StorageBuffer %_struct_61
- %63 = OpVariable %_ptr_StorageBuffer__struct_61 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_uint = OpTypePointer Input %uint
- %gl_VertexIndex = OpVariable %_ptr_Input_uint Input
- %gl_InstanceIndex = OpVariable %_ptr_Input_uint Input
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_74 = OpConstant %uint 74
- %106 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %lod = OpVariable %_ptr_Function_float Function
- %coords1D = OpVariable %_ptr_Function_float Function
- OpStore %lod %float_3
- OpStore %coords1D %float_1_78900003
- %31 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
- %32 = OpLoad %int %31
- %34 = OpAccessChain %_ptr_UniformConstant_22 %texSampler1D %32
- %35 = OpLoad %22 %34
- %36 = OpLoad %float %coords1D
- %37 = OpLoad %float %lod
- %38 = OpImageSampleExplicitLod %v4float %35 %36 Lod %37
- %40 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %40 %38
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %12
- %35 = OpLabel
- %lod = OpVariable %_ptr_Function_float Function
- %coords1D = OpVariable %_ptr_Function_float Function
- OpStore %lod %float_3
- OpStore %coords1D %float_1_78900003
- %36 = OpAccessChain %_ptr_Uniform_int %__0 %int_0
- %37 = OpLoad %int %36
- %38 = OpAccessChain %_ptr_UniformConstant_25 %texSampler1D %37
- %39 = OpLoad %25 %38
- %40 = OpLoad %float %coords1D
- %41 = OpLoad %float %lod
- %46 = OpULessThan %bool %37 %uint_128
- OpSelectionMerge %47 None
- OpBranchConditional %46 %48 %49
- %48 = OpLabel
- %50 = OpLoad %25 %38
- %51 = OpImageSampleExplicitLod %v4float %50 %40 Lod %41
- OpBranch %47
- %49 = OpLabel
- %52 = OpBitcast %uint %37
- %105 = OpFunctionCall %void %53 %uint_74 %uint_0 %52 %uint_128
- OpBranch %47
- %47 = OpLabel
- %107 = OpPhi %v4float %51 %48 %106 %49
- %43 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %43 %107
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%53 = OpFunction %void None %54
- %55 = OpFunctionParameter %uint
- %56 = OpFunctionParameter %uint
- %57 = OpFunctionParameter %uint
- %58 = OpFunctionParameter %uint
- %59 = OpLabel
- %65 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_0
- %68 = OpAtomicIAdd %uint %65 %uint_4 %uint_0 %uint_10
- %69 = OpIAdd %uint %68 %uint_10
- %70 = OpArrayLength %uint %63 1
- %71 = OpULessThanEqual %bool %69 %70
- OpSelectionMerge %72 None
- OpBranchConditional %71 %73 %72
- %73 = OpLabel
- %74 = OpIAdd %uint %68 %uint_0
- %75 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %74
- OpStore %75 %uint_10
- %77 = OpIAdd %uint %68 %uint_1
- %78 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %77
- OpStore %78 %uint_23
- %80 = OpIAdd %uint %68 %uint_2
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %80
- OpStore %81 %55
- %83 = OpIAdd %uint %68 %uint_3
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %83
- OpStore %84 %uint_0
- %87 = OpLoad %uint %gl_VertexIndex
- %88 = OpIAdd %uint %68 %uint_4
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %88
- OpStore %89 %87
- %91 = OpLoad %uint %gl_InstanceIndex
- %93 = OpIAdd %uint %68 %uint_5
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %93
- OpStore %94 %91
- %96 = OpIAdd %uint %68 %uint_7
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %96
- OpStore %97 %56
- %99 = OpIAdd %uint %68 %uint_8
- %100 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %99
- OpStore %100 %57
- %102 = OpIAdd %uint %68 %uint_9
- %103 = OpAccessChain %_ptr_StorageBuffer_uint %63 %uint_1 %102
- OpStore %103 %58
- OpBranch %72
- %72 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 2u);
- }
- TEST_F(InstBindlessTest, InstrumentTeseSimpleV2) {
- // This test verifies that the pass will correctly instrument tessellation
- // evaluation shader doing bindless buffer load.
- //
- // clang-format off
- //
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(std140, set = 0, binding = 0) uniform ufoo { uint index; } uniform_index_buffer;
- //
- // layout(set = 0, binding = 1) buffer bfoo { vec4 val; } adds[11];
- //
- // layout(triangles, equal_spacing, cw) in;
- //
- // void main() {
- // gl_Position = adds[uniform_index_buffer.index].val;
- // }
- //
- // clang-format on
- const std::string defs_before =
- R"(OpCapability Tessellation
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main" %_
- OpExecutionMode %main Triangles
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main VertexOrderCw
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %bfoo "bfoo"
- OpMemberName %bfoo 0 "val"
- OpName %adds "adds"
- OpName %ufoo "ufoo"
- OpMemberName %ufoo 0 "index"
- OpName %uniform_index_buffer "uniform_index_buffer"
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpMemberDecorate %bfoo 0 Offset 0
- OpDecorate %bfoo Block
- OpDecorate %adds DescriptorSet 0
- OpDecorate %adds Binding 1
- OpMemberDecorate %ufoo 0 Offset 0
- OpDecorate %ufoo Block
- OpDecorate %uniform_index_buffer DescriptorSet 0
- OpDecorate %uniform_index_buffer Binding 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %bfoo = OpTypeStruct %v4float
- %uint_11 = OpConstant %uint 11
- %_arr_bfoo_uint_11 = OpTypeArray %bfoo %uint_11
- %_ptr_StorageBuffer__arr_bfoo_uint_11 = OpTypePointer StorageBuffer %_arr_bfoo_uint_11
- %adds = OpVariable %_ptr_StorageBuffer__arr_bfoo_uint_11 StorageBuffer
- %ufoo = OpTypeStruct %uint
- %_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
- %uniform_index_buffer = OpVariable %_ptr_Uniform_ufoo Uniform
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- )";
- const std::string defs_after =
- R"(OpCapability Tessellation
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint TessellationEvaluation %main "main" %_ %gl_PrimitiveID %gl_TessCoord
- OpExecutionMode %main Triangles
- OpExecutionMode %main SpacingEqual
- OpExecutionMode %main VertexOrderCw
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %gl_PerVertex "gl_PerVertex"
- OpMemberName %gl_PerVertex 0 "gl_Position"
- OpMemberName %gl_PerVertex 1 "gl_PointSize"
- OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
- OpMemberName %gl_PerVertex 3 "gl_CullDistance"
- OpName %_ ""
- OpName %bfoo "bfoo"
- OpMemberName %bfoo 0 "val"
- OpName %adds "adds"
- OpName %ufoo "ufoo"
- OpMemberName %ufoo 0 "index"
- OpName %uniform_index_buffer "uniform_index_buffer"
- OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
- OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
- OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
- OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
- OpDecorate %gl_PerVertex Block
- OpMemberDecorate %bfoo 0 Offset 0
- OpDecorate %bfoo Block
- OpDecorate %adds DescriptorSet 0
- OpDecorate %adds Binding 1
- OpMemberDecorate %ufoo 0 Offset 0
- OpDecorate %ufoo Block
- OpDecorate %uniform_index_buffer DescriptorSet 0
- OpDecorate %uniform_index_buffer Binding 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_47 Block
- OpMemberDecorate %_struct_47 0 Offset 0
- OpMemberDecorate %_struct_47 1 Offset 4
- OpDecorate %49 DescriptorSet 7
- OpDecorate %49 Binding 0
- OpDecorate %gl_PrimitiveID BuiltIn PrimitiveId
- OpDecorate %gl_TessCoord BuiltIn TessCoord
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v4float = OpTypeVector %float 4
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_arr_float_uint_1 = OpTypeArray %float %uint_1
- %gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
- %_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
- %_ = OpVariable %_ptr_Output_gl_PerVertex Output
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %bfoo = OpTypeStruct %v4float
- %uint_11 = OpConstant %uint 11
- %_arr_bfoo_uint_11 = OpTypeArray %bfoo %uint_11
- %_ptr_StorageBuffer__arr_bfoo_uint_11 = OpTypePointer StorageBuffer %_arr_bfoo_uint_11
- %adds = OpVariable %_ptr_StorageBuffer__arr_bfoo_uint_11 StorageBuffer
- %ufoo = OpTypeStruct %uint
- %_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
- %uniform_index_buffer = OpVariable %_ptr_Uniform_ufoo Uniform
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_StorageBuffer_v4float = OpTypePointer StorageBuffer %v4float
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %40 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_47 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_47 = OpTypePointer StorageBuffer %_struct_47
- %49 = OpVariable %_ptr_StorageBuffer__struct_47 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_uint = OpTypePointer Input %uint
- %gl_PrimitiveID = OpVariable %_ptr_Input_uint Input
- %v3float = OpTypeVector %float 3
- %_ptr_Input_v3float = OpTypePointer Input %v3float
- %gl_TessCoord = OpVariable %_ptr_Input_v3float Input
- %v3uint = OpTypeVector %uint 3
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_63 = OpConstant %uint 63
- %101 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0
- %26 = OpLoad %uint %25
- %28 = OpAccessChain %_ptr_StorageBuffer_v4float %adds %26 %int_0
- %29 = OpLoad %v4float %28
- %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %26 = OpLabel
- %27 = OpAccessChain %_ptr_Uniform_uint %uniform_index_buffer %int_0
- %28 = OpLoad %uint %27
- %29 = OpAccessChain %_ptr_StorageBuffer_v4float %adds %28 %int_0
- %34 = OpULessThan %bool %28 %uint_11
- OpSelectionMerge %35 None
- OpBranchConditional %34 %36 %37
- %36 = OpLabel
- %38 = OpLoad %v4float %29
- OpBranch %35
- %37 = OpLabel
- %100 = OpFunctionCall %void %39 %uint_63 %uint_0 %28 %uint_11
- OpBranch %35
- %35 = OpLabel
- %102 = OpPhi %v4float %38 %36 %101 %37
- %31 = OpAccessChain %_ptr_Output_v4float %_ %int_0
- OpStore %31 %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%39 = OpFunction %void None %40
- %41 = OpFunctionParameter %uint
- %42 = OpFunctionParameter %uint
- %43 = OpFunctionParameter %uint
- %44 = OpFunctionParameter %uint
- %45 = OpLabel
- %51 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_0
- %54 = OpAtomicIAdd %uint %51 %uint_4 %uint_0 %uint_10
- %55 = OpIAdd %uint %54 %uint_10
- %56 = OpArrayLength %uint %49 1
- %57 = OpULessThanEqual %bool %55 %56
- OpSelectionMerge %58 None
- OpBranchConditional %57 %59 %58
- %59 = OpLabel
- %60 = OpIAdd %uint %54 %uint_0
- %61 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %60
- OpStore %61 %uint_10
- %63 = OpIAdd %uint %54 %uint_1
- %64 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %63
- OpStore %64 %uint_23
- %66 = OpIAdd %uint %54 %uint_2
- %67 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %66
- OpStore %67 %41
- %69 = OpIAdd %uint %54 %uint_3
- %70 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %69
- OpStore %70 %uint_2
- %73 = OpLoad %uint %gl_PrimitiveID
- %74 = OpIAdd %uint %54 %uint_4
- %75 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %74
- OpStore %75 %73
- %79 = OpLoad %v3float %gl_TessCoord
- %81 = OpBitcast %v3uint %79
- %82 = OpCompositeExtract %uint %81 0
- %83 = OpCompositeExtract %uint %81 1
- %85 = OpIAdd %uint %54 %uint_5
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %85
- OpStore %86 %82
- %88 = OpIAdd %uint %54 %uint_6
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %88
- OpStore %89 %83
- %91 = OpIAdd %uint %54 %uint_7
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %91
- OpStore %92 %42
- %94 = OpIAdd %uint %54 %uint_8
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %94
- OpStore %95 %43
- %97 = OpIAdd %uint %54 %uint_9
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %49 %uint_1 %97
- OpStore %98 %44
- OpBranch %58
- %58 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + output_func, true,
- true, 7u, 23u, false, false, 2u);
- }
- TEST_F(InstBindlessTest, MultipleDebugFunctionsV2) {
- // Same source as Simple, but compiled -g and not optimized, especially not
- // inlined. The OpSource has had the source extracted for the sake of brevity.
- const std::string defs_before =
- R"(OpCapability Shader
- %2 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- %1 = OpString "foo5.frag"
- OpSource HLSL 500 %1
- OpName %MainPs "MainPs"
- OpName %PS_INPUT "PS_INPUT"
- OpMemberName %PS_INPUT 0 "vTextureCoords"
- OpName %PS_OUTPUT "PS_OUTPUT"
- OpMemberName %PS_OUTPUT 0 "vColor"
- OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
- OpName %i "i"
- OpName %ps_output "ps_output"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_0 "i"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpName %param "param"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 1
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %4 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %PS_INPUT = OpTypeStruct %v2float
- %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
- %v4float = OpTypeVector %float 4
- %PS_OUTPUT = OpTypeStruct %v4float
- %13 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
- %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %21 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_21_uint_128 = OpTypeArray %21 %uint_128
- %_ptr_UniformConstant__arr_21_uint_128 = OpTypePointer UniformConstant %_arr_21_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_21_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_21 = OpTypePointer UniformConstant %21
- %36 = OpTypeSampler
- %_ptr_UniformConstant_36 = OpTypePointer UniformConstant %36
- %g_sAniso = OpVariable %_ptr_UniformConstant_36 UniformConstant
- %40 = OpTypeSampledImage %21
- %_ptr_Function_v2float = OpTypePointer Function %v2float
- %_ptr_Function_v4float = OpTypePointer Function %v4float
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- %5 = OpString "foo5.frag"
- OpSource HLSL 500 %5
- OpName %MainPs "MainPs"
- OpName %PS_INPUT "PS_INPUT"
- OpMemberName %PS_INPUT 0 "vTextureCoords"
- OpName %PS_OUTPUT "PS_OUTPUT"
- OpMemberName %PS_OUTPUT 0 "vColor"
- OpName %_MainPs_struct_PS_INPUT_vf21_ "@MainPs(struct-PS_INPUT-vf21;"
- OpName %i "i"
- OpName %ps_output "ps_output"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_0 "i"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpName %param "param"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 1
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_77 Block
- OpMemberDecorate %_struct_77 0 Offset 0
- OpMemberDecorate %_struct_77 1 Offset 4
- OpDecorate %79 DescriptorSet 7
- OpDecorate %79 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %18 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %PS_INPUT = OpTypeStruct %v2float
- %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
- %v4float = OpTypeVector %float 4
- %PS_OUTPUT = OpTypeStruct %v4float
- %23 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
- %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %27 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_27_uint_128 = OpTypeArray %27 %uint_128
- %_ptr_UniformConstant__arr_27_uint_128 = OpTypePointer UniformConstant %_arr_27_uint_128
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_27_uint_128 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_27 = OpTypePointer UniformConstant %27
- %35 = OpTypeSampler
- %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
- %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
- %37 = OpTypeSampledImage %27
- %_ptr_Function_v2float = OpTypePointer Function %v2float
- %_ptr_Function_v4float = OpTypePointer Function %v4float
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %70 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_77 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_77 = OpTypePointer StorageBuffer %_struct_77
- %79 = OpVariable %_ptr_StorageBuffer__struct_77 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_93 = OpConstant %uint 93
- %125 = OpConstantNull %v4float
- )";
- const std::string func1_before =
- R"(%MainPs = OpFunction %void None %4
- %6 = OpLabel
- %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
- %param = OpVariable %_ptr_Function_PS_INPUT Function
- OpLine %1 21 0
- %54 = OpLoad %v2float %i_vTextureCoords
- %55 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
- OpStore %55 %54
- %59 = OpLoad %PS_INPUT %i_0
- OpStore %param %59
- %60 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
- %61 = OpCompositeExtract %v4float %60 0
- OpStore %_entryPointOutput_vColor %61
- OpReturn
- OpFunctionEnd
- )";
- const std::string func1_after =
- R"(%MainPs = OpFunction %void None %18
- %42 = OpLabel
- %i_0 = OpVariable %_ptr_Function_PS_INPUT Function
- %param = OpVariable %_ptr_Function_PS_INPUT Function
- OpLine %5 21 0
- %43 = OpLoad %v2float %i_vTextureCoords
- %44 = OpAccessChain %_ptr_Function_v2float %i_0 %int_0
- OpStore %44 %43
- %45 = OpLoad %PS_INPUT %i_0
- OpStore %param %45
- %46 = OpFunctionCall %PS_OUTPUT %_MainPs_struct_PS_INPUT_vf21_ %param
- %47 = OpCompositeExtract %v4float %46 0
- OpStore %_entryPointOutput_vColor %47
- OpReturn
- OpFunctionEnd
- )";
- const std::string func2_before =
- R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %13
- %i = OpFunctionParameter %_ptr_Function_PS_INPUT
- %16 = OpLabel
- %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
- OpLine %1 24 0
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %34 = OpAccessChain %_ptr_UniformConstant_21 %g_tColor %32
- %35 = OpLoad %21 %34
- %39 = OpLoad %36 %g_sAniso
- %41 = OpSampledImage %40 %35 %39
- %43 = OpAccessChain %_ptr_Function_v2float %i %int_0
- %44 = OpLoad %v2float %43
- %45 = OpImageSampleImplicitLod %v4float %41 %44
- %47 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
- OpStore %47 %45
- OpLine %1 25 0
- %48 = OpLoad %PS_OUTPUT %ps_output
- OpReturnValue %48
- OpFunctionEnd
- )";
- const std::string func2_after =
- R"(%_MainPs_struct_PS_INPUT_vf21_ = OpFunction %PS_OUTPUT None %23
- %i = OpFunctionParameter %_ptr_Function_PS_INPUT
- %48 = OpLabel
- %ps_output = OpVariable %_ptr_Function_PS_OUTPUT Function
- OpLine %5 24 0
- %49 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %50 = OpLoad %uint %49
- %51 = OpAccessChain %_ptr_UniformConstant_27 %g_tColor %50
- %52 = OpLoad %27 %51
- %53 = OpLoad %35 %g_sAniso
- %54 = OpSampledImage %37 %52 %53
- %55 = OpAccessChain %_ptr_Function_v2float %i %int_0
- %56 = OpLoad %v2float %55
- %62 = OpULessThan %bool %50 %uint_128
- OpSelectionMerge %63 None
- OpBranchConditional %62 %64 %65
- %64 = OpLabel
- %66 = OpLoad %27 %51
- %67 = OpSampledImage %37 %66 %53
- %68 = OpImageSampleImplicitLod %v4float %67 %56
- OpBranch %63
- %65 = OpLabel
- %124 = OpFunctionCall %void %69 %uint_93 %uint_0 %50 %uint_128
- OpBranch %63
- %63 = OpLabel
- %126 = OpPhi %v4float %68 %64 %125 %65
- %58 = OpAccessChain %_ptr_Function_v4float %ps_output %int_0
- OpStore %58 %126
- OpLine %5 25 0
- %59 = OpLoad %PS_OUTPUT %ps_output
- OpReturnValue %59
- OpFunctionEnd
- )";
- const std::string output_func =
- R"(%69 = OpFunction %void None %70
- %71 = OpFunctionParameter %uint
- %72 = OpFunctionParameter %uint
- %73 = OpFunctionParameter %uint
- %74 = OpFunctionParameter %uint
- %75 = OpLabel
- %81 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_0
- %84 = OpAtomicIAdd %uint %81 %uint_4 %uint_0 %uint_10
- %85 = OpIAdd %uint %84 %uint_10
- %86 = OpArrayLength %uint %79 1
- %87 = OpULessThanEqual %bool %85 %86
- OpSelectionMerge %88 None
- OpBranchConditional %87 %89 %88
- %89 = OpLabel
- %90 = OpIAdd %uint %84 %uint_0
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %90
- OpStore %92 %uint_10
- %94 = OpIAdd %uint %84 %uint_1
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %94
- OpStore %95 %uint_23
- %97 = OpIAdd %uint %84 %uint_2
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %97
- OpStore %98 %71
- %100 = OpIAdd %uint %84 %uint_3
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %100
- OpStore %101 %uint_4
- %104 = OpLoad %v4float %gl_FragCoord
- %106 = OpBitcast %v4uint %104
- %107 = OpCompositeExtract %uint %106 0
- %108 = OpIAdd %uint %84 %uint_4
- %109 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %108
- OpStore %109 %107
- %110 = OpCompositeExtract %uint %106 1
- %112 = OpIAdd %uint %84 %uint_5
- %113 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %112
- OpStore %113 %110
- %115 = OpIAdd %uint %84 %uint_7
- %116 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %115
- OpStore %116 %72
- %118 = OpIAdd %uint %84 %uint_8
- %119 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %118
- OpStore %119 %73
- %121 = OpIAdd %uint %84 %uint_9
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %121
- OpStore %122 %74
- OpBranch %88
- %88 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func1_before + func2_before,
- defs_after + func1_after + func2_after + output_func, true, true, 7u, 23u,
- false, false, 2u);
- }
- TEST_F(InstBindlessTest, RuntimeArrayV2) {
- // This test verifies that the pass will correctly instrument shader
- // with runtime descriptor array. This test was created by editing the
- // SPIR-V from the Simple test.
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 1
- OpDecorate %g_tColor Binding 2
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 1
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %20 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_rarr_20 = OpTypeRuntimeArray %20
- %_ptr_UniformConstant__arr_20 = OpTypePointer UniformConstant %_rarr_20
- %g_tColor = OpVariable %_ptr_UniformConstant__arr_20 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
- %35 = OpTypeSampler
- %_ptr_UniformConstant_35 = OpTypePointer UniformConstant %35
- %g_sAniso = OpVariable %_ptr_UniformConstant_35 UniformConstant
- %39 = OpTypeSampledImage %20
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %PerViewConstantBuffer_t "PerViewConstantBuffer_t"
- OpMemberName %PerViewConstantBuffer_t 0 "g_nDataIdx"
- OpName %_ ""
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 1
- OpDecorate %g_tColor Binding 2
- OpMemberDecorate %PerViewConstantBuffer_t 0 Offset 0
- OpDecorate %PerViewConstantBuffer_t Block
- OpDecorate %g_sAniso DescriptorSet 1
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_46 Block
- OpMemberDecorate %_struct_46 0 Offset 0
- OpDecorate %48 DescriptorSet 7
- OpDecorate %48 Binding 1
- OpDecorate %_struct_71 Block
- OpMemberDecorate %_struct_71 0 Offset 0
- OpMemberDecorate %_struct_71 1 Offset 4
- OpDecorate %73 DescriptorSet 7
- OpDecorate %73 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %16 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %uint = OpTypeInt 32 0
- %uint_1 = OpConstant %uint 1
- %_runtimearr_16 = OpTypeRuntimeArray %16
- %_ptr_UniformConstant__runtimearr_16 = OpTypePointer UniformConstant %_runtimearr_16
- %g_tColor = OpVariable %_ptr_UniformConstant__runtimearr_16 UniformConstant
- %PerViewConstantBuffer_t = OpTypeStruct %uint
- %_ptr_PushConstant_PerViewConstantBuffer_t = OpTypePointer PushConstant %PerViewConstantBuffer_t
- %_ = OpVariable %_ptr_PushConstant_PerViewConstantBuffer_t PushConstant
- %_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
- %_ptr_UniformConstant_16 = OpTypePointer UniformConstant %16
- %24 = OpTypeSampler
- %_ptr_UniformConstant_24 = OpTypePointer UniformConstant %24
- %g_sAniso = OpVariable %_ptr_UniformConstant_24 UniformConstant
- %26 = OpTypeSampledImage %16
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint_0 = OpConstant %uint 0
- %uint_2 = OpConstant %uint 2
- %41 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_46 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_46 = OpTypePointer StorageBuffer %_struct_46
- %48 = OpVariable %_ptr_StorageBuffer__struct_46 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %65 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_71 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_71 = OpTypePointer StorageBuffer %_struct_71
- %73 = OpVariable %_ptr_StorageBuffer__struct_71 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_59 = OpConstant %uint 59
- %116 = OpConstantNull %v4float
- %119 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %3
- %5 = OpLabel
- %53 = OpLoad %v2float %i_vTextureCoords
- %63 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %64 = OpLoad %uint %63
- %65 = OpAccessChain %_ptr_UniformConstant_20 %g_tColor %64
- %66 = OpLoad %20 %65
- %67 = OpLoad %35 %g_sAniso
- %68 = OpSampledImage %39 %66 %67
- %71 = OpImageSampleImplicitLod %v4float %68 %53
- OpStore %_entryPointOutput_vColor %71
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %10
- %29 = OpLabel
- %30 = OpLoad %v2float %i_vTextureCoords
- %31 = OpAccessChain %_ptr_PushConstant_uint %_ %int_0
- %32 = OpLoad %uint %31
- %33 = OpAccessChain %_ptr_UniformConstant_16 %g_tColor %32
- %34 = OpLoad %16 %33
- %35 = OpLoad %24 %g_sAniso
- %36 = OpSampledImage %26 %34 %35
- %55 = OpFunctionCall %uint %40 %uint_2 %uint_2
- %57 = OpULessThan %bool %32 %55
- OpSelectionMerge %58 None
- OpBranchConditional %57 %59 %60
- %59 = OpLabel
- %61 = OpLoad %16 %33
- %62 = OpSampledImage %26 %61 %35
- %136 = OpFunctionCall %uint %118 %uint_0 %uint_1 %uint_2 %32
- %137 = OpINotEqual %bool %136 %uint_0
- OpSelectionMerge %138 None
- OpBranchConditional %137 %139 %140
- %139 = OpLabel
- %141 = OpLoad %16 %33
- %142 = OpSampledImage %26 %141 %35
- %143 = OpImageSampleImplicitLod %v4float %142 %30
- OpBranch %138
- %140 = OpLabel
- %144 = OpFunctionCall %void %64 %uint_59 %uint_1 %32 %uint_0
- OpBranch %138
- %138 = OpLabel
- %145 = OpPhi %v4float %143 %139 %116 %140
- OpBranch %58
- %60 = OpLabel
- %115 = OpFunctionCall %void %64 %uint_59 %uint_0 %32 %55
- OpBranch %58
- %58 = OpLabel
- %117 = OpPhi %v4float %145 %138 %116 %60
- OpStore %_entryPointOutput_vColor %117
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%40 = OpFunction %uint None %41
- %42 = OpFunctionParameter %uint
- %43 = OpFunctionParameter %uint
- %44 = OpLabel
- %50 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %42
- %51 = OpLoad %uint %50
- %52 = OpIAdd %uint %51 %43
- %53 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %52
- %54 = OpLoad %uint %53
- OpReturnValue %54
- OpFunctionEnd
- %64 = OpFunction %void None %65
- %66 = OpFunctionParameter %uint
- %67 = OpFunctionParameter %uint
- %68 = OpFunctionParameter %uint
- %69 = OpFunctionParameter %uint
- %70 = OpLabel
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_0
- %77 = OpAtomicIAdd %uint %74 %uint_4 %uint_0 %uint_10
- %78 = OpIAdd %uint %77 %uint_10
- %79 = OpArrayLength %uint %73 1
- %80 = OpULessThanEqual %bool %78 %79
- OpSelectionMerge %81 None
- OpBranchConditional %80 %82 %81
- %82 = OpLabel
- %83 = OpIAdd %uint %77 %uint_0
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %83
- OpStore %84 %uint_10
- %86 = OpIAdd %uint %77 %uint_1
- %87 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %86
- OpStore %87 %uint_23
- %88 = OpIAdd %uint %77 %uint_2
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %88
- OpStore %89 %66
- %91 = OpIAdd %uint %77 %uint_3
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %91
- OpStore %92 %uint_4
- %95 = OpLoad %v4float %gl_FragCoord
- %97 = OpBitcast %v4uint %95
- %98 = OpCompositeExtract %uint %97 0
- %99 = OpIAdd %uint %77 %uint_4
- %100 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %99
- OpStore %100 %98
- %101 = OpCompositeExtract %uint %97 1
- %103 = OpIAdd %uint %77 %uint_5
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %103
- OpStore %104 %101
- %106 = OpIAdd %uint %77 %uint_7
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %106
- OpStore %107 %67
- %109 = OpIAdd %uint %77 %uint_8
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %109
- OpStore %110 %68
- %112 = OpIAdd %uint %77 %uint_9
- %113 = OpAccessChain %_ptr_StorageBuffer_uint %73 %uint_1 %112
- OpStore %113 %69
- OpBranch %81
- %81 = OpLabel
- OpReturn
- OpFunctionEnd
- %118 = OpFunction %uint None %119
- %120 = OpFunctionParameter %uint
- %121 = OpFunctionParameter %uint
- %122 = OpFunctionParameter %uint
- %123 = OpFunctionParameter %uint
- %124 = OpLabel
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %120
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %121
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %122
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %130
- %132 = OpLoad %uint %131
- %133 = OpIAdd %uint %132 %123
- %134 = OpAccessChain %_ptr_StorageBuffer_uint %48 %uint_0 %133
- %135 = OpLoad %uint %134
- OpReturnValue %135
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest, InstrumentInitCheckOnScalarDescriptorV2) {
- // This test verifies that the pass will correctly instrument vanilla
- // texture sample on a scalar descriptor with an initialization check if the
- // input_init_enable argument is set to true. This can happen when the
- // descriptor indexing extension is enabled in the API but the SPIR-V
- // does not have the extension enabled because it does not contain a
- // runtime array. This is the same shader as NoInstrumentNonBindless.
- const std::string defs_before =
- R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
- %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %16 = OpTypeSampledImage %12
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %MainPs "MainPs" %i_vTextureCoords %_entryPointOutput_vColor %gl_FragCoord
- OpExecutionMode %MainPs OriginUpperLeft
- OpSource HLSL 500
- OpName %MainPs "MainPs"
- OpName %g_tColor "g_tColor"
- OpName %g_sAniso "g_sAniso"
- OpName %i_vTextureCoords "i.vTextureCoords"
- OpName %_entryPointOutput_vColor "@entryPointOutput.vColor"
- OpDecorate %g_tColor DescriptorSet 0
- OpDecorate %g_tColor Binding 0
- OpDecorate %g_sAniso DescriptorSet 0
- OpDecorate %g_sAniso Binding 0
- OpDecorate %i_vTextureCoords Location 0
- OpDecorate %_entryPointOutput_vColor Location 0
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_35 Block
- OpMemberDecorate %_struct_35 0 Offset 0
- OpDecorate %37 DescriptorSet 7
- OpDecorate %37 Binding 1
- OpDecorate %_struct_67 Block
- OpMemberDecorate %_struct_67 0 Offset 0
- OpMemberDecorate %_struct_67 1 Offset 4
- OpDecorate %69 DescriptorSet 7
- OpDecorate %69 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %8 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %v2float = OpTypeVector %float 2
- %v4float = OpTypeVector %float 4
- %12 = OpTypeImage %float 2D 0 0 0 1 Unknown
- %_ptr_UniformConstant_12 = OpTypePointer UniformConstant %12
- %g_tColor = OpVariable %_ptr_UniformConstant_12 UniformConstant
- %14 = OpTypeSampler
- %_ptr_UniformConstant_14 = OpTypePointer UniformConstant %14
- %g_sAniso = OpVariable %_ptr_UniformConstant_14 UniformConstant
- %16 = OpTypeSampledImage %12
- %_ptr_Input_v2float = OpTypePointer Input %v2float
- %i_vTextureCoords = OpVariable %_ptr_Input_v2float Input
- %_ptr_Output_v4float = OpTypePointer Output %v4float
- %_entryPointOutput_vColor = OpVariable %_ptr_Output_v4float Output
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %28 = OpTypeFunction %uint %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_35 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_35 = OpTypePointer StorageBuffer %_struct_35
- %37 = OpVariable %_ptr_StorageBuffer__struct_35 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %uint_1 = OpConstant %uint 1
- %61 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_67 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_67 = OpTypePointer StorageBuffer %_struct_67
- %69 = OpVariable %_ptr_StorageBuffer__struct_67 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_39 = OpConstant %uint 39
- %113 = OpConstantNull %v4float
- )";
- const std::string func_before =
- R"(%MainPs = OpFunction %void None %8
- %19 = OpLabel
- %20 = OpLoad %v2float %i_vTextureCoords
- %21 = OpLoad %12 %g_tColor
- %22 = OpLoad %14 %g_sAniso
- %23 = OpSampledImage %16 %21 %22
- %24 = OpImageSampleImplicitLod %v4float %23 %20
- OpStore %_entryPointOutput_vColor %24
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%MainPs = OpFunction %void None %8
- %19 = OpLabel
- %20 = OpLoad %v2float %i_vTextureCoords
- %21 = OpLoad %12 %g_tColor
- %22 = OpLoad %14 %g_sAniso
- %23 = OpSampledImage %16 %21 %22
- %50 = OpFunctionCall %uint %27 %uint_0 %uint_0 %uint_0 %uint_0
- %52 = OpINotEqual %bool %50 %uint_0
- OpSelectionMerge %54 None
- OpBranchConditional %52 %55 %56
- %55 = OpLabel
- %57 = OpLoad %12 %g_tColor
- %58 = OpSampledImage %16 %57 %22
- %59 = OpImageSampleImplicitLod %v4float %58 %20
- OpBranch %54
- %56 = OpLabel
- %112 = OpFunctionCall %void %60 %uint_39 %uint_1 %uint_0 %uint_0
- OpBranch %54
- %54 = OpLabel
- %114 = OpPhi %v4float %59 %55 %113 %56
- OpStore %_entryPointOutput_vColor %114
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%27 = OpFunction %uint None %28
- %29 = OpFunctionParameter %uint
- %30 = OpFunctionParameter %uint
- %31 = OpFunctionParameter %uint
- %32 = OpFunctionParameter %uint
- %33 = OpLabel
- %39 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %29
- %40 = OpLoad %uint %39
- %41 = OpIAdd %uint %40 %30
- %42 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %41
- %43 = OpLoad %uint %42
- %44 = OpIAdd %uint %43 %31
- %45 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %44
- %46 = OpLoad %uint %45
- %47 = OpIAdd %uint %46 %32
- %48 = OpAccessChain %_ptr_StorageBuffer_uint %37 %uint_0 %47
- %49 = OpLoad %uint %48
- OpReturnValue %49
- OpFunctionEnd
- %60 = OpFunction %void None %61
- %62 = OpFunctionParameter %uint
- %63 = OpFunctionParameter %uint
- %64 = OpFunctionParameter %uint
- %65 = OpFunctionParameter %uint
- %66 = OpLabel
- %70 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_0
- %73 = OpAtomicIAdd %uint %70 %uint_4 %uint_0 %uint_10
- %74 = OpIAdd %uint %73 %uint_10
- %75 = OpArrayLength %uint %69 1
- %76 = OpULessThanEqual %bool %74 %75
- OpSelectionMerge %77 None
- OpBranchConditional %76 %78 %77
- %78 = OpLabel
- %79 = OpIAdd %uint %73 %uint_0
- %80 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %79
- OpStore %80 %uint_10
- %82 = OpIAdd %uint %73 %uint_1
- %83 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %82
- OpStore %83 %uint_23
- %85 = OpIAdd %uint %73 %uint_2
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %85
- OpStore %86 %62
- %88 = OpIAdd %uint %73 %uint_3
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %88
- OpStore %89 %uint_4
- %92 = OpLoad %v4float %gl_FragCoord
- %94 = OpBitcast %v4uint %92
- %95 = OpCompositeExtract %uint %94 0
- %96 = OpIAdd %uint %73 %uint_4
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %96
- OpStore %97 %95
- %98 = OpCompositeExtract %uint %94 1
- %100 = OpIAdd %uint %73 %uint_5
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %100
- OpStore %101 %98
- %103 = OpIAdd %uint %73 %uint_7
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %103
- OpStore %104 %63
- %106 = OpIAdd %uint %73 %uint_8
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %106
- OpStore %107 %64
- %109 = OpIAdd %uint %73 %uint_9
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %69 %uint_1 %109
- OpStore %110 %65
- OpBranch %77
- %77 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest, SPV14AddToEntryPointV2) {
- const std::string text = R"(
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpDecorate [[v1]] DescriptorSet 7
- ; CHECK: OpDecorate [[v2]] DescriptorSet 7
- ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
- ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
- OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
- OpExecutionMode %foo OriginUpperLeft
- OpDecorate %image_var DescriptorSet 0
- OpDecorate %image_var Binding 0
- OpDecorate %sampler_var DescriptorSet 0
- OpDecorate %sampler_var Binding 1
- OpDecorate %gid DescriptorSet 0
- OpDecorate %gid Binding 2
- OpDecorate %struct Block
- OpMemberDecorate %struct 0 Offset 0
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int_0 = OpConstant %int 0
- %v3int = OpTypeVector %int 3
- %float = OpTypeFloat 32
- %v3float = OpTypeVector %float 3
- %v4float = OpTypeVector %float 4
- %struct = OpTypeStruct %v3int
- %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
- %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
- %gid = OpVariable %ptr_ssbo_struct StorageBuffer
- %image = OpTypeImage %float 3D 0 0 0 1 Unknown
- %ptr_uc_image = OpTypePointer UniformConstant %image
- %sampler = OpTypeSampler
- %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
- %image_var = OpVariable %ptr_uc_image UniformConstant
- %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
- %sampled = OpTypeSampledImage %image
- %void_fn = OpTypeFunction %void
- %foo = OpFunction %void None %void_fn
- %entry = OpLabel
- %ld_image = OpLoad %image %image_var
- %ld_sampler = OpLoad %sampler %sampler_var
- %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
- %ld_gid = OpLoad %v3int %gep
- %convert = OpConvertUToF %v3float %ld_gid
- %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
- %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
- OpReturn
- OpFunctionEnd
- )";
- SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
- 2u);
- }
- TEST_F(InstBindlessTest, SPV14AddToEntryPointsV2) {
- const std::string text = R"(
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "foo" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpEntryPoint Fragment {{%\w+}} "bar" {{%\w+}} {{%\w+}} {{%\w+}} [[v1:%\w+]] [[v2:%\w+]]
- ; CHECK: OpDecorate [[v1]] DescriptorSet 7
- ; CHECK: OpDecorate [[v2]] DescriptorSet 7
- ; CHECK: [[v1]] = OpVariable {{%\w+}} StorageBuffer
- ; CHECK: [[v2]] = OpVariable {{%\w+}} StorageBuffer
- OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %foo "foo" %gid %image_var %sampler_var
- OpEntryPoint Fragment %foo "bar" %gid %image_var %sampler_var
- OpExecutionMode %foo OriginUpperLeft
- OpDecorate %image_var DescriptorSet 0
- OpDecorate %image_var Binding 0
- OpDecorate %sampler_var DescriptorSet 0
- OpDecorate %sampler_var Binding 1
- OpDecorate %gid DescriptorSet 0
- OpDecorate %gid Binding 2
- OpDecorate %struct Block
- OpMemberDecorate %struct 0 Offset 0
- %void = OpTypeVoid
- %int = OpTypeInt 32 0
- %int_0 = OpConstant %int 0
- %v3int = OpTypeVector %int 3
- %float = OpTypeFloat 32
- %v3float = OpTypeVector %float 3
- %v4float = OpTypeVector %float 4
- %struct = OpTypeStruct %v3int
- %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
- %ptr_ssbo_v3int = OpTypePointer StorageBuffer %v3int
- %gid = OpVariable %ptr_ssbo_struct StorageBuffer
- %image = OpTypeImage %float 3D 0 0 0 1 Unknown
- %ptr_uc_image = OpTypePointer UniformConstant %image
- %sampler = OpTypeSampler
- %ptr_uc_sampler = OpTypePointer UniformConstant %sampler
- %image_var = OpVariable %ptr_uc_image UniformConstant
- %sampler_var = OpVariable %ptr_uc_sampler UniformConstant
- %sampled = OpTypeSampledImage %image
- %void_fn = OpTypeFunction %void
- %foo = OpFunction %void None %void_fn
- %entry = OpLabel
- %ld_image = OpLoad %image %image_var
- %ld_sampler = OpLoad %sampler %sampler_var
- %gep = OpAccessChain %ptr_ssbo_v3int %gid %int_0
- %ld_gid = OpLoad %v3int %gep
- %convert = OpConvertUToF %v3float %ld_gid
- %sampled_image = OpSampledImage %sampled %ld_image %ld_sampler
- %sample = OpImageSampleImplicitLod %v4float %sampled_image %convert
- OpReturn
- OpFunctionEnd
- )";
- SetTargetEnv(SPV_ENV_VULKAN_1_1_SPIRV_1_4);
- SinglePassRunAndMatch<InstBindlessCheckPass>(text, true, 7u, 23u, true, true,
- 2u);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedUBOArrayV2) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) uniform uname { float a; } uniformBuffer[];
- //
- // void main()
- // {
- // b = uniformBuffer[nu_ii].a;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_runtimearr_uname = OpTypeRuntimeArray %uname
- %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
- %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %102 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %130 NonUniform
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_runtimearr_uname = OpTypeRuntimeArray %uname
- %_ptr_Uniform__runtimearr_uname = OpTypePointer Uniform %_runtimearr_uname
- %uniformBuffer = OpVariable %_ptr_Uniform__runtimearr_uname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_3 = OpConstant %uint 3
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %49 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_45 = OpConstant %uint 45
- %101 = OpConstantNull %float
- %105 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %19 = OpLabel
- %7 = OpLoad %int %nu_ii
- %20 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %103 = OpBitcast %uint %7
- %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
- %123 = OpINotEqual %bool %122 %uint_0
- OpSelectionMerge %124 None
- OpBranchConditional %123 %125 %126
- %125 = OpLabel
- %127 = OpLoad %float %20
- OpBranch %124
- %126 = OpLabel
- %128 = OpBitcast %uint %7
- %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
- OpBranch %124
- %124 = OpLabel
- %130 = OpPhi %float %127 %125 %101 %126
- OpBranch %43
- %45 = OpLabel
- %47 = OpBitcast %uint %7
- %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
- OpBranch %43
- %43 = OpLabel
- %102 = OpPhi %float %130 %124 %101 %45
- OpStore %b %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %48 = OpFunction %void None %49
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpFunctionParameter %uint
- %54 = OpLabel
- %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_10
- %62 = OpIAdd %uint %61 %uint_10
- %63 = OpArrayLength %uint %57 1
- %64 = OpULessThanEqual %bool %62 %63
- OpSelectionMerge %65 None
- OpBranchConditional %64 %66 %65
- %66 = OpLabel
- %67 = OpIAdd %uint %61 %uint_0
- %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
- OpStore %68 %uint_10
- %70 = OpIAdd %uint %61 %uint_1
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
- OpStore %71 %uint_23
- %73 = OpIAdd %uint %61 %uint_2
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
- OpStore %74 %50
- %75 = OpIAdd %uint %61 %uint_3
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %uint_4
- %80 = OpLoad %v4float %gl_FragCoord
- %82 = OpBitcast %v4uint %80
- %83 = OpCompositeExtract %uint %82 0
- %84 = OpIAdd %uint %61 %uint_4
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
- OpStore %85 %83
- %86 = OpCompositeExtract %uint %82 1
- %88 = OpIAdd %uint %61 %uint_5
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
- OpStore %89 %86
- %91 = OpIAdd %uint %61 %uint_7
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
- OpStore %92 %51
- %94 = OpIAdd %uint %61 %uint_8
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
- OpStore %95 %52
- %97 = OpIAdd %uint %61 %uint_9
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
- OpStore %98 %53
- OpBranch %65
- %65 = OpLabel
- OpReturn
- OpFunctionEnd
- %104 = OpFunction %uint None %105
- %106 = OpFunctionParameter %uint
- %107 = OpFunctionParameter %uint
- %108 = OpFunctionParameter %uint
- %109 = OpFunctionParameter %uint
- %110 = OpLabel
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %107
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %108
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- %119 = OpIAdd %uint %118 %109
- %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
- %121 = OpLoad %uint %120
- OpReturnValue %121
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayDeprecatedV2) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) buffer bname { float b; } storageBuffer[];
- //
- // void main()
- // {
- // b = storageBuffer[nu_ii].b;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %102 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %130 NonUniform
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_3 = OpConstant %uint 3
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %49 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_45 = OpConstant %uint 45
- %101 = OpConstantNull %float
- %105 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %19 = OpLabel
- %7 = OpLoad %int %nu_ii
- %20 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %103 = OpBitcast %uint %7
- %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
- %123 = OpINotEqual %bool %122 %uint_0
- OpSelectionMerge %124 None
- OpBranchConditional %123 %125 %126
- %125 = OpLabel
- %127 = OpLoad %float %20
- OpBranch %124
- %126 = OpLabel
- %128 = OpBitcast %uint %7
- %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
- OpBranch %124
- %124 = OpLabel
- %130 = OpPhi %float %127 %125 %101 %126
- OpBranch %43
- %45 = OpLabel
- %47 = OpBitcast %uint %7
- %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
- OpBranch %43
- %43 = OpLabel
- %102 = OpPhi %float %130 %124 %101 %45
- OpStore %b %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %48 = OpFunction %void None %49
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpFunctionParameter %uint
- %54 = OpLabel
- %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_10
- %62 = OpIAdd %uint %61 %uint_10
- %63 = OpArrayLength %uint %57 1
- %64 = OpULessThanEqual %bool %62 %63
- OpSelectionMerge %65 None
- OpBranchConditional %64 %66 %65
- %66 = OpLabel
- %67 = OpIAdd %uint %61 %uint_0
- %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
- OpStore %68 %uint_10
- %70 = OpIAdd %uint %61 %uint_1
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
- OpStore %71 %uint_23
- %73 = OpIAdd %uint %61 %uint_2
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
- OpStore %74 %50
- %75 = OpIAdd %uint %61 %uint_3
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %uint_4
- %80 = OpLoad %v4float %gl_FragCoord
- %82 = OpBitcast %v4uint %80
- %83 = OpCompositeExtract %uint %82 0
- %84 = OpIAdd %uint %61 %uint_4
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
- OpStore %85 %83
- %86 = OpCompositeExtract %uint %82 1
- %88 = OpIAdd %uint %61 %uint_5
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
- OpStore %89 %86
- %91 = OpIAdd %uint %61 %uint_7
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
- OpStore %92 %51
- %94 = OpIAdd %uint %61 %uint_8
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
- OpStore %95 %52
- %97 = OpIAdd %uint %61 %uint_9
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
- OpStore %98 %53
- OpBranch %65
- %65 = OpLabel
- OpReturn
- OpFunctionEnd
- %104 = OpFunction %uint None %105
- %106 = OpFunctionParameter %uint
- %107 = OpFunctionParameter %uint
- %108 = OpFunctionParameter %uint
- %109 = OpFunctionParameter %uint
- %110 = OpLabel
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %107
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %108
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- %119 = OpIAdd %uint %118 %109
- %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
- %121 = OpLoad %uint %120
- OpReturnValue %121
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest, InstBoundsAndInitLoadUnsizedSSBOArrayV2) {
- // Same as Deprecated but declaring as StorageBuffer Block
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %16 NonUniform
- OpDecorate %20 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %bname "bname"
- OpMemberName %bname 0 "a"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname Block
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %102 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %130 NonUniform
- OpDecorate %_struct_55 Block
- OpMemberDecorate %_struct_55 0 Offset 0
- OpMemberDecorate %_struct_55 1 Offset 4
- OpDecorate %57 DescriptorSet 7
- OpDecorate %57 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %127 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_StorageBuffer__runtimearr_bname = OpTypePointer StorageBuffer %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_StorageBuffer__runtimearr_bname StorageBuffer
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_StorageBuffer_float = OpTypePointer StorageBuffer %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_3 = OpConstant %uint 3
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %49 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_55 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_55 = OpTypePointer StorageBuffer %_struct_55
- %57 = OpVariable %_ptr_StorageBuffer__struct_55 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_45 = OpConstant %uint 45
- %101 = OpConstantNull %float
- %105 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %16 = OpLoad %int %nu_ii
- %19 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %16 %int_0
- %20 = OpLoad %float %19
- OpStore %b %20
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %19 = OpLabel
- %7 = OpLoad %int %nu_ii
- %20 = OpAccessChain %_ptr_StorageBuffer_float %storageBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_3
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %103 = OpBitcast %uint %7
- %122 = OpFunctionCall %uint %104 %uint_0 %uint_0 %uint_3 %103
- %123 = OpINotEqual %bool %122 %uint_0
- OpSelectionMerge %124 None
- OpBranchConditional %123 %125 %126
- %125 = OpLabel
- %127 = OpLoad %float %20
- OpBranch %124
- %126 = OpLabel
- %128 = OpBitcast %uint %7
- %129 = OpFunctionCall %void %48 %uint_45 %uint_1 %128 %uint_0
- OpBranch %124
- %124 = OpLabel
- %130 = OpPhi %float %127 %125 %101 %126
- OpBranch %43
- %45 = OpLabel
- %47 = OpBitcast %uint %7
- %100 = OpFunctionCall %void %48 %uint_45 %uint_0 %47 %40
- OpBranch %43
- %43 = OpLabel
- %102 = OpPhi %float %130 %124 %101 %45
- OpStore %b %102
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %48 = OpFunction %void None %49
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpFunctionParameter %uint
- %54 = OpLabel
- %58 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_0
- %61 = OpAtomicIAdd %uint %58 %uint_4 %uint_0 %uint_10
- %62 = OpIAdd %uint %61 %uint_10
- %63 = OpArrayLength %uint %57 1
- %64 = OpULessThanEqual %bool %62 %63
- OpSelectionMerge %65 None
- OpBranchConditional %64 %66 %65
- %66 = OpLabel
- %67 = OpIAdd %uint %61 %uint_0
- %68 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %67
- OpStore %68 %uint_10
- %70 = OpIAdd %uint %61 %uint_1
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %70
- OpStore %71 %uint_23
- %73 = OpIAdd %uint %61 %uint_2
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %73
- OpStore %74 %50
- %75 = OpIAdd %uint %61 %uint_3
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %75
- OpStore %76 %uint_4
- %80 = OpLoad %v4float %gl_FragCoord
- %82 = OpBitcast %v4uint %80
- %83 = OpCompositeExtract %uint %82 0
- %84 = OpIAdd %uint %61 %uint_4
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %84
- OpStore %85 %83
- %86 = OpCompositeExtract %uint %82 1
- %88 = OpIAdd %uint %61 %uint_5
- %89 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %88
- OpStore %89 %86
- %91 = OpIAdd %uint %61 %uint_7
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %91
- OpStore %92 %51
- %94 = OpIAdd %uint %61 %uint_8
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %94
- OpStore %95 %52
- %97 = OpIAdd %uint %61 %uint_9
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %57 %uint_1 %97
- OpStore %98 %53
- OpBranch %65
- %65 = OpLabel
- OpReturn
- OpFunctionEnd
- %104 = OpFunction %uint None %105
- %106 = OpFunctionParameter %uint
- %107 = OpFunctionParameter %uint
- %108 = OpFunctionParameter %uint
- %109 = OpFunctionParameter %uint
- %110 = OpLabel
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %106
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %107
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %108
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- %119 = OpIAdd %uint %118 %109
- %120 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %119
- %121 = OpLoad %uint %120
- OpReturnValue %121
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest, InstInitLoadUBOScalarV2) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) out float b;
- // layout(binding=3) uniform uname { float a; } uniformBuffer;
- //
- // void main()
- // {
- // b = uniformBuffer.a;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_ptr_Uniform_uname = OpTypePointer Uniform %uname
- %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_28 Block
- OpMemberDecorate %_struct_28 0 Offset 0
- OpDecorate %30 DescriptorSet 7
- OpDecorate %30 Binding 1
- OpDecorate %_struct_58 Block
- OpMemberDecorate %_struct_58 0 Offset 0
- OpMemberDecorate %_struct_58 1 Offset 4
- OpDecorate %60 DescriptorSet 7
- OpDecorate %60 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %7 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %_ptr_Uniform_uname = OpTypePointer Uniform %uname
- %uniformBuffer = OpVariable %_ptr_Uniform_uname Uniform
- %int = OpTypeInt 32 1
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_3 = OpConstant %uint 3
- %21 = OpTypeFunction %uint %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_28 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_28 = OpTypePointer StorageBuffer %_struct_28
- %30 = OpVariable %_ptr_StorageBuffer__struct_28 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %uint_1 = OpConstant %uint 1
- %52 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_58 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_58 = OpTypePointer StorageBuffer %_struct_58
- %60 = OpVariable %_ptr_StorageBuffer__struct_58 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_32 = OpConstant %uint 32
- %104 = OpConstantNull %float
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
- %16 = OpLoad %float %15
- OpStore %b %16
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %7
- %14 = OpLabel
- %15 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %int_0
- %43 = OpFunctionCall %uint %20 %uint_0 %uint_0 %uint_3 %uint_0
- %45 = OpINotEqual %bool %43 %uint_0
- OpSelectionMerge %47 None
- OpBranchConditional %45 %48 %49
- %48 = OpLabel
- %50 = OpLoad %float %15
- OpBranch %47
- %49 = OpLabel
- %103 = OpFunctionCall %void %51 %uint_32 %uint_1 %uint_0 %uint_0
- OpBranch %47
- %47 = OpLabel
- %105 = OpPhi %float %50 %48 %104 %49
- OpStore %b %105
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%20 = OpFunction %uint None %21
- %22 = OpFunctionParameter %uint
- %23 = OpFunctionParameter %uint
- %24 = OpFunctionParameter %uint
- %25 = OpFunctionParameter %uint
- %26 = OpLabel
- %32 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %22
- %33 = OpLoad %uint %32
- %34 = OpIAdd %uint %33 %23
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %34
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %24
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %37
- %39 = OpLoad %uint %38
- %40 = OpIAdd %uint %39 %25
- %41 = OpAccessChain %_ptr_StorageBuffer_uint %30 %uint_0 %40
- %42 = OpLoad %uint %41
- OpReturnValue %42
- OpFunctionEnd
- %51 = OpFunction %void None %52
- %53 = OpFunctionParameter %uint
- %54 = OpFunctionParameter %uint
- %55 = OpFunctionParameter %uint
- %56 = OpFunctionParameter %uint
- %57 = OpLabel
- %61 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_0
- %64 = OpAtomicIAdd %uint %61 %uint_4 %uint_0 %uint_10
- %65 = OpIAdd %uint %64 %uint_10
- %66 = OpArrayLength %uint %60 1
- %67 = OpULessThanEqual %bool %65 %66
- OpSelectionMerge %68 None
- OpBranchConditional %67 %69 %68
- %69 = OpLabel
- %70 = OpIAdd %uint %64 %uint_0
- %71 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %70
- OpStore %71 %uint_10
- %73 = OpIAdd %uint %64 %uint_1
- %74 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %73
- OpStore %74 %uint_23
- %76 = OpIAdd %uint %64 %uint_2
- %77 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %76
- OpStore %77 %53
- %78 = OpIAdd %uint %64 %uint_3
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %78
- OpStore %79 %uint_4
- %83 = OpLoad %v4float %gl_FragCoord
- %85 = OpBitcast %v4uint %83
- %86 = OpCompositeExtract %uint %85 0
- %87 = OpIAdd %uint %64 %uint_4
- %88 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %87
- OpStore %88 %86
- %89 = OpCompositeExtract %uint %85 1
- %91 = OpIAdd %uint %64 %uint_5
- %92 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %91
- OpStore %92 %89
- %94 = OpIAdd %uint %64 %uint_7
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %94
- OpStore %95 %54
- %97 = OpIAdd %uint %64 %uint_8
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %97
- OpStore %98 %55
- %100 = OpIAdd %uint %64 %uint_9
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %60 %uint_1 %100
- OpStore %101 %56
- OpBranch %68
- %68 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest, InstBoundsInitStoreUnsizedSSBOArrayV2) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=1) in float b;
- //
- // layout(binding=4) buffer bname { float b; } storageBuffer[];
- //
- // void main()
- // {
- // storageBuffer[nu_ii].b = b;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %nu_ii %b
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %bname "bname"
- OpMemberName %bname 0 "b"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpName %b "b"
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname BufferBlock
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 4
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %14 NonUniform
- OpDecorate %b Location 1
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Input_float = OpTypePointer Input %float
- %b = OpVariable %_ptr_Input_float Input
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability RuntimeDescriptorArray
- OpCapability StorageBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %nu_ii %b %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %bname "bname"
- OpMemberName %bname 0 "b"
- OpName %storageBuffer "storageBuffer"
- OpName %nu_ii "nu_ii"
- OpName %b "b"
- OpMemberDecorate %bname 0 Offset 0
- OpDecorate %bname BufferBlock
- OpDecorate %storageBuffer DescriptorSet 0
- OpDecorate %storageBuffer Binding 4
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %b Location 1
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_31 Block
- OpMemberDecorate %_struct_31 0 Offset 0
- OpDecorate %33 DescriptorSet 7
- OpDecorate %33 Binding 1
- OpDecorate %_struct_54 Block
- OpMemberDecorate %_struct_54 0 Offset 0
- OpMemberDecorate %_struct_54 1 Offset 4
- OpDecorate %56 DescriptorSet 7
- OpDecorate %56 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- %void = OpTypeVoid
- %9 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %bname = OpTypeStruct %float
- %_runtimearr_bname = OpTypeRuntimeArray %bname
- %_ptr_Uniform__runtimearr_bname = OpTypePointer Uniform %_runtimearr_bname
- %storageBuffer = OpVariable %_ptr_Uniform__runtimearr_bname Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Input_float = OpTypePointer Input %float
- %b = OpVariable %_ptr_Input_float Input
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint = OpTypeInt 32 0
- %uint_0 = OpConstant %uint 0
- %uint_1 = OpConstant %uint 1
- %uint_4 = OpConstant %uint 4
- %26 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_31 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_31 = OpTypePointer StorageBuffer %_struct_31
- %33 = OpVariable %_ptr_StorageBuffer__struct_31 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %48 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_54 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_54 = OpTypePointer StorageBuffer %_struct_54
- %56 = OpVariable %_ptr_StorageBuffer__struct_54 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_45 = OpConstant %uint 45
- %102 = OpTypeFunction %uint %uint %uint %uint %uint
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %14 = OpLoad %int %nu_ii
- %18 = OpLoad %float %b
- %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %14 %int_0
- OpStore %20 %18
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %9
- %18 = OpLabel
- %7 = OpLoad %int %nu_ii
- %19 = OpLoad %float %b
- %20 = OpAccessChain %_ptr_Uniform_float %storageBuffer %7 %int_0
- %40 = OpFunctionCall %uint %25 %uint_1 %uint_4
- %42 = OpULessThan %bool %7 %40
- OpSelectionMerge %43 None
- OpBranchConditional %42 %44 %45
- %44 = OpLabel
- %100 = OpBitcast %uint %7
- %119 = OpFunctionCall %uint %101 %uint_0 %uint_0 %uint_4 %100
- %120 = OpINotEqual %bool %119 %uint_0
- OpSelectionMerge %121 None
- OpBranchConditional %120 %122 %123
- %122 = OpLabel
- OpStore %20 %19
- OpBranch %121
- %123 = OpLabel
- %124 = OpBitcast %uint %7
- %125 = OpFunctionCall %void %47 %uint_45 %uint_1 %124 %uint_0
- OpBranch %121
- %121 = OpLabel
- OpBranch %43
- %45 = OpLabel
- %46 = OpBitcast %uint %7
- %99 = OpFunctionCall %void %47 %uint_45 %uint_0 %46 %40
- OpBranch %43
- %43 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%25 = OpFunction %uint None %26
- %27 = OpFunctionParameter %uint
- %28 = OpFunctionParameter %uint
- %29 = OpLabel
- %35 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %27
- %36 = OpLoad %uint %35
- %37 = OpIAdd %uint %36 %28
- %38 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %37
- %39 = OpLoad %uint %38
- OpReturnValue %39
- OpFunctionEnd
- %47 = OpFunction %void None %48
- %49 = OpFunctionParameter %uint
- %50 = OpFunctionParameter %uint
- %51 = OpFunctionParameter %uint
- %52 = OpFunctionParameter %uint
- %53 = OpLabel
- %57 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_0
- %59 = OpAtomicIAdd %uint %57 %uint_4 %uint_0 %uint_10
- %60 = OpIAdd %uint %59 %uint_10
- %61 = OpArrayLength %uint %56 1
- %62 = OpULessThanEqual %bool %60 %61
- OpSelectionMerge %63 None
- OpBranchConditional %62 %64 %63
- %64 = OpLabel
- %65 = OpIAdd %uint %59 %uint_0
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %65
- OpStore %66 %uint_10
- %68 = OpIAdd %uint %59 %uint_1
- %69 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %68
- OpStore %69 %uint_23
- %71 = OpIAdd %uint %59 %uint_2
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %71
- OpStore %72 %49
- %74 = OpIAdd %uint %59 %uint_3
- %75 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %74
- OpStore %75 %uint_4
- %79 = OpLoad %v4float %gl_FragCoord
- %81 = OpBitcast %v4uint %79
- %82 = OpCompositeExtract %uint %81 0
- %83 = OpIAdd %uint %59 %uint_4
- %84 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %83
- OpStore %84 %82
- %85 = OpCompositeExtract %uint %81 1
- %87 = OpIAdd %uint %59 %uint_5
- %88 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %87
- OpStore %88 %85
- %90 = OpIAdd %uint %59 %uint_7
- %91 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %90
- OpStore %91 %50
- %93 = OpIAdd %uint %59 %uint_8
- %94 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %93
- OpStore %94 %51
- %96 = OpIAdd %uint %59 %uint_9
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %56 %uint_1 %96
- OpStore %97 %52
- OpBranch %63
- %63 = OpLabel
- OpReturn
- OpFunctionEnd
- %101 = OpFunction %uint None %102
- %103 = OpFunctionParameter %uint
- %104 = OpFunctionParameter %uint
- %105 = OpFunctionParameter %uint
- %106 = OpFunctionParameter %uint
- %107 = OpLabel
- %108 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %103
- %109 = OpLoad %uint %108
- %110 = OpIAdd %uint %109 %104
- %111 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %110
- %112 = OpLoad %uint %111
- %113 = OpIAdd %uint %112 %105
- %114 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %113
- %115 = OpLoad %uint %114
- %116 = OpIAdd %uint %115 %106
- %117 = OpAccessChain %_ptr_StorageBuffer_uint %33 %uint_0 %116
- %118 = OpLoad %uint %117
- OpReturnValue %118
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest, InstBoundsInitLoadSizedUBOArrayV2) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout(location=0) in nonuniformEXT flat int nu_ii;
- // layout(location=0) out float b;
- //
- // layout(binding=3) uniform uname { float a; } uniformBuffer[128];
- //
- // void main()
- // {
- // b = uniformBuffer[nu_ii].a;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %18 NonUniform
- OpDecorate %22 NonUniform
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
- %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
- %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability ShaderNonUniform
- OpCapability UniformBufferArrayNonUniformIndexing
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %main "main" %b %nu_ii %gl_FragCoord
- OpExecutionMode %main OriginUpperLeft
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %b "b"
- OpName %uname "uname"
- OpMemberName %uname 0 "a"
- OpName %uniformBuffer "uniformBuffer"
- OpName %nu_ii "nu_ii"
- OpDecorate %b Location 0
- OpMemberDecorate %uname 0 Offset 0
- OpDecorate %uname Block
- OpDecorate %uniformBuffer DescriptorSet 0
- OpDecorate %uniformBuffer Binding 3
- OpDecorate %nu_ii Flat
- OpDecorate %nu_ii Location 0
- OpDecorate %nu_ii NonUniform
- OpDecorate %7 NonUniform
- OpDecorate %89 NonUniform
- OpDecorate %120 NonUniform
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpMemberDecorate %_struct_39 1 Offset 4
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 0
- OpDecorate %gl_FragCoord BuiltIn FragCoord
- OpDecorate %_struct_98 Block
- OpMemberDecorate %_struct_98 0 Offset 0
- OpDecorate %100 DescriptorSet 7
- OpDecorate %100 Binding 1
- OpDecorate %117 NonUniform
- %void = OpTypeVoid
- %10 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %_ptr_Output_float = OpTypePointer Output %float
- %b = OpVariable %_ptr_Output_float Output
- %uname = OpTypeStruct %float
- %uint = OpTypeInt 32 0
- %uint_128 = OpConstant %uint 128
- %_arr_uname_uint_128 = OpTypeArray %uname %uint_128
- %_ptr_Uniform__arr_uname_uint_128 = OpTypePointer Uniform %_arr_uname_uint_128
- %uniformBuffer = OpVariable %_ptr_Uniform__arr_uname_uint_128 Uniform
- %int = OpTypeInt 32 1
- %_ptr_Input_int = OpTypePointer Input %int
- %nu_ii = OpVariable %_ptr_Input_int Input
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_0 = OpConstant %uint 0
- %bool = OpTypeBool
- %32 = OpTypeFunction %void %uint %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_1 = OpConstant %uint 1
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_3 = OpConstant %uint 3
- %v4float = OpTypeVector %float 4
- %_ptr_Input_v4float = OpTypePointer Input %v4float
- %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
- %v4uint = OpTypeVector %uint 4
- %uint_5 = OpConstant %uint 5
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_46 = OpConstant %uint 46
- %88 = OpConstantNull %float
- %92 = OpTypeFunction %uint %uint %uint %uint %uint
- %_struct_98 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_98 = OpTypePointer StorageBuffer %_struct_98
- %100 = OpVariable %_ptr_StorageBuffer__struct_98 StorageBuffer
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %18 = OpLoad %int %nu_ii
- %21 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %18 %int_0
- %22 = OpLoad %float %21
- OpStore %b %22
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %10
- %21 = OpLabel
- %7 = OpLoad %int %nu_ii
- %22 = OpAccessChain %_ptr_Uniform_float %uniformBuffer %7 %int_0
- %25 = OpULessThan %bool %7 %uint_128
- OpSelectionMerge %26 None
- OpBranchConditional %25 %27 %28
- %27 = OpLabel
- %90 = OpBitcast %uint %7
- %112 = OpFunctionCall %uint %91 %uint_0 %uint_0 %uint_3 %90
- %113 = OpINotEqual %bool %112 %uint_0
- OpSelectionMerge %114 None
- OpBranchConditional %113 %115 %116
- %115 = OpLabel
- %117 = OpLoad %float %22
- OpBranch %114
- %116 = OpLabel
- %118 = OpBitcast %uint %7
- %119 = OpFunctionCall %void %31 %uint_46 %uint_1 %118 %uint_0
- OpBranch %114
- %114 = OpLabel
- %120 = OpPhi %float %117 %115 %88 %116
- OpBranch %26
- %28 = OpLabel
- %30 = OpBitcast %uint %7
- %87 = OpFunctionCall %void %31 %uint_46 %uint_0 %30 %uint_128
- OpBranch %26
- %26 = OpLabel
- %89 = OpPhi %float %120 %114 %88 %28
- OpStore %b %89
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%31 = OpFunction %void None %32
- %33 = OpFunctionParameter %uint
- %34 = OpFunctionParameter %uint
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0
- %46 = OpAtomicIAdd %uint %43 %uint_4 %uint_0 %uint_10
- %47 = OpIAdd %uint %46 %uint_10
- %48 = OpArrayLength %uint %41 1
- %49 = OpULessThanEqual %bool %47 %48
- OpSelectionMerge %50 None
- OpBranchConditional %49 %51 %50
- %51 = OpLabel
- %52 = OpIAdd %uint %46 %uint_0
- %54 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %52
- OpStore %54 %uint_10
- %56 = OpIAdd %uint %46 %uint_1
- %57 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %56
- OpStore %57 %uint_23
- %59 = OpIAdd %uint %46 %uint_2
- %60 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %59
- OpStore %60 %33
- %62 = OpIAdd %uint %46 %uint_3
- %63 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %62
- OpStore %63 %uint_4
- %67 = OpLoad %v4float %gl_FragCoord
- %69 = OpBitcast %v4uint %67
- %70 = OpCompositeExtract %uint %69 0
- %71 = OpIAdd %uint %46 %uint_4
- %72 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %71
- OpStore %72 %70
- %73 = OpCompositeExtract %uint %69 1
- %75 = OpIAdd %uint %46 %uint_5
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %75
- OpStore %76 %73
- %78 = OpIAdd %uint %46 %uint_7
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %78
- OpStore %79 %34
- %81 = OpIAdd %uint %46 %uint_8
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %81
- OpStore %82 %35
- %84 = OpIAdd %uint %46 %uint_9
- %85 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_1 %84
- OpStore %85 %36
- OpBranch %50
- %50 = OpLabel
- OpReturn
- OpFunctionEnd
- %91 = OpFunction %uint None %92
- %93 = OpFunctionParameter %uint
- %94 = OpFunctionParameter %uint
- %95 = OpFunctionParameter %uint
- %96 = OpFunctionParameter %uint
- %97 = OpLabel
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %93
- %102 = OpLoad %uint %101
- %103 = OpIAdd %uint %102 %94
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %103
- %105 = OpLoad %uint %104
- %106 = OpIAdd %uint %105 %95
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %106
- %108 = OpLoad %uint %107
- %109 = OpIAdd %uint %108 %96
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %100 %uint_0 %109
- %111 = OpLoad %uint %110
- OpReturnValue %111
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest,
- InstBoundsComputeShaderInitLoadVariableSizedSampledImagesArray) {
- // #version 450
- // #extension GL_EXT_nonuniform_qualifier : enable
- //
- // layout (local_size_x = 1, local_size_y = 1) in;
- //
- // layout(set = 0, binding = 0, std140) buffer Input {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- const std::string defs_before =
- R"(OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main"
- OpExecutionMode %main LocalSize 1 1 1
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %Input "Input"
- OpMemberName %Input 0 "index"
- OpMemberName %Input 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %Input 0 Offset 0
- OpMemberDecorate %Input 1 Offset 4
- OpDecorate %Input BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- %void = OpTypeVoid
- %3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %Input = OpTypeStruct %uint %float
- %_ptr_Uniform_Input = OpTypePointer Uniform %Input
- %sbo = OpVariable %_ptr_Uniform_Input Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- )";
- const std::string defs_after =
- R"(OpCapability Shader
- OpCapability RuntimeDescriptorArray
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
- OpExecutionMode %main LocalSize 1 1 1
- OpSource GLSL 450
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpName %main "main"
- OpName %Input "Input"
- OpMemberName %Input 0 "index"
- OpMemberName %Input 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %Input 0 Offset 0
- OpMemberDecorate %Input 1 Offset 4
- OpDecorate %Input BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 1
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
- %void = OpTypeVoid
- %7 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %Input = OpTypeStruct %uint %float
- %_ptr_Uniform_Input = OpTypePointer Uniform %Input
- %sbo = OpVariable %_ptr_Uniform_Input Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %20 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_1 = OpConstant %uint 1
- %34 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %57 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_5 = OpConstant %uint 5
- %uint_3 = OpConstant %uint 3
- %v3uint = OpTypeVector %uint 3
- %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_50 = OpConstant %uint 50
- %112 = OpConstantNull %v4float
- %115 = OpTypeFunction %uint %uint %uint %uint %uint
- %uint_47 = OpConstant %uint 47
- %140 = OpConstantNull %uint
- %uint_53 = OpConstant %uint 53
- )";
- const std::string func_before =
- R"(%main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%main = OpFunction %void None %7
- %24 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %132 = OpFunctionCall %uint %114 %uint_0 %uint_0 %uint_0 %uint_0
- %133 = OpINotEqual %bool %132 %uint_0
- OpSelectionMerge %134 None
- OpBranchConditional %133 %135 %136
- %135 = OpLabel
- %137 = OpLoad %uint %25
- OpBranch %134
- %136 = OpLabel
- %139 = OpFunctionCall %void %56 %uint_47 %uint_1 %uint_0 %uint_0
- OpBranch %134
- %134 = OpLabel
- %141 = OpPhi %uint %137 %135 %140 %136
- %27 = OpAccessChain %_ptr_UniformConstant_13 %images %141
- %28 = OpLoad %13 %27
- %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
- %50 = OpULessThan %bool %141 %48
- OpSelectionMerge %51 None
- OpBranchConditional %50 %52 %53
- %52 = OpLabel
- %54 = OpLoad %13 %27
- %142 = OpFunctionCall %uint %114 %uint_0 %uint_0 %uint_1 %141
- %143 = OpINotEqual %bool %142 %uint_0
- OpSelectionMerge %144 None
- OpBranchConditional %143 %145 %146
- %145 = OpLabel
- %147 = OpLoad %13 %27
- %148 = OpImageRead %v4float %147 %20
- OpBranch %144
- %146 = OpLabel
- %149 = OpFunctionCall %void %56 %uint_50 %uint_1 %141 %uint_0
- OpBranch %144
- %144 = OpLabel
- %150 = OpPhi %v4float %148 %145 %112 %146
- OpBranch %51
- %53 = OpLabel
- %111 = OpFunctionCall %void %56 %uint_50 %uint_0 %141 %48
- OpBranch %51
- %51 = OpLabel
- %113 = OpPhi %v4float %150 %144 %112 %53
- %30 = OpCompositeExtract %float %113 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- %151 = OpFunctionCall %uint %114 %uint_0 %uint_0 %uint_0 %uint_0
- %152 = OpINotEqual %bool %151 %uint_0
- OpSelectionMerge %153 None
- OpBranchConditional %152 %154 %155
- %154 = OpLabel
- OpStore %31 %30
- OpBranch %153
- %155 = OpLabel
- %157 = OpFunctionCall %void %56 %uint_53 %uint_1 %uint_0 %uint_0
- OpBranch %153
- %153 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%33 = OpFunction %uint None %34
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
- %44 = OpLoad %uint %43
- %45 = OpIAdd %uint %44 %36
- %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
- %47 = OpLoad %uint %46
- OpReturnValue %47
- OpFunctionEnd
- %56 = OpFunction %void None %57
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpFunctionParameter %uint
- %62 = OpLabel
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
- %70 = OpIAdd %uint %69 %uint_10
- %71 = OpArrayLength %uint %65 1
- %72 = OpULessThanEqual %bool %70 %71
- OpSelectionMerge %73 None
- OpBranchConditional %72 %74 %73
- %74 = OpLabel
- %75 = OpIAdd %uint %69 %uint_0
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
- OpStore %76 %uint_10
- %78 = OpIAdd %uint %69 %uint_1
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
- OpStore %79 %uint_23
- %81 = OpIAdd %uint %69 %uint_2
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
- OpStore %82 %58
- %85 = OpIAdd %uint %69 %uint_3
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
- OpStore %86 %uint_5
- %90 = OpLoad %v3uint %gl_GlobalInvocationID
- %91 = OpCompositeExtract %uint %90 0
- %92 = OpCompositeExtract %uint %90 1
- %93 = OpCompositeExtract %uint %90 2
- %94 = OpIAdd %uint %69 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %91
- %96 = OpIAdd %uint %69 %uint_5
- %97 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %96
- OpStore %97 %92
- %99 = OpIAdd %uint %69 %uint_6
- %100 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %99
- OpStore %100 %93
- %102 = OpIAdd %uint %69 %uint_7
- %103 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %102
- OpStore %103 %59
- %105 = OpIAdd %uint %69 %uint_8
- %106 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %105
- OpStore %106 %60
- %108 = OpIAdd %uint %69 %uint_9
- %109 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %108
- OpStore %109 %61
- OpBranch %73
- %73 = OpLabel
- OpReturn
- OpFunctionEnd
- %114 = OpFunction %uint None %115
- %116 = OpFunctionParameter %uint
- %117 = OpFunctionParameter %uint
- %118 = OpFunctionParameter %uint
- %119 = OpFunctionParameter %uint
- %120 = OpLabel
- %121 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %116
- %122 = OpLoad %uint %121
- %123 = OpIAdd %uint %122 %117
- %124 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %123
- %125 = OpLoad %uint %124
- %126 = OpIAdd %uint %125 %118
- %127 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %126
- %128 = OpLoad %uint %127
- %129 = OpIAdd %uint %128 %119
- %130 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %129
- %131 = OpLoad %uint %130
- OpReturnValue %131
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest,
- InstBoundsRayGenerationInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- const std::string defs_before =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint RayGenerationNV %main "main"
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- %void = OpTypeVoid
- )";
- const std::string defs_after =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint RayGenerationNV %main "main" %89
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 1
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %89 BuiltIn LaunchIdNV
- %void = OpTypeVoid
- )";
- const std::string func_before =
- R"(%3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%7 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %20 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_1 = OpConstant %uint 1
- %34 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %57 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_5313 = OpConstant %uint 5313
- %uint_3 = OpConstant %uint 3
- %v3uint = OpTypeVector %uint 3
- %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- %89 = OpVariable %_ptr_Input_v3uint Input
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- %113 = OpConstantNull %v4float
- %116 = OpTypeFunction %uint %uint %uint %uint %uint
- %uint_48 = OpConstant %uint 48
- %141 = OpConstantNull %uint
- %uint_54 = OpConstant %uint 54
- %main = OpFunction %void None %7
- %24 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %134 = OpINotEqual %bool %133 %uint_0
- OpSelectionMerge %135 None
- OpBranchConditional %134 %136 %137
- %136 = OpLabel
- %138 = OpLoad %uint %25
- OpBranch %135
- %137 = OpLabel
- %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
- OpBranch %135
- %135 = OpLabel
- %142 = OpPhi %uint %138 %136 %141 %137
- %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- %28 = OpLoad %13 %27
- %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
- %50 = OpULessThan %bool %142 %48
- OpSelectionMerge %51 None
- OpBranchConditional %50 %52 %53
- %52 = OpLabel
- %54 = OpLoad %13 %27
- %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
- %144 = OpINotEqual %bool %143 %uint_0
- OpSelectionMerge %145 None
- OpBranchConditional %144 %146 %147
- %146 = OpLabel
- %148 = OpLoad %13 %27
- %149 = OpImageRead %v4float %148 %20
- OpBranch %145
- %147 = OpLabel
- %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
- OpBranch %145
- %145 = OpLabel
- %151 = OpPhi %v4float %149 %146 %113 %147
- OpBranch %51
- %53 = OpLabel
- %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
- OpBranch %51
- %51 = OpLabel
- %114 = OpPhi %v4float %151 %145 %113 %53
- %30 = OpCompositeExtract %float %114 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %153 = OpINotEqual %bool %152 %uint_0
- OpSelectionMerge %154 None
- OpBranchConditional %153 %155 %156
- %155 = OpLabel
- OpStore %31 %30
- OpBranch %154
- %156 = OpLabel
- %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
- OpBranch %154
- %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%33 = OpFunction %uint None %34
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
- %44 = OpLoad %uint %43
- %45 = OpIAdd %uint %44 %36
- %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
- %47 = OpLoad %uint %46
- OpReturnValue %47
- OpFunctionEnd
- %56 = OpFunction %void None %57
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpFunctionParameter %uint
- %62 = OpLabel
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
- %70 = OpIAdd %uint %69 %uint_10
- %71 = OpArrayLength %uint %65 1
- %72 = OpULessThanEqual %bool %70 %71
- OpSelectionMerge %73 None
- OpBranchConditional %72 %74 %73
- %74 = OpLabel
- %75 = OpIAdd %uint %69 %uint_0
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
- OpStore %76 %uint_10
- %78 = OpIAdd %uint %69 %uint_1
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
- OpStore %79 %uint_23
- %81 = OpIAdd %uint %69 %uint_2
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
- OpStore %82 %58
- %85 = OpIAdd %uint %69 %uint_3
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
- OpStore %86 %uint_5313
- %90 = OpLoad %v3uint %89
- %91 = OpCompositeExtract %uint %90 0
- %92 = OpCompositeExtract %uint %90 1
- %93 = OpCompositeExtract %uint %90 2
- %94 = OpIAdd %uint %69 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %91
- %97 = OpIAdd %uint %69 %uint_5
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
- OpStore %98 %92
- %100 = OpIAdd %uint %69 %uint_6
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
- OpStore %101 %93
- %103 = OpIAdd %uint %69 %uint_7
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
- OpStore %104 %59
- %106 = OpIAdd %uint %69 %uint_8
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
- OpStore %107 %60
- %109 = OpIAdd %uint %69 %uint_9
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
- OpStore %110 %61
- OpBranch %73
- %73 = OpLabel
- OpReturn
- OpFunctionEnd
- %115 = OpFunction %uint None %116
- %117 = OpFunctionParameter %uint
- %118 = OpFunctionParameter %uint
- %119 = OpFunctionParameter %uint
- %120 = OpFunctionParameter %uint
- %121 = OpLabel
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
- %123 = OpLoad %uint %122
- %124 = OpIAdd %uint %123 %118
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %119
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %120
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
- %132 = OpLoad %uint %131
- OpReturnValue %132
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest,
- InstBoundsIntersectionInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- const std::string defs_before =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint IntersectionNV %main "main"
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- %void = OpTypeVoid
- )";
- const std::string defs_after =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint IntersectionNV %main "main" %89
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 1
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %89 BuiltIn LaunchIdNV
- %void = OpTypeVoid
- )";
- const std::string func_before =
- R"(%3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%7 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %20 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_1 = OpConstant %uint 1
- %34 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %57 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_5314 = OpConstant %uint 5314
- %uint_3 = OpConstant %uint 3
- %v3uint = OpTypeVector %uint 3
- %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- %89 = OpVariable %_ptr_Input_v3uint Input
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- %113 = OpConstantNull %v4float
- %116 = OpTypeFunction %uint %uint %uint %uint %uint
- %uint_48 = OpConstant %uint 48
- %141 = OpConstantNull %uint
- %uint_54 = OpConstant %uint 54
- %main = OpFunction %void None %7
- %24 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %134 = OpINotEqual %bool %133 %uint_0
- OpSelectionMerge %135 None
- OpBranchConditional %134 %136 %137
- %136 = OpLabel
- %138 = OpLoad %uint %25
- OpBranch %135
- %137 = OpLabel
- %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
- OpBranch %135
- %135 = OpLabel
- %142 = OpPhi %uint %138 %136 %141 %137
- %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- %28 = OpLoad %13 %27
- %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
- %50 = OpULessThan %bool %142 %48
- OpSelectionMerge %51 None
- OpBranchConditional %50 %52 %53
- %52 = OpLabel
- %54 = OpLoad %13 %27
- %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
- %144 = OpINotEqual %bool %143 %uint_0
- OpSelectionMerge %145 None
- OpBranchConditional %144 %146 %147
- %146 = OpLabel
- %148 = OpLoad %13 %27
- %149 = OpImageRead %v4float %148 %20
- OpBranch %145
- %147 = OpLabel
- %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
- OpBranch %145
- %145 = OpLabel
- %151 = OpPhi %v4float %149 %146 %113 %147
- OpBranch %51
- %53 = OpLabel
- %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
- OpBranch %51
- %51 = OpLabel
- %114 = OpPhi %v4float %151 %145 %113 %53
- %30 = OpCompositeExtract %float %114 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %153 = OpINotEqual %bool %152 %uint_0
- OpSelectionMerge %154 None
- OpBranchConditional %153 %155 %156
- %155 = OpLabel
- OpStore %31 %30
- OpBranch %154
- %156 = OpLabel
- %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
- OpBranch %154
- %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%33 = OpFunction %uint None %34
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
- %44 = OpLoad %uint %43
- %45 = OpIAdd %uint %44 %36
- %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
- %47 = OpLoad %uint %46
- OpReturnValue %47
- OpFunctionEnd
- %56 = OpFunction %void None %57
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpFunctionParameter %uint
- %62 = OpLabel
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
- %70 = OpIAdd %uint %69 %uint_10
- %71 = OpArrayLength %uint %65 1
- %72 = OpULessThanEqual %bool %70 %71
- OpSelectionMerge %73 None
- OpBranchConditional %72 %74 %73
- %74 = OpLabel
- %75 = OpIAdd %uint %69 %uint_0
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
- OpStore %76 %uint_10
- %78 = OpIAdd %uint %69 %uint_1
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
- OpStore %79 %uint_23
- %81 = OpIAdd %uint %69 %uint_2
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
- OpStore %82 %58
- %85 = OpIAdd %uint %69 %uint_3
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
- OpStore %86 %uint_5314
- %90 = OpLoad %v3uint %89
- %91 = OpCompositeExtract %uint %90 0
- %92 = OpCompositeExtract %uint %90 1
- %93 = OpCompositeExtract %uint %90 2
- %94 = OpIAdd %uint %69 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %91
- %97 = OpIAdd %uint %69 %uint_5
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
- OpStore %98 %92
- %100 = OpIAdd %uint %69 %uint_6
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
- OpStore %101 %93
- %103 = OpIAdd %uint %69 %uint_7
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
- OpStore %104 %59
- %106 = OpIAdd %uint %69 %uint_8
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
- OpStore %107 %60
- %109 = OpIAdd %uint %69 %uint_9
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
- OpStore %110 %61
- OpBranch %73
- %73 = OpLabel
- OpReturn
- OpFunctionEnd
- %115 = OpFunction %uint None %116
- %117 = OpFunctionParameter %uint
- %118 = OpFunctionParameter %uint
- %119 = OpFunctionParameter %uint
- %120 = OpFunctionParameter %uint
- %121 = OpLabel
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
- %123 = OpLoad %uint %122
- %124 = OpIAdd %uint %123 %118
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %119
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %120
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
- %132 = OpLoad %uint %131
- OpReturnValue %132
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest,
- InstBoundsAnyHitInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- const std::string defs_before =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint AnyHitNV %main "main"
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- %void = OpTypeVoid
- )";
- const std::string defs_after =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint AnyHitNV %main "main" %89
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 1
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %89 BuiltIn LaunchIdNV
- %void = OpTypeVoid
- )";
- const std::string func_before =
- R"(%3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%7 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %20 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_1 = OpConstant %uint 1
- %34 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %57 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_5315 = OpConstant %uint 5315
- %uint_3 = OpConstant %uint 3
- %v3uint = OpTypeVector %uint 3
- %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- %89 = OpVariable %_ptr_Input_v3uint Input
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- %113 = OpConstantNull %v4float
- %116 = OpTypeFunction %uint %uint %uint %uint %uint
- %uint_48 = OpConstant %uint 48
- %141 = OpConstantNull %uint
- %uint_54 = OpConstant %uint 54
- %main = OpFunction %void None %7
- %24 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %134 = OpINotEqual %bool %133 %uint_0
- OpSelectionMerge %135 None
- OpBranchConditional %134 %136 %137
- %136 = OpLabel
- %138 = OpLoad %uint %25
- OpBranch %135
- %137 = OpLabel
- %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
- OpBranch %135
- %135 = OpLabel
- %142 = OpPhi %uint %138 %136 %141 %137
- %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- %28 = OpLoad %13 %27
- %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
- %50 = OpULessThan %bool %142 %48
- OpSelectionMerge %51 None
- OpBranchConditional %50 %52 %53
- %52 = OpLabel
- %54 = OpLoad %13 %27
- %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
- %144 = OpINotEqual %bool %143 %uint_0
- OpSelectionMerge %145 None
- OpBranchConditional %144 %146 %147
- %146 = OpLabel
- %148 = OpLoad %13 %27
- %149 = OpImageRead %v4float %148 %20
- OpBranch %145
- %147 = OpLabel
- %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
- OpBranch %145
- %145 = OpLabel
- %151 = OpPhi %v4float %149 %146 %113 %147
- OpBranch %51
- %53 = OpLabel
- %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
- OpBranch %51
- %51 = OpLabel
- %114 = OpPhi %v4float %151 %145 %113 %53
- %30 = OpCompositeExtract %float %114 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %153 = OpINotEqual %bool %152 %uint_0
- OpSelectionMerge %154 None
- OpBranchConditional %153 %155 %156
- %155 = OpLabel
- OpStore %31 %30
- OpBranch %154
- %156 = OpLabel
- %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
- OpBranch %154
- %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%33 = OpFunction %uint None %34
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
- %44 = OpLoad %uint %43
- %45 = OpIAdd %uint %44 %36
- %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
- %47 = OpLoad %uint %46
- OpReturnValue %47
- OpFunctionEnd
- %56 = OpFunction %void None %57
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpFunctionParameter %uint
- %62 = OpLabel
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
- %70 = OpIAdd %uint %69 %uint_10
- %71 = OpArrayLength %uint %65 1
- %72 = OpULessThanEqual %bool %70 %71
- OpSelectionMerge %73 None
- OpBranchConditional %72 %74 %73
- %74 = OpLabel
- %75 = OpIAdd %uint %69 %uint_0
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
- OpStore %76 %uint_10
- %78 = OpIAdd %uint %69 %uint_1
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
- OpStore %79 %uint_23
- %81 = OpIAdd %uint %69 %uint_2
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
- OpStore %82 %58
- %85 = OpIAdd %uint %69 %uint_3
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
- OpStore %86 %uint_5315
- %90 = OpLoad %v3uint %89
- %91 = OpCompositeExtract %uint %90 0
- %92 = OpCompositeExtract %uint %90 1
- %93 = OpCompositeExtract %uint %90 2
- %94 = OpIAdd %uint %69 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %91
- %97 = OpIAdd %uint %69 %uint_5
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
- OpStore %98 %92
- %100 = OpIAdd %uint %69 %uint_6
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
- OpStore %101 %93
- %103 = OpIAdd %uint %69 %uint_7
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
- OpStore %104 %59
- %106 = OpIAdd %uint %69 %uint_8
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
- OpStore %107 %60
- %109 = OpIAdd %uint %69 %uint_9
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
- OpStore %110 %61
- OpBranch %73
- %73 = OpLabel
- OpReturn
- OpFunctionEnd
- %115 = OpFunction %uint None %116
- %117 = OpFunctionParameter %uint
- %118 = OpFunctionParameter %uint
- %119 = OpFunctionParameter %uint
- %120 = OpFunctionParameter %uint
- %121 = OpLabel
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
- %123 = OpLoad %uint %122
- %124 = OpIAdd %uint %123 %118
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %119
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %120
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
- %132 = OpLoad %uint %131
- OpReturnValue %132
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest,
- InstBoundsClosestHitInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- const std::string defs_before =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint ClosestHitNV %main "main"
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- %void = OpTypeVoid
- )";
- const std::string defs_after =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint ClosestHitNV %main "main" %89
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 1
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %89 BuiltIn LaunchIdNV
- %void = OpTypeVoid
- )";
- const std::string func_before =
- R"(%3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%7 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %20 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_1 = OpConstant %uint 1
- %34 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %57 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_5316 = OpConstant %uint 5316
- %uint_3 = OpConstant %uint 3
- %v3uint = OpTypeVector %uint 3
- %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- %89 = OpVariable %_ptr_Input_v3uint Input
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- %113 = OpConstantNull %v4float
- %116 = OpTypeFunction %uint %uint %uint %uint %uint
- %uint_48 = OpConstant %uint 48
- %141 = OpConstantNull %uint
- %uint_54 = OpConstant %uint 54
- %main = OpFunction %void None %7
- %24 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %134 = OpINotEqual %bool %133 %uint_0
- OpSelectionMerge %135 None
- OpBranchConditional %134 %136 %137
- %136 = OpLabel
- %138 = OpLoad %uint %25
- OpBranch %135
- %137 = OpLabel
- %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
- OpBranch %135
- %135 = OpLabel
- %142 = OpPhi %uint %138 %136 %141 %137
- %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- %28 = OpLoad %13 %27
- %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
- %50 = OpULessThan %bool %142 %48
- OpSelectionMerge %51 None
- OpBranchConditional %50 %52 %53
- %52 = OpLabel
- %54 = OpLoad %13 %27
- %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
- %144 = OpINotEqual %bool %143 %uint_0
- OpSelectionMerge %145 None
- OpBranchConditional %144 %146 %147
- %146 = OpLabel
- %148 = OpLoad %13 %27
- %149 = OpImageRead %v4float %148 %20
- OpBranch %145
- %147 = OpLabel
- %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
- OpBranch %145
- %145 = OpLabel
- %151 = OpPhi %v4float %149 %146 %113 %147
- OpBranch %51
- %53 = OpLabel
- %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
- OpBranch %51
- %51 = OpLabel
- %114 = OpPhi %v4float %151 %145 %113 %53
- %30 = OpCompositeExtract %float %114 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %153 = OpINotEqual %bool %152 %uint_0
- OpSelectionMerge %154 None
- OpBranchConditional %153 %155 %156
- %155 = OpLabel
- OpStore %31 %30
- OpBranch %154
- %156 = OpLabel
- %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
- OpBranch %154
- %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%33 = OpFunction %uint None %34
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
- %44 = OpLoad %uint %43
- %45 = OpIAdd %uint %44 %36
- %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
- %47 = OpLoad %uint %46
- OpReturnValue %47
- OpFunctionEnd
- %56 = OpFunction %void None %57
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpFunctionParameter %uint
- %62 = OpLabel
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
- %70 = OpIAdd %uint %69 %uint_10
- %71 = OpArrayLength %uint %65 1
- %72 = OpULessThanEqual %bool %70 %71
- OpSelectionMerge %73 None
- OpBranchConditional %72 %74 %73
- %74 = OpLabel
- %75 = OpIAdd %uint %69 %uint_0
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
- OpStore %76 %uint_10
- %78 = OpIAdd %uint %69 %uint_1
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
- OpStore %79 %uint_23
- %81 = OpIAdd %uint %69 %uint_2
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
- OpStore %82 %58
- %85 = OpIAdd %uint %69 %uint_3
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
- OpStore %86 %uint_5316
- %90 = OpLoad %v3uint %89
- %91 = OpCompositeExtract %uint %90 0
- %92 = OpCompositeExtract %uint %90 1
- %93 = OpCompositeExtract %uint %90 2
- %94 = OpIAdd %uint %69 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %91
- %97 = OpIAdd %uint %69 %uint_5
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
- OpStore %98 %92
- %100 = OpIAdd %uint %69 %uint_6
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
- OpStore %101 %93
- %103 = OpIAdd %uint %69 %uint_7
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
- OpStore %104 %59
- %106 = OpIAdd %uint %69 %uint_8
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
- OpStore %107 %60
- %109 = OpIAdd %uint %69 %uint_9
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
- OpStore %110 %61
- OpBranch %73
- %73 = OpLabel
- OpReturn
- OpFunctionEnd
- %115 = OpFunction %uint None %116
- %117 = OpFunctionParameter %uint
- %118 = OpFunctionParameter %uint
- %119 = OpFunctionParameter %uint
- %120 = OpFunctionParameter %uint
- %121 = OpLabel
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
- %123 = OpLoad %uint %122
- %124 = OpIAdd %uint %123 %118
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %119
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %120
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
- %132 = OpLoad %uint %131
- OpReturnValue %132
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest,
- InstBoundsMissInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- const std::string defs_before =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint MissNV %main "main"
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- %void = OpTypeVoid
- )";
- const std::string defs_after =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint MissNV %main "main" %89
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 1
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %89 BuiltIn LaunchIdNV
- %void = OpTypeVoid
- )";
- const std::string func_before =
- R"(%3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%7 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %20 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_1 = OpConstant %uint 1
- %34 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %57 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_5317 = OpConstant %uint 5317
- %uint_3 = OpConstant %uint 3
- %v3uint = OpTypeVector %uint 3
- %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- %89 = OpVariable %_ptr_Input_v3uint Input
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- %113 = OpConstantNull %v4float
- %116 = OpTypeFunction %uint %uint %uint %uint %uint
- %uint_48 = OpConstant %uint 48
- %141 = OpConstantNull %uint
- %uint_54 = OpConstant %uint 54
- %main = OpFunction %void None %7
- %24 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %134 = OpINotEqual %bool %133 %uint_0
- OpSelectionMerge %135 None
- OpBranchConditional %134 %136 %137
- %136 = OpLabel
- %138 = OpLoad %uint %25
- OpBranch %135
- %137 = OpLabel
- %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
- OpBranch %135
- %135 = OpLabel
- %142 = OpPhi %uint %138 %136 %141 %137
- %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- %28 = OpLoad %13 %27
- %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
- %50 = OpULessThan %bool %142 %48
- OpSelectionMerge %51 None
- OpBranchConditional %50 %52 %53
- %52 = OpLabel
- %54 = OpLoad %13 %27
- %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
- %144 = OpINotEqual %bool %143 %uint_0
- OpSelectionMerge %145 None
- OpBranchConditional %144 %146 %147
- %146 = OpLabel
- %148 = OpLoad %13 %27
- %149 = OpImageRead %v4float %148 %20
- OpBranch %145
- %147 = OpLabel
- %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
- OpBranch %145
- %145 = OpLabel
- %151 = OpPhi %v4float %149 %146 %113 %147
- OpBranch %51
- %53 = OpLabel
- %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
- OpBranch %51
- %51 = OpLabel
- %114 = OpPhi %v4float %151 %145 %113 %53
- %30 = OpCompositeExtract %float %114 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %153 = OpINotEqual %bool %152 %uint_0
- OpSelectionMerge %154 None
- OpBranchConditional %153 %155 %156
- %155 = OpLabel
- OpStore %31 %30
- OpBranch %154
- %156 = OpLabel
- %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
- OpBranch %154
- %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%33 = OpFunction %uint None %34
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
- %44 = OpLoad %uint %43
- %45 = OpIAdd %uint %44 %36
- %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
- %47 = OpLoad %uint %46
- OpReturnValue %47
- OpFunctionEnd
- %56 = OpFunction %void None %57
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpFunctionParameter %uint
- %62 = OpLabel
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
- %70 = OpIAdd %uint %69 %uint_10
- %71 = OpArrayLength %uint %65 1
- %72 = OpULessThanEqual %bool %70 %71
- OpSelectionMerge %73 None
- OpBranchConditional %72 %74 %73
- %74 = OpLabel
- %75 = OpIAdd %uint %69 %uint_0
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
- OpStore %76 %uint_10
- %78 = OpIAdd %uint %69 %uint_1
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
- OpStore %79 %uint_23
- %81 = OpIAdd %uint %69 %uint_2
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
- OpStore %82 %58
- %85 = OpIAdd %uint %69 %uint_3
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
- OpStore %86 %uint_5317
- %90 = OpLoad %v3uint %89
- %91 = OpCompositeExtract %uint %90 0
- %92 = OpCompositeExtract %uint %90 1
- %93 = OpCompositeExtract %uint %90 2
- %94 = OpIAdd %uint %69 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %91
- %97 = OpIAdd %uint %69 %uint_5
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
- OpStore %98 %92
- %100 = OpIAdd %uint %69 %uint_6
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
- OpStore %101 %93
- %103 = OpIAdd %uint %69 %uint_7
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
- OpStore %104 %59
- %106 = OpIAdd %uint %69 %uint_8
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
- OpStore %107 %60
- %109 = OpIAdd %uint %69 %uint_9
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
- OpStore %110 %61
- OpBranch %73
- %73 = OpLabel
- OpReturn
- OpFunctionEnd
- %115 = OpFunction %uint None %116
- %117 = OpFunctionParameter %uint
- %118 = OpFunctionParameter %uint
- %119 = OpFunctionParameter %uint
- %120 = OpFunctionParameter %uint
- %121 = OpLabel
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
- %123 = OpLoad %uint %122
- %124 = OpIAdd %uint %123 %118
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %119
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %120
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
- %132 = OpLoad %uint %131
- OpReturnValue %132
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- TEST_F(InstBindlessTest,
- InstBoundsCallableInitLoadVariableSizedSampledImagesArray) {
- // #version 460
- // #extension GL_EXT_nonuniform_qualifier : require
- // #extension GL_NV_ray_tracing : require
- //
- // layout(set = 0, binding = 0, std140) buffer StorageBuffer {
- // uint index;
- // float red;
- // } sbo;
- //
- // layout(set = 0, binding = 1, rgba32f) readonly uniform image2D images[];
- //
- // void main()
- // {
- // sbo.red = imageLoad(images[sbo.index], ivec2(0, 0)).r;
- // }
- const std::string defs_before =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint CallableNV %main "main"
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- %void = OpTypeVoid
- )";
- const std::string defs_after =
- R"(OpCapability RuntimeDescriptorArray
- OpCapability RayTracingNV
- OpExtension "SPV_EXT_descriptor_indexing"
- OpExtension "SPV_NV_ray_tracing"
- OpExtension "SPV_KHR_storage_buffer_storage_class"
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint CallableNV %main "main" %89
- OpSource GLSL 460
- OpSourceExtension "GL_EXT_nonuniform_qualifier"
- OpSourceExtension "GL_NV_ray_tracing"
- OpName %main "main"
- OpName %StorageBuffer "StorageBuffer"
- OpMemberName %StorageBuffer 0 "index"
- OpMemberName %StorageBuffer 1 "red"
- OpName %sbo "sbo"
- OpName %images "images"
- OpMemberDecorate %StorageBuffer 0 Offset 0
- OpMemberDecorate %StorageBuffer 1 Offset 4
- OpDecorate %StorageBuffer BufferBlock
- OpDecorate %sbo DescriptorSet 0
- OpDecorate %sbo Binding 0
- OpDecorate %images DescriptorSet 0
- OpDecorate %images Binding 1
- OpDecorate %images NonWritable
- OpDecorate %_runtimearr_uint ArrayStride 4
- OpDecorate %_struct_39 Block
- OpMemberDecorate %_struct_39 0 Offset 0
- OpDecorate %41 DescriptorSet 7
- OpDecorate %41 Binding 1
- OpDecorate %_struct_63 Block
- OpMemberDecorate %_struct_63 0 Offset 0
- OpMemberDecorate %_struct_63 1 Offset 4
- OpDecorate %65 DescriptorSet 7
- OpDecorate %65 Binding 0
- OpDecorate %89 BuiltIn LaunchIdNV
- %void = OpTypeVoid
- )";
- const std::string func_before =
- R"(%3 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %25 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %main = OpFunction %void None %3
- %5 = OpLabel
- %19 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %20 = OpLoad %uint %19
- %22 = OpAccessChain %_ptr_UniformConstant_13 %images %20
- %23 = OpLoad %13 %22
- %27 = OpImageRead %v4float %23 %25
- %29 = OpCompositeExtract %float %27 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- OpStore %31 %29
- OpReturn
- OpFunctionEnd
- )";
- const std::string func_after =
- R"(%7 = OpTypeFunction %void
- %uint = OpTypeInt 32 0
- %float = OpTypeFloat 32
- %StorageBuffer = OpTypeStruct %uint %float
- %_ptr_Uniform_StorageBuffer = OpTypePointer Uniform %StorageBuffer
- %sbo = OpVariable %_ptr_Uniform_StorageBuffer Uniform
- %int = OpTypeInt 32 1
- %int_1 = OpConstant %int 1
- %13 = OpTypeImage %float 2D 0 0 0 2 Rgba32f
- %_runtimearr_13 = OpTypeRuntimeArray %13
- %_ptr_UniformConstant__runtimearr_13 = OpTypePointer UniformConstant %_runtimearr_13
- %images = OpVariable %_ptr_UniformConstant__runtimearr_13 UniformConstant
- %int_0 = OpConstant %int 0
- %_ptr_Uniform_uint = OpTypePointer Uniform %uint
- %_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
- %v2int = OpTypeVector %int 2
- %20 = OpConstantComposite %v2int %int_0 %int_0
- %v4float = OpTypeVector %float 4
- %uint_0 = OpConstant %uint 0
- %_ptr_Uniform_float = OpTypePointer Uniform %float
- %uint_1 = OpConstant %uint 1
- %34 = OpTypeFunction %uint %uint %uint
- %_runtimearr_uint = OpTypeRuntimeArray %uint
- %_struct_39 = OpTypeStruct %_runtimearr_uint
- %_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
- %41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
- %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
- %bool = OpTypeBool
- %57 = OpTypeFunction %void %uint %uint %uint %uint
- %_struct_63 = OpTypeStruct %uint %_runtimearr_uint
- %_ptr_StorageBuffer__struct_63 = OpTypePointer StorageBuffer %_struct_63
- %65 = OpVariable %_ptr_StorageBuffer__struct_63 StorageBuffer
- %uint_10 = OpConstant %uint 10
- %uint_4 = OpConstant %uint 4
- %uint_23 = OpConstant %uint 23
- %uint_2 = OpConstant %uint 2
- %uint_5318 = OpConstant %uint 5318
- %uint_3 = OpConstant %uint 3
- %v3uint = OpTypeVector %uint 3
- %_ptr_Input_v3uint = OpTypePointer Input %v3uint
- %89 = OpVariable %_ptr_Input_v3uint Input
- %uint_5 = OpConstant %uint 5
- %uint_6 = OpConstant %uint 6
- %uint_7 = OpConstant %uint 7
- %uint_8 = OpConstant %uint 8
- %uint_9 = OpConstant %uint 9
- %uint_51 = OpConstant %uint 51
- %113 = OpConstantNull %v4float
- %116 = OpTypeFunction %uint %uint %uint %uint %uint
- %uint_48 = OpConstant %uint 48
- %141 = OpConstantNull %uint
- %uint_54 = OpConstant %uint 54
- %main = OpFunction %void None %7
- %24 = OpLabel
- %25 = OpAccessChain %_ptr_Uniform_uint %sbo %int_0
- %133 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %134 = OpINotEqual %bool %133 %uint_0
- OpSelectionMerge %135 None
- OpBranchConditional %134 %136 %137
- %136 = OpLabel
- %138 = OpLoad %uint %25
- OpBranch %135
- %137 = OpLabel
- %140 = OpFunctionCall %void %56 %uint_48 %uint_1 %uint_0 %uint_0
- OpBranch %135
- %135 = OpLabel
- %142 = OpPhi %uint %138 %136 %141 %137
- %27 = OpAccessChain %_ptr_UniformConstant_13 %images %142
- %28 = OpLoad %13 %27
- %48 = OpFunctionCall %uint %33 %uint_1 %uint_1
- %50 = OpULessThan %bool %142 %48
- OpSelectionMerge %51 None
- OpBranchConditional %50 %52 %53
- %52 = OpLabel
- %54 = OpLoad %13 %27
- %143 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_1 %142
- %144 = OpINotEqual %bool %143 %uint_0
- OpSelectionMerge %145 None
- OpBranchConditional %144 %146 %147
- %146 = OpLabel
- %148 = OpLoad %13 %27
- %149 = OpImageRead %v4float %148 %20
- OpBranch %145
- %147 = OpLabel
- %150 = OpFunctionCall %void %56 %uint_51 %uint_1 %142 %uint_0
- OpBranch %145
- %145 = OpLabel
- %151 = OpPhi %v4float %149 %146 %113 %147
- OpBranch %51
- %53 = OpLabel
- %112 = OpFunctionCall %void %56 %uint_51 %uint_0 %142 %48
- OpBranch %51
- %51 = OpLabel
- %114 = OpPhi %v4float %151 %145 %113 %53
- %30 = OpCompositeExtract %float %114 0
- %31 = OpAccessChain %_ptr_Uniform_float %sbo %int_1
- %152 = OpFunctionCall %uint %115 %uint_0 %uint_0 %uint_0 %uint_0
- %153 = OpINotEqual %bool %152 %uint_0
- OpSelectionMerge %154 None
- OpBranchConditional %153 %155 %156
- %155 = OpLabel
- OpStore %31 %30
- OpBranch %154
- %156 = OpLabel
- %158 = OpFunctionCall %void %56 %uint_54 %uint_1 %uint_0 %uint_0
- OpBranch %154
- %154 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string new_funcs =
- R"(%33 = OpFunction %uint None %34
- %35 = OpFunctionParameter %uint
- %36 = OpFunctionParameter %uint
- %37 = OpLabel
- %43 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %35
- %44 = OpLoad %uint %43
- %45 = OpIAdd %uint %44 %36
- %46 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %45
- %47 = OpLoad %uint %46
- OpReturnValue %47
- OpFunctionEnd
- %56 = OpFunction %void None %57
- %58 = OpFunctionParameter %uint
- %59 = OpFunctionParameter %uint
- %60 = OpFunctionParameter %uint
- %61 = OpFunctionParameter %uint
- %62 = OpLabel
- %66 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_0
- %69 = OpAtomicIAdd %uint %66 %uint_4 %uint_0 %uint_10
- %70 = OpIAdd %uint %69 %uint_10
- %71 = OpArrayLength %uint %65 1
- %72 = OpULessThanEqual %bool %70 %71
- OpSelectionMerge %73 None
- OpBranchConditional %72 %74 %73
- %74 = OpLabel
- %75 = OpIAdd %uint %69 %uint_0
- %76 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %75
- OpStore %76 %uint_10
- %78 = OpIAdd %uint %69 %uint_1
- %79 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %78
- OpStore %79 %uint_23
- %81 = OpIAdd %uint %69 %uint_2
- %82 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %81
- OpStore %82 %58
- %85 = OpIAdd %uint %69 %uint_3
- %86 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %85
- OpStore %86 %uint_5318
- %90 = OpLoad %v3uint %89
- %91 = OpCompositeExtract %uint %90 0
- %92 = OpCompositeExtract %uint %90 1
- %93 = OpCompositeExtract %uint %90 2
- %94 = OpIAdd %uint %69 %uint_4
- %95 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %94
- OpStore %95 %91
- %97 = OpIAdd %uint %69 %uint_5
- %98 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %97
- OpStore %98 %92
- %100 = OpIAdd %uint %69 %uint_6
- %101 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %100
- OpStore %101 %93
- %103 = OpIAdd %uint %69 %uint_7
- %104 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %103
- OpStore %104 %59
- %106 = OpIAdd %uint %69 %uint_8
- %107 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %106
- OpStore %107 %60
- %109 = OpIAdd %uint %69 %uint_9
- %110 = OpAccessChain %_ptr_StorageBuffer_uint %65 %uint_1 %109
- OpStore %110 %61
- OpBranch %73
- %73 = OpLabel
- OpReturn
- OpFunctionEnd
- %115 = OpFunction %uint None %116
- %117 = OpFunctionParameter %uint
- %118 = OpFunctionParameter %uint
- %119 = OpFunctionParameter %uint
- %120 = OpFunctionParameter %uint
- %121 = OpLabel
- %122 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %117
- %123 = OpLoad %uint %122
- %124 = OpIAdd %uint %123 %118
- %125 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %124
- %126 = OpLoad %uint %125
- %127 = OpIAdd %uint %126 %119
- %128 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %127
- %129 = OpLoad %uint %128
- %130 = OpIAdd %uint %129 %120
- %131 = OpAccessChain %_ptr_StorageBuffer_uint %41 %uint_0 %130
- %132 = OpLoad %uint %131
- OpReturnValue %132
- OpFunctionEnd
- )";
- // SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- SinglePassRunAndCheck<InstBindlessCheckPass>(
- defs_before + func_before, defs_after + func_after + new_funcs, true,
- true, 7u, 23u, true, true, 2u);
- }
- // TODO(greg-lunarg): Add tests to verify handling of these cases:
- //
- // Compute shader
- // Geometry shader
- // Tesselation control shader
- // Tesselation eval shader
- // OpImage
- // SampledImage variable
- } // namespace
- } // namespace opt
- } // namespace spvtools
|