2
0

val_ext_inst_test.cpp 349 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337
  1. // Copyright (c) 2017 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Tests validation rules of GLSL.450.std and OpenCL.std extended instructions.
  15. // Doesn't test OpenCL.std vector size 2, 3, 4, 8 or 16 rules (not supported
  16. // by standard SPIR-V).
  17. #include <sstream>
  18. #include <string>
  19. #include <vector>
  20. #include "gmock/gmock.h"
  21. #include "test/unit_spirv.h"
  22. #include "test/val/val_fixtures.h"
  23. namespace spvtools {
  24. namespace val {
  25. namespace {
  26. using ::testing::Eq;
  27. using ::testing::HasSubstr;
  28. using ::testing::Not;
  29. using ValidateExtInst = spvtest::ValidateBase<bool>;
  30. using ValidateOldDebugInfo = spvtest::ValidateBase<std::string>;
  31. using ValidateOpenCL100DebugInfo = spvtest::ValidateBase<std::string>;
  32. using ValidateLocalDebugInfoOutOfFunction = spvtest::ValidateBase<std::string>;
  33. using ValidateOpenCL100DebugInfoDebugTypedef =
  34. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  35. using ValidateOpenCL100DebugInfoDebugTypeEnum =
  36. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  37. using ValidateOpenCL100DebugInfoDebugTypeComposite =
  38. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  39. using ValidateOpenCL100DebugInfoDebugTypeMember =
  40. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  41. using ValidateOpenCL100DebugInfoDebugTypeInheritance =
  42. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  43. using ValidateOpenCL100DebugInfoDebugFunction =
  44. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  45. using ValidateOpenCL100DebugInfoDebugFunctionDeclaration =
  46. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  47. using ValidateOpenCL100DebugInfoDebugLexicalBlock =
  48. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  49. using ValidateOpenCL100DebugInfoDebugLocalVariable =
  50. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  51. using ValidateOpenCL100DebugInfoDebugGlobalVariable =
  52. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  53. using ValidateOpenCL100DebugInfoDebugDeclare =
  54. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  55. using ValidateOpenCL100DebugInfoDebugValue =
  56. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  57. using ValidateGlslStd450SqrtLike = spvtest::ValidateBase<std::string>;
  58. using ValidateGlslStd450FMinLike = spvtest::ValidateBase<std::string>;
  59. using ValidateGlslStd450FClampLike = spvtest::ValidateBase<std::string>;
  60. using ValidateGlslStd450SAbsLike = spvtest::ValidateBase<std::string>;
  61. using ValidateGlslStd450UMinLike = spvtest::ValidateBase<std::string>;
  62. using ValidateGlslStd450UClampLike = spvtest::ValidateBase<std::string>;
  63. using ValidateGlslStd450SinLike = spvtest::ValidateBase<std::string>;
  64. using ValidateGlslStd450PowLike = spvtest::ValidateBase<std::string>;
  65. using ValidateGlslStd450Pack = spvtest::ValidateBase<std::string>;
  66. using ValidateGlslStd450Unpack = spvtest::ValidateBase<std::string>;
  67. using ValidateOpenCLStdSqrtLike = spvtest::ValidateBase<std::string>;
  68. using ValidateOpenCLStdFMinLike = spvtest::ValidateBase<std::string>;
  69. using ValidateOpenCLStdFClampLike = spvtest::ValidateBase<std::string>;
  70. using ValidateOpenCLStdSAbsLike = spvtest::ValidateBase<std::string>;
  71. using ValidateOpenCLStdUMinLike = spvtest::ValidateBase<std::string>;
  72. using ValidateOpenCLStdUClampLike = spvtest::ValidateBase<std::string>;
  73. using ValidateOpenCLStdUMul24Like = spvtest::ValidateBase<std::string>;
  74. using ValidateOpenCLStdUMad24Like = spvtest::ValidateBase<std::string>;
  75. using ValidateOpenCLStdLengthLike = spvtest::ValidateBase<std::string>;
  76. using ValidateOpenCLStdDistanceLike = spvtest::ValidateBase<std::string>;
  77. using ValidateOpenCLStdNormalizeLike = spvtest::ValidateBase<std::string>;
  78. using ValidateOpenCLStdVStoreHalfLike = spvtest::ValidateBase<std::string>;
  79. using ValidateOpenCLStdVLoadHalfLike = spvtest::ValidateBase<std::string>;
  80. using ValidateOpenCLStdFractLike = spvtest::ValidateBase<std::string>;
  81. using ValidateOpenCLStdFrexpLike = spvtest::ValidateBase<std::string>;
  82. using ValidateOpenCLStdLdexpLike = spvtest::ValidateBase<std::string>;
  83. using ValidateOpenCLStdUpsampleLike = spvtest::ValidateBase<std::string>;
  84. using ValidateClspvReflection = spvtest::ValidateBase<bool>;
  85. // Returns number of components in Pack/Unpack extended instructions.
  86. // |ext_inst_name| is expected to be of the format "PackHalf2x16".
  87. // Number of components is assumed to be single-digit.
  88. uint32_t GetPackedNumComponents(const std::string& ext_inst_name) {
  89. const size_t x_index = ext_inst_name.find_last_of('x');
  90. const std::string num_components_str =
  91. ext_inst_name.substr(x_index - 1, x_index);
  92. return uint32_t(std::stoul(num_components_str));
  93. }
  94. // Returns packed bit width in Pack/Unpack extended instructions.
  95. // |ext_inst_name| is expected to be of the format "PackHalf2x16".
  96. uint32_t GetPackedBitWidth(const std::string& ext_inst_name) {
  97. const size_t x_index = ext_inst_name.find_last_of('x');
  98. const std::string packed_bit_width_str = ext_inst_name.substr(x_index + 1);
  99. return uint32_t(std::stoul(packed_bit_width_str));
  100. }
  101. std::string GenerateShaderCode(
  102. const std::string& body,
  103. const std::string& capabilities_and_extensions = "",
  104. const std::string& execution_model = "Fragment") {
  105. std::ostringstream ss;
  106. ss << R"(
  107. OpCapability Shader
  108. OpCapability Float16
  109. OpCapability Float64
  110. OpCapability Int16
  111. OpCapability Int64
  112. )";
  113. ss << capabilities_and_extensions;
  114. ss << "%extinst = OpExtInstImport \"GLSL.std.450\"\n";
  115. ss << "OpMemoryModel Logical GLSL450\n";
  116. ss << "OpEntryPoint " << execution_model << " %main \"main\""
  117. << " %f32_output"
  118. << " %f32vec2_output"
  119. << " %u32_output"
  120. << " %u32vec2_output"
  121. << " %u64_output"
  122. << " %f32_input"
  123. << " %f32vec2_input"
  124. << " %u32_input"
  125. << " %u32vec2_input"
  126. << " %u64_input"
  127. << "\n";
  128. if (execution_model == "Fragment") {
  129. ss << "OpExecutionMode %main OriginUpperLeft\n";
  130. }
  131. ss << R"(
  132. %void = OpTypeVoid
  133. %func = OpTypeFunction %void
  134. %bool = OpTypeBool
  135. %f16 = OpTypeFloat 16
  136. %f32 = OpTypeFloat 32
  137. %f64 = OpTypeFloat 64
  138. %u32 = OpTypeInt 32 0
  139. %s32 = OpTypeInt 32 1
  140. %u64 = OpTypeInt 64 0
  141. %s64 = OpTypeInt 64 1
  142. %u16 = OpTypeInt 16 0
  143. %s16 = OpTypeInt 16 1
  144. %f32vec2 = OpTypeVector %f32 2
  145. %f32vec3 = OpTypeVector %f32 3
  146. %f32vec4 = OpTypeVector %f32 4
  147. %f64vec2 = OpTypeVector %f64 2
  148. %f64vec3 = OpTypeVector %f64 3
  149. %f64vec4 = OpTypeVector %f64 4
  150. %u32vec2 = OpTypeVector %u32 2
  151. %u32vec3 = OpTypeVector %u32 3
  152. %s32vec2 = OpTypeVector %s32 2
  153. %u32vec4 = OpTypeVector %u32 4
  154. %s32vec4 = OpTypeVector %s32 4
  155. %u64vec2 = OpTypeVector %u64 2
  156. %s64vec2 = OpTypeVector %s64 2
  157. %f64mat22 = OpTypeMatrix %f64vec2 2
  158. %f32mat22 = OpTypeMatrix %f32vec2 2
  159. %f32mat23 = OpTypeMatrix %f32vec2 3
  160. %f32mat32 = OpTypeMatrix %f32vec3 2
  161. %f32mat33 = OpTypeMatrix %f32vec3 3
  162. %f32_0 = OpConstant %f32 0
  163. %f32_1 = OpConstant %f32 1
  164. %f32_2 = OpConstant %f32 2
  165. %f32_3 = OpConstant %f32 3
  166. %f32_4 = OpConstant %f32 4
  167. %f32_h = OpConstant %f32 0.5
  168. %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
  169. %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
  170. %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
  171. %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
  172. %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
  173. %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
  174. %f64_0 = OpConstant %f64 0
  175. %f64_1 = OpConstant %f64 1
  176. %f64_2 = OpConstant %f64 2
  177. %f64_3 = OpConstant %f64 3
  178. %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
  179. %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
  180. %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
  181. %f16_0 = OpConstant %f16 0
  182. %f16_1 = OpConstant %f16 1
  183. %f16_h = OpConstant %f16 0.5
  184. %u32_0 = OpConstant %u32 0
  185. %u32_1 = OpConstant %u32 1
  186. %u32_2 = OpConstant %u32 2
  187. %u32_3 = OpConstant %u32 3
  188. %s32_0 = OpConstant %s32 0
  189. %s32_1 = OpConstant %s32 1
  190. %s32_2 = OpConstant %s32 2
  191. %s32_3 = OpConstant %s32 3
  192. %u64_0 = OpConstant %u64 0
  193. %u64_1 = OpConstant %u64 1
  194. %u64_2 = OpConstant %u64 2
  195. %u64_3 = OpConstant %u64 3
  196. %s64_0 = OpConstant %s64 0
  197. %s64_1 = OpConstant %s64 1
  198. %s64_2 = OpConstant %s64 2
  199. %s64_3 = OpConstant %s64 3
  200. %s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
  201. %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
  202. %s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
  203. %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
  204. %s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
  205. %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
  206. %s64vec2_01 = OpConstantComposite %s64vec2 %s64_0 %s64_1
  207. %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
  208. %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
  209. %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
  210. %f32_ptr_output = OpTypePointer Output %f32
  211. %f32vec2_ptr_output = OpTypePointer Output %f32vec2
  212. %u32_ptr_output = OpTypePointer Output %u32
  213. %u32vec2_ptr_output = OpTypePointer Output %u32vec2
  214. %u64_ptr_output = OpTypePointer Output %u64
  215. %f32_output = OpVariable %f32_ptr_output Output
  216. %f32vec2_output = OpVariable %f32vec2_ptr_output Output
  217. %u32_output = OpVariable %u32_ptr_output Output
  218. %u32vec2_output = OpVariable %u32vec2_ptr_output Output
  219. %u64_output = OpVariable %u64_ptr_output Output
  220. %f32_ptr_input = OpTypePointer Input %f32
  221. %f32vec2_ptr_input = OpTypePointer Input %f32vec2
  222. %u32_ptr_input = OpTypePointer Input %u32
  223. %u32vec2_ptr_input = OpTypePointer Input %u32vec2
  224. %u64_ptr_input = OpTypePointer Input %u64
  225. %f32_input = OpVariable %f32_ptr_input Input
  226. %f32vec2_input = OpVariable %f32vec2_ptr_input Input
  227. %u32_input = OpVariable %u32_ptr_input Input
  228. %u32vec2_input = OpVariable %u32vec2_ptr_input Input
  229. %u64_input = OpVariable %u64_ptr_input Input
  230. %struct_f16_u16 = OpTypeStruct %f16 %u16
  231. %struct_f32_f32 = OpTypeStruct %f32 %f32
  232. %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
  233. %struct_f32_u32 = OpTypeStruct %f32 %u32
  234. %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
  235. %struct_u32_f32 = OpTypeStruct %u32 %f32
  236. %struct_u32_u32 = OpTypeStruct %u32 %u32
  237. %struct_f32_f64 = OpTypeStruct %f32 %f64
  238. %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
  239. %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
  240. %main = OpFunction %void None %func
  241. %main_entry = OpLabel
  242. )";
  243. ss << body;
  244. ss << R"(
  245. OpReturn
  246. OpFunctionEnd)";
  247. return ss.str();
  248. }
  249. std::string GenerateKernelCode(
  250. const std::string& body,
  251. const std::string& capabilities_and_extensions = "",
  252. const std::string& memory_model = "Physical32") {
  253. std::ostringstream ss;
  254. ss << R"(
  255. OpCapability Addresses
  256. OpCapability Kernel
  257. OpCapability Linkage
  258. OpCapability GenericPointer
  259. OpCapability Int8
  260. OpCapability Int16
  261. OpCapability Int64
  262. OpCapability Float16
  263. OpCapability Float64
  264. OpCapability Vector16
  265. OpCapability Matrix
  266. )";
  267. ss << capabilities_and_extensions;
  268. ss << "%extinst = OpExtInstImport \"OpenCL.std\"\n";
  269. ss << "OpMemoryModel " << memory_model << " OpenCL\n";
  270. ss << R"(
  271. %void = OpTypeVoid
  272. %func = OpTypeFunction %void
  273. %bool = OpTypeBool
  274. %f16 = OpTypeFloat 16
  275. %f32 = OpTypeFloat 32
  276. %f64 = OpTypeFloat 64
  277. %u32 = OpTypeInt 32 0
  278. %u64 = OpTypeInt 64 0
  279. %u16 = OpTypeInt 16 0
  280. %u8 = OpTypeInt 8 0
  281. %f32vec2 = OpTypeVector %f32 2
  282. %f32vec3 = OpTypeVector %f32 3
  283. %f32vec4 = OpTypeVector %f32 4
  284. %f32vec8 = OpTypeVector %f32 8
  285. %f16vec8 = OpTypeVector %f16 8
  286. %f32vec16 = OpTypeVector %f32 16
  287. %f64vec2 = OpTypeVector %f64 2
  288. %f64vec3 = OpTypeVector %f64 3
  289. %f64vec4 = OpTypeVector %f64 4
  290. %u32vec2 = OpTypeVector %u32 2
  291. %u32vec3 = OpTypeVector %u32 3
  292. %u32vec4 = OpTypeVector %u32 4
  293. %u32vec8 = OpTypeVector %u32 8
  294. %u64vec2 = OpTypeVector %u64 2
  295. %f64mat22 = OpTypeMatrix %f64vec2 2
  296. %f32mat22 = OpTypeMatrix %f32vec2 2
  297. %f32mat23 = OpTypeMatrix %f32vec2 3
  298. %f32mat32 = OpTypeMatrix %f32vec3 2
  299. %f32mat33 = OpTypeMatrix %f32vec3 3
  300. %f32_0 = OpConstant %f32 0
  301. %f32_1 = OpConstant %f32 1
  302. %f32_2 = OpConstant %f32 2
  303. %f32_3 = OpConstant %f32 3
  304. %f32_4 = OpConstant %f32 4
  305. %f32_h = OpConstant %f32 0.5
  306. %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
  307. %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
  308. %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
  309. %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
  310. %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
  311. %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
  312. %f32vec8_01010101 = OpConstantComposite %f32vec8 %f32_0 %f32_1 %f32_0 %f32_1 %f32_0 %f32_1 %f32_0 %f32_1
  313. %f64_0 = OpConstant %f64 0
  314. %f64_1 = OpConstant %f64 1
  315. %f64_2 = OpConstant %f64 2
  316. %f64_3 = OpConstant %f64 3
  317. %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
  318. %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
  319. %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
  320. %f16_0 = OpConstant %f16 0
  321. %f16_1 = OpConstant %f16 1
  322. %u8_0 = OpConstant %u8 0
  323. %u8_1 = OpConstant %u8 1
  324. %u8_2 = OpConstant %u8 2
  325. %u8_3 = OpConstant %u8 3
  326. %u16_0 = OpConstant %u16 0
  327. %u16_1 = OpConstant %u16 1
  328. %u16_2 = OpConstant %u16 2
  329. %u16_3 = OpConstant %u16 3
  330. %u32_0 = OpConstant %u32 0
  331. %u32_1 = OpConstant %u32 1
  332. %u32_2 = OpConstant %u32 2
  333. %u32_3 = OpConstant %u32 3
  334. %u32_256 = OpConstant %u32 256
  335. %u64_0 = OpConstant %u64 0
  336. %u64_1 = OpConstant %u64 1
  337. %u64_2 = OpConstant %u64 2
  338. %u64_3 = OpConstant %u64 3
  339. %u64_256 = OpConstant %u64 256
  340. %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
  341. %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
  342. %u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
  343. %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
  344. %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
  345. %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
  346. %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
  347. %struct_f32_f32 = OpTypeStruct %f32 %f32
  348. %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
  349. %struct_f32_u32 = OpTypeStruct %f32 %u32
  350. %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
  351. %struct_u32_f32 = OpTypeStruct %u32 %f32
  352. %struct_u32_u32 = OpTypeStruct %u32 %u32
  353. %struct_f32_f64 = OpTypeStruct %f32 %f64
  354. %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
  355. %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
  356. %f16vec8_ptr_workgroup = OpTypePointer Workgroup %f16vec8
  357. %f16vec8_workgroup = OpVariable %f16vec8_ptr_workgroup Workgroup
  358. %f16_ptr_workgroup = OpTypePointer Workgroup %f16
  359. %u32vec8_ptr_workgroup = OpTypePointer Workgroup %u32vec8
  360. %u32vec8_workgroup = OpVariable %u32vec8_ptr_workgroup Workgroup
  361. %u32_ptr_workgroup = OpTypePointer Workgroup %u32
  362. %f32vec8_ptr_workgroup = OpTypePointer Workgroup %f32vec8
  363. %f32vec8_workgroup = OpVariable %f32vec8_ptr_workgroup Workgroup
  364. %f32_ptr_workgroup = OpTypePointer Workgroup %f32
  365. %u32arr = OpTypeArray %u32 %u32_256
  366. %u32arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %u32arr
  367. %u32arr_cross_workgroup = OpVariable %u32arr_ptr_cross_workgroup CrossWorkgroup
  368. %u32_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %u32
  369. %f32arr = OpTypeArray %f32 %u32_256
  370. %f32arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32arr
  371. %f32arr_cross_workgroup = OpVariable %f32arr_ptr_cross_workgroup CrossWorkgroup
  372. %f32_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32
  373. %f32vec2arr = OpTypeArray %f32vec2 %u32_256
  374. %f32vec2arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32vec2arr
  375. %f32vec2arr_cross_workgroup = OpVariable %f32vec2arr_ptr_cross_workgroup CrossWorkgroup
  376. %f32vec2_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32vec2
  377. %struct_arr = OpTypeArray %struct_f32_f32 %u32_256
  378. %struct_arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %struct_arr
  379. %struct_arr_cross_workgroup = OpVariable %struct_arr_ptr_cross_workgroup CrossWorkgroup
  380. %struct_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %struct_f32_f32
  381. %f16vec8_ptr_uniform_constant = OpTypePointer UniformConstant %f16vec8
  382. %f16vec8_uniform_constant = OpVariable %f16vec8_ptr_uniform_constant UniformConstant
  383. %f16_ptr_uniform_constant = OpTypePointer UniformConstant %f16
  384. %u32vec8_ptr_uniform_constant = OpTypePointer UniformConstant %u32vec8
  385. %u32vec8_uniform_constant = OpVariable %u32vec8_ptr_uniform_constant UniformConstant
  386. %u32_ptr_uniform_constant = OpTypePointer UniformConstant %u32
  387. %f32vec8_ptr_uniform_constant = OpTypePointer UniformConstant %f32vec8
  388. %f32vec8_uniform_constant = OpVariable %f32vec8_ptr_uniform_constant UniformConstant
  389. %f32_ptr_uniform_constant = OpTypePointer UniformConstant %f32
  390. %f16vec8_ptr_input = OpTypePointer Input %f16vec8
  391. %f16vec8_input = OpVariable %f16vec8_ptr_input Input
  392. %f16_ptr_input = OpTypePointer Input %f16
  393. %u32vec8_ptr_input = OpTypePointer Input %u32vec8
  394. %u32vec8_input = OpVariable %u32vec8_ptr_input Input
  395. %u32_ptr_input = OpTypePointer Input %u32
  396. %f32_ptr_generic = OpTypePointer Generic %f32
  397. %u32_ptr_generic = OpTypePointer Generic %u32
  398. %f32_ptr_function = OpTypePointer Function %f32
  399. %f32vec2_ptr_function = OpTypePointer Function %f32vec2
  400. %u32_ptr_function = OpTypePointer Function %u32
  401. %u64_ptr_function = OpTypePointer Function %u64
  402. %u32vec2_ptr_function = OpTypePointer Function %u32vec2
  403. %u8arr = OpTypeArray %u8 %u32_256
  404. %u8arr_ptr_uniform_constant = OpTypePointer UniformConstant %u8arr
  405. %u8arr_uniform_constant = OpVariable %u8arr_ptr_uniform_constant UniformConstant
  406. %u8_ptr_uniform_constant = OpTypePointer UniformConstant %u8
  407. %u8_ptr_generic = OpTypePointer Generic %u8
  408. %main = OpFunction %void None %func
  409. %main_entry = OpLabel
  410. )";
  411. ss << body;
  412. ss << R"(
  413. OpReturn
  414. OpFunctionEnd)";
  415. return ss.str();
  416. }
  417. std::string GenerateShaderCodeForDebugInfo(
  418. const std::string& op_string_instructions,
  419. const std::string& op_const_instructions,
  420. const std::string& debug_instructions_before_main, const std::string& body,
  421. const std::string& capabilities_and_extensions = "",
  422. const std::string& execution_model = "Fragment") {
  423. std::ostringstream ss;
  424. ss << R"(
  425. OpCapability Shader
  426. OpCapability Float16
  427. OpCapability Float64
  428. OpCapability Int16
  429. OpCapability Int64
  430. )";
  431. ss << capabilities_and_extensions;
  432. ss << "%extinst = OpExtInstImport \"GLSL.std.450\"\n";
  433. ss << "OpMemoryModel Logical GLSL450\n";
  434. ss << "OpEntryPoint " << execution_model << " %main \"main\""
  435. << " %f32_output"
  436. << " %f32vec2_output"
  437. << " %u32_output"
  438. << " %u32vec2_output"
  439. << " %u64_output"
  440. << " %f32_input"
  441. << " %f32vec2_input"
  442. << " %u32_input"
  443. << " %u32vec2_input"
  444. << " %u64_input"
  445. << "\n";
  446. if (execution_model == "Fragment") {
  447. ss << "OpExecutionMode %main OriginUpperLeft\n";
  448. }
  449. ss << op_string_instructions;
  450. ss << R"(
  451. %void = OpTypeVoid
  452. %func = OpTypeFunction %void
  453. %bool = OpTypeBool
  454. %f16 = OpTypeFloat 16
  455. %f32 = OpTypeFloat 32
  456. %f64 = OpTypeFloat 64
  457. %u32 = OpTypeInt 32 0
  458. %s32 = OpTypeInt 32 1
  459. %u64 = OpTypeInt 64 0
  460. %s64 = OpTypeInt 64 1
  461. %u16 = OpTypeInt 16 0
  462. %s16 = OpTypeInt 16 1
  463. %f32vec2 = OpTypeVector %f32 2
  464. %f32vec3 = OpTypeVector %f32 3
  465. %f32vec4 = OpTypeVector %f32 4
  466. %f64vec2 = OpTypeVector %f64 2
  467. %f64vec3 = OpTypeVector %f64 3
  468. %f64vec4 = OpTypeVector %f64 4
  469. %u32vec2 = OpTypeVector %u32 2
  470. %u32vec3 = OpTypeVector %u32 3
  471. %s32vec2 = OpTypeVector %s32 2
  472. %u32vec4 = OpTypeVector %u32 4
  473. %s32vec4 = OpTypeVector %s32 4
  474. %u64vec2 = OpTypeVector %u64 2
  475. %s64vec2 = OpTypeVector %s64 2
  476. %f64mat22 = OpTypeMatrix %f64vec2 2
  477. %f32mat22 = OpTypeMatrix %f32vec2 2
  478. %f32mat23 = OpTypeMatrix %f32vec2 3
  479. %f32mat32 = OpTypeMatrix %f32vec3 2
  480. %f32mat33 = OpTypeMatrix %f32vec3 3
  481. %f32_0 = OpConstant %f32 0
  482. %f32_1 = OpConstant %f32 1
  483. %f32_2 = OpConstant %f32 2
  484. %f32_3 = OpConstant %f32 3
  485. %f32_4 = OpConstant %f32 4
  486. %f32_h = OpConstant %f32 0.5
  487. %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
  488. %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
  489. %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
  490. %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
  491. %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
  492. %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
  493. %f64_0 = OpConstant %f64 0
  494. %f64_1 = OpConstant %f64 1
  495. %f64_2 = OpConstant %f64 2
  496. %f64_3 = OpConstant %f64 3
  497. %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
  498. %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
  499. %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
  500. %f16_0 = OpConstant %f16 0
  501. %f16_1 = OpConstant %f16 1
  502. %f16_h = OpConstant %f16 0.5
  503. %u32_0 = OpConstant %u32 0
  504. %u32_1 = OpConstant %u32 1
  505. %u32_2 = OpConstant %u32 2
  506. %u32_3 = OpConstant %u32 3
  507. %s32_0 = OpConstant %s32 0
  508. %s32_1 = OpConstant %s32 1
  509. %s32_2 = OpConstant %s32 2
  510. %s32_3 = OpConstant %s32 3
  511. %u64_0 = OpConstant %u64 0
  512. %u64_1 = OpConstant %u64 1
  513. %u64_2 = OpConstant %u64 2
  514. %u64_3 = OpConstant %u64 3
  515. %s64_0 = OpConstant %s64 0
  516. %s64_1 = OpConstant %s64 1
  517. %s64_2 = OpConstant %s64 2
  518. %s64_3 = OpConstant %s64 3
  519. )";
  520. ss << op_const_instructions;
  521. ss << R"(
  522. %s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
  523. %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
  524. %s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
  525. %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
  526. %s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
  527. %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
  528. %s64vec2_01 = OpConstantComposite %s64vec2 %s64_0 %s64_1
  529. %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
  530. %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
  531. %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
  532. %f32_ptr_output = OpTypePointer Output %f32
  533. %f32vec2_ptr_output = OpTypePointer Output %f32vec2
  534. %u32_ptr_output = OpTypePointer Output %u32
  535. %u32vec2_ptr_output = OpTypePointer Output %u32vec2
  536. %u64_ptr_output = OpTypePointer Output %u64
  537. %f32_output = OpVariable %f32_ptr_output Output
  538. %f32vec2_output = OpVariable %f32vec2_ptr_output Output
  539. %u32_output = OpVariable %u32_ptr_output Output
  540. %u32vec2_output = OpVariable %u32vec2_ptr_output Output
  541. %u64_output = OpVariable %u64_ptr_output Output
  542. %f32_ptr_input = OpTypePointer Input %f32
  543. %f32vec2_ptr_input = OpTypePointer Input %f32vec2
  544. %u32_ptr_input = OpTypePointer Input %u32
  545. %u32vec2_ptr_input = OpTypePointer Input %u32vec2
  546. %u64_ptr_input = OpTypePointer Input %u64
  547. %f32_ptr_function = OpTypePointer Function %f32
  548. %f32_input = OpVariable %f32_ptr_input Input
  549. %f32vec2_input = OpVariable %f32vec2_ptr_input Input
  550. %u32_input = OpVariable %u32_ptr_input Input
  551. %u32vec2_input = OpVariable %u32vec2_ptr_input Input
  552. %u64_input = OpVariable %u64_ptr_input Input
  553. %u32_ptr_function = OpTypePointer Function %u32
  554. %struct_f16_u16 = OpTypeStruct %f16 %u16
  555. %struct_f32_f32 = OpTypeStruct %f32 %f32
  556. %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
  557. %struct_f32_u32 = OpTypeStruct %f32 %u32
  558. %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
  559. %struct_u32_f32 = OpTypeStruct %u32 %f32
  560. %struct_u32_u32 = OpTypeStruct %u32 %u32
  561. %struct_f32_f64 = OpTypeStruct %f32 %f64
  562. %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
  563. %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
  564. )";
  565. ss << debug_instructions_before_main;
  566. ss << R"(
  567. %main = OpFunction %void None %func
  568. %main_entry = OpLabel
  569. )";
  570. ss << body;
  571. ss << R"(
  572. OpReturn
  573. OpFunctionEnd)";
  574. return ss.str();
  575. }
  576. TEST_F(ValidateOldDebugInfo, UseDebugInstructionOutOfFunction) {
  577. const std::string src = R"(
  578. %code = OpString "main() {}"
  579. )";
  580. const std::string dbg_inst = R"(
  581. %cu = OpExtInst %void %DbgExt DebugCompilationUnit %code 1 1
  582. )";
  583. const std::string extension = R"(
  584. %DbgExt = OpExtInstImport "DebugInfo"
  585. )";
  586. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  587. extension, "Vertex"));
  588. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  589. }
  590. TEST_F(ValidateOpenCL100DebugInfo, UseDebugInstructionOutOfFunction) {
  591. const std::string src = R"(
  592. %src = OpString "simple.hlsl"
  593. %code = OpString "main() {}"
  594. )";
  595. const std::string dbg_inst = R"(
  596. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  597. )";
  598. const std::string extension = R"(
  599. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  600. )";
  601. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  602. extension, "Vertex"));
  603. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  604. }
  605. TEST_F(ValidateOpenCL100DebugInfo, DebugSourceInFunction) {
  606. const std::string src = R"(
  607. %src = OpString "simple.hlsl"
  608. %code = OpString "main() {}"
  609. )";
  610. const std::string dbg_inst = R"(
  611. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  612. )";
  613. const std::string extension = R"(
  614. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  615. )";
  616. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", "", dbg_inst,
  617. extension, "Vertex"));
  618. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  619. EXPECT_THAT(
  620. getDiagnosticString(),
  621. HasSubstr("Debug info extension instructions other than DebugScope, "
  622. "DebugNoScope, DebugDeclare, DebugValue must appear between "
  623. "section 9 (types, constants, global variables) and section 10 "
  624. "(function declarations)"));
  625. }
  626. TEST_P(ValidateLocalDebugInfoOutOfFunction, OpenCLDebugInfo100DebugScope) {
  627. const std::string src = R"(
  628. %src = OpString "simple.hlsl"
  629. %code = OpString "void main() {}"
  630. %void_name = OpString "void"
  631. %main_name = OpString "main"
  632. %main_linkage_name = OpString "v_main"
  633. %int_name = OpString "int"
  634. %foo_name = OpString "foo"
  635. )";
  636. const std::string dbg_inst_header = R"(
  637. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  638. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  639. %int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %u32_0 Signed
  640. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  641. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
  642. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %int_info %dbg_src 1 1 %main_info FlagIsLocal
  643. %expr = OpExtInst %void %DbgExt DebugExpression
  644. )";
  645. const std::string body = R"(
  646. %foo = OpVariable %u32_ptr_function Function
  647. %foo_val = OpLoad %u32 %foo
  648. )";
  649. const std::string extension = R"(
  650. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  651. )";
  652. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  653. src, "", dbg_inst_header + GetParam(), body, extension, "Vertex"));
  654. ASSERT_EQ(SPV_ERROR_INVALID_LAYOUT, ValidateInstructions());
  655. EXPECT_THAT(getDiagnosticString(),
  656. HasSubstr("DebugScope, DebugNoScope, DebugDeclare, DebugValue "
  657. "of debug info extension must appear in a function "
  658. "body"));
  659. }
  660. INSTANTIATE_TEST_SUITE_P(
  661. AllLocalDebugInfo, ValidateLocalDebugInfoOutOfFunction,
  662. ::testing::ValuesIn(std::vector<std::string>{
  663. "%main_scope = OpExtInst %void %DbgExt DebugScope %main_info",
  664. "%no_scope = OpExtInst %void %DbgExt DebugNoScope",
  665. }));
  666. TEST_F(ValidateOpenCL100DebugInfo, DebugFunctionForwardReference) {
  667. const std::string src = R"(
  668. %src = OpString "simple.hlsl"
  669. %code = OpString "void main() {}"
  670. %void_name = OpString "void"
  671. %main_name = OpString "main"
  672. %main_linkage_name = OpString "v_main"
  673. )";
  674. const std::string dbg_inst_header = R"(
  675. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  676. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  677. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  678. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
  679. )";
  680. const std::string body = R"(
  681. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info
  682. )";
  683. const std::string extension = R"(
  684. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  685. )";
  686. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  687. src, "", dbg_inst_header, body, extension, "Vertex"));
  688. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  689. }
  690. TEST_F(ValidateOpenCL100DebugInfo, DebugFunctionMissingOpFunction) {
  691. const std::string src = R"(
  692. %src = OpString "simple.hlsl"
  693. %code = OpString "void main() {}"
  694. %void_name = OpString "void"
  695. %main_name = OpString "main"
  696. %main_linkage_name = OpString "v_main"
  697. )";
  698. const std::string dbg_inst_header = R"(
  699. %dbgNone = OpExtInst %void %DbgExt DebugInfoNone
  700. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  701. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  702. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  703. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %dbgNone
  704. )";
  705. const std::string body = R"(
  706. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info
  707. )";
  708. const std::string extension = R"(
  709. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  710. )";
  711. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  712. src, "", dbg_inst_header, body, extension, "Vertex"));
  713. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  714. }
  715. TEST_F(ValidateOpenCL100DebugInfo, DebugScopeBeforeOpVariableInFunction) {
  716. const std::string src = R"(
  717. %src = OpString "simple.hlsl"
  718. %code = OpString "float4 main(float arg) {
  719. float foo;
  720. return float4(0, 0, 0, 0);
  721. }
  722. "
  723. %float_name = OpString "float"
  724. %main_name = OpString "main"
  725. %main_linkage_name = OpString "v4f_main_f"
  726. )";
  727. const std::string size_const = R"(
  728. %int_32 = OpConstant %u32 32
  729. )";
  730. const std::string dbg_inst_header = R"(
  731. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  732. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  733. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  734. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  735. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
  736. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main
  737. )";
  738. const std::string body = R"(
  739. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info
  740. %foo = OpVariable %f32_ptr_function Function
  741. )";
  742. const std::string extension = R"(
  743. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  744. )";
  745. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  746. src, size_const, dbg_inst_header, body, extension, "Vertex"));
  747. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  748. }
  749. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeSizeDebugInfoNone) {
  750. const std::string src = R"(
  751. %src = OpString "simple.hlsl"
  752. %code = OpString "OpaqueType foo;
  753. main() {}
  754. "
  755. %ty_name = OpString "struct VS_OUTPUT"
  756. )";
  757. const std::string dbg_inst_header = R"(
  758. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  759. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  760. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  761. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
  762. )";
  763. const std::string extension = R"(
  764. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  765. )";
  766. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst_header,
  767. "", extension, "Vertex"));
  768. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  769. }
  770. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeForwardReference) {
  771. const std::string src = R"(
  772. %src = OpString "simple.hlsl"
  773. %code = OpString "struct VS_OUTPUT {
  774. float4 pos : SV_POSITION;
  775. float4 color : COLOR;
  776. };
  777. main() {}
  778. "
  779. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  780. %float_name = OpString "float"
  781. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  782. %VS_OUTPUT_color_name = OpString "color : COLOR"
  783. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  784. )";
  785. const std::string size_const = R"(
  786. %int_32 = OpConstant %u32 32
  787. %int_128 = OpConstant %u32 128
  788. )";
  789. const std::string dbg_inst_header = R"(
  790. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  791. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  792. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %VS_OUTPUT_color_info
  793. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  794. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  795. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  796. %VS_OUTPUT_color_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_color_name %v4float_info %dbg_src 3 3 %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
  797. )";
  798. const std::string extension = R"(
  799. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  800. )";
  801. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  802. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  803. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  804. }
  805. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeMissingReference) {
  806. const std::string src = R"(
  807. %src = OpString "simple.hlsl"
  808. %code = OpString "struct VS_OUTPUT {
  809. float4 pos : SV_POSITION;
  810. float4 color : COLOR;
  811. };
  812. main() {}
  813. "
  814. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  815. %float_name = OpString "float"
  816. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  817. %VS_OUTPUT_color_name = OpString "color : COLOR"
  818. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  819. )";
  820. const std::string size_const = R"(
  821. %int_32 = OpConstant %u32 32
  822. %int_128 = OpConstant %u32 128
  823. )";
  824. const std::string dbg_inst_header = R"(
  825. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  826. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  827. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %VS_OUTPUT_color_info
  828. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  829. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  830. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  831. )";
  832. const std::string extension = R"(
  833. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  834. )";
  835. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  836. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  837. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  838. EXPECT_THAT(getDiagnosticString(),
  839. HasSubstr("forward referenced IDs have not been defined"));
  840. }
  841. TEST_F(ValidateOpenCL100DebugInfo, DebugInstructionWrongResultType) {
  842. const std::string src = R"(
  843. %src = OpString "simple.hlsl"
  844. %code = OpString "main() {}"
  845. )";
  846. const std::string dbg_inst = R"(
  847. %dbg_src = OpExtInst %bool %DbgExt DebugSource %src %code
  848. )";
  849. const std::string extension = R"(
  850. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  851. )";
  852. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  853. extension, "Vertex"));
  854. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  855. EXPECT_THAT(getDiagnosticString(),
  856. HasSubstr("expected result type must be a result id of "
  857. "OpTypeVoid"));
  858. }
  859. TEST_F(ValidateOpenCL100DebugInfo, DebugCompilationUnit) {
  860. const std::string src = R"(
  861. %src = OpString "simple.hlsl"
  862. %code = OpString "main() {}"
  863. )";
  864. const std::string dbg_inst = R"(
  865. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  866. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  867. )";
  868. const std::string extension = R"(
  869. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  870. )";
  871. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  872. extension, "Vertex"));
  873. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  874. }
  875. TEST_F(ValidateOpenCL100DebugInfo, DebugCompilationUnitFail) {
  876. const std::string src = R"(
  877. %src = OpString "simple.hlsl"
  878. %code = OpString "main() {}"
  879. )";
  880. const std::string dbg_inst = R"(
  881. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  882. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %src HLSL
  883. )";
  884. const std::string extension = R"(
  885. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  886. )";
  887. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  888. extension, "Vertex"));
  889. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  890. EXPECT_THAT(getDiagnosticString(),
  891. HasSubstr("expected operand Source must be a result id of "
  892. "DebugSource"));
  893. }
  894. TEST_F(ValidateOpenCL100DebugInfo, DebugSourceFailFile) {
  895. const std::string src = R"(
  896. %code = OpString "main() {}"
  897. )";
  898. const std::string dbg_inst = R"(
  899. %dbg_src = OpExtInst %void %DbgExt DebugSource %DbgExt %code
  900. )";
  901. const std::string extension = R"(
  902. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  903. )";
  904. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  905. extension, "Vertex"));
  906. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  907. EXPECT_THAT(getDiagnosticString(),
  908. HasSubstr("expected operand File must be a result id of "
  909. "OpString"));
  910. }
  911. TEST_F(ValidateOpenCL100DebugInfo, DebugSourceFailSource) {
  912. const std::string src = R"(
  913. %src = OpString "simple.hlsl"
  914. )";
  915. const std::string dbg_inst = R"(
  916. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %DbgExt
  917. )";
  918. const std::string extension = R"(
  919. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  920. )";
  921. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  922. extension, "Vertex"));
  923. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  924. EXPECT_THAT(getDiagnosticString(),
  925. HasSubstr("expected operand Text must be a result id of "
  926. "OpString"));
  927. }
  928. TEST_F(ValidateOpenCL100DebugInfo, DebugSourceNoText) {
  929. const std::string src = R"(
  930. %src = OpString "simple.hlsl"
  931. )";
  932. const std::string dbg_inst = R"(
  933. %dbg_src = OpExtInst %void %DbgExt DebugSource %src
  934. )";
  935. const std::string extension = R"(
  936. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  937. )";
  938. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst, "",
  939. extension, "Vertex"));
  940. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  941. }
  942. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeBasicFailName) {
  943. const std::string src = R"(
  944. %src = OpString "simple.hlsl"
  945. %code = OpString "float4 main(float arg) {
  946. float foo;
  947. return float4(0, 0, 0, 0);
  948. }
  949. "
  950. %float_name = OpString "float"
  951. )";
  952. const std::string size_const = R"(
  953. %int_32 = OpConstant %u32 32
  954. )";
  955. const std::string dbg_inst_header = R"(
  956. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  957. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  958. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %int_32 %int_32 Float
  959. )";
  960. const std::string extension = R"(
  961. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  962. )";
  963. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  964. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  965. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  966. EXPECT_THAT(getDiagnosticString(),
  967. HasSubstr("expected operand Name must be a result id of "
  968. "OpString"));
  969. }
  970. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeBasicFailSize) {
  971. const std::string src = R"(
  972. %src = OpString "simple.hlsl"
  973. %code = OpString "float4 main(float arg) {
  974. float foo;
  975. return float4(0, 0, 0, 0);
  976. }
  977. "
  978. %float_name = OpString "float"
  979. )";
  980. const std::string size_const = R"(
  981. %int_32 = OpConstant %u32 32
  982. )";
  983. const std::string dbg_inst_header = R"(
  984. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  985. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  986. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %float_name Float
  987. )";
  988. const std::string extension = R"(
  989. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  990. )";
  991. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  992. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  993. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  994. EXPECT_THAT(getDiagnosticString(),
  995. HasSubstr("expected operand Size must be a result id of "
  996. "OpConstant"));
  997. }
  998. TEST_F(ValidateOpenCL100DebugInfo, DebugTypePointer) {
  999. const std::string src = R"(
  1000. %src = OpString "simple.hlsl"
  1001. %code = OpString "float4 main(float arg) {
  1002. float foo;
  1003. return float4(0, 0, 0, 0);
  1004. }
  1005. "
  1006. %float_name = OpString "float"
  1007. )";
  1008. const std::string size_const = R"(
  1009. %int_32 = OpConstant %u32 32
  1010. )";
  1011. const std::string dbg_inst_header = R"(
  1012. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1013. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1014. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1015. %pfloat_info = OpExtInst %void %DbgExt DebugTypePointer %float_info Function FlagIsLocal
  1016. )";
  1017. const std::string extension = R"(
  1018. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1019. )";
  1020. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1021. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1022. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1023. }
  1024. TEST_F(ValidateOpenCL100DebugInfo, DebugTypePointerFail) {
  1025. const std::string src = R"(
  1026. %src = OpString "simple.hlsl"
  1027. %code = OpString "float4 main(float arg) {
  1028. float foo;
  1029. return float4(0, 0, 0, 0);
  1030. }
  1031. "
  1032. %float_name = OpString "float"
  1033. )";
  1034. const std::string size_const = R"(
  1035. %int_32 = OpConstant %u32 32
  1036. )";
  1037. const std::string dbg_inst_header = R"(
  1038. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1039. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1040. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1041. %pfloat_info = OpExtInst %void %DbgExt DebugTypePointer %dbg_src Function FlagIsLocal
  1042. )";
  1043. const std::string extension = R"(
  1044. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1045. )";
  1046. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1047. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1048. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1049. EXPECT_THAT(getDiagnosticString(),
  1050. HasSubstr("expected operand Base Type must be a result id of "
  1051. "DebugTypeBasic"));
  1052. }
  1053. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeQualifier) {
  1054. const std::string src = R"(
  1055. %src = OpString "simple.hlsl"
  1056. %code = OpString "float4 main(float arg) {
  1057. float foo;
  1058. return float4(0, 0, 0, 0);
  1059. }
  1060. "
  1061. %float_name = OpString "float"
  1062. )";
  1063. const std::string size_const = R"(
  1064. %int_32 = OpConstant %u32 32
  1065. )";
  1066. const std::string dbg_inst_header = R"(
  1067. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1068. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1069. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1070. %cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %float_info ConstType
  1071. )";
  1072. const std::string extension = R"(
  1073. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1074. )";
  1075. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1076. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1077. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1078. }
  1079. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeQualifierFail) {
  1080. const std::string src = R"(
  1081. %src = OpString "simple.hlsl"
  1082. %code = OpString "float4 main(float arg) {
  1083. float foo;
  1084. return float4(0, 0, 0, 0);
  1085. }
  1086. "
  1087. %float_name = OpString "float"
  1088. )";
  1089. const std::string size_const = R"(
  1090. %int_32 = OpConstant %u32 32
  1091. )";
  1092. const std::string dbg_inst_header = R"(
  1093. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1094. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1095. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1096. %cfloat_info = OpExtInst %void %DbgExt DebugTypeQualifier %comp_unit ConstType
  1097. )";
  1098. const std::string extension = R"(
  1099. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1100. )";
  1101. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1102. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1103. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1104. EXPECT_THAT(getDiagnosticString(),
  1105. HasSubstr("expected operand Base Type must be a result id of "
  1106. "DebugTypeBasic"));
  1107. }
  1108. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArray) {
  1109. const std::string src = R"(
  1110. %src = OpString "simple.hlsl"
  1111. %code = OpString "main() {}"
  1112. %float_name = OpString "float"
  1113. )";
  1114. const std::string size_const = R"(
  1115. %int_32 = OpConstant %u32 32
  1116. )";
  1117. const std::string dbg_inst_header = R"(
  1118. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1119. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1120. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1121. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %int_32
  1122. )";
  1123. const std::string extension = R"(
  1124. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1125. )";
  1126. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1127. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1128. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1129. }
  1130. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayWithVariableSize) {
  1131. const std::string src = R"(
  1132. %src = OpString "simple.hlsl"
  1133. %code = OpString "main() {}"
  1134. %float_name = OpString "float"
  1135. %int_name = OpString "int"
  1136. %main_name = OpString "main"
  1137. %foo_name = OpString "foo"
  1138. )";
  1139. const std::string size_const = R"(
  1140. %int_32 = OpConstant %u32 32
  1141. )";
  1142. const std::string dbg_inst_header = R"(
  1143. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1144. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1145. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1146. %uint_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %int_32 Unsigned
  1147. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1148. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  1149. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %uint_info %dbg_src 1 1 %main_info FlagIsLocal
  1150. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
  1151. )";
  1152. const std::string extension = R"(
  1153. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1154. )";
  1155. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1156. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1157. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1158. }
  1159. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailBaseType) {
  1160. const std::string src = R"(
  1161. %src = OpString "simple.hlsl"
  1162. %code = OpString "main() {}"
  1163. %float_name = OpString "float"
  1164. )";
  1165. const std::string size_const = R"(
  1166. %int_32 = OpConstant %u32 32
  1167. )";
  1168. const std::string dbg_inst_header = R"(
  1169. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1170. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1171. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1172. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %comp_unit %int_32
  1173. )";
  1174. const std::string extension = R"(
  1175. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1176. )";
  1177. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1178. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1179. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1180. EXPECT_THAT(getDiagnosticString(),
  1181. HasSubstr("expected operand Base Type is not a valid debug "
  1182. "type"));
  1183. }
  1184. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCount) {
  1185. const std::string src = R"(
  1186. %src = OpString "simple.hlsl"
  1187. %code = OpString "main() {}"
  1188. %float_name = OpString "float"
  1189. )";
  1190. const std::string size_const = R"(
  1191. %int_32 = OpConstant %u32 32
  1192. )";
  1193. const std::string dbg_inst_header = R"(
  1194. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1195. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1196. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1197. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %float_info
  1198. )";
  1199. const std::string extension = R"(
  1200. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1201. )";
  1202. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1203. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1204. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1205. EXPECT_THAT(getDiagnosticString(),
  1206. HasSubstr("Component Count must be OpConstant with a 32- or "
  1207. "64-bits integer scalar type or DebugGlobalVariable or "
  1208. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1209. "integer scalar type"));
  1210. }
  1211. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCountFloat) {
  1212. const std::string src = R"(
  1213. %src = OpString "simple.hlsl"
  1214. %code = OpString "main() {}"
  1215. %float_name = OpString "float"
  1216. )";
  1217. const std::string size_const = R"(
  1218. %int_32 = OpConstant %u32 32
  1219. )";
  1220. const std::string dbg_inst_header = R"(
  1221. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1222. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1223. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1224. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %f32_4
  1225. )";
  1226. const std::string extension = R"(
  1227. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1228. )";
  1229. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1230. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1231. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1232. EXPECT_THAT(getDiagnosticString(),
  1233. HasSubstr("Component Count must be OpConstant with a 32- or "
  1234. "64-bits integer scalar type or DebugGlobalVariable or "
  1235. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1236. "integer scalar type"));
  1237. }
  1238. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailComponentCountZero) {
  1239. const std::string src = R"(
  1240. %src = OpString "simple.hlsl"
  1241. %code = OpString "main() {}"
  1242. %float_name = OpString "float"
  1243. )";
  1244. const std::string size_const = R"(
  1245. %int_32 = OpConstant %u32 32
  1246. )";
  1247. const std::string dbg_inst_header = R"(
  1248. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1249. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1250. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1251. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %u32_0
  1252. )";
  1253. const std::string extension = R"(
  1254. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1255. )";
  1256. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1257. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1258. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1259. EXPECT_THAT(getDiagnosticString(),
  1260. HasSubstr("Component Count must be OpConstant with a 32- or "
  1261. "64-bits integer scalar type or DebugGlobalVariable or "
  1262. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1263. "integer scalar type"));
  1264. }
  1265. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeArrayFailVariableSizeTypeFloat) {
  1266. const std::string src = R"(
  1267. %src = OpString "simple.hlsl"
  1268. %code = OpString "main() {}"
  1269. %float_name = OpString "float"
  1270. %main_name = OpString "main"
  1271. %foo_name = OpString "foo"
  1272. )";
  1273. const std::string size_const = R"(
  1274. %int_32 = OpConstant %u32 32
  1275. )";
  1276. const std::string dbg_inst_header = R"(
  1277. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1278. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1279. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1280. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1281. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  1282. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 1 %main_info FlagIsLocal
  1283. %float_arr_info = OpExtInst %void %DbgExt DebugTypeArray %float_info %foo_info
  1284. )";
  1285. const std::string extension = R"(
  1286. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1287. )";
  1288. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1289. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1290. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1291. EXPECT_THAT(getDiagnosticString(),
  1292. HasSubstr("Component Count must be OpConstant with a 32- or "
  1293. "64-bits integer scalar type or DebugGlobalVariable or "
  1294. "DebugLocalVariable with a 32- or 64-bits unsigned "
  1295. "integer scalar type"));
  1296. }
  1297. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVector) {
  1298. const std::string src = R"(
  1299. %src = OpString "simple.hlsl"
  1300. %code = OpString "main() {}"
  1301. %float_name = OpString "float"
  1302. )";
  1303. const std::string size_const = R"(
  1304. %int_32 = OpConstant %u32 32
  1305. )";
  1306. const std::string dbg_inst_header = R"(
  1307. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1308. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1309. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1310. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  1311. )";
  1312. const std::string extension = R"(
  1313. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1314. )";
  1315. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1316. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1317. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1318. }
  1319. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFail) {
  1320. const std::string src = R"(
  1321. %src = OpString "simple.hlsl"
  1322. %code = OpString "main() {}"
  1323. %float_name = OpString "float"
  1324. )";
  1325. const std::string size_const = R"(
  1326. %int_32 = OpConstant %u32 32
  1327. )";
  1328. const std::string dbg_inst_header = R"(
  1329. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1330. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1331. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1332. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 4
  1333. )";
  1334. const std::string extension = R"(
  1335. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1336. )";
  1337. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1338. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1339. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1340. EXPECT_THAT(getDiagnosticString(),
  1341. HasSubstr("expected operand Base Type must be a result id of "
  1342. "DebugTypeBasic"));
  1343. }
  1344. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFailComponentZero) {
  1345. const std::string src = R"(
  1346. %src = OpString "simple.hlsl"
  1347. %code = OpString "main() {}"
  1348. %float_name = OpString "float"
  1349. )";
  1350. const std::string size_const = R"(
  1351. %int_32 = OpConstant %u32 32
  1352. )";
  1353. const std::string dbg_inst_header = R"(
  1354. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1355. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1356. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1357. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 0
  1358. )";
  1359. const std::string extension = R"(
  1360. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1361. )";
  1362. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1363. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1364. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1365. EXPECT_THAT(getDiagnosticString(),
  1366. HasSubstr("expected operand Base Type must be a result id of "
  1367. "DebugTypeBasic"));
  1368. }
  1369. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeVectorFailComponentFive) {
  1370. const std::string src = R"(
  1371. %src = OpString "simple.hlsl"
  1372. %code = OpString "main() {}"
  1373. %float_name = OpString "float"
  1374. )";
  1375. const std::string size_const = R"(
  1376. %int_32 = OpConstant %u32 32
  1377. )";
  1378. const std::string dbg_inst_header = R"(
  1379. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1380. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1381. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1382. %vfloat_info = OpExtInst %void %DbgExt DebugTypeVector %dbg_src 5
  1383. )";
  1384. const std::string extension = R"(
  1385. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1386. )";
  1387. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1388. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1389. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1390. EXPECT_THAT(getDiagnosticString(),
  1391. HasSubstr("expected operand Base Type must be a result id of "
  1392. "DebugTypeBasic"));
  1393. }
  1394. TEST_F(ValidateOpenCL100DebugInfo, DebugTypedef) {
  1395. const std::string src = R"(
  1396. %src = OpString "simple.hlsl"
  1397. %code = OpString "main() {}"
  1398. %float_name = OpString "float"
  1399. %foo_name = OpString "foo"
  1400. )";
  1401. const std::string size_const = R"(
  1402. %int_32 = OpConstant %u32 32
  1403. )";
  1404. const std::string dbg_inst_header = R"(
  1405. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1406. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1407. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1408. %foo_info = OpExtInst %void %DbgExt DebugTypedef %foo_name %float_info %dbg_src 1 1 %comp_unit
  1409. )";
  1410. const std::string extension = R"(
  1411. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1412. )";
  1413. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1414. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1415. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1416. }
  1417. TEST_P(ValidateOpenCL100DebugInfoDebugTypedef, Fail) {
  1418. const std::string src = R"(
  1419. %src = OpString "simple.hlsl"
  1420. %code = OpString "main() {}"
  1421. %float_name = OpString "float"
  1422. %foo_name = OpString "foo"
  1423. )";
  1424. const std::string size_const = R"(
  1425. %int_32 = OpConstant %u32 32
  1426. )";
  1427. const auto& param = GetParam();
  1428. std::ostringstream ss;
  1429. ss << R"(
  1430. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1431. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1432. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1433. %foo_info = OpExtInst %void %DbgExt DebugTypedef )";
  1434. ss << param.first;
  1435. const std::string extension = R"(
  1436. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1437. )";
  1438. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
  1439. "", extension, "Vertex"));
  1440. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1441. EXPECT_THAT(getDiagnosticString(),
  1442. HasSubstr("expected operand " + param.second +
  1443. " must be a result id of "));
  1444. }
  1445. INSTANTIATE_TEST_SUITE_P(
  1446. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypedef,
  1447. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1448. std::make_pair(R"(%dbg_src %float_info %dbg_src 1 1 %comp_unit)",
  1449. "Name"),
  1450. std::make_pair(R"(%foo_name %dbg_src %dbg_src 1 1 %comp_unit)",
  1451. "Base Type"),
  1452. std::make_pair(R"(%foo_name %float_info %comp_unit 1 1 %comp_unit)",
  1453. "Source"),
  1454. std::make_pair(R"(%foo_name %float_info %dbg_src 1 1 %dbg_src)",
  1455. "Parent"),
  1456. }));
  1457. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunction) {
  1458. const std::string src = R"(
  1459. %src = OpString "simple.hlsl"
  1460. %code = OpString "main() {}"
  1461. %main_name = OpString "main"
  1462. %main_linkage_name = OpString "v_main"
  1463. %float_name = OpString "float"
  1464. )";
  1465. const std::string size_const = R"(
  1466. %int_32 = OpConstant %u32 32
  1467. )";
  1468. const std::string dbg_inst_header = R"(
  1469. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1470. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1471. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1472. %main_type_info1 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1473. %main_type_info2 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info
  1474. %main_type_info3 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info %float_info
  1475. %main_type_info4 = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void %float_info %float_info
  1476. )";
  1477. const std::string extension = R"(
  1478. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1479. )";
  1480. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1481. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1482. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1483. }
  1484. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunctionFailReturn) {
  1485. const std::string src = R"(
  1486. %src = OpString "simple.hlsl"
  1487. %code = OpString "main() {}"
  1488. %main_name = OpString "main"
  1489. %main_linkage_name = OpString "v_main"
  1490. %float_name = OpString "float"
  1491. )";
  1492. const std::string size_const = R"(
  1493. %int_32 = OpConstant %u32 32
  1494. )";
  1495. const std::string dbg_inst_header = R"(
  1496. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1497. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1498. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1499. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %dbg_src %float_info
  1500. )";
  1501. const std::string extension = R"(
  1502. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1503. )";
  1504. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1505. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1506. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1507. EXPECT_THAT(
  1508. getDiagnosticString(),
  1509. HasSubstr("expected operand Return Type is not a valid debug type"));
  1510. }
  1511. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeFunctionFailParam) {
  1512. const std::string src = R"(
  1513. %src = OpString "simple.hlsl"
  1514. %code = OpString "main() {}"
  1515. %main_name = OpString "main"
  1516. %main_linkage_name = OpString "v_main"
  1517. %float_name = OpString "float"
  1518. )";
  1519. const std::string size_const = R"(
  1520. %int_32 = OpConstant %u32 32
  1521. )";
  1522. const std::string dbg_inst_header = R"(
  1523. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1524. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1525. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1526. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %float_info %void
  1527. )";
  1528. const std::string extension = R"(
  1529. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1530. )";
  1531. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1532. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1533. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1534. EXPECT_THAT(
  1535. getDiagnosticString(),
  1536. HasSubstr("expected operand Parameter Types is not a valid debug type"));
  1537. }
  1538. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeEnum) {
  1539. const std::string src = R"(
  1540. %src = OpString "simple.hlsl"
  1541. %code = OpString "main() {}"
  1542. %float_name = OpString "float"
  1543. %foo_name = OpString "foo"
  1544. )";
  1545. const std::string size_const = R"(
  1546. %int_32 = OpConstant %u32 32
  1547. )";
  1548. const std::string dbg_inst_header = R"(
  1549. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1550. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1551. %none = OpExtInst %void %DbgExt DebugInfoNone
  1552. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1553. %foo_info1 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name %u32_1 %foo_name
  1554. %foo_info2 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name %u32_1 %foo_name
  1555. %foo_info3 = OpExtInst %void %DbgExt DebugTypeEnum %foo_name %none %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic
  1556. )";
  1557. const std::string extension = R"(
  1558. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1559. )";
  1560. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1561. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1562. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1563. }
  1564. TEST_P(ValidateOpenCL100DebugInfoDebugTypeEnum, Fail) {
  1565. const std::string src = R"(
  1566. %src = OpString "simple.hlsl"
  1567. %code = OpString "main() {}"
  1568. %float_name = OpString "float"
  1569. %foo_name = OpString "foo"
  1570. )";
  1571. const std::string size_const = R"(
  1572. %int_32 = OpConstant %u32 32
  1573. )";
  1574. const auto& param = GetParam();
  1575. std::ostringstream ss;
  1576. ss << R"(
  1577. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1578. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1579. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1580. %foo_info = OpExtInst %void %DbgExt DebugTypeEnum )";
  1581. ss << param.first;
  1582. const std::string extension = R"(
  1583. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1584. )";
  1585. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
  1586. "", extension, "Vertex"));
  1587. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1588. EXPECT_THAT(getDiagnosticString(),
  1589. HasSubstr("expected operand " + param.second));
  1590. }
  1591. INSTANTIATE_TEST_SUITE_P(
  1592. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeEnum,
  1593. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1594. std::make_pair(
  1595. R"(%dbg_src %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
  1596. "Name"),
  1597. std::make_pair(
  1598. R"(%foo_name %dbg_src %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
  1599. "Underlying Types"),
  1600. std::make_pair(
  1601. R"(%foo_name %float_info %comp_unit 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %foo_name)",
  1602. "Source"),
  1603. std::make_pair(
  1604. R"(%foo_name %float_info %dbg_src 1 1 %dbg_src %int_32 FlagIsPublic %u32_0 %foo_name)",
  1605. "Parent"),
  1606. std::make_pair(
  1607. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %void FlagIsPublic %u32_0 %foo_name)",
  1608. "Size"),
  1609. std::make_pair(
  1610. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %u32_0 FlagIsPublic %u32_0 %foo_name)",
  1611. "Size"),
  1612. std::make_pair(
  1613. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %foo_name %foo_name)",
  1614. "Value"),
  1615. std::make_pair(
  1616. R"(%foo_name %float_info %dbg_src 1 1 %comp_unit %int_32 FlagIsPublic %u32_0 %u32_1)",
  1617. "Name"),
  1618. }));
  1619. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeCompositeFunctionAndInheritance) {
  1620. const std::string src = R"(
  1621. %src = OpString "simple.hlsl"
  1622. %code = OpString "struct VS_OUTPUT {
  1623. float4 pos : SV_POSITION;
  1624. };
  1625. struct foo : VS_OUTPUT {
  1626. };
  1627. main() {}
  1628. "
  1629. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  1630. %float_name = OpString "float"
  1631. %foo_name = OpString "foo"
  1632. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  1633. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  1634. %main_name = OpString "main"
  1635. %main_linkage_name = OpString "v4f_main_f"
  1636. )";
  1637. const std::string size_const = R"(
  1638. %int_32 = OpConstant %u32 32
  1639. %int_128 = OpConstant %u32 128
  1640. )";
  1641. const std::string dbg_inst_header = R"(
  1642. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1643. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1644. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child
  1645. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1646. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  1647. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  1648. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
  1649. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main
  1650. %foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  1651. %child = OpExtInst %void %DbgExt DebugTypeInheritance %foo_info %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
  1652. )";
  1653. const std::string extension = R"(
  1654. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1655. )";
  1656. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  1657. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  1658. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1659. }
  1660. TEST_P(ValidateOpenCL100DebugInfoDebugTypeComposite, Fail) {
  1661. const std::string src = R"(
  1662. %src = OpString "simple.hlsl"
  1663. %code = OpString "struct VS_OUTPUT {
  1664. float4 pos : SV_POSITION;
  1665. };
  1666. struct foo : VS_OUTPUT {
  1667. };
  1668. main() {}
  1669. "
  1670. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  1671. %float_name = OpString "float"
  1672. %foo_name = OpString "foo"
  1673. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  1674. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  1675. %main_name = OpString "main"
  1676. %main_linkage_name = OpString "v4f_main_f"
  1677. )";
  1678. const std::string size_const = R"(
  1679. %int_32 = OpConstant %u32 32
  1680. %int_128 = OpConstant %u32 128
  1681. )";
  1682. const auto& param = GetParam();
  1683. std::ostringstream ss;
  1684. ss << R"(
  1685. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1686. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1687. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite )";
  1688. ss << param.first;
  1689. ss << R"(
  1690. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1691. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  1692. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember %VS_OUTPUT_pos_name %v4float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_128 FlagIsPublic
  1693. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %v4float_info %float_info
  1694. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main
  1695. %foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  1696. %child = OpExtInst %void %DbgExt DebugTypeInheritance %foo_info %VS_OUTPUT_info %int_128 %int_128 FlagIsPublic
  1697. )";
  1698. const std::string extension = R"(
  1699. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1700. )";
  1701. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
  1702. "", extension, "Vertex"));
  1703. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1704. EXPECT_THAT(getDiagnosticString(),
  1705. HasSubstr("expected operand " + param.second + " must be "));
  1706. }
  1707. INSTANTIATE_TEST_SUITE_P(
  1708. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeComposite,
  1709. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1710. std::make_pair(
  1711. R"(%dbg_src Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1712. "Name"),
  1713. std::make_pair(
  1714. R"(%VS_OUTPUT_name Structure %comp_unit 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1715. "Source"),
  1716. std::make_pair(
  1717. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %dbg_src %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1718. "Parent"),
  1719. std::make_pair(
  1720. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %int_128 %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1721. "Linkage Name"),
  1722. std::make_pair(
  1723. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %dbg_src FlagIsPublic %VS_OUTPUT_pos_info %main_info %child)",
  1724. "Size"),
  1725. std::make_pair(
  1726. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %dbg_src %main_info %child)",
  1727. "Members"),
  1728. std::make_pair(
  1729. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %dbg_src %child)",
  1730. "Members"),
  1731. std::make_pair(
  1732. R"(%VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_128 FlagIsPublic %VS_OUTPUT_pos_info %main_info %dbg_src)",
  1733. "Members"),
  1734. }));
  1735. TEST_P(ValidateOpenCL100DebugInfoDebugTypeMember, Fail) {
  1736. const std::string src = R"(
  1737. %src = OpString "simple.hlsl"
  1738. %code = OpString "struct VS_OUTPUT {
  1739. float pos : SV_POSITION;
  1740. };
  1741. main() {}
  1742. "
  1743. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  1744. %float_name = OpString "float"
  1745. %VS_OUTPUT_pos_name = OpString "pos : SV_POSITION"
  1746. %VS_OUTPUT_linkage_name = OpString "VS_OUTPUT"
  1747. )";
  1748. const std::string size_const = R"(
  1749. %int_32 = OpConstant %u32 32
  1750. )";
  1751. const auto& param = GetParam();
  1752. std::ostringstream ss;
  1753. ss << R"(
  1754. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1755. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1756. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_linkage_name %int_32 FlagIsPublic %VS_OUTPUT_pos_info
  1757. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  1758. %VS_OUTPUT_pos_info = OpExtInst %void %DbgExt DebugTypeMember )";
  1759. ss << param.first;
  1760. const std::string extension = R"(
  1761. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1762. )";
  1763. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
  1764. "", extension, "Vertex"));
  1765. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1766. if (!param.second.empty()) {
  1767. EXPECT_THAT(getDiagnosticString(),
  1768. HasSubstr("expected operand " + param.second +
  1769. " must be a result id of "));
  1770. }
  1771. }
  1772. INSTANTIATE_TEST_SUITE_P(
  1773. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeMember,
  1774. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1775. std::make_pair(
  1776. R"(%dbg_src %float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
  1777. "Name"),
  1778. std::make_pair(
  1779. R"(%VS_OUTPUT_pos_name %dbg_src %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
  1780. ""),
  1781. std::make_pair(
  1782. R"(%VS_OUTPUT_pos_name %float_info %float_info 2 3 %VS_OUTPUT_info %u32_0 %int_32 FlagIsPublic)",
  1783. "Source"),
  1784. std::make_pair(
  1785. R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %float_info %u32_0 %int_32 FlagIsPublic)",
  1786. "Parent"),
  1787. std::make_pair(
  1788. R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %VS_OUTPUT_info %void %int_32 FlagIsPublic)",
  1789. "Offset"),
  1790. std::make_pair(
  1791. R"(%VS_OUTPUT_pos_name %float_info %dbg_src 2 3 %VS_OUTPUT_info %u32_0 %void FlagIsPublic)",
  1792. "Size"),
  1793. }));
  1794. TEST_P(ValidateOpenCL100DebugInfoDebugTypeInheritance, Fail) {
  1795. const std::string src = R"(
  1796. %src = OpString "simple.hlsl"
  1797. %code = OpString "struct VS_OUTPUT {};
  1798. struct foo : VS_OUTPUT {};
  1799. "
  1800. %VS_OUTPUT_name = OpString "struct VS_OUTPUT"
  1801. %foo_name = OpString "foo"
  1802. )";
  1803. const auto& param = GetParam();
  1804. std::ostringstream ss;
  1805. ss << R"(
  1806. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1807. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1808. %VS_OUTPUT_info = OpExtInst %void %DbgExt DebugTypeComposite %VS_OUTPUT_name Structure %dbg_src 1 1 %comp_unit %VS_OUTPUT_name %u32_0 FlagIsPublic %child
  1809. %foo_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Structure %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  1810. %bar_info = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Union %dbg_src 1 1 %comp_unit %foo_name %u32_0 FlagIsPublic
  1811. %child = OpExtInst %void %DbgExt DebugTypeInheritance )"
  1812. << param.first;
  1813. const std::string extension = R"(
  1814. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1815. )";
  1816. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
  1817. extension, "Vertex"));
  1818. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1819. EXPECT_THAT(getDiagnosticString(),
  1820. HasSubstr("expected operand " + param.second));
  1821. }
  1822. INSTANTIATE_TEST_SUITE_P(
  1823. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugTypeInheritance,
  1824. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1825. std::make_pair(R"(%dbg_src %VS_OUTPUT_info %u32_0 %u32_0 FlagIsPublic)",
  1826. "Child must be a result id of"),
  1827. std::make_pair(R"(%foo_info %dbg_src %u32_0 %u32_0 FlagIsPublic)",
  1828. "Parent must be a result id of"),
  1829. std::make_pair(
  1830. R"(%bar_info %VS_OUTPUT_info %u32_0 %u32_0 FlagIsPublic)",
  1831. "Child must be class or struct debug type"),
  1832. std::make_pair(R"(%foo_info %bar_info %u32_0 %u32_0 FlagIsPublic)",
  1833. "Parent must be class or struct debug type"),
  1834. std::make_pair(R"(%foo_info %VS_OUTPUT_info %void %u32_0 FlagIsPublic)",
  1835. "Offset"),
  1836. std::make_pair(R"(%foo_info %VS_OUTPUT_info %u32_0 %void FlagIsPublic)",
  1837. "Size"),
  1838. }));
  1839. TEST_P(ValidateGlslStd450SqrtLike, Success) {
  1840. const std::string ext_inst_name = GetParam();
  1841. std::ostringstream ss;
  1842. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
  1843. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  1844. << " %f32vec2_01\n";
  1845. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name << " %f64_0\n";
  1846. CompileSuccessfully(GenerateShaderCode(ss.str()));
  1847. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1848. }
  1849. TEST_F(ValidateOpenCL100DebugInfo, DebugFunctionDeclaration) {
  1850. const std::string src = R"(
  1851. %src = OpString "simple.hlsl"
  1852. %code = OpString "struct VS_OUTPUT {
  1853. float4 pos : SV_POSITION;
  1854. };
  1855. main() {}
  1856. "
  1857. %main_name = OpString "main"
  1858. %main_linkage_name = OpString "v4f_main_f"
  1859. )";
  1860. const std::string dbg_inst_header = R"(
  1861. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1862. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1863. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1864. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic
  1865. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)";
  1866. const std::string extension = R"(
  1867. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1868. )";
  1869. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst_header,
  1870. "", extension, "Vertex"));
  1871. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1872. }
  1873. TEST_P(ValidateOpenCL100DebugInfoDebugFunction, Fail) {
  1874. const std::string src = R"(
  1875. %src = OpString "simple.hlsl"
  1876. %code = OpString "struct VS_OUTPUT {
  1877. float4 pos : SV_POSITION;
  1878. };
  1879. main() {}
  1880. "
  1881. %main_name = OpString "main"
  1882. %main_linkage_name = OpString "v4f_main_f"
  1883. )";
  1884. const auto& param = GetParam();
  1885. std::ostringstream ss;
  1886. ss << R"(
  1887. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1888. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1889. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1890. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration %main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic
  1891. %main_info = OpExtInst %void %DbgExt DebugFunction )"
  1892. << param.first;
  1893. const std::string extension = R"(
  1894. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1895. )";
  1896. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
  1897. extension, "Vertex"));
  1898. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1899. EXPECT_THAT(getDiagnosticString(),
  1900. HasSubstr("expected operand " + param.second));
  1901. }
  1902. INSTANTIATE_TEST_SUITE_P(
  1903. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugFunction,
  1904. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1905. std::make_pair(
  1906. R"(%u32_0 %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)",
  1907. "Name"),
  1908. std::make_pair(
  1909. R"(%main_name %dbg_src %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)",
  1910. "Type"),
  1911. std::make_pair(
  1912. R"(%main_name %main_type_info %comp_unit 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main)",
  1913. "Source"),
  1914. std::make_pair(
  1915. R"(%main_name %main_type_info %dbg_src 12 1 %dbg_src %main_linkage_name FlagIsPublic 13 %main)",
  1916. "Parent"),
  1917. std::make_pair(
  1918. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %void FlagIsPublic 13 %main)",
  1919. "Linkage Name"),
  1920. std::make_pair(
  1921. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %void)",
  1922. "Function"),
  1923. std::make_pair(
  1924. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic 13 %main %dbg_src)",
  1925. "Declaration"),
  1926. }));
  1927. TEST_P(ValidateOpenCL100DebugInfoDebugFunctionDeclaration, Fail) {
  1928. const std::string src = R"(
  1929. %src = OpString "simple.hlsl"
  1930. %code = OpString "struct VS_OUTPUT {
  1931. float4 pos : SV_POSITION;
  1932. };
  1933. main() {}
  1934. "
  1935. %main_name = OpString "main"
  1936. %main_linkage_name = OpString "v4f_main_f"
  1937. )";
  1938. const auto& param = GetParam();
  1939. std::ostringstream ss;
  1940. ss << R"(
  1941. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1942. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1943. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  1944. %main_decl = OpExtInst %void %DbgExt DebugFunctionDeclaration )"
  1945. << param.first;
  1946. const std::string extension = R"(
  1947. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1948. )";
  1949. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
  1950. extension, "Vertex"));
  1951. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1952. EXPECT_THAT(getDiagnosticString(),
  1953. HasSubstr("expected operand " + param.second));
  1954. }
  1955. INSTANTIATE_TEST_SUITE_P(
  1956. AllOpenCL100DebugInfoFail,
  1957. ValidateOpenCL100DebugInfoDebugFunctionDeclaration,
  1958. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  1959. std::make_pair(
  1960. R"(%u32_0 %main_type_info %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic)",
  1961. "Name"),
  1962. std::make_pair(
  1963. R"(%main_name %dbg_src %dbg_src 12 1 %comp_unit %main_linkage_name FlagIsPublic)",
  1964. "Type"),
  1965. std::make_pair(
  1966. R"(%main_name %main_type_info %comp_unit 12 1 %comp_unit %main_linkage_name FlagIsPublic)",
  1967. "Source"),
  1968. std::make_pair(
  1969. R"(%main_name %main_type_info %dbg_src 12 1 %dbg_src %main_linkage_name FlagIsPublic)",
  1970. "Parent"),
  1971. std::make_pair(
  1972. R"(%main_name %main_type_info %dbg_src 12 1 %comp_unit %void FlagIsPublic)",
  1973. "Linkage Name"),
  1974. }));
  1975. TEST_F(ValidateOpenCL100DebugInfo, DebugLexicalBlock) {
  1976. const std::string src = R"(
  1977. %src = OpString "simple.hlsl"
  1978. %code = OpString "main() {}"
  1979. %main_name = OpString "main"
  1980. )";
  1981. const std::string dbg_inst_header = R"(
  1982. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  1983. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  1984. %main_block = OpExtInst %void %DbgExt DebugLexicalBlock %dbg_src 1 1 %comp_unit %main_name)";
  1985. const std::string extension = R"(
  1986. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  1987. )";
  1988. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", dbg_inst_header,
  1989. "", extension, "Vertex"));
  1990. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1991. }
  1992. TEST_P(ValidateOpenCL100DebugInfoDebugLexicalBlock, Fail) {
  1993. const std::string src = R"(
  1994. %src = OpString "simple.hlsl"
  1995. %code = OpString "main() {}"
  1996. %main_name = OpString "main"
  1997. )";
  1998. const auto& param = GetParam();
  1999. std::ostringstream ss;
  2000. ss << R"(
  2001. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2002. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2003. %main_block = OpExtInst %void %DbgExt DebugLexicalBlock )"
  2004. << param.first;
  2005. const std::string extension = R"(
  2006. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2007. )";
  2008. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, "", ss.str(), "",
  2009. extension, "Vertex"));
  2010. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2011. EXPECT_THAT(getDiagnosticString(),
  2012. HasSubstr("expected operand " + param.second));
  2013. }
  2014. INSTANTIATE_TEST_SUITE_P(
  2015. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugLexicalBlock,
  2016. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2017. std::make_pair(R"(%comp_unit 1 1 %comp_unit %main_name)", "Source"),
  2018. std::make_pair(R"(%dbg_src 1 1 %dbg_src %main_name)", "Parent"),
  2019. std::make_pair(R"(%dbg_src 1 1 %comp_unit %void)", "Name"),
  2020. }));
  2021. TEST_F(ValidateOpenCL100DebugInfo, DebugScopeFailScope) {
  2022. const std::string src = R"(
  2023. %src = OpString "simple.hlsl"
  2024. %code = OpString "void main() {}"
  2025. )";
  2026. const std::string dbg_inst_header = R"(
  2027. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2028. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2029. )";
  2030. const std::string body = R"(
  2031. %main_scope = OpExtInst %void %DbgExt DebugScope %dbg_src
  2032. )";
  2033. const std::string extension = R"(
  2034. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2035. )";
  2036. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2037. src, "", dbg_inst_header, body, extension, "Vertex"));
  2038. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2039. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
  2040. }
  2041. TEST_F(ValidateOpenCL100DebugInfo, DebugScopeFailInlinedAt) {
  2042. const std::string src = R"(
  2043. %src = OpString "simple.hlsl"
  2044. %code = OpString "void main() {}"
  2045. )";
  2046. const std::string dbg_inst_header = R"(
  2047. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2048. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2049. )";
  2050. const std::string body = R"(
  2051. %main_scope = OpExtInst %void %DbgExt DebugScope %comp_unit %dbg_src
  2052. )";
  2053. const std::string extension = R"(
  2054. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2055. )";
  2056. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2057. src, "", dbg_inst_header, body, extension, "Vertex"));
  2058. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2059. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined At"));
  2060. }
  2061. TEST_F(ValidateOpenCL100DebugInfo, DebugLocalVariable) {
  2062. const std::string src = R"(
  2063. %src = OpString "simple.hlsl"
  2064. %code = OpString "void main() { float foo; }"
  2065. %float_name = OpString "float"
  2066. %foo_name = OpString "foo"
  2067. )";
  2068. const std::string size_const = R"(
  2069. %int_32 = OpConstant %u32 32
  2070. )";
  2071. const std::string dbg_inst_header = R"(
  2072. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2073. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2074. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2075. %foo = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2076. )";
  2077. const std::string extension = R"(
  2078. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2079. )";
  2080. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2081. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2082. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2083. }
  2084. TEST_P(ValidateOpenCL100DebugInfoDebugLocalVariable, Fail) {
  2085. const std::string src = R"(
  2086. %src = OpString "simple.hlsl"
  2087. %code = OpString "void main() { float foo; }"
  2088. %float_name = OpString "float"
  2089. %foo_name = OpString "foo"
  2090. )";
  2091. const std::string size_const = R"(
  2092. %int_32 = OpConstant %u32 32
  2093. )";
  2094. const auto& param = GetParam();
  2095. std::ostringstream ss;
  2096. ss << R"(
  2097. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2098. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2099. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2100. %foo = OpExtInst %void %DbgExt DebugLocalVariable )"
  2101. << param.first;
  2102. const std::string extension = R"(
  2103. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2104. )";
  2105. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
  2106. "", extension, "Vertex"));
  2107. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2108. EXPECT_THAT(getDiagnosticString(),
  2109. HasSubstr("expected operand " + param.second));
  2110. }
  2111. INSTANTIATE_TEST_SUITE_P(
  2112. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugLocalVariable,
  2113. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2114. std::make_pair(
  2115. R"(%void %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0)",
  2116. "Name"),
  2117. std::make_pair(
  2118. R"(%foo_name %dbg_src %dbg_src 1 10 %comp_unit FlagIsLocal 0)",
  2119. "Type"),
  2120. std::make_pair(
  2121. R"(%foo_name %float_info %comp_unit 1 10 %comp_unit FlagIsLocal 0)",
  2122. "Source"),
  2123. std::make_pair(
  2124. R"(%foo_name %float_info %dbg_src 1 10 %dbg_src FlagIsLocal 0)",
  2125. "Parent"),
  2126. }));
  2127. TEST_F(ValidateOpenCL100DebugInfo, DebugDeclare) {
  2128. const std::string src = R"(
  2129. %src = OpString "simple.hlsl"
  2130. %code = OpString "void main() { float foo; }"
  2131. %float_name = OpString "float"
  2132. %foo_name = OpString "foo"
  2133. )";
  2134. const std::string size_const = R"(
  2135. %int_32 = OpConstant %u32 32
  2136. )";
  2137. const std::string dbg_inst_header = R"(
  2138. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2139. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2140. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2141. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2142. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2143. )";
  2144. const std::string body = R"(
  2145. %foo = OpVariable %f32_ptr_function Function
  2146. %decl = OpExtInst %void %DbgExt DebugDeclare %foo_info %foo %null_expr
  2147. )";
  2148. const std::string extension = R"(
  2149. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2150. )";
  2151. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2152. src, size_const, dbg_inst_header, body, extension, "Vertex"));
  2153. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2154. }
  2155. TEST_F(ValidateOpenCL100DebugInfo, DebugDeclareParam) {
  2156. CompileSuccessfully(R"(
  2157. OpCapability Shader
  2158. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  2159. OpMemoryModel Logical GLSL450
  2160. OpEntryPoint Vertex %main "main" %in_var_COLOR
  2161. %4 = OpString "test.hlsl"
  2162. OpSource HLSL 620 %4 "#line 1 \"test.hlsl\"
  2163. void main(float foo:COLOR) {}
  2164. "
  2165. %11 = OpString "#line 1 \"test.hlsl\"
  2166. void main(float foo:COLOR) {}
  2167. "
  2168. %14 = OpString "float"
  2169. %17 = OpString "src.main"
  2170. %20 = OpString "foo"
  2171. OpName %in_var_COLOR "in.var.COLOR"
  2172. OpName %main "main"
  2173. OpName %param_var_foo "param.var.foo"
  2174. OpName %src_main "src.main"
  2175. OpName %foo "foo"
  2176. OpName %bb_entry "bb.entry"
  2177. OpDecorate %in_var_COLOR Location 0
  2178. %uint = OpTypeInt 32 0
  2179. %uint_32 = OpConstant %uint 32
  2180. %float = OpTypeFloat 32
  2181. %_ptr_Input_float = OpTypePointer Input %float
  2182. %void = OpTypeVoid
  2183. %23 = OpTypeFunction %void
  2184. %_ptr_Function_float = OpTypePointer Function %float
  2185. %29 = OpTypeFunction %void %_ptr_Function_float
  2186. OpLine %4 1 21
  2187. %in_var_COLOR = OpVariable %_ptr_Input_float Input
  2188. %10 = OpExtInst %void %1 DebugExpression
  2189. %12 = OpExtInst %void %1 DebugSource %4 %11
  2190. %13 = OpExtInst %void %1 DebugCompilationUnit 1 4 %12 HLSL
  2191. %15 = OpExtInst %void %1 DebugTypeBasic %14 %uint_32 Float
  2192. %16 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %void %15
  2193. %18 = OpExtInst %void %1 DebugFunction %17 %16 %12 1 1 %13 %17 FlagIsProtected|FlagIsPrivate 1 %src_main
  2194. %21 = OpExtInst %void %1 DebugLocalVariable %20 %15 %12 1 17 %18 FlagIsLocal 0
  2195. %22 = OpExtInst %void %1 DebugLexicalBlock %12 1 28 %18
  2196. OpLine %4 1 1
  2197. %main = OpFunction %void None %23
  2198. %24 = OpLabel
  2199. OpLine %4 1 17
  2200. %param_var_foo = OpVariable %_ptr_Function_float Function
  2201. %27 = OpLoad %float %in_var_COLOR
  2202. OpLine %4 1 1
  2203. %28 = OpFunctionCall %void %src_main %param_var_foo
  2204. OpReturn
  2205. OpFunctionEnd
  2206. %src_main = OpFunction %void None %29
  2207. OpLine %4 1 17
  2208. %foo = OpFunctionParameter %_ptr_Function_float
  2209. %31 = OpExtInst %void %1 DebugDeclare %21 %foo %10
  2210. %bb_entry = OpLabel
  2211. OpLine %4 1 29
  2212. OpReturn
  2213. OpFunctionEnd
  2214. )");
  2215. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2216. }
  2217. TEST_P(ValidateOpenCL100DebugInfoDebugDeclare, Fail) {
  2218. const std::string src = R"(
  2219. %src = OpString "simple.hlsl"
  2220. %code = OpString "void main() { float foo; }"
  2221. %float_name = OpString "float"
  2222. %foo_name = OpString "foo"
  2223. )";
  2224. const std::string size_const = R"(
  2225. %int_32 = OpConstant %u32 32
  2226. )";
  2227. const std::string dbg_inst_header = R"(
  2228. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2229. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2230. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2231. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2232. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2233. )";
  2234. const auto& param = GetParam();
  2235. std::ostringstream ss;
  2236. ss << R"(
  2237. %foo = OpVariable %f32_ptr_function Function
  2238. %decl = OpExtInst %void %DbgExt DebugDeclare )"
  2239. << param.first;
  2240. const std::string extension = R"(
  2241. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2242. )";
  2243. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2244. src, size_const, dbg_inst_header, ss.str(), extension, "Vertex"));
  2245. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2246. EXPECT_THAT(getDiagnosticString(),
  2247. HasSubstr("expected operand " + param.second));
  2248. }
  2249. INSTANTIATE_TEST_SUITE_P(
  2250. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugDeclare,
  2251. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2252. std::make_pair(R"(%dbg_src %foo %null_expr)", "Local Variable"),
  2253. std::make_pair(R"(%foo_info %void %null_expr)", "Variable"),
  2254. std::make_pair(R"(%foo_info %foo %dbg_src)", "Expression"),
  2255. }));
  2256. TEST_F(ValidateOpenCL100DebugInfo, DebugExpression) {
  2257. const std::string dbg_inst_header = R"(
  2258. %op0 = OpExtInst %void %DbgExt DebugOperation Deref
  2259. %op1 = OpExtInst %void %DbgExt DebugOperation Plus
  2260. %null_expr = OpExtInst %void %DbgExt DebugExpression %op0 %op1
  2261. )";
  2262. const std::string extension = R"(
  2263. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2264. )";
  2265. CompileSuccessfully(GenerateShaderCodeForDebugInfo("", "", dbg_inst_header,
  2266. "", extension, "Vertex"));
  2267. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2268. }
  2269. TEST_F(ValidateOpenCL100DebugInfo, DebugExpressionFail) {
  2270. const std::string dbg_inst_header = R"(
  2271. %op = OpExtInst %void %DbgExt DebugOperation Deref
  2272. %null_expr = OpExtInst %void %DbgExt DebugExpression %op %void
  2273. )";
  2274. const std::string extension = R"(
  2275. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2276. )";
  2277. CompileSuccessfully(GenerateShaderCodeForDebugInfo("", "", dbg_inst_header,
  2278. "", extension, "Vertex"));
  2279. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2280. EXPECT_THAT(
  2281. getDiagnosticString(),
  2282. HasSubstr(
  2283. "expected operand Operation must be a result id of DebugOperation"));
  2284. }
  2285. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplate) {
  2286. const std::string src = R"(
  2287. %src = OpString "simple.hlsl"
  2288. %code = OpString "OpaqueType foo;
  2289. main() {}
  2290. "
  2291. %float_name = OpString "float"
  2292. %ty_name = OpString "Texture"
  2293. %t_name = OpString "T"
  2294. )";
  2295. const std::string size_const = R"(
  2296. %int_32 = OpConstant %u32 32
  2297. %int_128 = OpConstant %u32 128
  2298. )";
  2299. const std::string dbg_inst_header = R"(
  2300. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  2301. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2302. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2303. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2304. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
  2305. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  2306. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
  2307. )";
  2308. const std::string extension = R"(
  2309. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2310. )";
  2311. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2312. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2313. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2314. }
  2315. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateUsedForVariableType) {
  2316. const std::string src = R"(
  2317. %src = OpString "simple.hlsl"
  2318. %code = OpString "OpaqueType foo;
  2319. main() {}
  2320. "
  2321. %float_name = OpString "float"
  2322. %ty_name = OpString "Texture"
  2323. %t_name = OpString "T"
  2324. %foo_name = OpString "foo"
  2325. )";
  2326. const std::string size_const = R"(
  2327. %int_32 = OpConstant %u32 32
  2328. %int_128 = OpConstant %u32 128
  2329. )";
  2330. const std::string dbg_inst_header = R"(
  2331. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  2332. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2333. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2334. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2335. %opaque = OpExtInst %void %DbgExt DebugTypeComposite %ty_name Class %dbg_src 1 1 %comp_unit %ty_name %dbg_none FlagIsPublic
  2336. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  2337. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %opaque %param
  2338. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %temp %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate
  2339. )";
  2340. const std::string extension = R"(
  2341. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2342. )";
  2343. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2344. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2345. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2346. }
  2347. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFunction) {
  2348. const std::string src = R"(
  2349. %src = OpString "simple.hlsl"
  2350. %code = OpString "OpaqueType foo;
  2351. main() {}
  2352. "
  2353. %float_name = OpString "float"
  2354. %ty_name = OpString "Texture"
  2355. %t_name = OpString "T"
  2356. %main_name = OpString "main"
  2357. )";
  2358. const std::string size_const = R"(
  2359. %int_32 = OpConstant %u32 32
  2360. %int_128 = OpConstant %u32 128
  2361. )";
  2362. const std::string dbg_inst_header = R"(
  2363. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  2364. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2365. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2366. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2367. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  2368. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %param %param
  2369. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  2370. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %param
  2371. )";
  2372. const std::string extension = R"(
  2373. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2374. )";
  2375. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2376. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2377. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2378. }
  2379. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFailTarget) {
  2380. const std::string src = R"(
  2381. %src = OpString "simple.hlsl"
  2382. %code = OpString "OpaqueType foo;
  2383. main() {}
  2384. "
  2385. %float_name = OpString "float"
  2386. %ty_name = OpString "Texture"
  2387. %t_name = OpString "T"
  2388. %main_name = OpString "main"
  2389. )";
  2390. const std::string size_const = R"(
  2391. %int_32 = OpConstant %u32 32
  2392. %int_128 = OpConstant %u32 128
  2393. )";
  2394. const std::string dbg_inst_header = R"(
  2395. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  2396. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2397. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2398. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2399. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  2400. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %float_info %param
  2401. )";
  2402. const std::string extension = R"(
  2403. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2404. )";
  2405. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2406. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2407. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2408. EXPECT_THAT(getDiagnosticString(),
  2409. HasSubstr("expected operand Target must be DebugTypeComposite or "
  2410. "DebugFunction"));
  2411. }
  2412. TEST_F(ValidateOpenCL100DebugInfo, DebugTypeTemplateFailParam) {
  2413. const std::string src = R"(
  2414. %src = OpString "simple.hlsl"
  2415. %code = OpString "OpaqueType foo;
  2416. main() {}
  2417. "
  2418. %float_name = OpString "float"
  2419. %ty_name = OpString "Texture"
  2420. %t_name = OpString "T"
  2421. %main_name = OpString "main"
  2422. )";
  2423. const std::string size_const = R"(
  2424. %int_32 = OpConstant %u32 32
  2425. %int_128 = OpConstant %u32 128
  2426. )";
  2427. const std::string dbg_inst_header = R"(
  2428. %dbg_none = OpExtInst %void %DbgExt DebugInfoNone
  2429. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2430. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2431. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2432. %param = OpExtInst %void %DbgExt DebugTypeTemplateParameter %t_name %float_info %dbg_none %dbg_src 0 0
  2433. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %param %param
  2434. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_name FlagIsPublic 1 %main
  2435. %temp = OpExtInst %void %DbgExt DebugTypeTemplate %main_info %float_info
  2436. )";
  2437. const std::string extension = R"(
  2438. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2439. )";
  2440. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2441. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2442. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2443. EXPECT_THAT(
  2444. getDiagnosticString(),
  2445. HasSubstr(
  2446. "expected operand Parameters must be DebugTypeTemplateParameter or "
  2447. "DebugTypeTemplateTemplateParameter"));
  2448. }
  2449. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariable) {
  2450. const std::string src = R"(
  2451. %src = OpString "simple.hlsl"
  2452. %code = OpString "float foo; void main() {}"
  2453. %float_name = OpString "float"
  2454. %foo_name = OpString "foo"
  2455. )";
  2456. const std::string size_const = R"(
  2457. %int_32 = OpConstant %u32 32
  2458. )";
  2459. const std::string dbg_inst_header = R"(
  2460. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2461. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2462. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2463. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate
  2464. )";
  2465. const std::string extension = R"(
  2466. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2467. )";
  2468. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2469. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2470. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2471. }
  2472. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableStaticMember) {
  2473. const std::string src = R"(
  2474. %src = OpString "simple.hlsl"
  2475. %code = OpString "float foo; void main() {}"
  2476. %float_name = OpString "float"
  2477. %foo_name = OpString "foo"
  2478. )";
  2479. const std::string size_const = R"(
  2480. %int_32 = OpConstant %u32 32
  2481. )";
  2482. const std::string dbg_inst_header = R"(
  2483. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2484. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2485. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2486. %t = OpExtInst %void %DbgExt DebugTypeComposite %foo_name Class %dbg_src 0 0 %comp_unit %foo_name %int_32 FlagIsPublic %a
  2487. %a = OpExtInst %void %DbgExt DebugTypeMember %foo_name %float_info %dbg_src 0 0 %t %u32_0 %int_32 FlagIsPublic
  2488. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate %a
  2489. )";
  2490. const std::string extension = R"(
  2491. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2492. )";
  2493. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2494. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2495. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2496. }
  2497. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableDebugInfoNone) {
  2498. const std::string src = R"(
  2499. %src = OpString "simple.hlsl"
  2500. %code = OpString "float foo; void main() {}"
  2501. %float_name = OpString "float"
  2502. %foo_name = OpString "foo"
  2503. )";
  2504. const std::string size_const = R"(
  2505. %int_32 = OpConstant %u32 32
  2506. )";
  2507. const std::string dbg_inst_header = R"(
  2508. %dbgNone = OpExtInst %void %DbgExt DebugInfoNone
  2509. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2510. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2511. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2512. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %dbgNone FlagIsProtected|FlagIsPrivate
  2513. )";
  2514. const std::string extension = R"(
  2515. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2516. )";
  2517. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2518. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2519. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2520. }
  2521. TEST_F(ValidateOpenCL100DebugInfo, DebugGlobalVariableConst) {
  2522. const std::string src = R"(
  2523. %src = OpString "simple.hlsl"
  2524. %code = OpString "float foo; void main() {}"
  2525. %float_name = OpString "float"
  2526. %foo_name = OpString "foo"
  2527. )";
  2528. const std::string size_const = R"(
  2529. %int_32 = OpConstant %u32 32
  2530. )";
  2531. const std::string dbg_inst_header = R"(
  2532. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2533. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2534. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2535. %foo = OpExtInst %void %DbgExt DebugGlobalVariable %foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %int_32 FlagIsProtected|FlagIsPrivate
  2536. )";
  2537. const std::string extension = R"(
  2538. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2539. )";
  2540. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2541. src, size_const, dbg_inst_header, "", extension, "Vertex"));
  2542. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2543. }
  2544. TEST_P(ValidateOpenCL100DebugInfoDebugGlobalVariable, Fail) {
  2545. const std::string src = R"(
  2546. %src = OpString "simple.hlsl"
  2547. %code = OpString "float foo; void main() {}"
  2548. %float_name = OpString "float"
  2549. %foo_name = OpString "foo"
  2550. )";
  2551. const std::string size_const = R"(
  2552. %int_32 = OpConstant %u32 32
  2553. )";
  2554. const auto& param = GetParam();
  2555. std::ostringstream ss;
  2556. ss << R"(
  2557. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2558. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2559. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2560. %foo = OpExtInst %void %DbgExt DebugGlobalVariable )"
  2561. << param.first;
  2562. const std::string extension = R"(
  2563. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2564. )";
  2565. CompileSuccessfully(GenerateShaderCodeForDebugInfo(src, size_const, ss.str(),
  2566. "", extension, "Vertex"));
  2567. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2568. EXPECT_THAT(getDiagnosticString(),
  2569. HasSubstr("expected operand " + param.second));
  2570. }
  2571. INSTANTIATE_TEST_SUITE_P(
  2572. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugGlobalVariable,
  2573. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2574. std::make_pair(
  2575. R"(%void %float_info %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  2576. "Name"),
  2577. std::make_pair(
  2578. R"(%foo_name %dbg_src %dbg_src 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  2579. "Type"),
  2580. std::make_pair(
  2581. R"(%foo_name %float_info %comp_unit 0 0 %comp_unit %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  2582. "Source"),
  2583. std::make_pair(
  2584. R"(%foo_name %float_info %dbg_src 0 0 %dbg_src %foo_name %f32_input FlagIsProtected|FlagIsPrivate)",
  2585. "Scope"),
  2586. std::make_pair(
  2587. R"(%foo_name %float_info %dbg_src 0 0 %comp_unit %void %f32_input FlagIsProtected|FlagIsPrivate)",
  2588. "Linkage Name"),
  2589. std::make_pair(
  2590. R"(%foo_name %float_info %dbg_src 0 0 %comp_unit %foo_name %void FlagIsProtected|FlagIsPrivate)",
  2591. "Variable"),
  2592. }));
  2593. TEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAt) {
  2594. const std::string src = R"(
  2595. %src = OpString "simple.hlsl"
  2596. %code = OpString "void main() {}"
  2597. %void_name = OpString "void"
  2598. %main_name = OpString "main"
  2599. %main_linkage_name = OpString "v_main"
  2600. )";
  2601. const std::string dbg_inst_header = R"(
  2602. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2603. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2604. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  2605. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
  2606. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
  2607. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info %inlined_at
  2608. )";
  2609. const std::string body = R"(
  2610. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  2611. )";
  2612. const std::string extension = R"(
  2613. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2614. )";
  2615. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2616. src, "", dbg_inst_header, body, extension, "Vertex"));
  2617. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2618. }
  2619. TEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAtFail) {
  2620. const std::string src = R"(
  2621. %src = OpString "simple.hlsl"
  2622. %code = OpString "void main() {}"
  2623. %void_name = OpString "void"
  2624. %main_name = OpString "main"
  2625. %main_linkage_name = OpString "v_main"
  2626. )";
  2627. const std::string dbg_inst_header = R"(
  2628. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2629. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2630. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  2631. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
  2632. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
  2633. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %inlined_at
  2634. )";
  2635. const std::string body = R"(
  2636. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  2637. )";
  2638. const std::string extension = R"(
  2639. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2640. )";
  2641. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2642. src, "", dbg_inst_header, body, extension, "Vertex"));
  2643. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2644. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Scope"));
  2645. }
  2646. TEST_F(ValidateOpenCL100DebugInfo, DebugInlinedAtFail2) {
  2647. const std::string src = R"(
  2648. %src = OpString "simple.hlsl"
  2649. %code = OpString "void main() {}"
  2650. %void_name = OpString "void"
  2651. %main_name = OpString "main"
  2652. %main_linkage_name = OpString "v_main"
  2653. )";
  2654. const std::string dbg_inst_header = R"(
  2655. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2656. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2657. %main_type_info = OpExtInst %void %DbgExt DebugTypeFunction FlagIsPublic %void
  2658. %main_info = OpExtInst %void %DbgExt DebugFunction %main_name %main_type_info %dbg_src 1 1 %comp_unit %main_linkage_name FlagIsPublic 1 %main
  2659. %inlined_at = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info
  2660. %inlined_at_recursive = OpExtInst %void %DbgExt DebugInlinedAt 0 %main_info %main_info
  2661. )";
  2662. const std::string body = R"(
  2663. %main_scope = OpExtInst %void %DbgExt DebugScope %main_info %inlined_at
  2664. )";
  2665. const std::string extension = R"(
  2666. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2667. )";
  2668. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2669. src, "", dbg_inst_header, body, extension, "Vertex"));
  2670. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2671. EXPECT_THAT(getDiagnosticString(), HasSubstr("expected operand Inlined"));
  2672. }
  2673. TEST_F(ValidateOpenCL100DebugInfo, DebugValue) {
  2674. const std::string src = R"(
  2675. %src = OpString "simple.hlsl"
  2676. %code = OpString "void main() { float foo; }"
  2677. %float_name = OpString "float"
  2678. %foo_name = OpString "foo"
  2679. )";
  2680. const std::string size_const = R"(
  2681. %int_3 = OpConstant %u32 3
  2682. %int_32 = OpConstant %u32 32
  2683. )";
  2684. const std::string dbg_inst_header = R"(
  2685. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2686. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2687. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2688. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2689. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  2690. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2691. )";
  2692. const std::string body = R"(
  2693. %value = OpExtInst %void %DbgExt DebugValue %foo_info %int_32 %null_expr %int_3
  2694. )";
  2695. const std::string extension = R"(
  2696. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2697. )";
  2698. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2699. src, size_const, dbg_inst_header, body, extension, "Vertex"));
  2700. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2701. }
  2702. TEST_F(ValidateOpenCL100DebugInfo, DebugValueWithVariableIndex) {
  2703. const std::string src = R"(
  2704. %src = OpString "simple.hlsl"
  2705. %code = OpString "void main() { float foo; }"
  2706. %float_name = OpString "float"
  2707. %int_name = OpString "int"
  2708. %foo_name = OpString "foo"
  2709. %len_name = OpString "length"
  2710. )";
  2711. const std::string size_const = R"(
  2712. %int_3 = OpConstant %u32 3
  2713. %int_32 = OpConstant %u32 32
  2714. )";
  2715. const std::string dbg_inst_header = R"(
  2716. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2717. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2718. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2719. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2720. %int_info = OpExtInst %void %DbgExt DebugTypeBasic %int_name %int_32 Signed
  2721. %v4float_info = OpExtInst %void %DbgExt DebugTypeVector %float_info 4
  2722. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %v4float_info %dbg_src 1 10 %comp_unit FlagIsLocal
  2723. %len_info = OpExtInst %void %DbgExt DebugLocalVariable %len_name %int_info %dbg_src 0 0 %comp_unit FlagIsLocal
  2724. )";
  2725. const std::string body = R"(
  2726. %value = OpExtInst %void %DbgExt DebugValue %foo_info %int_32 %null_expr %len_info
  2727. )";
  2728. const std::string extension = R"(
  2729. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2730. )";
  2731. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2732. src, size_const, dbg_inst_header, body, extension, "Vertex"));
  2733. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2734. }
  2735. TEST_P(ValidateOpenCL100DebugInfoDebugValue, Fail) {
  2736. const std::string src = R"(
  2737. %src = OpString "simple.hlsl"
  2738. %code = OpString "void main() { float foo; }"
  2739. %float_name = OpString "float"
  2740. %foo_name = OpString "foo"
  2741. )";
  2742. const std::string size_const = R"(
  2743. %int_32 = OpConstant %u32 32
  2744. )";
  2745. const std::string dbg_inst_header = R"(
  2746. %dbg_src = OpExtInst %void %DbgExt DebugSource %src %code
  2747. %comp_unit = OpExtInst %void %DbgExt DebugCompilationUnit 2 4 %dbg_src HLSL
  2748. %null_expr = OpExtInst %void %DbgExt DebugExpression
  2749. %float_info = OpExtInst %void %DbgExt DebugTypeBasic %float_name %int_32 Float
  2750. %foo_info = OpExtInst %void %DbgExt DebugLocalVariable %foo_name %float_info %dbg_src 1 10 %comp_unit FlagIsLocal 0
  2751. )";
  2752. const auto& param = GetParam();
  2753. std::ostringstream ss;
  2754. ss << R"(
  2755. %decl = OpExtInst %void %DbgExt DebugValue )"
  2756. << param.first;
  2757. const std::string extension = R"(
  2758. %DbgExt = OpExtInstImport "OpenCL.DebugInfo.100"
  2759. )";
  2760. CompileSuccessfully(GenerateShaderCodeForDebugInfo(
  2761. src, size_const, dbg_inst_header, ss.str(), extension, "Vertex"));
  2762. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2763. EXPECT_THAT(getDiagnosticString(),
  2764. HasSubstr("expected operand " + param.second));
  2765. }
  2766. INSTANTIATE_TEST_SUITE_P(
  2767. AllOpenCL100DebugInfoFail, ValidateOpenCL100DebugInfoDebugValue,
  2768. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  2769. std::make_pair(R"(%dbg_src %int_32 %null_expr)", "Local Variable"),
  2770. std::make_pair(R"(%foo_info %int_32 %dbg_src)", "Expression"),
  2771. std::make_pair(R"(%foo_info %int_32 %null_expr %dbg_src)", "Indexes"),
  2772. }));
  2773. TEST_P(ValidateGlslStd450SqrtLike, IntResultType) {
  2774. const std::string ext_inst_name = GetParam();
  2775. const std::string body =
  2776. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  2777. CompileSuccessfully(GenerateShaderCode(body));
  2778. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2779. EXPECT_THAT(getDiagnosticString(),
  2780. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2781. ": expected Result Type to be a float scalar "
  2782. "or vector type"));
  2783. }
  2784. TEST_P(ValidateGlslStd450SqrtLike, IntOperand) {
  2785. const std::string ext_inst_name = GetParam();
  2786. const std::string body =
  2787. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  2788. CompileSuccessfully(GenerateShaderCode(body));
  2789. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2790. EXPECT_THAT(getDiagnosticString(),
  2791. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2792. ": expected types of all operands to be equal to "
  2793. "Result Type"));
  2794. }
  2795. INSTANTIATE_TEST_SUITE_P(AllSqrtLike, ValidateGlslStd450SqrtLike,
  2796. ::testing::ValuesIn(std::vector<std::string>{
  2797. "Round",
  2798. "RoundEven",
  2799. "FAbs",
  2800. "Trunc",
  2801. "FSign",
  2802. "Floor",
  2803. "Ceil",
  2804. "Fract",
  2805. "Sqrt",
  2806. "InverseSqrt",
  2807. "Normalize",
  2808. }));
  2809. TEST_P(ValidateGlslStd450FMinLike, Success) {
  2810. const std::string ext_inst_name = GetParam();
  2811. std::ostringstream ss;
  2812. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  2813. << " %f32_0 %f32_1\n";
  2814. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  2815. << " %f32vec2_01 %f32vec2_12\n";
  2816. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  2817. << " %f64_0 %f64_0\n";
  2818. CompileSuccessfully(GenerateShaderCode(ss.str()));
  2819. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2820. }
  2821. TEST_P(ValidateGlslStd450FMinLike, IntResultType) {
  2822. const std::string ext_inst_name = GetParam();
  2823. const std::string body =
  2824. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %f32_1\n";
  2825. CompileSuccessfully(GenerateShaderCode(body));
  2826. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2827. EXPECT_THAT(getDiagnosticString(),
  2828. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2829. ": expected Result Type to be a float scalar "
  2830. "or vector type"));
  2831. }
  2832. TEST_P(ValidateGlslStd450FMinLike, IntOperand1) {
  2833. const std::string ext_inst_name = GetParam();
  2834. const std::string body =
  2835. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
  2836. CompileSuccessfully(GenerateShaderCode(body));
  2837. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2838. EXPECT_THAT(getDiagnosticString(),
  2839. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2840. ": expected types of all operands to be equal to "
  2841. "Result Type"));
  2842. }
  2843. TEST_P(ValidateGlslStd450FMinLike, IntOperand2) {
  2844. const std::string ext_inst_name = GetParam();
  2845. const std::string body =
  2846. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
  2847. CompileSuccessfully(GenerateShaderCode(body));
  2848. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2849. EXPECT_THAT(getDiagnosticString(),
  2850. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2851. ": expected types of all operands to be equal to "
  2852. "Result Type"));
  2853. }
  2854. INSTANTIATE_TEST_SUITE_P(AllFMinLike, ValidateGlslStd450FMinLike,
  2855. ::testing::ValuesIn(std::vector<std::string>{
  2856. "FMin",
  2857. "FMax",
  2858. "Step",
  2859. "Reflect",
  2860. "NMin",
  2861. "NMax",
  2862. }));
  2863. TEST_P(ValidateGlslStd450FClampLike, Success) {
  2864. const std::string ext_inst_name = GetParam();
  2865. std::ostringstream ss;
  2866. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  2867. << " %f32_0 %f32_1 %f32_2\n";
  2868. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  2869. << " %f32vec2_01 %f32vec2_01 %f32vec2_12\n";
  2870. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  2871. << " %f64_0 %f64_0 %f64_1\n";
  2872. CompileSuccessfully(GenerateShaderCode(ss.str()));
  2873. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2874. }
  2875. TEST_P(ValidateGlslStd450FClampLike, IntResultType) {
  2876. const std::string ext_inst_name = GetParam();
  2877. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2878. " %f32_0 %f32_1 %f32_2\n";
  2879. CompileSuccessfully(GenerateShaderCode(body));
  2880. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2881. EXPECT_THAT(getDiagnosticString(),
  2882. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2883. ": expected Result Type to be a float scalar "
  2884. "or vector type"));
  2885. }
  2886. TEST_P(ValidateGlslStd450FClampLike, IntOperand1) {
  2887. const std::string ext_inst_name = GetParam();
  2888. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  2889. " %u32_0 %f32_0 %f32_1\n";
  2890. CompileSuccessfully(GenerateShaderCode(body));
  2891. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2892. EXPECT_THAT(getDiagnosticString(),
  2893. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2894. ": expected types of all operands to be equal to "
  2895. "Result Type"));
  2896. }
  2897. TEST_P(ValidateGlslStd450FClampLike, IntOperand2) {
  2898. const std::string ext_inst_name = GetParam();
  2899. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  2900. " %f32_0 %u32_0 %f32_1\n";
  2901. CompileSuccessfully(GenerateShaderCode(body));
  2902. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2903. EXPECT_THAT(getDiagnosticString(),
  2904. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2905. ": expected types of all operands to be equal to "
  2906. "Result Type"));
  2907. }
  2908. TEST_P(ValidateGlslStd450FClampLike, IntOperand3) {
  2909. const std::string ext_inst_name = GetParam();
  2910. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  2911. " %f32_1 %f32_0 %u32_2\n";
  2912. CompileSuccessfully(GenerateShaderCode(body));
  2913. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2914. EXPECT_THAT(getDiagnosticString(),
  2915. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2916. ": expected types of all operands to be equal to "
  2917. "Result Type"));
  2918. }
  2919. INSTANTIATE_TEST_SUITE_P(AllFClampLike, ValidateGlslStd450FClampLike,
  2920. ::testing::ValuesIn(std::vector<std::string>{
  2921. "FClamp",
  2922. "FMix",
  2923. "SmoothStep",
  2924. "Fma",
  2925. "FaceForward",
  2926. "NClamp",
  2927. }));
  2928. TEST_P(ValidateGlslStd450SAbsLike, Success) {
  2929. const std::string ext_inst_name = GetParam();
  2930. std::ostringstream ss;
  2931. ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name << " %u32_1\n";
  2932. ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name << " %s32_1\n";
  2933. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  2934. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name << " %s32_1\n";
  2935. ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  2936. << " %s32vec2_01\n";
  2937. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2938. << " %u32vec2_01\n";
  2939. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2940. << " %s32vec2_01\n";
  2941. ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  2942. << " %u32vec2_01\n";
  2943. CompileSuccessfully(GenerateShaderCode(ss.str()));
  2944. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2945. }
  2946. TEST_P(ValidateGlslStd450SAbsLike, FloatResultType) {
  2947. const std::string ext_inst_name = GetParam();
  2948. const std::string body =
  2949. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  2950. CompileSuccessfully(GenerateShaderCode(body));
  2951. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2952. EXPECT_THAT(getDiagnosticString(),
  2953. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2954. ": expected Result Type to be an int scalar "
  2955. "or vector type"));
  2956. }
  2957. TEST_P(ValidateGlslStd450SAbsLike, FloatOperand) {
  2958. const std::string ext_inst_name = GetParam();
  2959. const std::string body =
  2960. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %f32_0\n";
  2961. CompileSuccessfully(GenerateShaderCode(body));
  2962. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2963. EXPECT_THAT(getDiagnosticString(),
  2964. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2965. ": expected all operands to be int scalars or "
  2966. "vectors"));
  2967. }
  2968. TEST_P(ValidateGlslStd450SAbsLike, WrongDimOperand) {
  2969. const std::string ext_inst_name = GetParam();
  2970. const std::string body =
  2971. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %s32vec2_01\n";
  2972. CompileSuccessfully(GenerateShaderCode(body));
  2973. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2974. EXPECT_THAT(getDiagnosticString(),
  2975. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2976. ": expected all operands to have the same dimension as "
  2977. "Result Type"));
  2978. }
  2979. TEST_P(ValidateGlslStd450SAbsLike, WrongBitWidthOperand) {
  2980. const std::string ext_inst_name = GetParam();
  2981. const std::string body =
  2982. "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s32_0\n";
  2983. CompileSuccessfully(GenerateShaderCode(body));
  2984. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2985. EXPECT_THAT(getDiagnosticString(),
  2986. HasSubstr("GLSL.std.450 " + ext_inst_name +
  2987. ": expected all operands to have the same bit width as "
  2988. "Result Type"));
  2989. }
  2990. INSTANTIATE_TEST_SUITE_P(AllSAbsLike, ValidateGlslStd450SAbsLike,
  2991. ::testing::ValuesIn(std::vector<std::string>{
  2992. "SAbs",
  2993. "SSign",
  2994. "FindILsb",
  2995. "FindUMsb",
  2996. "FindSMsb",
  2997. }));
  2998. TEST_F(ValidateExtInst, FindUMsbNot32Bit) {
  2999. const std::string body = R"(
  3000. %val1 = OpExtInst %s64 %extinst FindUMsb %u64_1
  3001. )";
  3002. CompileSuccessfully(GenerateShaderCode(body));
  3003. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3004. EXPECT_THAT(getDiagnosticString(),
  3005. HasSubstr("GLSL.std.450 FindUMsb: this instruction is currently "
  3006. "limited to 32-bit width components"));
  3007. }
  3008. TEST_F(ValidateExtInst, FindSMsbNot32Bit) {
  3009. const std::string body = R"(
  3010. %val1 = OpExtInst %s64 %extinst FindSMsb %u64_1
  3011. )";
  3012. CompileSuccessfully(GenerateShaderCode(body));
  3013. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3014. EXPECT_THAT(getDiagnosticString(),
  3015. HasSubstr("GLSL.std.450 FindSMsb: this instruction is currently "
  3016. "limited to 32-bit width components"));
  3017. }
  3018. TEST_P(ValidateGlslStd450UMinLike, Success) {
  3019. const std::string ext_inst_name = GetParam();
  3020. std::ostringstream ss;
  3021. ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name
  3022. << " %u32_1 %s32_2\n";
  3023. ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name
  3024. << " %s32_1 %u32_2\n";
  3025. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  3026. << " %u32_1 %s32_2\n";
  3027. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  3028. << " %s32_1 %u32_2\n";
  3029. ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  3030. << " %s32vec2_01 %u32vec2_01\n";
  3031. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3032. << " %u32vec2_01 %s32vec2_01\n";
  3033. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3034. << " %s32vec2_01 %u32vec2_01\n";
  3035. ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  3036. << " %u32vec2_01 %s32vec2_01\n";
  3037. ss << "%val9 = OpExtInst %s64 %extinst " << ext_inst_name
  3038. << " %u64_1 %s64_0\n";
  3039. CompileSuccessfully(GenerateShaderCode(ss.str()));
  3040. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3041. }
  3042. TEST_P(ValidateGlslStd450UMinLike, FloatResultType) {
  3043. const std::string ext_inst_name = GetParam();
  3044. const std::string body =
  3045. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
  3046. CompileSuccessfully(GenerateShaderCode(body));
  3047. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3048. EXPECT_THAT(getDiagnosticString(),
  3049. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3050. ": expected Result Type to be an int scalar "
  3051. "or vector type"));
  3052. }
  3053. TEST_P(ValidateGlslStd450UMinLike, FloatOperand1) {
  3054. const std::string ext_inst_name = GetParam();
  3055. const std::string body =
  3056. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
  3057. CompileSuccessfully(GenerateShaderCode(body));
  3058. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3059. EXPECT_THAT(getDiagnosticString(),
  3060. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3061. ": expected all operands to be int scalars or "
  3062. "vectors"));
  3063. }
  3064. TEST_P(ValidateGlslStd450UMinLike, FloatOperand2) {
  3065. const std::string ext_inst_name = GetParam();
  3066. const std::string body =
  3067. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
  3068. CompileSuccessfully(GenerateShaderCode(body));
  3069. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3070. EXPECT_THAT(getDiagnosticString(),
  3071. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3072. ": expected all operands to be int scalars or "
  3073. "vectors"));
  3074. }
  3075. TEST_P(ValidateGlslStd450UMinLike, WrongDimOperand1) {
  3076. const std::string ext_inst_name = GetParam();
  3077. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3078. " %s32vec2_01 %s32_0\n";
  3079. CompileSuccessfully(GenerateShaderCode(body));
  3080. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3081. EXPECT_THAT(getDiagnosticString(),
  3082. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3083. ": expected all operands to have the same dimension as "
  3084. "Result Type"));
  3085. }
  3086. TEST_P(ValidateGlslStd450UMinLike, WrongDimOperand2) {
  3087. const std::string ext_inst_name = GetParam();
  3088. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3089. " %s32_0 %s32vec2_01\n";
  3090. CompileSuccessfully(GenerateShaderCode(body));
  3091. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3092. EXPECT_THAT(getDiagnosticString(),
  3093. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3094. ": expected all operands to have the same dimension as "
  3095. "Result Type"));
  3096. }
  3097. TEST_P(ValidateGlslStd450UMinLike, WrongBitWidthOperand1) {
  3098. const std::string ext_inst_name = GetParam();
  3099. const std::string body =
  3100. "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s32_0 %s64_0\n";
  3101. CompileSuccessfully(GenerateShaderCode(body));
  3102. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3103. EXPECT_THAT(getDiagnosticString(),
  3104. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3105. ": expected all operands to have the same bit width as "
  3106. "Result Type"));
  3107. }
  3108. TEST_P(ValidateGlslStd450UMinLike, WrongBitWidthOperand2) {
  3109. const std::string ext_inst_name = GetParam();
  3110. const std::string body =
  3111. "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s64_0 %s32_0\n";
  3112. CompileSuccessfully(GenerateShaderCode(body));
  3113. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3114. EXPECT_THAT(getDiagnosticString(),
  3115. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3116. ": expected all operands to have the same bit width as "
  3117. "Result Type"));
  3118. }
  3119. INSTANTIATE_TEST_SUITE_P(AllUMinLike, ValidateGlslStd450UMinLike,
  3120. ::testing::ValuesIn(std::vector<std::string>{
  3121. "UMin",
  3122. "SMin",
  3123. "UMax",
  3124. "SMax",
  3125. }));
  3126. TEST_P(ValidateGlslStd450UClampLike, Success) {
  3127. const std::string ext_inst_name = GetParam();
  3128. std::ostringstream ss;
  3129. ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name
  3130. << " %s32_0 %u32_1 %s32_2\n";
  3131. ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name
  3132. << " %u32_0 %s32_1 %u32_2\n";
  3133. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  3134. << " %s32_0 %u32_1 %s32_2\n";
  3135. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  3136. << " %u32_0 %s32_1 %u32_2\n";
  3137. ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  3138. << " %s32vec2_01 %u32vec2_01 %u32vec2_12\n";
  3139. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3140. << " %u32vec2_01 %s32vec2_01 %s32vec2_12\n";
  3141. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3142. << " %s32vec2_01 %u32vec2_01 %u32vec2_12\n";
  3143. ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  3144. << " %u32vec2_01 %s32vec2_01 %s32vec2_12\n";
  3145. ss << "%val9 = OpExtInst %s64 %extinst " << ext_inst_name
  3146. << " %u64_1 %s64_0 %s64_1\n";
  3147. CompileSuccessfully(GenerateShaderCode(ss.str()));
  3148. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3149. }
  3150. TEST_P(ValidateGlslStd450UClampLike, FloatResultType) {
  3151. const std::string ext_inst_name = GetParam();
  3152. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  3153. " %u32_0 %u32_0 %u32_1\n";
  3154. CompileSuccessfully(GenerateShaderCode(body));
  3155. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3156. EXPECT_THAT(getDiagnosticString(),
  3157. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3158. ": expected Result Type to be an int scalar "
  3159. "or vector type"));
  3160. }
  3161. TEST_P(ValidateGlslStd450UClampLike, FloatOperand1) {
  3162. const std::string ext_inst_name = GetParam();
  3163. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3164. " %f32_0 %u32_0 %u32_1\n";
  3165. CompileSuccessfully(GenerateShaderCode(body));
  3166. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3167. EXPECT_THAT(getDiagnosticString(),
  3168. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3169. ": expected all operands to be int scalars or "
  3170. "vectors"));
  3171. }
  3172. TEST_P(ValidateGlslStd450UClampLike, FloatOperand2) {
  3173. const std::string ext_inst_name = GetParam();
  3174. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3175. " %u32_0 %f32_0 %u32_1\n";
  3176. CompileSuccessfully(GenerateShaderCode(body));
  3177. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3178. EXPECT_THAT(getDiagnosticString(),
  3179. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3180. ": expected all operands to be int scalars or "
  3181. "vectors"));
  3182. }
  3183. TEST_P(ValidateGlslStd450UClampLike, FloatOperand3) {
  3184. const std::string ext_inst_name = GetParam();
  3185. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3186. " %u32_0 %u32_0 %f32_1\n";
  3187. CompileSuccessfully(GenerateShaderCode(body));
  3188. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3189. EXPECT_THAT(getDiagnosticString(),
  3190. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3191. ": expected all operands to be int scalars or "
  3192. "vectors"));
  3193. }
  3194. TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand1) {
  3195. const std::string ext_inst_name = GetParam();
  3196. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3197. " %s32vec2_01 %s32_0 %u32_1\n";
  3198. CompileSuccessfully(GenerateShaderCode(body));
  3199. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3200. EXPECT_THAT(getDiagnosticString(),
  3201. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3202. ": expected all operands to have the same dimension as "
  3203. "Result Type"));
  3204. }
  3205. TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand2) {
  3206. const std::string ext_inst_name = GetParam();
  3207. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3208. " %s32_0 %s32vec2_01 %u32_1\n";
  3209. CompileSuccessfully(GenerateShaderCode(body));
  3210. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3211. EXPECT_THAT(getDiagnosticString(),
  3212. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3213. ": expected all operands to have the same dimension as "
  3214. "Result Type"));
  3215. }
  3216. TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand3) {
  3217. const std::string ext_inst_name = GetParam();
  3218. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  3219. " %s32_0 %u32_1 %s32vec2_01\n";
  3220. CompileSuccessfully(GenerateShaderCode(body));
  3221. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3222. EXPECT_THAT(getDiagnosticString(),
  3223. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3224. ": expected all operands to have the same dimension as "
  3225. "Result Type"));
  3226. }
  3227. TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand1) {
  3228. const std::string ext_inst_name = GetParam();
  3229. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  3230. " %s32_0 %s64_0 %s64_1\n";
  3231. CompileSuccessfully(GenerateShaderCode(body));
  3232. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3233. EXPECT_THAT(getDiagnosticString(),
  3234. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3235. ": expected all operands to have the same bit width as "
  3236. "Result Type"));
  3237. }
  3238. TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand2) {
  3239. const std::string ext_inst_name = GetParam();
  3240. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  3241. " %s64_0 %s32_0 %s64_1\n";
  3242. CompileSuccessfully(GenerateShaderCode(body));
  3243. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3244. EXPECT_THAT(getDiagnosticString(),
  3245. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3246. ": expected all operands to have the same bit width as "
  3247. "Result Type"));
  3248. }
  3249. TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand3) {
  3250. const std::string ext_inst_name = GetParam();
  3251. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  3252. " %s64_0 %s64_0 %s32_1\n";
  3253. CompileSuccessfully(GenerateShaderCode(body));
  3254. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3255. EXPECT_THAT(getDiagnosticString(),
  3256. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3257. ": expected all operands to have the same bit width as "
  3258. "Result Type"));
  3259. }
  3260. INSTANTIATE_TEST_SUITE_P(AllUClampLike, ValidateGlslStd450UClampLike,
  3261. ::testing::ValuesIn(std::vector<std::string>{
  3262. "UClamp",
  3263. "SClamp",
  3264. }));
  3265. TEST_P(ValidateGlslStd450SinLike, Success) {
  3266. const std::string ext_inst_name = GetParam();
  3267. std::ostringstream ss;
  3268. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
  3269. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3270. << " %f32vec2_01\n";
  3271. CompileSuccessfully(GenerateShaderCode(ss.str()));
  3272. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3273. }
  3274. TEST_P(ValidateGlslStd450SinLike, IntResultType) {
  3275. const std::string ext_inst_name = GetParam();
  3276. const std::string body =
  3277. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  3278. CompileSuccessfully(GenerateShaderCode(body));
  3279. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3280. EXPECT_THAT(getDiagnosticString(),
  3281. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3282. ": expected Result Type to be a 16 or 32-bit scalar "
  3283. "or vector float type"));
  3284. }
  3285. TEST_P(ValidateGlslStd450SinLike, F64ResultType) {
  3286. const std::string ext_inst_name = GetParam();
  3287. const std::string body =
  3288. "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32_0\n";
  3289. CompileSuccessfully(GenerateShaderCode(body));
  3290. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3291. EXPECT_THAT(getDiagnosticString(),
  3292. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3293. ": expected Result Type to be a 16 or 32-bit scalar "
  3294. "or vector float type"));
  3295. }
  3296. TEST_P(ValidateGlslStd450SinLike, IntOperand) {
  3297. const std::string ext_inst_name = GetParam();
  3298. const std::string body =
  3299. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  3300. CompileSuccessfully(GenerateShaderCode(body));
  3301. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3302. EXPECT_THAT(getDiagnosticString(),
  3303. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3304. ": expected types of all operands to be equal to "
  3305. "Result Type"));
  3306. }
  3307. INSTANTIATE_TEST_SUITE_P(AllSinLike, ValidateGlslStd450SinLike,
  3308. ::testing::ValuesIn(std::vector<std::string>{
  3309. "Radians",
  3310. "Degrees",
  3311. "Sin",
  3312. "Cos",
  3313. "Tan",
  3314. "Asin",
  3315. "Acos",
  3316. "Atan",
  3317. "Sinh",
  3318. "Cosh",
  3319. "Tanh",
  3320. "Asinh",
  3321. "Acosh",
  3322. "Atanh",
  3323. "Exp",
  3324. "Exp2",
  3325. "Log",
  3326. "Log2",
  3327. }));
  3328. TEST_P(ValidateGlslStd450PowLike, Success) {
  3329. const std::string ext_inst_name = GetParam();
  3330. std::ostringstream ss;
  3331. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  3332. << " %f32_1 %f32_1\n";
  3333. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3334. << " %f32vec2_01 %f32vec2_12\n";
  3335. CompileSuccessfully(GenerateShaderCode(ss.str()));
  3336. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3337. }
  3338. TEST_P(ValidateGlslStd450PowLike, IntResultType) {
  3339. const std::string ext_inst_name = GetParam();
  3340. const std::string body =
  3341. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_1 %f32_0\n";
  3342. CompileSuccessfully(GenerateShaderCode(body));
  3343. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3344. EXPECT_THAT(getDiagnosticString(),
  3345. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3346. ": expected Result Type to be a 16 or 32-bit scalar "
  3347. "or vector float type"));
  3348. }
  3349. TEST_P(ValidateGlslStd450PowLike, F64ResultType) {
  3350. const std::string ext_inst_name = GetParam();
  3351. const std::string body =
  3352. "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32_1 %f32_0\n";
  3353. CompileSuccessfully(GenerateShaderCode(body));
  3354. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3355. EXPECT_THAT(getDiagnosticString(),
  3356. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3357. ": expected Result Type to be a 16 or 32-bit scalar "
  3358. "or vector float type"));
  3359. }
  3360. TEST_P(ValidateGlslStd450PowLike, IntOperand1) {
  3361. const std::string ext_inst_name = GetParam();
  3362. const std::string body =
  3363. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
  3364. CompileSuccessfully(GenerateShaderCode(body));
  3365. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3366. EXPECT_THAT(getDiagnosticString(),
  3367. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3368. ": expected types of all operands to be equal to "
  3369. "Result Type"));
  3370. }
  3371. TEST_P(ValidateGlslStd450PowLike, IntOperand2) {
  3372. const std::string ext_inst_name = GetParam();
  3373. const std::string body =
  3374. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
  3375. CompileSuccessfully(GenerateShaderCode(body));
  3376. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3377. EXPECT_THAT(getDiagnosticString(),
  3378. HasSubstr("GLSL.std.450 " + ext_inst_name +
  3379. ": expected types of all operands to be equal to "
  3380. "Result Type"));
  3381. }
  3382. INSTANTIATE_TEST_SUITE_P(AllPowLike, ValidateGlslStd450PowLike,
  3383. ::testing::ValuesIn(std::vector<std::string>{
  3384. "Atan2",
  3385. "Pow",
  3386. }));
  3387. TEST_F(ValidateExtInst, GlslStd450DeterminantSuccess) {
  3388. const std::string body = R"(
  3389. %val1 = OpExtInst %f32 %extinst Determinant %f32mat22_1212
  3390. )";
  3391. CompileSuccessfully(GenerateShaderCode(body));
  3392. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3393. }
  3394. TEST_F(ValidateExtInst, GlslStd450DeterminantIncompatibleResultType) {
  3395. const std::string body = R"(
  3396. %val1 = OpExtInst %f64 %extinst Determinant %f32mat22_1212
  3397. )";
  3398. CompileSuccessfully(GenerateShaderCode(body));
  3399. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3400. EXPECT_THAT(getDiagnosticString(),
  3401. HasSubstr("GLSL.std.450 Determinant: "
  3402. "expected operand X component type to be equal to "
  3403. "Result Type"));
  3404. }
  3405. TEST_F(ValidateExtInst, GlslStd450DeterminantNotMatrix) {
  3406. const std::string body = R"(
  3407. %val1 = OpExtInst %f32 %extinst Determinant %f32_1
  3408. )";
  3409. CompileSuccessfully(GenerateShaderCode(body));
  3410. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3411. EXPECT_THAT(getDiagnosticString(),
  3412. HasSubstr("GLSL.std.450 Determinant: "
  3413. "expected operand X to be a square matrix"));
  3414. }
  3415. TEST_F(ValidateExtInst, GlslStd450DeterminantMatrixNotSquare) {
  3416. const std::string body = R"(
  3417. %val1 = OpExtInst %f32 %extinst Determinant %f32mat23_121212
  3418. )";
  3419. CompileSuccessfully(GenerateShaderCode(body));
  3420. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3421. EXPECT_THAT(getDiagnosticString(),
  3422. HasSubstr("GLSL.std.450 Determinant: "
  3423. "expected operand X to be a square matrix"));
  3424. }
  3425. TEST_F(ValidateExtInst, GlslStd450MatrixInverseSuccess) {
  3426. const std::string body = R"(
  3427. %val1 = OpExtInst %f32mat22 %extinst MatrixInverse %f32mat22_1212
  3428. )";
  3429. CompileSuccessfully(GenerateShaderCode(body));
  3430. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3431. }
  3432. TEST_F(ValidateExtInst, GlslStd450MatrixInverseIncompatibleResultType) {
  3433. const std::string body = R"(
  3434. %val1 = OpExtInst %f32mat33 %extinst MatrixInverse %f32mat22_1212
  3435. )";
  3436. CompileSuccessfully(GenerateShaderCode(body));
  3437. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3438. EXPECT_THAT(getDiagnosticString(),
  3439. HasSubstr("GLSL.std.450 MatrixInverse: "
  3440. "expected operand X type to be equal to "
  3441. "Result Type"));
  3442. }
  3443. TEST_F(ValidateExtInst, GlslStd450MatrixInverseNotMatrix) {
  3444. const std::string body = R"(
  3445. %val1 = OpExtInst %f32 %extinst MatrixInverse %f32mat22_1212
  3446. )";
  3447. CompileSuccessfully(GenerateShaderCode(body));
  3448. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3449. EXPECT_THAT(getDiagnosticString(),
  3450. HasSubstr("GLSL.std.450 MatrixInverse: "
  3451. "expected Result Type to be a square matrix"));
  3452. }
  3453. TEST_F(ValidateExtInst, GlslStd450MatrixInverseMatrixNotSquare) {
  3454. const std::string body = R"(
  3455. %val1 = OpExtInst %f32mat23 %extinst MatrixInverse %f32mat23_121212
  3456. )";
  3457. CompileSuccessfully(GenerateShaderCode(body));
  3458. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3459. EXPECT_THAT(getDiagnosticString(),
  3460. HasSubstr("GLSL.std.450 MatrixInverse: "
  3461. "expected Result Type to be a square matrix"));
  3462. }
  3463. TEST_F(ValidateExtInst, GlslStd450ModfSuccess) {
  3464. const std::string body = R"(
  3465. %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32_output
  3466. %val2 = OpExtInst %f32vec2 %extinst Modf %f32vec2_01 %f32vec2_output
  3467. )";
  3468. CompileSuccessfully(GenerateShaderCode(body));
  3469. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3470. }
  3471. TEST_F(ValidateExtInst, GlslStd450ModfIntResultType) {
  3472. const std::string body = R"(
  3473. %val1 = OpExtInst %u32 %extinst Modf %f32_h %f32_output
  3474. )";
  3475. CompileSuccessfully(GenerateShaderCode(body));
  3476. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3477. EXPECT_THAT(getDiagnosticString(),
  3478. HasSubstr("GLSL.std.450 Modf: "
  3479. "expected Result Type to be a scalar or vector "
  3480. "float type"));
  3481. }
  3482. TEST_F(ValidateExtInst, GlslStd450ModfXNotOfResultType) {
  3483. const std::string body = R"(
  3484. %val1 = OpExtInst %f32 %extinst Modf %f64_0 %f32_output
  3485. )";
  3486. CompileSuccessfully(GenerateShaderCode(body));
  3487. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3488. EXPECT_THAT(getDiagnosticString(),
  3489. HasSubstr("GLSL.std.450 Modf: "
  3490. "expected operand X type to be equal to Result Type"));
  3491. }
  3492. TEST_F(ValidateExtInst, GlslStd450ModfINotPointer) {
  3493. const std::string body = R"(
  3494. %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32_1
  3495. )";
  3496. CompileSuccessfully(GenerateShaderCode(body));
  3497. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3498. EXPECT_THAT(getDiagnosticString(),
  3499. HasSubstr("GLSL.std.450 Modf: "
  3500. "expected operand I to be a pointer"));
  3501. }
  3502. TEST_F(ValidateExtInst, GlslStd450ModfIDataNotOfResultType) {
  3503. const std::string body = R"(
  3504. %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32vec2_output
  3505. )";
  3506. CompileSuccessfully(GenerateShaderCode(body));
  3507. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3508. EXPECT_THAT(getDiagnosticString(),
  3509. HasSubstr("GLSL.std.450 Modf: "
  3510. "expected operand I data type to be equal to "
  3511. "Result Type"));
  3512. }
  3513. TEST_F(ValidateExtInst, GlslStd450ModfStructSuccess) {
  3514. const std::string body = R"(
  3515. %val1 = OpExtInst %struct_f32_f32 %extinst ModfStruct %f32_h
  3516. %val2 = OpExtInst %struct_f32vec2_f32vec2 %extinst ModfStruct %f32vec2_01
  3517. )";
  3518. CompileSuccessfully(GenerateShaderCode(body));
  3519. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3520. }
  3521. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeNotStruct) {
  3522. const std::string body = R"(
  3523. %val1 = OpExtInst %f32 %extinst ModfStruct %f32_h
  3524. )";
  3525. CompileSuccessfully(GenerateShaderCode(body));
  3526. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3527. EXPECT_THAT(getDiagnosticString(),
  3528. HasSubstr("GLSL.std.450 ModfStruct: "
  3529. "expected Result Type to be a struct with two "
  3530. "identical scalar or vector float type members"));
  3531. }
  3532. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructWrongSize) {
  3533. const std::string body = R"(
  3534. %val1 = OpExtInst %struct_f32_f32_f32 %extinst ModfStruct %f32_h
  3535. )";
  3536. CompileSuccessfully(GenerateShaderCode(body));
  3537. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3538. EXPECT_THAT(getDiagnosticString(),
  3539. HasSubstr("GLSL.std.450 ModfStruct: "
  3540. "expected Result Type to be a struct with two "
  3541. "identical scalar or vector float type members"));
  3542. }
  3543. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructWrongFirstMember) {
  3544. const std::string body = R"(
  3545. %val1 = OpExtInst %struct_u32_f32 %extinst ModfStruct %f32_h
  3546. )";
  3547. CompileSuccessfully(GenerateShaderCode(body));
  3548. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3549. EXPECT_THAT(getDiagnosticString(),
  3550. HasSubstr("GLSL.std.450 ModfStruct: "
  3551. "expected Result Type to be a struct with two "
  3552. "identical scalar or vector float type members"));
  3553. }
  3554. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructMembersNotEqual) {
  3555. const std::string body = R"(
  3556. %val1 = OpExtInst %struct_f32_f64 %extinst ModfStruct %f32_h
  3557. )";
  3558. CompileSuccessfully(GenerateShaderCode(body));
  3559. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3560. EXPECT_THAT(getDiagnosticString(),
  3561. HasSubstr("GLSL.std.450 ModfStruct: "
  3562. "expected Result Type to be a struct with two "
  3563. "identical scalar or vector float type members"));
  3564. }
  3565. TEST_F(ValidateExtInst, GlslStd450ModfStructXWrongType) {
  3566. const std::string body = R"(
  3567. %val1 = OpExtInst %struct_f32_f32 %extinst ModfStruct %f64_0
  3568. )";
  3569. CompileSuccessfully(GenerateShaderCode(body));
  3570. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3571. EXPECT_THAT(getDiagnosticString(),
  3572. HasSubstr("GLSL.std.450 ModfStruct: "
  3573. "expected operand X type to be equal to members of "
  3574. "Result Type struct"));
  3575. }
  3576. TEST_F(ValidateExtInst, GlslStd450FrexpSuccess) {
  3577. const std::string body = R"(
  3578. %val1 = OpExtInst %f32 %extinst Frexp %f32_h %u32_output
  3579. %val2 = OpExtInst %f32vec2 %extinst Frexp %f32vec2_01 %u32vec2_output
  3580. )";
  3581. CompileSuccessfully(GenerateShaderCode(body));
  3582. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3583. }
  3584. TEST_F(ValidateExtInst, GlslStd450FrexpIntResultType) {
  3585. const std::string body = R"(
  3586. %val1 = OpExtInst %u32 %extinst Frexp %f32_h %u32_output
  3587. )";
  3588. CompileSuccessfully(GenerateShaderCode(body));
  3589. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3590. EXPECT_THAT(getDiagnosticString(),
  3591. HasSubstr("GLSL.std.450 Frexp: "
  3592. "expected Result Type to be a scalar or vector "
  3593. "float type"));
  3594. }
  3595. TEST_F(ValidateExtInst, GlslStd450FrexpWrongXType) {
  3596. const std::string body = R"(
  3597. %val1 = OpExtInst %f32 %extinst Frexp %u32_1 %u32_output
  3598. )";
  3599. CompileSuccessfully(GenerateShaderCode(body));
  3600. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3601. EXPECT_THAT(getDiagnosticString(),
  3602. HasSubstr("GLSL.std.450 Frexp: "
  3603. "expected operand X type to be equal to Result Type"));
  3604. }
  3605. TEST_F(ValidateExtInst, GlslStd450FrexpExpNotPointer) {
  3606. const std::string body = R"(
  3607. %val1 = OpExtInst %f32 %extinst Frexp %f32_1 %u32_1
  3608. )";
  3609. CompileSuccessfully(GenerateShaderCode(body));
  3610. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3611. EXPECT_THAT(getDiagnosticString(),
  3612. HasSubstr("GLSL.std.450 Frexp: "
  3613. "expected operand Exp to be a pointer"));
  3614. }
  3615. TEST_F(ValidateExtInst, GlslStd450FrexpExpNotInt32Pointer) {
  3616. const std::string body = R"(
  3617. %val1 = OpExtInst %f32 %extinst Frexp %f32_1 %f32_output
  3618. )";
  3619. CompileSuccessfully(GenerateShaderCode(body));
  3620. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3621. EXPECT_THAT(getDiagnosticString(),
  3622. HasSubstr("GLSL.std.450 Frexp: "
  3623. "expected operand Exp data type to be a 32-bit int "
  3624. "scalar or vector type"));
  3625. }
  3626. TEST_F(ValidateExtInst, GlslStd450FrexpExpWrongComponentNumber) {
  3627. const std::string body = R"(
  3628. %val1 = OpExtInst %f32vec2 %extinst Frexp %f32vec2_01 %u32_output
  3629. )";
  3630. CompileSuccessfully(GenerateShaderCode(body));
  3631. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3632. EXPECT_THAT(getDiagnosticString(),
  3633. HasSubstr("GLSL.std.450 Frexp: "
  3634. "expected operand Exp data type to have the same "
  3635. "component number as Result Type"));
  3636. }
  3637. TEST_F(ValidateExtInst, GlslStd450LdexpSuccess) {
  3638. const std::string body = R"(
  3639. %val1 = OpExtInst %f32 %extinst Ldexp %f32_h %u32_2
  3640. %val2 = OpExtInst %f32vec2 %extinst Ldexp %f32vec2_01 %u32vec2_12
  3641. %val3 = OpExtInst %f32 %extinst Ldexp %f32_h %u64_1
  3642. )";
  3643. CompileSuccessfully(GenerateShaderCode(body));
  3644. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3645. }
  3646. TEST_F(ValidateExtInst, GlslStd450LdexpIntResultType) {
  3647. const std::string body = R"(
  3648. %val1 = OpExtInst %u32 %extinst Ldexp %f32_h %u32_2
  3649. )";
  3650. CompileSuccessfully(GenerateShaderCode(body));
  3651. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3652. EXPECT_THAT(getDiagnosticString(),
  3653. HasSubstr("GLSL.std.450 Ldexp: "
  3654. "expected Result Type to be a scalar or vector "
  3655. "float type"));
  3656. }
  3657. TEST_F(ValidateExtInst, GlslStd450LdexpWrongXType) {
  3658. const std::string body = R"(
  3659. %val1 = OpExtInst %f32 %extinst Ldexp %u32_1 %u32_2
  3660. )";
  3661. CompileSuccessfully(GenerateShaderCode(body));
  3662. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3663. EXPECT_THAT(getDiagnosticString(),
  3664. HasSubstr("GLSL.std.450 Ldexp: "
  3665. "expected operand X type to be equal to Result Type"));
  3666. }
  3667. TEST_F(ValidateExtInst, GlslStd450LdexpFloatExp) {
  3668. const std::string body = R"(
  3669. %val1 = OpExtInst %f32 %extinst Ldexp %f32_1 %f32_2
  3670. )";
  3671. CompileSuccessfully(GenerateShaderCode(body));
  3672. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3673. EXPECT_THAT(getDiagnosticString(),
  3674. HasSubstr("GLSL.std.450 Ldexp: "
  3675. "expected operand Exp to be a 32-bit int scalar "
  3676. "or vector type"));
  3677. }
  3678. TEST_F(ValidateExtInst, GlslStd450LdexpExpWrongSize) {
  3679. const std::string body = R"(
  3680. %val1 = OpExtInst %f32vec2 %extinst Ldexp %f32vec2_12 %u32_2
  3681. )";
  3682. CompileSuccessfully(GenerateShaderCode(body));
  3683. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3684. EXPECT_THAT(getDiagnosticString(),
  3685. HasSubstr("GLSL.std.450 Ldexp: "
  3686. "expected operand Exp to have the same component "
  3687. "number as Result Type"));
  3688. }
  3689. TEST_F(ValidateExtInst, GlslStd450FrexpStructSuccess) {
  3690. const std::string body = R"(
  3691. %val1 = OpExtInst %struct_f32_u32 %extinst FrexpStruct %f32_h
  3692. %val2 = OpExtInst %struct_f32vec2_u32vec2 %extinst FrexpStruct %f32vec2_01
  3693. )";
  3694. CompileSuccessfully(GenerateShaderCode(body));
  3695. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3696. }
  3697. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeNotStruct) {
  3698. const std::string body = R"(
  3699. %val1 = OpExtInst %f32 %extinst FrexpStruct %f32_h
  3700. )";
  3701. CompileSuccessfully(GenerateShaderCode(body));
  3702. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3703. EXPECT_THAT(getDiagnosticString(),
  3704. HasSubstr("GLSL.std.450 FrexpStruct: "
  3705. "expected Result Type to be a struct with two members, "
  3706. "first member a float scalar or vector, second member "
  3707. "a 32-bit int scalar or vector with the same number of "
  3708. "components as the first member"));
  3709. }
  3710. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongSize) {
  3711. const std::string body = R"(
  3712. %val1 = OpExtInst %struct_f32_u32_f32 %extinst FrexpStruct %f32_h
  3713. )";
  3714. CompileSuccessfully(GenerateShaderCode(body));
  3715. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3716. EXPECT_THAT(getDiagnosticString(),
  3717. HasSubstr("GLSL.std.450 FrexpStruct: "
  3718. "expected Result Type to be a struct with two members, "
  3719. "first member a float scalar or vector, second member "
  3720. "a 32-bit int scalar or vector with the same number of "
  3721. "components as the first member"));
  3722. }
  3723. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongMember1) {
  3724. const std::string body = R"(
  3725. %val1 = OpExtInst %struct_u32_u32 %extinst FrexpStruct %f32_h
  3726. )";
  3727. CompileSuccessfully(GenerateShaderCode(body));
  3728. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3729. EXPECT_THAT(getDiagnosticString(),
  3730. HasSubstr("GLSL.std.450 FrexpStruct: "
  3731. "expected Result Type to be a struct with two members, "
  3732. "first member a float scalar or vector, second member "
  3733. "a 32-bit int scalar or vector with the same number of "
  3734. "components as the first member"));
  3735. }
  3736. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongMember2) {
  3737. const std::string body = R"(
  3738. %val1 = OpExtInst %struct_f32_f32 %extinst FrexpStruct %f32_h
  3739. )";
  3740. CompileSuccessfully(GenerateShaderCode(body));
  3741. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3742. EXPECT_THAT(getDiagnosticString(),
  3743. HasSubstr("GLSL.std.450 FrexpStruct: "
  3744. "expected Result Type to be a struct with two members, "
  3745. "first member a float scalar or vector, second member "
  3746. "a 32-bit int scalar or vector with the same number of "
  3747. "components as the first member"));
  3748. }
  3749. TEST_F(ValidateExtInst, GlslStd450FrexpStructXWrongType) {
  3750. const std::string body = R"(
  3751. %val1 = OpExtInst %struct_f32_u32 %extinst FrexpStruct %f64_0
  3752. )";
  3753. CompileSuccessfully(GenerateShaderCode(body));
  3754. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3755. EXPECT_THAT(getDiagnosticString(),
  3756. HasSubstr("GLSL.std.450 FrexpStruct: "
  3757. "expected operand X type to be equal to the first "
  3758. "member of Result Type struct"));
  3759. }
  3760. TEST_F(ValidateExtInst,
  3761. GlslStd450FrexpStructResultTypeStructRightInt16Member2) {
  3762. const std::string body = R"(
  3763. %val1 = OpExtInst %struct_f16_u16 %extinst FrexpStruct %f16_h
  3764. )";
  3765. const std::string extension = R"(
  3766. OpExtension "SPV_AMD_gpu_shader_int16"
  3767. )";
  3768. CompileSuccessfully(GenerateShaderCode(body, extension));
  3769. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3770. }
  3771. TEST_F(ValidateExtInst,
  3772. GlslStd450FrexpStructResultTypeStructWrongInt16Member2) {
  3773. const std::string body = R"(
  3774. %val1 = OpExtInst %struct_f16_u16 %extinst FrexpStruct %f16_h
  3775. )";
  3776. CompileSuccessfully(GenerateShaderCode(body));
  3777. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3778. EXPECT_THAT(getDiagnosticString(),
  3779. HasSubstr("GLSL.std.450 FrexpStruct: "
  3780. "expected Result Type to be a struct with two members, "
  3781. "first member a float scalar or vector, second member "
  3782. "a 32-bit int scalar or vector with the same number of "
  3783. "components as the first member"));
  3784. }
  3785. TEST_P(ValidateGlslStd450Pack, Success) {
  3786. const std::string ext_inst_name = GetParam();
  3787. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3788. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3789. const uint32_t total_bit_width = num_components * packed_bit_width;
  3790. const std::string vec_str =
  3791. num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  3792. std::ostringstream body;
  3793. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  3794. << ext_inst_name << vec_str;
  3795. body << "%val2 = OpExtInst %s" << total_bit_width << " %extinst "
  3796. << ext_inst_name << vec_str;
  3797. CompileSuccessfully(GenerateShaderCode(body.str()));
  3798. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3799. }
  3800. TEST_P(ValidateGlslStd450Pack, Float32ResultType) {
  3801. const std::string ext_inst_name = GetParam();
  3802. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3803. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3804. const uint32_t total_bit_width = num_components * packed_bit_width;
  3805. const std::string vec_str =
  3806. num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  3807. std::ostringstream body;
  3808. body << "%val1 = OpExtInst %f" << total_bit_width << " %extinst "
  3809. << ext_inst_name << vec_str;
  3810. std::ostringstream expected;
  3811. expected << "GLSL.std.450 " << ext_inst_name
  3812. << ": expected Result Type to be " << total_bit_width
  3813. << "-bit int scalar type";
  3814. CompileSuccessfully(GenerateShaderCode(body.str()));
  3815. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3816. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  3817. }
  3818. TEST_P(ValidateGlslStd450Pack, Int16ResultType) {
  3819. const std::string ext_inst_name = GetParam();
  3820. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3821. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3822. const uint32_t total_bit_width = num_components * packed_bit_width;
  3823. const std::string vec_str =
  3824. num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  3825. std::ostringstream body;
  3826. body << "%val1 = OpExtInst %u16 %extinst " << ext_inst_name << vec_str;
  3827. std::ostringstream expected;
  3828. expected << "GLSL.std.450 " << ext_inst_name
  3829. << ": expected Result Type to be " << total_bit_width
  3830. << "-bit int scalar type";
  3831. CompileSuccessfully(GenerateShaderCode(body.str()));
  3832. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3833. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  3834. }
  3835. TEST_P(ValidateGlslStd450Pack, VNotVector) {
  3836. const std::string ext_inst_name = GetParam();
  3837. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3838. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3839. const uint32_t total_bit_width = num_components * packed_bit_width;
  3840. std::ostringstream body;
  3841. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  3842. << ext_inst_name << " %f32_1\n";
  3843. std::ostringstream expected;
  3844. expected << "GLSL.std.450 " << ext_inst_name
  3845. << ": expected operand V to be a 32-bit float vector of size "
  3846. << num_components;
  3847. CompileSuccessfully(GenerateShaderCode(body.str()));
  3848. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3849. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  3850. }
  3851. TEST_P(ValidateGlslStd450Pack, VNotFloatVector) {
  3852. const std::string ext_inst_name = GetParam();
  3853. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3854. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3855. const uint32_t total_bit_width = num_components * packed_bit_width;
  3856. const std::string vec_str =
  3857. num_components == 2 ? " %u32vec2_01\n" : " %u32vec4_0123\n";
  3858. std::ostringstream body;
  3859. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  3860. << ext_inst_name << vec_str;
  3861. std::ostringstream expected;
  3862. expected << "GLSL.std.450 " << ext_inst_name
  3863. << ": expected operand V to be a 32-bit float vector of size "
  3864. << num_components;
  3865. CompileSuccessfully(GenerateShaderCode(body.str()));
  3866. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3867. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  3868. }
  3869. TEST_P(ValidateGlslStd450Pack, VNotFloat32Vector) {
  3870. const std::string ext_inst_name = GetParam();
  3871. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3872. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3873. const uint32_t total_bit_width = num_components * packed_bit_width;
  3874. const std::string vec_str =
  3875. num_components == 2 ? " %f64vec2_01\n" : " %f64vec4_0123\n";
  3876. std::ostringstream body;
  3877. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  3878. << ext_inst_name << vec_str;
  3879. std::ostringstream expected;
  3880. expected << "GLSL.std.450 " << ext_inst_name
  3881. << ": expected operand V to be a 32-bit float vector of size "
  3882. << num_components;
  3883. CompileSuccessfully(GenerateShaderCode(body.str()));
  3884. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3885. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  3886. }
  3887. TEST_P(ValidateGlslStd450Pack, VWrongSizeVector) {
  3888. const std::string ext_inst_name = GetParam();
  3889. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3890. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3891. const uint32_t total_bit_width = num_components * packed_bit_width;
  3892. const std::string vec_str =
  3893. num_components == 4 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  3894. std::ostringstream body;
  3895. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  3896. << ext_inst_name << vec_str;
  3897. std::ostringstream expected;
  3898. expected << "GLSL.std.450 " << ext_inst_name
  3899. << ": expected operand V to be a 32-bit float vector of size "
  3900. << num_components;
  3901. CompileSuccessfully(GenerateShaderCode(body.str()));
  3902. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3903. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  3904. }
  3905. INSTANTIATE_TEST_SUITE_P(AllPack, ValidateGlslStd450Pack,
  3906. ::testing::ValuesIn(std::vector<std::string>{
  3907. "PackSnorm4x8",
  3908. "PackUnorm4x8",
  3909. "PackSnorm2x16",
  3910. "PackUnorm2x16",
  3911. "PackHalf2x16",
  3912. }));
  3913. TEST_F(ValidateExtInst, PackDouble2x32Success) {
  3914. const std::string body = R"(
  3915. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u32vec2_01
  3916. )";
  3917. CompileSuccessfully(GenerateShaderCode(body));
  3918. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3919. }
  3920. TEST_F(ValidateExtInst, PackDouble2x32Float32ResultType) {
  3921. const std::string body = R"(
  3922. %val1 = OpExtInst %f32 %extinst PackDouble2x32 %u32vec2_01
  3923. )";
  3924. CompileSuccessfully(GenerateShaderCode(body));
  3925. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3926. EXPECT_THAT(getDiagnosticString(),
  3927. HasSubstr("GLSL.std.450 PackDouble2x32: expected Result Type to "
  3928. "be 64-bit float scalar type"));
  3929. }
  3930. TEST_F(ValidateExtInst, PackDouble2x32Int64ResultType) {
  3931. const std::string body = R"(
  3932. %val1 = OpExtInst %u64 %extinst PackDouble2x32 %u32vec2_01
  3933. )";
  3934. CompileSuccessfully(GenerateShaderCode(body));
  3935. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3936. EXPECT_THAT(getDiagnosticString(),
  3937. HasSubstr("GLSL.std.450 PackDouble2x32: expected Result Type to "
  3938. "be 64-bit float scalar type"));
  3939. }
  3940. TEST_F(ValidateExtInst, PackDouble2x32VNotVector) {
  3941. const std::string body = R"(
  3942. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u64_1
  3943. )";
  3944. CompileSuccessfully(GenerateShaderCode(body));
  3945. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3946. EXPECT_THAT(getDiagnosticString(),
  3947. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  3948. "a 32-bit int vector of size 2"));
  3949. }
  3950. TEST_F(ValidateExtInst, PackDouble2x32VNotIntVector) {
  3951. const std::string body = R"(
  3952. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %f32vec2_01
  3953. )";
  3954. CompileSuccessfully(GenerateShaderCode(body));
  3955. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3956. EXPECT_THAT(getDiagnosticString(),
  3957. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  3958. "a 32-bit int vector of size 2"));
  3959. }
  3960. TEST_F(ValidateExtInst, PackDouble2x32VNotInt32Vector) {
  3961. const std::string body = R"(
  3962. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u64vec2_01
  3963. )";
  3964. CompileSuccessfully(GenerateShaderCode(body));
  3965. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3966. EXPECT_THAT(getDiagnosticString(),
  3967. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  3968. "a 32-bit int vector of size 2"));
  3969. }
  3970. TEST_F(ValidateExtInst, PackDouble2x32VWrongSize) {
  3971. const std::string body = R"(
  3972. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u32vec4_0123
  3973. )";
  3974. CompileSuccessfully(GenerateShaderCode(body));
  3975. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3976. EXPECT_THAT(getDiagnosticString(),
  3977. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  3978. "a 32-bit int vector of size 2"));
  3979. }
  3980. TEST_P(ValidateGlslStd450Unpack, Success) {
  3981. const std::string ext_inst_name = GetParam();
  3982. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3983. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3984. const uint32_t total_bit_width = num_components * packed_bit_width;
  3985. const std::string result_type_str =
  3986. num_components == 2 ? "%f32vec2" : " %f32vec4";
  3987. std::ostringstream body;
  3988. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  3989. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  3990. body << "%val2 = OpExtInst " << result_type_str << " %extinst "
  3991. << ext_inst_name << " %s" << total_bit_width << "_1\n";
  3992. CompileSuccessfully(GenerateShaderCode(body.str()));
  3993. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3994. }
  3995. TEST_P(ValidateGlslStd450Unpack, ResultTypeNotVector) {
  3996. const std::string ext_inst_name = GetParam();
  3997. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  3998. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  3999. const uint32_t total_bit_width = num_components * packed_bit_width;
  4000. const std::string result_type_str = "%f32";
  4001. std::ostringstream body;
  4002. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  4003. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  4004. std::ostringstream expected;
  4005. expected << "GLSL.std.450 " << ext_inst_name
  4006. << ": expected Result Type to be a 32-bit float vector of size "
  4007. << num_components;
  4008. CompileSuccessfully(GenerateShaderCode(body.str()));
  4009. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4010. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  4011. }
  4012. TEST_P(ValidateGlslStd450Unpack, ResultTypeNotFloatVector) {
  4013. const std::string ext_inst_name = GetParam();
  4014. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  4015. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  4016. const uint32_t total_bit_width = num_components * packed_bit_width;
  4017. const std::string result_type_str =
  4018. num_components == 2 ? "%u32vec2" : " %u32vec4";
  4019. std::ostringstream body;
  4020. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  4021. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  4022. std::ostringstream expected;
  4023. expected << "GLSL.std.450 " << ext_inst_name
  4024. << ": expected Result Type to be a 32-bit float vector of size "
  4025. << num_components;
  4026. CompileSuccessfully(GenerateShaderCode(body.str()));
  4027. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4028. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  4029. }
  4030. TEST_P(ValidateGlslStd450Unpack, ResultTypeNotFloat32Vector) {
  4031. const std::string ext_inst_name = GetParam();
  4032. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  4033. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  4034. const uint32_t total_bit_width = num_components * packed_bit_width;
  4035. const std::string result_type_str =
  4036. num_components == 2 ? "%f64vec2" : " %f64vec4";
  4037. std::ostringstream body;
  4038. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  4039. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  4040. std::ostringstream expected;
  4041. expected << "GLSL.std.450 " << ext_inst_name
  4042. << ": expected Result Type to be a 32-bit float vector of size "
  4043. << num_components;
  4044. CompileSuccessfully(GenerateShaderCode(body.str()));
  4045. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4046. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  4047. }
  4048. TEST_P(ValidateGlslStd450Unpack, ResultTypeWrongSize) {
  4049. const std::string ext_inst_name = GetParam();
  4050. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  4051. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  4052. const uint32_t total_bit_width = num_components * packed_bit_width;
  4053. const std::string result_type_str =
  4054. num_components == 4 ? "%f32vec2" : " %f32vec4";
  4055. std::ostringstream body;
  4056. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  4057. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  4058. std::ostringstream expected;
  4059. expected << "GLSL.std.450 " << ext_inst_name
  4060. << ": expected Result Type to be a 32-bit float vector of size "
  4061. << num_components;
  4062. CompileSuccessfully(GenerateShaderCode(body.str()));
  4063. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4064. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  4065. }
  4066. TEST_P(ValidateGlslStd450Unpack, ResultPNotInt) {
  4067. const std::string ext_inst_name = GetParam();
  4068. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  4069. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  4070. const uint32_t total_bit_width = num_components * packed_bit_width;
  4071. const std::string result_type_str =
  4072. num_components == 2 ? "%f32vec2" : " %f32vec4";
  4073. std::ostringstream body;
  4074. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  4075. << ext_inst_name << " %f" << total_bit_width << "_1\n";
  4076. std::ostringstream expected;
  4077. expected << "GLSL.std.450 " << ext_inst_name
  4078. << ": expected operand P to be a " << total_bit_width
  4079. << "-bit int scalar";
  4080. CompileSuccessfully(GenerateShaderCode(body.str()));
  4081. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4082. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  4083. }
  4084. TEST_P(ValidateGlslStd450Unpack, ResultPWrongBitWidth) {
  4085. const std::string ext_inst_name = GetParam();
  4086. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  4087. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  4088. const uint32_t total_bit_width = num_components * packed_bit_width;
  4089. const uint32_t wrong_bit_width = total_bit_width == 32 ? 64 : 32;
  4090. const std::string result_type_str =
  4091. num_components == 2 ? "%f32vec2" : " %f32vec4";
  4092. std::ostringstream body;
  4093. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  4094. << ext_inst_name << " %u" << wrong_bit_width << "_1\n";
  4095. std::ostringstream expected;
  4096. expected << "GLSL.std.450 " << ext_inst_name
  4097. << ": expected operand P to be a " << total_bit_width
  4098. << "-bit int scalar";
  4099. CompileSuccessfully(GenerateShaderCode(body.str()));
  4100. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4101. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  4102. }
  4103. INSTANTIATE_TEST_SUITE_P(AllUnpack, ValidateGlslStd450Unpack,
  4104. ::testing::ValuesIn(std::vector<std::string>{
  4105. "UnpackSnorm4x8",
  4106. "UnpackUnorm4x8",
  4107. "UnpackSnorm2x16",
  4108. "UnpackUnorm2x16",
  4109. "UnpackHalf2x16",
  4110. }));
  4111. TEST_F(ValidateExtInst, UnpackDouble2x32Success) {
  4112. const std::string body = R"(
  4113. %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %f64_1
  4114. )";
  4115. CompileSuccessfully(GenerateShaderCode(body));
  4116. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4117. }
  4118. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotVector) {
  4119. const std::string body = R"(
  4120. %val1 = OpExtInst %u64 %extinst UnpackDouble2x32 %f64_1
  4121. )";
  4122. CompileSuccessfully(GenerateShaderCode(body));
  4123. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4124. EXPECT_THAT(getDiagnosticString(),
  4125. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  4126. "to be a 32-bit int vector of size 2"));
  4127. }
  4128. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotIntVector) {
  4129. const std::string body = R"(
  4130. %val1 = OpExtInst %f32vec2 %extinst UnpackDouble2x32 %f64_1
  4131. )";
  4132. CompileSuccessfully(GenerateShaderCode(body));
  4133. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4134. EXPECT_THAT(getDiagnosticString(),
  4135. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  4136. "to be a 32-bit int vector of size 2"));
  4137. }
  4138. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotInt32Vector) {
  4139. const std::string body = R"(
  4140. %val1 = OpExtInst %u64vec2 %extinst UnpackDouble2x32 %f64_1
  4141. )";
  4142. CompileSuccessfully(GenerateShaderCode(body));
  4143. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4144. EXPECT_THAT(getDiagnosticString(),
  4145. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  4146. "to be a 32-bit int vector of size 2"));
  4147. }
  4148. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeWrongSize) {
  4149. const std::string body = R"(
  4150. %val1 = OpExtInst %u32vec4 %extinst UnpackDouble2x32 %f64_1
  4151. )";
  4152. CompileSuccessfully(GenerateShaderCode(body));
  4153. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4154. EXPECT_THAT(getDiagnosticString(),
  4155. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  4156. "to be a 32-bit int vector of size 2"));
  4157. }
  4158. TEST_F(ValidateExtInst, UnpackDouble2x32VNotFloat) {
  4159. const std::string body = R"(
  4160. %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %u64_1
  4161. )";
  4162. CompileSuccessfully(GenerateShaderCode(body));
  4163. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4164. EXPECT_THAT(getDiagnosticString(),
  4165. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected operand V to "
  4166. "be a 64-bit float scalar"));
  4167. }
  4168. TEST_F(ValidateExtInst, UnpackDouble2x32VNotFloat64) {
  4169. const std::string body = R"(
  4170. %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %f32_1
  4171. )";
  4172. CompileSuccessfully(GenerateShaderCode(body));
  4173. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4174. EXPECT_THAT(getDiagnosticString(),
  4175. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected operand V to "
  4176. "be a 64-bit float scalar"));
  4177. }
  4178. TEST_F(ValidateExtInst, GlslStd450LengthSuccess) {
  4179. const std::string body = R"(
  4180. %val1 = OpExtInst %f32 %extinst Length %f32_1
  4181. %val2 = OpExtInst %f32 %extinst Length %f32vec2_01
  4182. %val3 = OpExtInst %f32 %extinst Length %f32vec4_0123
  4183. )";
  4184. CompileSuccessfully(GenerateShaderCode(body));
  4185. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4186. }
  4187. TEST_F(ValidateExtInst, GlslStd450LengthIntResultType) {
  4188. const std::string body = R"(
  4189. %val1 = OpExtInst %u32 %extinst Length %f32vec2_01
  4190. )";
  4191. CompileSuccessfully(GenerateShaderCode(body));
  4192. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4193. EXPECT_THAT(getDiagnosticString(),
  4194. HasSubstr("GLSL.std.450 Length: "
  4195. "expected Result Type to be a float scalar type"));
  4196. }
  4197. TEST_F(ValidateExtInst, GlslStd450LengthIntX) {
  4198. const std::string body = R"(
  4199. %val1 = OpExtInst %f32 %extinst Length %u32vec2_01
  4200. )";
  4201. CompileSuccessfully(GenerateShaderCode(body));
  4202. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4203. EXPECT_THAT(getDiagnosticString(),
  4204. HasSubstr("GLSL.std.450 Length: "
  4205. "expected operand X to be of float scalar or "
  4206. "vector type"));
  4207. }
  4208. TEST_F(ValidateExtInst, GlslStd450LengthDifferentType) {
  4209. const std::string body = R"(
  4210. %val1 = OpExtInst %f64 %extinst Length %f32vec2_01
  4211. )";
  4212. CompileSuccessfully(GenerateShaderCode(body));
  4213. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4214. EXPECT_THAT(getDiagnosticString(),
  4215. HasSubstr("GLSL.std.450 Length: "
  4216. "expected operand X component type to be equal to "
  4217. "Result Type"));
  4218. }
  4219. TEST_F(ValidateExtInst, GlslStd450DistanceSuccess) {
  4220. const std::string body = R"(
  4221. %val1 = OpExtInst %f32 %extinst Distance %f32_0 %f32_1
  4222. %val2 = OpExtInst %f32 %extinst Distance %f32vec2_01 %f32vec2_12
  4223. %val3 = OpExtInst %f32 %extinst Distance %f32vec4_0123 %f32vec4_1234
  4224. )";
  4225. CompileSuccessfully(GenerateShaderCode(body));
  4226. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4227. }
  4228. TEST_F(ValidateExtInst, GlslStd450DistanceIntResultType) {
  4229. const std::string body = R"(
  4230. %val1 = OpExtInst %u32 %extinst Distance %f32vec2_01 %f32vec2_12
  4231. )";
  4232. CompileSuccessfully(GenerateShaderCode(body));
  4233. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4234. EXPECT_THAT(getDiagnosticString(),
  4235. HasSubstr("GLSL.std.450 Distance: "
  4236. "expected Result Type to be a float scalar type"));
  4237. }
  4238. TEST_F(ValidateExtInst, GlslStd450DistanceIntP0) {
  4239. const std::string body = R"(
  4240. %val1 = OpExtInst %f32 %extinst Distance %u32_0 %f32_1
  4241. )";
  4242. CompileSuccessfully(GenerateShaderCode(body));
  4243. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4244. EXPECT_THAT(getDiagnosticString(),
  4245. HasSubstr("GLSL.std.450 Distance: "
  4246. "expected operand P0 to be of float scalar or "
  4247. "vector type"));
  4248. }
  4249. TEST_F(ValidateExtInst, GlslStd450DistanceF64VectorP0) {
  4250. const std::string body = R"(
  4251. %val1 = OpExtInst %f32 %extinst Distance %f64vec2_01 %f32vec2_12
  4252. )";
  4253. CompileSuccessfully(GenerateShaderCode(body));
  4254. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4255. EXPECT_THAT(getDiagnosticString(),
  4256. HasSubstr("GLSL.std.450 Distance: "
  4257. "expected operand P0 component type to be equal to "
  4258. "Result Type"));
  4259. }
  4260. TEST_F(ValidateExtInst, GlslStd450DistanceIntP1) {
  4261. const std::string body = R"(
  4262. %val1 = OpExtInst %f32 %extinst Distance %f32_0 %u32_1
  4263. )";
  4264. CompileSuccessfully(GenerateShaderCode(body));
  4265. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4266. EXPECT_THAT(getDiagnosticString(),
  4267. HasSubstr("GLSL.std.450 Distance: "
  4268. "expected operand P1 to be of float scalar or "
  4269. "vector type"));
  4270. }
  4271. TEST_F(ValidateExtInst, GlslStd450DistanceF64VectorP1) {
  4272. const std::string body = R"(
  4273. %val1 = OpExtInst %f32 %extinst Distance %f32vec2_12 %f64vec2_01
  4274. )";
  4275. CompileSuccessfully(GenerateShaderCode(body));
  4276. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4277. EXPECT_THAT(getDiagnosticString(),
  4278. HasSubstr("GLSL.std.450 Distance: "
  4279. "expected operand P1 component type to be equal to "
  4280. "Result Type"));
  4281. }
  4282. TEST_F(ValidateExtInst, GlslStd450DistanceDifferentSize) {
  4283. const std::string body = R"(
  4284. %val1 = OpExtInst %f32 %extinst Distance %f32vec2_01 %f32vec4_0123
  4285. )";
  4286. CompileSuccessfully(GenerateShaderCode(body));
  4287. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4288. EXPECT_THAT(getDiagnosticString(),
  4289. HasSubstr("GLSL.std.450 Distance: "
  4290. "expected operands P0 and P1 to have the same number "
  4291. "of components"));
  4292. }
  4293. TEST_F(ValidateExtInst, GlslStd450CrossSuccess) {
  4294. const std::string body = R"(
  4295. %val1 = OpExtInst %f32vec3 %extinst Cross %f32vec3_012 %f32vec3_123
  4296. )";
  4297. CompileSuccessfully(GenerateShaderCode(body));
  4298. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4299. }
  4300. TEST_F(ValidateExtInst, GlslStd450CrossIntVectorResultType) {
  4301. const std::string body = R"(
  4302. %val1 = OpExtInst %u32vec3 %extinst Cross %f32vec3_012 %f32vec3_123
  4303. )";
  4304. CompileSuccessfully(GenerateShaderCode(body));
  4305. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4306. EXPECT_THAT(getDiagnosticString(),
  4307. HasSubstr("GLSL.std.450 Cross: "
  4308. "expected Result Type to be a float vector type"));
  4309. }
  4310. TEST_F(ValidateExtInst, GlslStd450CrossResultTypeWrongSize) {
  4311. const std::string body = R"(
  4312. %val1 = OpExtInst %f32vec2 %extinst Cross %f32vec3_012 %f32vec3_123
  4313. )";
  4314. CompileSuccessfully(GenerateShaderCode(body));
  4315. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4316. EXPECT_THAT(getDiagnosticString(),
  4317. HasSubstr("GLSL.std.450 Cross: "
  4318. "expected Result Type to have 3 components"));
  4319. }
  4320. TEST_F(ValidateExtInst, GlslStd450CrossXWrongType) {
  4321. const std::string body = R"(
  4322. %val1 = OpExtInst %f32vec3 %extinst Cross %f64vec3_012 %f32vec3_123
  4323. )";
  4324. CompileSuccessfully(GenerateShaderCode(body));
  4325. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4326. EXPECT_THAT(getDiagnosticString(),
  4327. HasSubstr("GLSL.std.450 Cross: "
  4328. "expected operand X type to be equal to Result Type"));
  4329. }
  4330. TEST_F(ValidateExtInst, GlslStd450CrossYWrongType) {
  4331. const std::string body = R"(
  4332. %val1 = OpExtInst %f32vec3 %extinst Cross %f32vec3_123 %f64vec3_012
  4333. )";
  4334. CompileSuccessfully(GenerateShaderCode(body));
  4335. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4336. EXPECT_THAT(getDiagnosticString(),
  4337. HasSubstr("GLSL.std.450 Cross: "
  4338. "expected operand Y type to be equal to Result Type"));
  4339. }
  4340. TEST_F(ValidateExtInst, GlslStd450RefractSuccess) {
  4341. const std::string body = R"(
  4342. %val1 = OpExtInst %f32 %extinst Refract %f32_1 %f32_1 %f32_1
  4343. %val2 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f16_1
  4344. )";
  4345. CompileSuccessfully(GenerateShaderCode(body));
  4346. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4347. }
  4348. TEST_F(ValidateExtInst, GlslStd450RefractIntVectorResultType) {
  4349. const std::string body = R"(
  4350. %val1 = OpExtInst %u32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f32_1
  4351. )";
  4352. CompileSuccessfully(GenerateShaderCode(body));
  4353. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4354. EXPECT_THAT(getDiagnosticString(),
  4355. HasSubstr("GLSL.std.450 Refract: "
  4356. "expected Result Type to be a float scalar or "
  4357. "vector type"));
  4358. }
  4359. TEST_F(ValidateExtInst, GlslStd450RefractIntVectorI) {
  4360. const std::string body = R"(
  4361. %val1 = OpExtInst %f32vec2 %extinst Refract %u32vec2_01 %f32vec2_01 %f32_1
  4362. )";
  4363. CompileSuccessfully(GenerateShaderCode(body));
  4364. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4365. EXPECT_THAT(getDiagnosticString(),
  4366. HasSubstr("GLSL.std.450 Refract: "
  4367. "expected operand I to be of type equal to "
  4368. "Result Type"));
  4369. }
  4370. TEST_F(ValidateExtInst, GlslStd450RefractIntVectorN) {
  4371. const std::string body = R"(
  4372. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %u32vec2_01 %f32_1
  4373. )";
  4374. CompileSuccessfully(GenerateShaderCode(body));
  4375. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4376. EXPECT_THAT(getDiagnosticString(),
  4377. HasSubstr("GLSL.std.450 Refract: "
  4378. "expected operand N to be of type equal to "
  4379. "Result Type"));
  4380. }
  4381. TEST_F(ValidateExtInst, GlslStd450RefractIntEta) {
  4382. const std::string body = R"(
  4383. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %u32_1
  4384. )";
  4385. CompileSuccessfully(GenerateShaderCode(body));
  4386. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4387. EXPECT_THAT(getDiagnosticString(),
  4388. HasSubstr("GLSL.std.450 Refract: "
  4389. "expected operand Eta to be a float scalar"));
  4390. }
  4391. TEST_F(ValidateExtInst, GlslStd450RefractFloat64Eta) {
  4392. // SPIR-V issue 337: Eta can be 64-bit float scalar.
  4393. const std::string body = R"(
  4394. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f64_1
  4395. )";
  4396. CompileSuccessfully(GenerateShaderCode(body));
  4397. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4398. EXPECT_THAT(getDiagnosticString(), Eq(""));
  4399. }
  4400. TEST_F(ValidateExtInst, GlslStd450RefractVectorEta) {
  4401. const std::string body = R"(
  4402. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f32vec2_01
  4403. )";
  4404. CompileSuccessfully(GenerateShaderCode(body));
  4405. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4406. EXPECT_THAT(getDiagnosticString(),
  4407. HasSubstr("GLSL.std.450 Refract: "
  4408. "expected operand Eta to be a float scalar"));
  4409. }
  4410. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidSuccess) {
  4411. const std::string body = R"(
  4412. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
  4413. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtCentroid %f32vec2_input
  4414. )";
  4415. CompileSuccessfully(
  4416. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4417. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4418. }
  4419. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidNoCapability) {
  4420. const std::string body = R"(
  4421. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
  4422. )";
  4423. CompileSuccessfully(GenerateShaderCode(body));
  4424. ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
  4425. EXPECT_THAT(getDiagnosticString(),
  4426. HasSubstr("GLSL.std.450 InterpolateAtCentroid requires "
  4427. "capability InterpolationFunction"));
  4428. }
  4429. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidIntResultType) {
  4430. const std::string body = R"(
  4431. %val1 = OpExtInst %u32 %extinst InterpolateAtCentroid %f32_input
  4432. )";
  4433. CompileSuccessfully(
  4434. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4435. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4436. EXPECT_THAT(getDiagnosticString(),
  4437. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  4438. "expected Result Type to be a 32-bit float scalar "
  4439. "or vector type"));
  4440. }
  4441. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidF64ResultType) {
  4442. const std::string body = R"(
  4443. %val1 = OpExtInst %f64 %extinst InterpolateAtCentroid %f32_input
  4444. )";
  4445. CompileSuccessfully(
  4446. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4447. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4448. EXPECT_THAT(getDiagnosticString(),
  4449. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  4450. "expected Result Type to be a 32-bit float scalar "
  4451. "or vector type"));
  4452. }
  4453. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidNotPointer) {
  4454. const std::string body = R"(
  4455. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_1
  4456. )";
  4457. CompileSuccessfully(
  4458. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4459. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4460. EXPECT_THAT(getDiagnosticString(),
  4461. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  4462. "expected Interpolant to be a pointer"));
  4463. }
  4464. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongDataType) {
  4465. const std::string body = R"(
  4466. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32vec2_input
  4467. )";
  4468. CompileSuccessfully(
  4469. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4470. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4471. EXPECT_THAT(getDiagnosticString(),
  4472. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  4473. "expected Interpolant data type to be equal to "
  4474. "Result Type"));
  4475. }
  4476. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongStorageClass) {
  4477. const std::string body = R"(
  4478. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_output
  4479. )";
  4480. CompileSuccessfully(
  4481. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4482. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4483. EXPECT_THAT(getDiagnosticString(),
  4484. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  4485. "expected Interpolant storage class to be Input"));
  4486. }
  4487. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongExecutionModel) {
  4488. const std::string body = R"(
  4489. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
  4490. )";
  4491. CompileSuccessfully(GenerateShaderCode(
  4492. body, "OpCapability InterpolationFunction\n", "Vertex"));
  4493. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  4494. EXPECT_THAT(getDiagnosticString(),
  4495. HasSubstr("GLSL.std.450 InterpolateAtCentroid requires "
  4496. "Fragment execution model"));
  4497. }
  4498. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleSuccess) {
  4499. const std::string body = R"(
  4500. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
  4501. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtSample %f32vec2_input %u32_1
  4502. )";
  4503. CompileSuccessfully(
  4504. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4505. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4506. }
  4507. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleNoCapability) {
  4508. const std::string body = R"(
  4509. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
  4510. )";
  4511. CompileSuccessfully(GenerateShaderCode(body));
  4512. ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
  4513. EXPECT_THAT(getDiagnosticString(),
  4514. HasSubstr("GLSL.std.450 InterpolateAtSample requires "
  4515. "capability InterpolationFunction"));
  4516. }
  4517. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleIntResultType) {
  4518. const std::string body = R"(
  4519. %val1 = OpExtInst %u32 %extinst InterpolateAtSample %f32_input %u32_1
  4520. )";
  4521. CompileSuccessfully(
  4522. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4523. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4524. EXPECT_THAT(getDiagnosticString(),
  4525. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  4526. "expected Result Type to be a 32-bit float scalar "
  4527. "or vector type"));
  4528. }
  4529. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleF64ResultType) {
  4530. const std::string body = R"(
  4531. %val1 = OpExtInst %f64 %extinst InterpolateAtSample %f32_input %u32_1
  4532. )";
  4533. CompileSuccessfully(
  4534. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4535. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4536. EXPECT_THAT(getDiagnosticString(),
  4537. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  4538. "expected Result Type to be a 32-bit float scalar "
  4539. "or vector type"));
  4540. }
  4541. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleNotPointer) {
  4542. const std::string body = R"(
  4543. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_1 %u32_1
  4544. )";
  4545. CompileSuccessfully(
  4546. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4547. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4548. EXPECT_THAT(getDiagnosticString(),
  4549. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  4550. "expected Interpolant to be a pointer"));
  4551. }
  4552. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongDataType) {
  4553. const std::string body = R"(
  4554. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32vec2_input %u32_1
  4555. )";
  4556. CompileSuccessfully(
  4557. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4558. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4559. EXPECT_THAT(getDiagnosticString(),
  4560. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  4561. "expected Interpolant data type to be equal to "
  4562. "Result Type"));
  4563. }
  4564. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongStorageClass) {
  4565. const std::string body = R"(
  4566. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_output %u32_1
  4567. )";
  4568. CompileSuccessfully(
  4569. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4570. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4571. EXPECT_THAT(getDiagnosticString(),
  4572. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  4573. "expected Interpolant storage class to be Input"));
  4574. }
  4575. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleFloatSample) {
  4576. const std::string body = R"(
  4577. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %f32_1
  4578. )";
  4579. CompileSuccessfully(
  4580. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4581. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4582. EXPECT_THAT(getDiagnosticString(),
  4583. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  4584. "expected Sample to be 32-bit integer"));
  4585. }
  4586. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleU64Sample) {
  4587. const std::string body = R"(
  4588. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u64_1
  4589. )";
  4590. CompileSuccessfully(
  4591. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4592. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4593. EXPECT_THAT(getDiagnosticString(),
  4594. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  4595. "expected Sample to be 32-bit integer"));
  4596. }
  4597. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongExecutionModel) {
  4598. const std::string body = R"(
  4599. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
  4600. )";
  4601. CompileSuccessfully(GenerateShaderCode(
  4602. body, "OpCapability InterpolationFunction\n", "Vertex"));
  4603. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  4604. EXPECT_THAT(getDiagnosticString(),
  4605. HasSubstr("GLSL.std.450 InterpolateAtSample requires "
  4606. "Fragment execution model"));
  4607. }
  4608. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetSuccess) {
  4609. const std::string body = R"(
  4610. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  4611. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtOffset %f32vec2_input %f32vec2_01
  4612. )";
  4613. CompileSuccessfully(
  4614. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4615. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4616. }
  4617. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetNoCapability) {
  4618. const std::string body = R"(
  4619. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  4620. )";
  4621. CompileSuccessfully(GenerateShaderCode(body));
  4622. ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
  4623. EXPECT_THAT(getDiagnosticString(),
  4624. HasSubstr("GLSL.std.450 InterpolateAtOffset requires "
  4625. "capability InterpolationFunction"));
  4626. }
  4627. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetIntResultType) {
  4628. const std::string body = R"(
  4629. %val1 = OpExtInst %u32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  4630. )";
  4631. CompileSuccessfully(
  4632. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4633. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4634. EXPECT_THAT(getDiagnosticString(),
  4635. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4636. "expected Result Type to be a 32-bit float scalar "
  4637. "or vector type"));
  4638. }
  4639. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetF64ResultType) {
  4640. const std::string body = R"(
  4641. %val1 = OpExtInst %f64 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  4642. )";
  4643. CompileSuccessfully(
  4644. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4645. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4646. EXPECT_THAT(getDiagnosticString(),
  4647. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4648. "expected Result Type to be a 32-bit float scalar "
  4649. "or vector type"));
  4650. }
  4651. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetNotPointer) {
  4652. const std::string body = R"(
  4653. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_1 %f32vec2_01
  4654. )";
  4655. CompileSuccessfully(
  4656. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4657. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4658. EXPECT_THAT(getDiagnosticString(),
  4659. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4660. "expected Interpolant to be a pointer"));
  4661. }
  4662. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongDataType) {
  4663. const std::string body = R"(
  4664. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32vec2_input %f32vec2_01
  4665. )";
  4666. CompileSuccessfully(
  4667. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4668. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4669. EXPECT_THAT(getDiagnosticString(),
  4670. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4671. "expected Interpolant data type to be equal to "
  4672. "Result Type"));
  4673. }
  4674. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongStorageClass) {
  4675. const std::string body = R"(
  4676. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_output %f32vec2_01
  4677. )";
  4678. CompileSuccessfully(
  4679. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4680. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4681. EXPECT_THAT(getDiagnosticString(),
  4682. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4683. "expected Interpolant storage class to be Input"));
  4684. }
  4685. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotVector) {
  4686. const std::string body = R"(
  4687. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32_0
  4688. )";
  4689. CompileSuccessfully(
  4690. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4691. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4692. EXPECT_THAT(getDiagnosticString(),
  4693. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4694. "expected Offset to be a vector of 2 32-bit floats"));
  4695. }
  4696. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotVector2) {
  4697. const std::string body = R"(
  4698. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec3_012
  4699. )";
  4700. CompileSuccessfully(
  4701. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4702. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4703. EXPECT_THAT(getDiagnosticString(),
  4704. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4705. "expected Offset to be a vector of 2 32-bit floats"));
  4706. }
  4707. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotFloatVector) {
  4708. const std::string body = R"(
  4709. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %u32vec2_01
  4710. )";
  4711. CompileSuccessfully(
  4712. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4713. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4714. EXPECT_THAT(getDiagnosticString(),
  4715. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4716. "expected Offset to be a vector of 2 32-bit floats"));
  4717. }
  4718. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotFloat32Vector) {
  4719. const std::string body = R"(
  4720. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f64vec2_01
  4721. )";
  4722. CompileSuccessfully(
  4723. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  4724. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4725. EXPECT_THAT(getDiagnosticString(),
  4726. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  4727. "expected Offset to be a vector of 2 32-bit floats"));
  4728. }
  4729. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongExecutionModel) {
  4730. const std::string body = R"(
  4731. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  4732. )";
  4733. CompileSuccessfully(GenerateShaderCode(
  4734. body, "OpCapability InterpolationFunction\n", "Vertex"));
  4735. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  4736. EXPECT_THAT(getDiagnosticString(),
  4737. HasSubstr("GLSL.std.450 InterpolateAtOffset requires "
  4738. "Fragment execution model"));
  4739. }
  4740. TEST_P(ValidateOpenCLStdSqrtLike, Success) {
  4741. const std::string ext_inst_name = GetParam();
  4742. std::ostringstream ss;
  4743. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
  4744. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  4745. << " %f32vec2_01\n";
  4746. ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  4747. << " %f32vec4_0123\n";
  4748. ss << "%val4 = OpExtInst %f64 %extinst " << ext_inst_name << " %f64_0\n";
  4749. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4750. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4751. }
  4752. TEST_P(ValidateOpenCLStdSqrtLike, IntResultType) {
  4753. const std::string ext_inst_name = GetParam();
  4754. const std::string body =
  4755. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  4756. CompileSuccessfully(GenerateKernelCode(body));
  4757. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4758. EXPECT_THAT(getDiagnosticString(),
  4759. HasSubstr("OpenCL.std " + ext_inst_name +
  4760. ": expected Result Type to be a float scalar "
  4761. "or vector type"));
  4762. }
  4763. TEST_P(ValidateOpenCLStdSqrtLike, IntOperand) {
  4764. const std::string ext_inst_name = GetParam();
  4765. const std::string body =
  4766. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  4767. CompileSuccessfully(GenerateKernelCode(body));
  4768. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4769. EXPECT_THAT(getDiagnosticString(),
  4770. HasSubstr("OpenCL.std " + ext_inst_name +
  4771. ": expected types of all operands to be equal to "
  4772. "Result Type"));
  4773. }
  4774. INSTANTIATE_TEST_SUITE_P(
  4775. AllSqrtLike, ValidateOpenCLStdSqrtLike,
  4776. ::testing::ValuesIn(std::vector<std::string>{
  4777. "acos", "acosh", "acospi", "asin",
  4778. "asinh", "asinpi", "atan", "atanh",
  4779. "atanpi", "cbrt", "ceil", "cos",
  4780. "cosh", "cospi", "erfc", "erf",
  4781. "exp", "exp2", "exp10", "expm1",
  4782. "fabs", "floor", "log", "log2",
  4783. "log10", "log1p", "logb", "rint",
  4784. "round", "rsqrt", "sin", "sinh",
  4785. "sinpi", "sqrt", "tan", "tanh",
  4786. "tanpi", "tgamma", "trunc", "half_cos",
  4787. "half_exp", "half_exp2", "half_exp10", "half_log",
  4788. "half_log2", "half_log10", "half_recip", "half_rsqrt",
  4789. "half_sin", "half_sqrt", "half_tan", "lgamma",
  4790. "native_cos", "native_exp", "native_exp2", "native_exp10",
  4791. "native_log", "native_log2", "native_log10", "native_recip",
  4792. "native_rsqrt", "native_sin", "native_sqrt", "native_tan",
  4793. "degrees", "radians", "sign",
  4794. }));
  4795. TEST_P(ValidateOpenCLStdFMinLike, Success) {
  4796. const std::string ext_inst_name = GetParam();
  4797. std::ostringstream ss;
  4798. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4799. << " %f32_0 %f32_1\n";
  4800. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  4801. << " %f32vec2_01 %f32vec2_12\n";
  4802. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  4803. << " %f64_0 %f64_0\n";
  4804. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4805. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4806. }
  4807. TEST_P(ValidateOpenCLStdFMinLike, IntResultType) {
  4808. const std::string ext_inst_name = GetParam();
  4809. const std::string body =
  4810. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %f32_1\n";
  4811. CompileSuccessfully(GenerateKernelCode(body));
  4812. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4813. EXPECT_THAT(getDiagnosticString(),
  4814. HasSubstr("OpenCL.std " + ext_inst_name +
  4815. ": expected Result Type to be a float scalar "
  4816. "or vector type"));
  4817. }
  4818. TEST_P(ValidateOpenCLStdFMinLike, IntOperand1) {
  4819. const std::string ext_inst_name = GetParam();
  4820. const std::string body =
  4821. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
  4822. CompileSuccessfully(GenerateKernelCode(body));
  4823. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4824. EXPECT_THAT(getDiagnosticString(),
  4825. HasSubstr("OpenCL.std " + ext_inst_name +
  4826. ": expected types of all operands to be equal to "
  4827. "Result Type"));
  4828. }
  4829. TEST_P(ValidateOpenCLStdFMinLike, IntOperand2) {
  4830. const std::string ext_inst_name = GetParam();
  4831. const std::string body =
  4832. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
  4833. CompileSuccessfully(GenerateKernelCode(body));
  4834. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4835. EXPECT_THAT(getDiagnosticString(),
  4836. HasSubstr("OpenCL.std " + ext_inst_name +
  4837. ": expected types of all operands to be equal to "
  4838. "Result Type"));
  4839. }
  4840. INSTANTIATE_TEST_SUITE_P(AllFMinLike, ValidateOpenCLStdFMinLike,
  4841. ::testing::ValuesIn(std::vector<std::string>{
  4842. "atan2", "atan2pi", "copysign",
  4843. "fdim", "fmax", "fmin",
  4844. "fmod", "maxmag", "minmag",
  4845. "hypot", "nextafter", "pow",
  4846. "powr", "remainder", "half_divide",
  4847. "half_powr", "native_divide", "native_powr",
  4848. "step", "fmax_common", "fmin_common",
  4849. }));
  4850. TEST_P(ValidateOpenCLStdFClampLike, Success) {
  4851. const std::string ext_inst_name = GetParam();
  4852. std::ostringstream ss;
  4853. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4854. << " %f32_0 %f32_1 %f32_2\n";
  4855. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  4856. << " %f32vec2_01 %f32vec2_01 %f32vec2_12\n";
  4857. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  4858. << " %f64_0 %f64_0 %f64_1\n";
  4859. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4860. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4861. }
  4862. TEST_P(ValidateOpenCLStdFClampLike, IntResultType) {
  4863. const std::string ext_inst_name = GetParam();
  4864. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  4865. " %f32_0 %f32_1 %f32_2\n";
  4866. CompileSuccessfully(GenerateKernelCode(body));
  4867. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4868. EXPECT_THAT(getDiagnosticString(),
  4869. HasSubstr("OpenCL.std " + ext_inst_name +
  4870. ": expected Result Type to be a float scalar "
  4871. "or vector type"));
  4872. }
  4873. TEST_P(ValidateOpenCLStdFClampLike, IntOperand1) {
  4874. const std::string ext_inst_name = GetParam();
  4875. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  4876. " %u32_0 %f32_0 %f32_1\n";
  4877. CompileSuccessfully(GenerateKernelCode(body));
  4878. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4879. EXPECT_THAT(getDiagnosticString(),
  4880. HasSubstr("OpenCL.std " + ext_inst_name +
  4881. ": expected types of all operands to be equal to "
  4882. "Result Type"));
  4883. }
  4884. TEST_P(ValidateOpenCLStdFClampLike, IntOperand2) {
  4885. const std::string ext_inst_name = GetParam();
  4886. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  4887. " %f32_0 %u32_0 %f32_1\n";
  4888. CompileSuccessfully(GenerateKernelCode(body));
  4889. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4890. EXPECT_THAT(getDiagnosticString(),
  4891. HasSubstr("OpenCL.std " + ext_inst_name +
  4892. ": expected types of all operands to be equal to "
  4893. "Result Type"));
  4894. }
  4895. TEST_P(ValidateOpenCLStdFClampLike, IntOperand3) {
  4896. const std::string ext_inst_name = GetParam();
  4897. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  4898. " %f32_1 %f32_0 %u32_2\n";
  4899. CompileSuccessfully(GenerateKernelCode(body));
  4900. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4901. EXPECT_THAT(getDiagnosticString(),
  4902. HasSubstr("OpenCL.std " + ext_inst_name +
  4903. ": expected types of all operands to be equal to "
  4904. "Result Type"));
  4905. }
  4906. INSTANTIATE_TEST_SUITE_P(AllFClampLike, ValidateOpenCLStdFClampLike,
  4907. ::testing::ValuesIn(std::vector<std::string>{
  4908. "fma",
  4909. "mad",
  4910. "fclamp",
  4911. "mix",
  4912. "smoothstep",
  4913. }));
  4914. TEST_P(ValidateOpenCLStdSAbsLike, Success) {
  4915. const std::string ext_inst_name = GetParam();
  4916. std::ostringstream ss;
  4917. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  4918. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  4919. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  4920. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  4921. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4922. << " %u32vec2_01\n";
  4923. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4924. << " %u32vec2_01\n";
  4925. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4926. << " %u32vec2_01\n";
  4927. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4928. << " %u32vec2_01\n";
  4929. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4930. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4931. }
  4932. TEST_P(ValidateOpenCLStdSAbsLike, FloatResultType) {
  4933. const std::string ext_inst_name = GetParam();
  4934. const std::string body =
  4935. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  4936. CompileSuccessfully(GenerateKernelCode(body));
  4937. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4938. EXPECT_THAT(getDiagnosticString(),
  4939. HasSubstr("OpenCL.std " + ext_inst_name +
  4940. ": expected Result Type to be an int scalar "
  4941. "or vector type"));
  4942. }
  4943. TEST_P(ValidateOpenCLStdSAbsLike, FloatOperand) {
  4944. const std::string ext_inst_name = GetParam();
  4945. const std::string body =
  4946. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  4947. CompileSuccessfully(GenerateKernelCode(body));
  4948. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4949. EXPECT_THAT(
  4950. getDiagnosticString(),
  4951. HasSubstr("OpenCL.std " + ext_inst_name +
  4952. ": expected types of all operands to be equal to Result Type"));
  4953. }
  4954. TEST_P(ValidateOpenCLStdSAbsLike, U64Operand) {
  4955. const std::string ext_inst_name = GetParam();
  4956. const std::string body =
  4957. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0\n";
  4958. CompileSuccessfully(GenerateKernelCode(body));
  4959. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4960. EXPECT_THAT(
  4961. getDiagnosticString(),
  4962. HasSubstr("OpenCL.std " + ext_inst_name +
  4963. ": expected types of all operands to be equal to Result Type"));
  4964. }
  4965. INSTANTIATE_TEST_SUITE_P(AllSAbsLike, ValidateOpenCLStdSAbsLike,
  4966. ::testing::ValuesIn(std::vector<std::string>{
  4967. "s_abs",
  4968. "clz",
  4969. "ctz",
  4970. "popcount",
  4971. "u_abs",
  4972. }));
  4973. TEST_P(ValidateOpenCLStdUMinLike, Success) {
  4974. const std::string ext_inst_name = GetParam();
  4975. std::ostringstream ss;
  4976. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  4977. << " %u32_1 %u32_2\n";
  4978. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  4979. << " %u32_1 %u32_2\n";
  4980. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  4981. << " %u32_1 %u32_2\n";
  4982. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  4983. << " %u32_1 %u32_2\n";
  4984. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4985. << " %u32vec2_01 %u32vec2_01\n";
  4986. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4987. << " %u32vec2_01 %u32vec2_01\n";
  4988. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4989. << " %u32vec2_01 %u32vec2_01\n";
  4990. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  4991. << " %u32vec2_01 %u32vec2_01\n";
  4992. ss << "%val9 = OpExtInst %u64 %extinst " << ext_inst_name
  4993. << " %u64_1 %u64_0\n";
  4994. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4995. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4996. }
  4997. TEST_P(ValidateOpenCLStdUMinLike, FloatResultType) {
  4998. const std::string ext_inst_name = GetParam();
  4999. const std::string body =
  5000. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
  5001. CompileSuccessfully(GenerateKernelCode(body));
  5002. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5003. EXPECT_THAT(getDiagnosticString(),
  5004. HasSubstr("OpenCL.std " + ext_inst_name +
  5005. ": expected Result Type to be an int scalar "
  5006. "or vector type"));
  5007. }
  5008. TEST_P(ValidateOpenCLStdUMinLike, FloatOperand1) {
  5009. const std::string ext_inst_name = GetParam();
  5010. const std::string body =
  5011. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
  5012. CompileSuccessfully(GenerateKernelCode(body));
  5013. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5014. EXPECT_THAT(
  5015. getDiagnosticString(),
  5016. HasSubstr("OpenCL.std " + ext_inst_name +
  5017. ": expected types of all operands to be equal to Result Type"));
  5018. }
  5019. TEST_P(ValidateOpenCLStdUMinLike, FloatOperand2) {
  5020. const std::string ext_inst_name = GetParam();
  5021. const std::string body =
  5022. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
  5023. CompileSuccessfully(GenerateKernelCode(body));
  5024. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5025. EXPECT_THAT(
  5026. getDiagnosticString(),
  5027. HasSubstr("OpenCL.std " + ext_inst_name +
  5028. ": expected types of all operands to be equal to Result Type"));
  5029. }
  5030. TEST_P(ValidateOpenCLStdUMinLike, U64Operand1) {
  5031. const std::string ext_inst_name = GetParam();
  5032. const std::string body =
  5033. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0 %u32_0\n";
  5034. CompileSuccessfully(GenerateKernelCode(body));
  5035. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5036. EXPECT_THAT(
  5037. getDiagnosticString(),
  5038. HasSubstr("OpenCL.std " + ext_inst_name +
  5039. ": expected types of all operands to be equal to Result Type"));
  5040. }
  5041. TEST_P(ValidateOpenCLStdUMinLike, U64Operand2) {
  5042. const std::string ext_inst_name = GetParam();
  5043. const std::string body =
  5044. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %u64_0\n";
  5045. CompileSuccessfully(GenerateKernelCode(body));
  5046. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5047. EXPECT_THAT(
  5048. getDiagnosticString(),
  5049. HasSubstr("OpenCL.std " + ext_inst_name +
  5050. ": expected types of all operands to be equal to Result Type"));
  5051. }
  5052. INSTANTIATE_TEST_SUITE_P(AllUMinLike, ValidateOpenCLStdUMinLike,
  5053. ::testing::ValuesIn(std::vector<std::string>{
  5054. "s_max",
  5055. "u_max",
  5056. "s_min",
  5057. "u_min",
  5058. "s_abs_diff",
  5059. "s_add_sat",
  5060. "u_add_sat",
  5061. "s_mul_hi",
  5062. "rotate",
  5063. "s_sub_sat",
  5064. "u_sub_sat",
  5065. "s_hadd",
  5066. "u_hadd",
  5067. "s_rhadd",
  5068. "u_rhadd",
  5069. "u_abs_diff",
  5070. "u_mul_hi",
  5071. }));
  5072. TEST_P(ValidateOpenCLStdUClampLike, Success) {
  5073. const std::string ext_inst_name = GetParam();
  5074. std::ostringstream ss;
  5075. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  5076. << " %u32_0 %u32_1 %u32_2\n";
  5077. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  5078. << " %u32_0 %u32_1 %u32_2\n";
  5079. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  5080. << " %u32_0 %u32_1 %u32_2\n";
  5081. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  5082. << " %u32_0 %u32_1 %u32_2\n";
  5083. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5084. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5085. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5086. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5087. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5088. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5089. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5090. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5091. ss << "%val9 = OpExtInst %u64 %extinst " << ext_inst_name
  5092. << " %u64_1 %u64_0 %u64_1\n";
  5093. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5094. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5095. }
  5096. TEST_P(ValidateOpenCLStdUClampLike, FloatResultType) {
  5097. const std::string ext_inst_name = GetParam();
  5098. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  5099. " %u32_0 %u32_0 %u32_1\n";
  5100. CompileSuccessfully(GenerateKernelCode(body));
  5101. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5102. EXPECT_THAT(getDiagnosticString(),
  5103. HasSubstr("OpenCL.std " + ext_inst_name +
  5104. ": expected Result Type to be an int scalar "
  5105. "or vector type"));
  5106. }
  5107. TEST_P(ValidateOpenCLStdUClampLike, FloatOperand1) {
  5108. const std::string ext_inst_name = GetParam();
  5109. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5110. " %f32_0 %u32_0 %u32_1\n";
  5111. CompileSuccessfully(GenerateKernelCode(body));
  5112. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5113. EXPECT_THAT(
  5114. getDiagnosticString(),
  5115. HasSubstr("OpenCL.std " + ext_inst_name +
  5116. ": expected types of all operands to be equal to Result Type"));
  5117. }
  5118. TEST_P(ValidateOpenCLStdUClampLike, FloatOperand2) {
  5119. const std::string ext_inst_name = GetParam();
  5120. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5121. " %u32_0 %f32_0 %u32_1\n";
  5122. CompileSuccessfully(GenerateKernelCode(body));
  5123. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5124. EXPECT_THAT(
  5125. getDiagnosticString(),
  5126. HasSubstr("OpenCL.std " + ext_inst_name +
  5127. ": expected types of all operands to be equal to Result Type"));
  5128. }
  5129. TEST_P(ValidateOpenCLStdUClampLike, FloatOperand3) {
  5130. const std::string ext_inst_name = GetParam();
  5131. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5132. " %u32_0 %u32_0 %f32_1\n";
  5133. CompileSuccessfully(GenerateKernelCode(body));
  5134. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5135. EXPECT_THAT(
  5136. getDiagnosticString(),
  5137. HasSubstr("OpenCL.std " + ext_inst_name +
  5138. ": expected types of all operands to be equal to Result Type"));
  5139. }
  5140. TEST_P(ValidateOpenCLStdUClampLike, U64Operand1) {
  5141. const std::string ext_inst_name = GetParam();
  5142. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5143. " %f32_0 %u32_0 %u64_1\n";
  5144. CompileSuccessfully(GenerateKernelCode(body));
  5145. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5146. EXPECT_THAT(
  5147. getDiagnosticString(),
  5148. HasSubstr("OpenCL.std " + ext_inst_name +
  5149. ": expected types of all operands to be equal to Result Type"));
  5150. }
  5151. TEST_P(ValidateOpenCLStdUClampLike, U64Operand2) {
  5152. const std::string ext_inst_name = GetParam();
  5153. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5154. " %u32_0 %f32_0 %u64_1\n";
  5155. CompileSuccessfully(GenerateKernelCode(body));
  5156. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5157. EXPECT_THAT(
  5158. getDiagnosticString(),
  5159. HasSubstr("OpenCL.std " + ext_inst_name +
  5160. ": expected types of all operands to be equal to Result Type"));
  5161. }
  5162. TEST_P(ValidateOpenCLStdUClampLike, U64Operand3) {
  5163. const std::string ext_inst_name = GetParam();
  5164. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5165. " %u32_0 %u32_0 %u64_1\n";
  5166. CompileSuccessfully(GenerateKernelCode(body));
  5167. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5168. EXPECT_THAT(
  5169. getDiagnosticString(),
  5170. HasSubstr("OpenCL.std " + ext_inst_name +
  5171. ": expected types of all operands to be equal to Result Type"));
  5172. }
  5173. INSTANTIATE_TEST_SUITE_P(AllUClampLike, ValidateOpenCLStdUClampLike,
  5174. ::testing::ValuesIn(std::vector<std::string>{
  5175. "s_clamp",
  5176. "u_clamp",
  5177. "s_mad_hi",
  5178. "u_mad_sat",
  5179. "s_mad_sat",
  5180. "u_mad_hi",
  5181. }));
  5182. // -------------------------------------------------------------
  5183. TEST_P(ValidateOpenCLStdUMul24Like, Success) {
  5184. const std::string ext_inst_name = GetParam();
  5185. std::ostringstream ss;
  5186. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  5187. << " %u32_1 %u32_2\n";
  5188. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  5189. << " %u32_1 %u32_2\n";
  5190. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  5191. << " %u32_1 %u32_2\n";
  5192. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  5193. << " %u32_1 %u32_2\n";
  5194. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5195. << " %u32vec2_01 %u32vec2_01\n";
  5196. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5197. << " %u32vec2_01 %u32vec2_01\n";
  5198. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5199. << " %u32vec2_01 %u32vec2_01\n";
  5200. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5201. << " %u32vec2_01 %u32vec2_01\n";
  5202. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5203. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5204. }
  5205. TEST_P(ValidateOpenCLStdUMul24Like, FloatResultType) {
  5206. const std::string ext_inst_name = GetParam();
  5207. const std::string body =
  5208. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
  5209. CompileSuccessfully(GenerateKernelCode(body));
  5210. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5211. EXPECT_THAT(
  5212. getDiagnosticString(),
  5213. HasSubstr(
  5214. "OpenCL.std " + ext_inst_name +
  5215. ": expected Result Type to be a 32-bit int scalar or vector type"));
  5216. }
  5217. TEST_P(ValidateOpenCLStdUMul24Like, U64ResultType) {
  5218. const std::string ext_inst_name = GetParam();
  5219. const std::string body =
  5220. "%val1 = OpExtInst %u64 %extinst " + ext_inst_name + " %u64_0 %u64_0\n";
  5221. CompileSuccessfully(GenerateKernelCode(body));
  5222. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5223. EXPECT_THAT(
  5224. getDiagnosticString(),
  5225. HasSubstr(
  5226. "OpenCL.std " + ext_inst_name +
  5227. ": expected Result Type to be a 32-bit int scalar or vector type"));
  5228. }
  5229. TEST_P(ValidateOpenCLStdUMul24Like, FloatOperand1) {
  5230. const std::string ext_inst_name = GetParam();
  5231. const std::string body =
  5232. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
  5233. CompileSuccessfully(GenerateKernelCode(body));
  5234. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5235. EXPECT_THAT(
  5236. getDiagnosticString(),
  5237. HasSubstr("OpenCL.std " + ext_inst_name +
  5238. ": expected types of all operands to be equal to Result Type"));
  5239. }
  5240. TEST_P(ValidateOpenCLStdUMul24Like, FloatOperand2) {
  5241. const std::string ext_inst_name = GetParam();
  5242. const std::string body =
  5243. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
  5244. CompileSuccessfully(GenerateKernelCode(body));
  5245. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5246. EXPECT_THAT(
  5247. getDiagnosticString(),
  5248. HasSubstr("OpenCL.std " + ext_inst_name +
  5249. ": expected types of all operands to be equal to Result Type"));
  5250. }
  5251. TEST_P(ValidateOpenCLStdUMul24Like, U64Operand1) {
  5252. const std::string ext_inst_name = GetParam();
  5253. const std::string body =
  5254. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0 %u32_0\n";
  5255. CompileSuccessfully(GenerateKernelCode(body));
  5256. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5257. EXPECT_THAT(
  5258. getDiagnosticString(),
  5259. HasSubstr("OpenCL.std " + ext_inst_name +
  5260. ": expected types of all operands to be equal to Result Type"));
  5261. }
  5262. TEST_P(ValidateOpenCLStdUMul24Like, U64Operand2) {
  5263. const std::string ext_inst_name = GetParam();
  5264. const std::string body =
  5265. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %u64_0\n";
  5266. CompileSuccessfully(GenerateKernelCode(body));
  5267. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5268. EXPECT_THAT(
  5269. getDiagnosticString(),
  5270. HasSubstr("OpenCL.std " + ext_inst_name +
  5271. ": expected types of all operands to be equal to Result Type"));
  5272. }
  5273. INSTANTIATE_TEST_SUITE_P(AllUMul24Like, ValidateOpenCLStdUMul24Like,
  5274. ::testing::ValuesIn(std::vector<std::string>{
  5275. "s_mul24",
  5276. "u_mul24",
  5277. }));
  5278. TEST_P(ValidateOpenCLStdUMad24Like, Success) {
  5279. const std::string ext_inst_name = GetParam();
  5280. std::ostringstream ss;
  5281. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  5282. << " %u32_0 %u32_1 %u32_2\n";
  5283. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  5284. << " %u32_0 %u32_1 %u32_2\n";
  5285. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  5286. << " %u32_0 %u32_1 %u32_2\n";
  5287. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  5288. << " %u32_0 %u32_1 %u32_2\n";
  5289. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5290. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5291. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5292. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5293. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5294. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5295. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  5296. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  5297. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5298. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5299. }
  5300. TEST_P(ValidateOpenCLStdUMad24Like, FloatResultType) {
  5301. const std::string ext_inst_name = GetParam();
  5302. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  5303. " %u32_0 %u32_0 %u32_1\n";
  5304. CompileSuccessfully(GenerateKernelCode(body));
  5305. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5306. EXPECT_THAT(
  5307. getDiagnosticString(),
  5308. HasSubstr(
  5309. "OpenCL.std " + ext_inst_name +
  5310. ": expected Result Type to be a 32-bit int scalar or vector type"));
  5311. }
  5312. TEST_P(ValidateOpenCLStdUMad24Like, U64ResultType) {
  5313. const std::string ext_inst_name = GetParam();
  5314. const std::string body = "%val1 = OpExtInst %u64 %extinst " + ext_inst_name +
  5315. " %u64_0 %u64_0 %u64_1\n";
  5316. CompileSuccessfully(GenerateKernelCode(body));
  5317. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5318. EXPECT_THAT(
  5319. getDiagnosticString(),
  5320. HasSubstr(
  5321. "OpenCL.std " + ext_inst_name +
  5322. ": expected Result Type to be a 32-bit int scalar or vector type"));
  5323. }
  5324. TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand1) {
  5325. const std::string ext_inst_name = GetParam();
  5326. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5327. " %f32_0 %u32_0 %u32_1\n";
  5328. CompileSuccessfully(GenerateKernelCode(body));
  5329. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5330. EXPECT_THAT(
  5331. getDiagnosticString(),
  5332. HasSubstr("OpenCL.std " + ext_inst_name +
  5333. ": expected types of all operands to be equal to Result Type"));
  5334. }
  5335. TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand2) {
  5336. const std::string ext_inst_name = GetParam();
  5337. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5338. " %u32_0 %f32_0 %u32_1\n";
  5339. CompileSuccessfully(GenerateKernelCode(body));
  5340. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5341. EXPECT_THAT(
  5342. getDiagnosticString(),
  5343. HasSubstr("OpenCL.std " + ext_inst_name +
  5344. ": expected types of all operands to be equal to Result Type"));
  5345. }
  5346. TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand3) {
  5347. const std::string ext_inst_name = GetParam();
  5348. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5349. " %u32_0 %u32_0 %f32_1\n";
  5350. CompileSuccessfully(GenerateKernelCode(body));
  5351. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5352. EXPECT_THAT(
  5353. getDiagnosticString(),
  5354. HasSubstr("OpenCL.std " + ext_inst_name +
  5355. ": expected types of all operands to be equal to Result Type"));
  5356. }
  5357. TEST_P(ValidateOpenCLStdUMad24Like, U64Operand1) {
  5358. const std::string ext_inst_name = GetParam();
  5359. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5360. " %f32_0 %u32_0 %u64_1\n";
  5361. CompileSuccessfully(GenerateKernelCode(body));
  5362. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5363. EXPECT_THAT(
  5364. getDiagnosticString(),
  5365. HasSubstr("OpenCL.std " + ext_inst_name +
  5366. ": expected types of all operands to be equal to Result Type"));
  5367. }
  5368. TEST_P(ValidateOpenCLStdUMad24Like, U64Operand2) {
  5369. const std::string ext_inst_name = GetParam();
  5370. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5371. " %u32_0 %f32_0 %u64_1\n";
  5372. CompileSuccessfully(GenerateKernelCode(body));
  5373. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5374. EXPECT_THAT(
  5375. getDiagnosticString(),
  5376. HasSubstr("OpenCL.std " + ext_inst_name +
  5377. ": expected types of all operands to be equal to Result Type"));
  5378. }
  5379. TEST_P(ValidateOpenCLStdUMad24Like, U64Operand3) {
  5380. const std::string ext_inst_name = GetParam();
  5381. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5382. " %u32_0 %u32_0 %u64_1\n";
  5383. CompileSuccessfully(GenerateKernelCode(body));
  5384. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5385. EXPECT_THAT(
  5386. getDiagnosticString(),
  5387. HasSubstr("OpenCL.std " + ext_inst_name +
  5388. ": expected types of all operands to be equal to Result Type"));
  5389. }
  5390. INSTANTIATE_TEST_SUITE_P(AllUMad24Like, ValidateOpenCLStdUMad24Like,
  5391. ::testing::ValuesIn(std::vector<std::string>{
  5392. "s_mad24",
  5393. "u_mad24",
  5394. }));
  5395. TEST_F(ValidateExtInst, OpenCLStdCrossSuccess) {
  5396. const std::string body = R"(
  5397. %val1 = OpExtInst %f32vec3 %extinst cross %f32vec3_012 %f32vec3_123
  5398. %val2 = OpExtInst %f32vec4 %extinst cross %f32vec4_0123 %f32vec4_0123
  5399. )";
  5400. CompileSuccessfully(GenerateKernelCode(body));
  5401. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5402. }
  5403. TEST_F(ValidateExtInst, OpenCLStdCrossIntVectorResultType) {
  5404. const std::string body = R"(
  5405. %val1 = OpExtInst %u32vec3 %extinst cross %f32vec3_012 %f32vec3_123
  5406. )";
  5407. CompileSuccessfully(GenerateKernelCode(body));
  5408. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5409. EXPECT_THAT(getDiagnosticString(),
  5410. HasSubstr("OpenCL.std cross: "
  5411. "expected Result Type to be a float vector type"));
  5412. }
  5413. TEST_F(ValidateExtInst, OpenCLStdCrossResultTypeWrongSize) {
  5414. const std::string body = R"(
  5415. %val1 = OpExtInst %f32vec2 %extinst cross %f32vec3_012 %f32vec3_123
  5416. )";
  5417. CompileSuccessfully(GenerateKernelCode(body));
  5418. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5419. EXPECT_THAT(getDiagnosticString(),
  5420. HasSubstr("OpenCL.std cross: "
  5421. "expected Result Type to have 3 or 4 components"));
  5422. }
  5423. TEST_F(ValidateExtInst, OpenCLStdCrossXWrongType) {
  5424. const std::string body = R"(
  5425. %val1 = OpExtInst %f32vec3 %extinst cross %f64vec3_012 %f32vec3_123
  5426. )";
  5427. CompileSuccessfully(GenerateKernelCode(body));
  5428. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5429. EXPECT_THAT(getDiagnosticString(),
  5430. HasSubstr("OpenCL.std cross: "
  5431. "expected operand X type to be equal to Result Type"));
  5432. }
  5433. TEST_F(ValidateExtInst, OpenCLStdCrossYWrongType) {
  5434. const std::string body = R"(
  5435. %val1 = OpExtInst %f32vec3 %extinst cross %f32vec3_123 %f64vec3_012
  5436. )";
  5437. CompileSuccessfully(GenerateKernelCode(body));
  5438. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5439. EXPECT_THAT(getDiagnosticString(),
  5440. HasSubstr("OpenCL.std cross: "
  5441. "expected operand Y type to be equal to Result Type"));
  5442. }
  5443. TEST_P(ValidateOpenCLStdLengthLike, Success) {
  5444. const std::string ext_inst_name = GetParam();
  5445. std::ostringstream ss;
  5446. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32vec2_01\n";
  5447. ss << "%val2 = OpExtInst %f32 %extinst " << ext_inst_name
  5448. << " %f32vec4_0123\n";
  5449. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5450. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5451. }
  5452. TEST_P(ValidateOpenCLStdLengthLike, IntResultType) {
  5453. const std::string ext_inst_name = GetParam();
  5454. const std::string body =
  5455. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32vec2_01\n";
  5456. CompileSuccessfully(GenerateKernelCode(body));
  5457. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5458. EXPECT_THAT(getDiagnosticString(),
  5459. HasSubstr("OpenCL.std " + ext_inst_name +
  5460. ": "
  5461. "expected Result Type to be a float scalar type"));
  5462. }
  5463. TEST_P(ValidateOpenCLStdLengthLike, IntX) {
  5464. const std::string ext_inst_name = GetParam();
  5465. const std::string body =
  5466. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32vec2_01\n";
  5467. CompileSuccessfully(GenerateKernelCode(body));
  5468. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5469. EXPECT_THAT(getDiagnosticString(),
  5470. HasSubstr("OpenCL.std " + ext_inst_name +
  5471. ": "
  5472. "expected operand P to be a float scalar or vector"));
  5473. }
  5474. TEST_P(ValidateOpenCLStdLengthLike, VectorTooBig) {
  5475. const std::string ext_inst_name = GetParam();
  5476. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  5477. " %f32vec8_01010101\n";
  5478. CompileSuccessfully(GenerateKernelCode(body));
  5479. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5480. EXPECT_THAT(
  5481. getDiagnosticString(),
  5482. HasSubstr("OpenCL.std " + ext_inst_name +
  5483. ": "
  5484. "expected operand P to have no more than 4 components"));
  5485. }
  5486. TEST_P(ValidateOpenCLStdLengthLike, DifferentType) {
  5487. const std::string ext_inst_name = GetParam();
  5488. const std::string body =
  5489. "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32vec2_01\n";
  5490. CompileSuccessfully(GenerateKernelCode(body));
  5491. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5492. EXPECT_THAT(getDiagnosticString(),
  5493. HasSubstr("OpenCL.std " + ext_inst_name +
  5494. ": "
  5495. "expected operand P component type to be equal to "
  5496. "Result Type"));
  5497. }
  5498. INSTANTIATE_TEST_SUITE_P(AllLengthLike, ValidateOpenCLStdLengthLike,
  5499. ::testing::ValuesIn(std::vector<std::string>{
  5500. "length",
  5501. "fast_length",
  5502. }));
  5503. TEST_P(ValidateOpenCLStdDistanceLike, Success) {
  5504. const std::string ext_inst_name = GetParam();
  5505. std::ostringstream ss;
  5506. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  5507. << " %f32vec2_01 %f32vec2_01\n";
  5508. ss << "%val2 = OpExtInst %f32 %extinst " << ext_inst_name
  5509. << " %f32vec4_0123 %f32vec4_1234\n";
  5510. ss << "%val3 = OpExtInst %f32 %extinst " << ext_inst_name
  5511. << " %f32_0 %f32_1\n";
  5512. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5513. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5514. }
  5515. TEST_P(ValidateOpenCLStdDistanceLike, IntResultType) {
  5516. const std::string ext_inst_name = GetParam();
  5517. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  5518. " %f32vec2_01 %f32vec2_12\n";
  5519. CompileSuccessfully(GenerateKernelCode(body));
  5520. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5521. EXPECT_THAT(getDiagnosticString(),
  5522. HasSubstr("OpenCL.std " + ext_inst_name +
  5523. ": "
  5524. "expected Result Type to be a float scalar type"));
  5525. }
  5526. TEST_P(ValidateOpenCLStdDistanceLike, IntP0) {
  5527. const std::string ext_inst_name = GetParam();
  5528. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  5529. " %u32vec2_01 %f32vec2_12\n";
  5530. CompileSuccessfully(GenerateKernelCode(body));
  5531. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5532. EXPECT_THAT(
  5533. getDiagnosticString(),
  5534. HasSubstr("OpenCL.std " + ext_inst_name +
  5535. ": "
  5536. "expected operand P0 to be of float scalar or vector type"));
  5537. }
  5538. TEST_P(ValidateOpenCLStdDistanceLike, VectorTooBig) {
  5539. const std::string ext_inst_name = GetParam();
  5540. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  5541. " %f32vec8_01010101 %f32vec8_01010101\n";
  5542. CompileSuccessfully(GenerateKernelCode(body));
  5543. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5544. EXPECT_THAT(
  5545. getDiagnosticString(),
  5546. HasSubstr("OpenCL.std " + ext_inst_name +
  5547. ": "
  5548. "expected operand P0 to have no more than 4 components"));
  5549. }
  5550. TEST_P(ValidateOpenCLStdDistanceLike, F64P0) {
  5551. const std::string ext_inst_name = GetParam();
  5552. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  5553. " %f64vec2_01 %f32vec2_12\n";
  5554. CompileSuccessfully(GenerateKernelCode(body));
  5555. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5556. EXPECT_THAT(
  5557. getDiagnosticString(),
  5558. HasSubstr(
  5559. "OpenCL.std " + ext_inst_name +
  5560. ": "
  5561. "expected operand P0 component type to be equal to Result Type"));
  5562. }
  5563. TEST_P(ValidateOpenCLStdDistanceLike, DifferentOperands) {
  5564. const std::string ext_inst_name = GetParam();
  5565. const std::string body = "%val1 = OpExtInst %f64 %extinst " + ext_inst_name +
  5566. " %f64vec2_01 %f32vec2_12\n";
  5567. CompileSuccessfully(GenerateKernelCode(body));
  5568. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5569. EXPECT_THAT(getDiagnosticString(),
  5570. HasSubstr("OpenCL.std " + ext_inst_name +
  5571. ": "
  5572. "expected operands P0 and P1 to be of the same type"));
  5573. }
  5574. INSTANTIATE_TEST_SUITE_P(AllDistanceLike, ValidateOpenCLStdDistanceLike,
  5575. ::testing::ValuesIn(std::vector<std::string>{
  5576. "distance",
  5577. "fast_distance",
  5578. }));
  5579. TEST_P(ValidateOpenCLStdNormalizeLike, Success) {
  5580. const std::string ext_inst_name = GetParam();
  5581. std::ostringstream ss;
  5582. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  5583. << " %f32vec2_01\n";
  5584. ss << "%val2 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  5585. << " %f32vec4_0123\n";
  5586. ss << "%val3 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_2\n";
  5587. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5588. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5589. }
  5590. TEST_P(ValidateOpenCLStdNormalizeLike, IntResultType) {
  5591. const std::string ext_inst_name = GetParam();
  5592. const std::string body =
  5593. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_2\n";
  5594. CompileSuccessfully(GenerateKernelCode(body));
  5595. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5596. EXPECT_THAT(
  5597. getDiagnosticString(),
  5598. HasSubstr("OpenCL.std " + ext_inst_name +
  5599. ": "
  5600. "expected Result Type to be a float scalar or vector type"));
  5601. }
  5602. TEST_P(ValidateOpenCLStdNormalizeLike, VectorTooBig) {
  5603. const std::string ext_inst_name = GetParam();
  5604. const std::string body = "%val1 = OpExtInst %f32vec8 %extinst " +
  5605. ext_inst_name + " %f32vec8_01010101\n";
  5606. CompileSuccessfully(GenerateKernelCode(body));
  5607. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5608. EXPECT_THAT(
  5609. getDiagnosticString(),
  5610. HasSubstr("OpenCL.std " + ext_inst_name +
  5611. ": "
  5612. "expected Result Type to have no more than 4 components"));
  5613. }
  5614. TEST_P(ValidateOpenCLStdNormalizeLike, DifferentType) {
  5615. const std::string ext_inst_name = GetParam();
  5616. const std::string body =
  5617. "%val1 = OpExtInst %f64vec2 %extinst " + ext_inst_name + " %f32vec2_01\n";
  5618. CompileSuccessfully(GenerateKernelCode(body));
  5619. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5620. EXPECT_THAT(getDiagnosticString(),
  5621. HasSubstr("OpenCL.std " + ext_inst_name +
  5622. ": "
  5623. "expected operand P type to be equal to Result Type"));
  5624. }
  5625. INSTANTIATE_TEST_SUITE_P(AllNormalizeLike, ValidateOpenCLStdNormalizeLike,
  5626. ::testing::ValuesIn(std::vector<std::string>{
  5627. "normalize",
  5628. "fast_normalize",
  5629. }));
  5630. TEST_F(ValidateExtInst, OpenCLStdBitselectSuccess) {
  5631. const std::string body = R"(
  5632. %val1 = OpExtInst %f32 %extinst bitselect %f32_2 %f32_1 %f32_1
  5633. %val2 = OpExtInst %f32vec4 %extinst bitselect %f32vec4_0123 %f32vec4_1234 %f32vec4_0123
  5634. %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %u32_1 %u32_1
  5635. %val4 = OpExtInst %u32vec4 %extinst bitselect %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
  5636. %val5 = OpExtInst %u64 %extinst bitselect %u64_2 %u64_1 %u64_1
  5637. )";
  5638. CompileSuccessfully(GenerateKernelCode(body));
  5639. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5640. }
  5641. TEST_F(ValidateExtInst, OpenCLStdBitselectWrongResultType) {
  5642. const std::string body = R"(
  5643. %val3 = OpExtInst %struct_f32_f32 %extinst bitselect %u32_2 %u32_1 %u32_1
  5644. )";
  5645. CompileSuccessfully(GenerateKernelCode(body));
  5646. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5647. EXPECT_THAT(
  5648. getDiagnosticString(),
  5649. HasSubstr(
  5650. "OpenCL.std bitselect: "
  5651. "expected Result Type to be an int or float scalar or vector type"));
  5652. }
  5653. TEST_F(ValidateExtInst, OpenCLStdBitselectAWrongType) {
  5654. const std::string body = R"(
  5655. %val3 = OpExtInst %u32 %extinst bitselect %f32_2 %u32_1 %u32_1
  5656. )";
  5657. CompileSuccessfully(GenerateKernelCode(body));
  5658. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5659. EXPECT_THAT(
  5660. getDiagnosticString(),
  5661. HasSubstr("OpenCL.std bitselect: "
  5662. "expected types of all operands to be equal to Result Type"));
  5663. }
  5664. TEST_F(ValidateExtInst, OpenCLStdBitselectBWrongType) {
  5665. const std::string body = R"(
  5666. %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %f32_1 %u32_1
  5667. )";
  5668. CompileSuccessfully(GenerateKernelCode(body));
  5669. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5670. EXPECT_THAT(
  5671. getDiagnosticString(),
  5672. HasSubstr("OpenCL.std bitselect: "
  5673. "expected types of all operands to be equal to Result Type"));
  5674. }
  5675. TEST_F(ValidateExtInst, OpenCLStdBitselectCWrongType) {
  5676. const std::string body = R"(
  5677. %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %u32_1 %f32_1
  5678. )";
  5679. CompileSuccessfully(GenerateKernelCode(body));
  5680. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5681. EXPECT_THAT(
  5682. getDiagnosticString(),
  5683. HasSubstr("OpenCL.std bitselect: "
  5684. "expected types of all operands to be equal to Result Type"));
  5685. }
  5686. TEST_F(ValidateExtInst, OpenCLStdSelectSuccess) {
  5687. const std::string body = R"(
  5688. %val1 = OpExtInst %f32 %extinst select %f32_2 %f32_1 %u32_1
  5689. %val2 = OpExtInst %f32vec4 %extinst select %f32vec4_0123 %f32vec4_1234 %u32vec4_0123
  5690. %val3 = OpExtInst %u32 %extinst select %u32_2 %u32_1 %u32_1
  5691. %val4 = OpExtInst %u32vec4 %extinst select %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
  5692. %val5 = OpExtInst %u64 %extinst select %u64_2 %u64_1 %u64_1
  5693. )";
  5694. CompileSuccessfully(GenerateKernelCode(body));
  5695. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5696. }
  5697. TEST_F(ValidateExtInst, OpenCLStdSelectWrongResultType) {
  5698. const std::string body = R"(
  5699. %val3 = OpExtInst %struct_f32_f32 %extinst select %u32_2 %u32_1 %u32_1
  5700. )";
  5701. CompileSuccessfully(GenerateKernelCode(body));
  5702. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5703. EXPECT_THAT(
  5704. getDiagnosticString(),
  5705. HasSubstr(
  5706. "OpenCL.std select: "
  5707. "expected Result Type to be an int or float scalar or vector type"));
  5708. }
  5709. TEST_F(ValidateExtInst, OpenCLStdSelectAWrongType) {
  5710. const std::string body = R"(
  5711. %val3 = OpExtInst %u32 %extinst select %f32_2 %u32_1 %u32_1
  5712. )";
  5713. CompileSuccessfully(GenerateKernelCode(body));
  5714. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5715. EXPECT_THAT(getDiagnosticString(),
  5716. HasSubstr("OpenCL.std select: "
  5717. "expected operand A type to be equal to Result Type"));
  5718. }
  5719. TEST_F(ValidateExtInst, OpenCLStdSelectBWrongType) {
  5720. const std::string body = R"(
  5721. %val3 = OpExtInst %u32 %extinst select %u32_2 %f32_1 %u32_1
  5722. )";
  5723. CompileSuccessfully(GenerateKernelCode(body));
  5724. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5725. EXPECT_THAT(getDiagnosticString(),
  5726. HasSubstr("OpenCL.std select: "
  5727. "expected operand B type to be equal to Result Type"));
  5728. }
  5729. TEST_F(ValidateExtInst, OpenCLStdSelectCWrongType) {
  5730. const std::string body = R"(
  5731. %val3 = OpExtInst %f32 %extinst select %f32_2 %f32_1 %f32_1
  5732. )";
  5733. CompileSuccessfully(GenerateKernelCode(body));
  5734. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5735. EXPECT_THAT(getDiagnosticString(),
  5736. HasSubstr("OpenCL.std select: "
  5737. "expected operand C to be an int scalar or vector"));
  5738. }
  5739. TEST_F(ValidateExtInst, OpenCLStdSelectCWrongComponentNumber) {
  5740. const std::string body = R"(
  5741. %val3 = OpExtInst %f32vec2 %extinst select %f32vec2_12 %f32vec2_01 %u32_1
  5742. )";
  5743. CompileSuccessfully(GenerateKernelCode(body));
  5744. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5745. EXPECT_THAT(getDiagnosticString(),
  5746. HasSubstr("OpenCL.std select: "
  5747. "expected operand C to have the same number of "
  5748. "components as Result Type"));
  5749. }
  5750. TEST_F(ValidateExtInst, OpenCLStdSelectCWrongBitWidth) {
  5751. const std::string body = R"(
  5752. %val3 = OpExtInst %f32vec2 %extinst select %f32vec2_12 %f32vec2_01 %u64vec2_01
  5753. )";
  5754. CompileSuccessfully(GenerateKernelCode(body));
  5755. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5756. EXPECT_THAT(
  5757. getDiagnosticString(),
  5758. HasSubstr(
  5759. "OpenCL.std select: "
  5760. "expected operand C to have the same bit width as Result Type"));
  5761. }
  5762. TEST_P(ValidateOpenCLStdVStoreHalfLike, SuccessPhysical32) {
  5763. const std::string ext_inst_name = GetParam();
  5764. const std::string rounding_mode =
  5765. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5766. std::ostringstream ss;
  5767. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5768. if (std::string::npos == ext_inst_name.find("halfn")) {
  5769. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5770. << " %f32_1 %u32_1 %ptr" << rounding_mode << "\n";
  5771. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  5772. << " %f64_0 %u32_2 %ptr" << rounding_mode << "\n";
  5773. } else {
  5774. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5775. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5776. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  5777. << " %f32vec4_0123 %u32_0 %ptr" << rounding_mode << "\n";
  5778. ss << "%val3 = OpExtInst %void %extinst " << ext_inst_name
  5779. << " %f64vec2_01 %u32_2 %ptr" << rounding_mode << "\n";
  5780. }
  5781. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5782. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5783. }
  5784. TEST_P(ValidateOpenCLStdVStoreHalfLike, SuccessPhysical64) {
  5785. const std::string ext_inst_name = GetParam();
  5786. const std::string rounding_mode =
  5787. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5788. std::ostringstream ss;
  5789. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5790. if (std::string::npos == ext_inst_name.find("halfn")) {
  5791. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5792. << " %f32_1 %u64_1 %ptr" << rounding_mode << "\n";
  5793. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  5794. << " %f64_0 %u64_2 %ptr" << rounding_mode << "\n";
  5795. } else {
  5796. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5797. << " %f32vec2_01 %u64_1 %ptr" << rounding_mode << "\n";
  5798. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  5799. << " %f32vec4_0123 %u64_0 %ptr" << rounding_mode << "\n";
  5800. ss << "%val3 = OpExtInst %void %extinst " << ext_inst_name
  5801. << " %f64vec2_01 %u64_2 %ptr" << rounding_mode << "\n";
  5802. }
  5803. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  5804. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5805. }
  5806. TEST_P(ValidateOpenCLStdVStoreHalfLike, NonVoidResultType) {
  5807. const std::string ext_inst_name = GetParam();
  5808. const std::string rounding_mode =
  5809. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5810. std::ostringstream ss;
  5811. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5812. if (std::string::npos == ext_inst_name.find("halfn")) {
  5813. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  5814. << " %f32_1 %u32_1 %ptr" << rounding_mode << "\n";
  5815. } else {
  5816. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  5817. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5818. }
  5819. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5820. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5821. EXPECT_THAT(getDiagnosticString(),
  5822. HasSubstr("OpenCL.std " + ext_inst_name +
  5823. ": expected Result Type to be void"));
  5824. }
  5825. TEST_P(ValidateOpenCLStdVStoreHalfLike, WrongDataType) {
  5826. const std::string ext_inst_name = GetParam();
  5827. const std::string rounding_mode =
  5828. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5829. std::ostringstream ss;
  5830. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5831. if (std::string::npos == ext_inst_name.find("halfn")) {
  5832. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5833. << " %f64vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5834. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5835. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5836. EXPECT_THAT(getDiagnosticString(),
  5837. HasSubstr("OpenCL.std " + ext_inst_name +
  5838. ": expected Data to be a 32 or 64-bit float scalar"));
  5839. } else {
  5840. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5841. << " %f64_0 %u32_1 %ptr" << rounding_mode << "\n";
  5842. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5843. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5844. EXPECT_THAT(getDiagnosticString(),
  5845. HasSubstr("OpenCL.std " + ext_inst_name +
  5846. ": expected Data to be a 32 or 64-bit float vector"));
  5847. }
  5848. }
  5849. TEST_P(ValidateOpenCLStdVStoreHalfLike, AddressingModelLogical) {
  5850. const std::string ext_inst_name = GetParam();
  5851. const std::string rounding_mode =
  5852. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5853. std::ostringstream ss;
  5854. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5855. if (std::string::npos == ext_inst_name.find("halfn")) {
  5856. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5857. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  5858. } else {
  5859. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5860. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5861. }
  5862. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  5863. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5864. EXPECT_THAT(getDiagnosticString(),
  5865. HasSubstr("OpenCL.std " + ext_inst_name +
  5866. " can only be used with physical addressing models"));
  5867. }
  5868. TEST_P(ValidateOpenCLStdVStoreHalfLike, OffsetNotSizeT) {
  5869. const std::string ext_inst_name = GetParam();
  5870. const std::string rounding_mode =
  5871. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5872. std::ostringstream ss;
  5873. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5874. if (std::string::npos == ext_inst_name.find("halfn")) {
  5875. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5876. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  5877. } else {
  5878. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5879. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5880. }
  5881. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  5882. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5883. EXPECT_THAT(
  5884. getDiagnosticString(),
  5885. HasSubstr("OpenCL.std " + ext_inst_name +
  5886. ": "
  5887. "expected operand Offset to be of type size_t (64-bit integer "
  5888. "for the addressing model used in the module)"));
  5889. }
  5890. TEST_P(ValidateOpenCLStdVStoreHalfLike, PNotPointer) {
  5891. const std::string ext_inst_name = GetParam();
  5892. const std::string rounding_mode =
  5893. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5894. std::ostringstream ss;
  5895. if (std::string::npos == ext_inst_name.find("halfn")) {
  5896. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5897. << " %f32_0 %u32_1 %f16_ptr_workgroup" << rounding_mode << "\n";
  5898. } else {
  5899. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5900. << " %f32vec2_01 %u32_1 %f16_ptr_workgroup" << rounding_mode << "\n";
  5901. }
  5902. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5903. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5904. EXPECT_THAT(getDiagnosticString(),
  5905. HasSubstr("Operand 89[%_ptr_Workgroup_half] cannot be a type"));
  5906. }
  5907. TEST_P(ValidateOpenCLStdVStoreHalfLike, ConstPointer) {
  5908. const std::string ext_inst_name = GetParam();
  5909. const std::string rounding_mode =
  5910. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5911. std::ostringstream ss;
  5912. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  5913. "%f16vec8_uniform_constant %u32_1\n";
  5914. if (std::string::npos == ext_inst_name.find("halfn")) {
  5915. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5916. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  5917. } else {
  5918. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5919. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5920. }
  5921. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5922. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5923. EXPECT_THAT(getDiagnosticString(),
  5924. HasSubstr("OpenCL.std " + ext_inst_name +
  5925. ": expected operand P storage class to be Generic, "
  5926. "CrossWorkgroup, Workgroup or Function"));
  5927. }
  5928. TEST_P(ValidateOpenCLStdVStoreHalfLike, PDataTypeInt) {
  5929. const std::string ext_inst_name = GetParam();
  5930. const std::string rounding_mode =
  5931. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5932. std::ostringstream ss;
  5933. ss << "%ptr = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  5934. if (std::string::npos == ext_inst_name.find("halfn")) {
  5935. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5936. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  5937. } else {
  5938. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5939. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5940. }
  5941. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5942. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5943. EXPECT_THAT(
  5944. getDiagnosticString(),
  5945. HasSubstr("OpenCL.std " + ext_inst_name +
  5946. ": expected operand P data type to be 16-bit float scalar"));
  5947. }
  5948. TEST_P(ValidateOpenCLStdVStoreHalfLike, PDataTypeFloat32) {
  5949. const std::string ext_inst_name = GetParam();
  5950. const std::string rounding_mode =
  5951. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  5952. std::ostringstream ss;
  5953. ss << "%ptr = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  5954. if (std::string::npos == ext_inst_name.find("halfn")) {
  5955. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5956. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  5957. } else {
  5958. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  5959. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  5960. }
  5961. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5962. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5963. EXPECT_THAT(
  5964. getDiagnosticString(),
  5965. HasSubstr("OpenCL.std " + ext_inst_name +
  5966. ": expected operand P data type to be 16-bit float scalar"));
  5967. }
  5968. INSTANTIATE_TEST_SUITE_P(AllVStoreHalfLike, ValidateOpenCLStdVStoreHalfLike,
  5969. ::testing::ValuesIn(std::vector<std::string>{
  5970. "vstore_half",
  5971. "vstore_half_r",
  5972. "vstore_halfn",
  5973. "vstore_halfn_r",
  5974. "vstorea_halfn",
  5975. "vstorea_halfn_r",
  5976. }));
  5977. TEST_P(ValidateOpenCLStdVLoadHalfLike, SuccessPhysical32) {
  5978. const std::string ext_inst_name = GetParam();
  5979. std::ostringstream ss;
  5980. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5981. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  5982. << " %u32_1 %ptr 2\n";
  5983. ss << "%val2 = OpExtInst %f32vec3 %extinst " << ext_inst_name
  5984. << " %u32_1 %ptr 3\n";
  5985. ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  5986. << " %u32_1 %ptr 4\n";
  5987. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5988. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5989. }
  5990. TEST_P(ValidateOpenCLStdVLoadHalfLike, SuccessPhysical64) {
  5991. const std::string ext_inst_name = GetParam();
  5992. std::ostringstream ss;
  5993. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  5994. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  5995. << " %u64_1 %ptr 2\n";
  5996. ss << "%val2 = OpExtInst %f32vec3 %extinst " << ext_inst_name
  5997. << " %u64_1 %ptr 3\n";
  5998. ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  5999. << " %u64_1 %ptr 4\n";
  6000. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  6001. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6002. }
  6003. TEST_P(ValidateOpenCLStdVLoadHalfLike, ResultTypeNotFloatVector) {
  6004. const std::string ext_inst_name = GetParam();
  6005. std::ostringstream ss;
  6006. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  6007. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  6008. << " %u32_1 %ptr 1\n";
  6009. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6010. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6011. EXPECT_THAT(getDiagnosticString(),
  6012. HasSubstr("OpenCL.std " + ext_inst_name +
  6013. ": expected Result Type to be a float vector type"));
  6014. }
  6015. TEST_P(ValidateOpenCLStdVLoadHalfLike, AddressingModelLogical) {
  6016. const std::string ext_inst_name = GetParam();
  6017. std::ostringstream ss;
  6018. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  6019. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6020. << " %u32_1 %ptr 2\n";
  6021. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  6022. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6023. EXPECT_THAT(getDiagnosticString(),
  6024. HasSubstr("OpenCL.std " + ext_inst_name +
  6025. " can only be used with physical addressing models"));
  6026. }
  6027. TEST_P(ValidateOpenCLStdVLoadHalfLike, OffsetNotSizeT) {
  6028. const std::string ext_inst_name = GetParam();
  6029. std::ostringstream ss;
  6030. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  6031. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6032. << " %u64_1 %ptr 2\n";
  6033. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6034. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6035. EXPECT_THAT(
  6036. getDiagnosticString(),
  6037. HasSubstr("OpenCL.std " + ext_inst_name +
  6038. ": expected operand Offset to be of type size_t (32-bit "
  6039. "integer for the addressing model used in the module)"));
  6040. }
  6041. TEST_P(ValidateOpenCLStdVLoadHalfLike, PNotPointer) {
  6042. const std::string ext_inst_name = GetParam();
  6043. std::ostringstream ss;
  6044. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6045. << " %u32_1 %f16_ptr_workgroup 2\n";
  6046. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6047. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6048. EXPECT_THAT(getDiagnosticString(),
  6049. HasSubstr("Operand 89[%_ptr_Workgroup_half] cannot be a type"));
  6050. }
  6051. TEST_P(ValidateOpenCLStdVLoadHalfLike, OffsetWrongStorageType) {
  6052. const std::string ext_inst_name = GetParam();
  6053. std::ostringstream ss;
  6054. ss << "%ptr = OpAccessChain %f16_ptr_input %f16vec8_input %u32_1\n";
  6055. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6056. << " %u32_1 %ptr 2\n";
  6057. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6058. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6059. EXPECT_THAT(
  6060. getDiagnosticString(),
  6061. HasSubstr("OpenCL.std " + ext_inst_name +
  6062. ": expected operand P storage class to be UniformConstant, "
  6063. "Generic, CrossWorkgroup, Workgroup or Function"));
  6064. }
  6065. TEST_P(ValidateOpenCLStdVLoadHalfLike, PDataTypeInt) {
  6066. const std::string ext_inst_name = GetParam();
  6067. std::ostringstream ss;
  6068. ss << "%ptr = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  6069. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6070. << " %u32_1 %ptr 2\n";
  6071. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6072. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6073. EXPECT_THAT(
  6074. getDiagnosticString(),
  6075. HasSubstr("OpenCL.std " + ext_inst_name +
  6076. ": expected operand P data type to be 16-bit float scalar"));
  6077. }
  6078. TEST_P(ValidateOpenCLStdVLoadHalfLike, PDataTypeFloat32) {
  6079. const std::string ext_inst_name = GetParam();
  6080. std::ostringstream ss;
  6081. ss << "%ptr = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6082. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6083. << " %u32_1 %ptr 2\n";
  6084. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6085. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6086. EXPECT_THAT(
  6087. getDiagnosticString(),
  6088. HasSubstr("OpenCL.std " + ext_inst_name +
  6089. ": expected operand P data type to be 16-bit float scalar"));
  6090. }
  6091. TEST_P(ValidateOpenCLStdVLoadHalfLike, WrongN) {
  6092. const std::string ext_inst_name = GetParam();
  6093. std::ostringstream ss;
  6094. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  6095. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6096. << " %u32_1 %ptr 3\n";
  6097. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6098. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6099. EXPECT_THAT(getDiagnosticString(),
  6100. HasSubstr("OpenCL.std " + ext_inst_name +
  6101. ": expected literal N to be equal to the number of "
  6102. "components of Result Type"));
  6103. }
  6104. INSTANTIATE_TEST_SUITE_P(AllVLoadHalfLike, ValidateOpenCLStdVLoadHalfLike,
  6105. ::testing::ValuesIn(std::vector<std::string>{
  6106. "vload_halfn",
  6107. "vloada_halfn",
  6108. }));
  6109. TEST_F(ValidateExtInst, VLoadNSuccessFloatPhysical32) {
  6110. std::ostringstream ss;
  6111. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6112. "%f32vec8_uniform_constant %u32_1\n";
  6113. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  6114. ss << "%val2 = OpExtInst %f32vec3 %extinst vloadn %u32_1 %ptr 3\n";
  6115. ss << "%val3 = OpExtInst %f32vec4 %extinst vloadn %u32_1 %ptr 4\n";
  6116. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6117. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6118. }
  6119. TEST_F(ValidateExtInst, VLoadNSuccessIntPhysical32) {
  6120. std::ostringstream ss;
  6121. ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
  6122. "%u32vec8_uniform_constant %u32_1\n";
  6123. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  6124. ss << "%val2 = OpExtInst %u32vec3 %extinst vloadn %u32_1 %ptr 3\n";
  6125. ss << "%val3 = OpExtInst %u32vec4 %extinst vloadn %u32_1 %ptr 4\n";
  6126. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6127. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6128. }
  6129. TEST_F(ValidateExtInst, VLoadNSuccessFloatPhysical64) {
  6130. std::ostringstream ss;
  6131. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6132. "%f32vec8_uniform_constant %u32_1\n";
  6133. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u64_1 %ptr 2\n";
  6134. ss << "%val2 = OpExtInst %f32vec3 %extinst vloadn %u64_1 %ptr 3\n";
  6135. ss << "%val3 = OpExtInst %f32vec4 %extinst vloadn %u64_1 %ptr 4\n";
  6136. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  6137. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6138. }
  6139. TEST_F(ValidateExtInst, VLoadNSuccessIntPhysical64) {
  6140. std::ostringstream ss;
  6141. ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
  6142. "%u32vec8_uniform_constant %u32_1\n";
  6143. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u64_1 %ptr 2\n";
  6144. ss << "%val2 = OpExtInst %u32vec3 %extinst vloadn %u64_1 %ptr 3\n";
  6145. ss << "%val3 = OpExtInst %u32vec4 %extinst vloadn %u64_1 %ptr 4\n";
  6146. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  6147. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6148. }
  6149. TEST_F(ValidateExtInst, VLoadNWrongResultType) {
  6150. std::ostringstream ss;
  6151. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6152. "%f32vec8_uniform_constant %u32_1\n";
  6153. ss << "%val1 = OpExtInst %f32 %extinst vloadn %u32_1 %ptr 2\n";
  6154. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6155. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6156. EXPECT_THAT(
  6157. getDiagnosticString(),
  6158. HasSubstr("OpenCL.std vloadn: "
  6159. "expected Result Type to be an int or float vector type"));
  6160. }
  6161. TEST_F(ValidateExtInst, VLoadNAddressingModelLogical) {
  6162. std::ostringstream ss;
  6163. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6164. "%f32vec8_uniform_constant %u32_1\n";
  6165. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  6166. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  6167. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6168. EXPECT_THAT(getDiagnosticString(),
  6169. HasSubstr("OpenCL.std vloadn can only be used with physical "
  6170. "addressing models"));
  6171. }
  6172. TEST_F(ValidateExtInst, VLoadNOffsetNotSizeT) {
  6173. std::ostringstream ss;
  6174. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6175. "%f32vec8_uniform_constant %u32_1\n";
  6176. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u64_1 %ptr 2\n";
  6177. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6178. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6179. EXPECT_THAT(
  6180. getDiagnosticString(),
  6181. HasSubstr(
  6182. "OpenCL.std vloadn: expected operand Offset to be of type size_t "
  6183. "(32-bit integer for the addressing model used in the module)"));
  6184. }
  6185. TEST_F(ValidateExtInst, VLoadNPNotPointer) {
  6186. std::ostringstream ss;
  6187. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 "
  6188. "%f32_ptr_uniform_constant 2\n";
  6189. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6190. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6191. EXPECT_THAT(getDiagnosticString(),
  6192. HasSubstr("Operand 120[%_ptr_UniformConstant_float] cannot be a "
  6193. "type"));
  6194. }
  6195. TEST_F(ValidateExtInst, VLoadNWrongStorageClass) {
  6196. std::ostringstream ss;
  6197. ss << "%ptr = OpAccessChain %u32_ptr_input %u32vec8_input %u32_1\n";
  6198. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  6199. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6200. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6201. EXPECT_THAT(getDiagnosticString(),
  6202. HasSubstr("OpenCL.std vloadn: expected operand P storage class "
  6203. "to be UniformConstant, Generic, CrossWorkgroup, "
  6204. "Workgroup or Function"));
  6205. }
  6206. TEST_F(ValidateExtInst, VLoadNWrongComponentType) {
  6207. std::ostringstream ss;
  6208. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6209. "%f32vec8_uniform_constant %u32_1\n";
  6210. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  6211. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6212. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6213. EXPECT_THAT(getDiagnosticString(),
  6214. HasSubstr("OpenCL.std vloadn: expected operand P data type to be "
  6215. "equal to component type of Result Type"));
  6216. }
  6217. TEST_F(ValidateExtInst, VLoadNWrongN) {
  6218. std::ostringstream ss;
  6219. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6220. "%f32vec8_uniform_constant %u32_1\n";
  6221. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 3\n";
  6222. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6223. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6224. EXPECT_THAT(getDiagnosticString(),
  6225. HasSubstr("OpenCL.std vloadn: expected literal N to be equal to "
  6226. "the number of components of Result Type"));
  6227. }
  6228. TEST_F(ValidateExtInst, VLoadHalfSuccessPhysical32) {
  6229. std::ostringstream ss;
  6230. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  6231. "%f16vec8_uniform_constant %u32_1\n";
  6232. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  6233. ss << "%val2 = OpExtInst %f64 %extinst vload_half %u32_1 %ptr\n";
  6234. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6235. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6236. }
  6237. TEST_F(ValidateExtInst, VLoadHalfSuccessPhysical64) {
  6238. std::ostringstream ss;
  6239. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  6240. "%f16vec8_uniform_constant %u32_1\n";
  6241. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u64_1 %ptr\n";
  6242. ss << "%val2 = OpExtInst %f64 %extinst vload_half %u64_1 %ptr\n";
  6243. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  6244. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6245. }
  6246. TEST_F(ValidateExtInst, VLoadHalfWrongResultType) {
  6247. std::ostringstream ss;
  6248. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  6249. "%f16vec8_uniform_constant %u32_1\n";
  6250. ss << "%val1 = OpExtInst %u32 %extinst vload_half %u32_1 %ptr\n";
  6251. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6252. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6253. EXPECT_THAT(getDiagnosticString(),
  6254. HasSubstr("OpenCL.std vload_half: "
  6255. "expected Result Type to be a float scalar type"));
  6256. }
  6257. TEST_F(ValidateExtInst, VLoadHalfAddressingModelLogical) {
  6258. std::ostringstream ss;
  6259. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  6260. "%f16vec8_uniform_constant %u32_1\n";
  6261. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  6262. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  6263. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6264. EXPECT_THAT(getDiagnosticString(),
  6265. HasSubstr("OpenCL.std vload_half can only be used with physical "
  6266. "addressing models"));
  6267. }
  6268. TEST_F(ValidateExtInst, VLoadHalfOffsetNotSizeT) {
  6269. std::ostringstream ss;
  6270. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  6271. "%f16vec8_uniform_constant %u32_1\n";
  6272. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u64_1 %ptr\n";
  6273. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6274. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6275. EXPECT_THAT(
  6276. getDiagnosticString(),
  6277. HasSubstr(
  6278. "OpenCL.std vload_half: expected operand Offset to be of type size_t "
  6279. "(32-bit integer for the addressing model used in the module)"));
  6280. }
  6281. TEST_F(ValidateExtInst, VLoadHalfPNotPointer) {
  6282. std::ostringstream ss;
  6283. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 "
  6284. "%f16_ptr_uniform_constant\n";
  6285. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6286. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6287. EXPECT_THAT(getDiagnosticString(),
  6288. HasSubstr("Operand 114[%_ptr_UniformConstant_half] cannot be a "
  6289. "type"));
  6290. }
  6291. TEST_F(ValidateExtInst, VLoadHalfWrongStorageClass) {
  6292. std::ostringstream ss;
  6293. ss << "%ptr = OpAccessChain %f16_ptr_input %f16vec8_input %u32_1\n";
  6294. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  6295. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6296. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6297. EXPECT_THAT(
  6298. getDiagnosticString(),
  6299. HasSubstr(
  6300. "OpenCL.std vload_half: expected operand P storage class to be "
  6301. "UniformConstant, Generic, CrossWorkgroup, Workgroup or Function"));
  6302. }
  6303. TEST_F(ValidateExtInst, VLoadHalfPDataTypeInt) {
  6304. std::ostringstream ss;
  6305. ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
  6306. "%u32vec8_uniform_constant %u32_1\n";
  6307. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  6308. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6309. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6310. EXPECT_THAT(getDiagnosticString(),
  6311. HasSubstr("OpenCL.std vload_half: expected operand P data type "
  6312. "to be 16-bit float scalar"));
  6313. }
  6314. TEST_F(ValidateExtInst, VLoadHalfPDataTypeFloat32) {
  6315. std::ostringstream ss;
  6316. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6317. "%f32vec8_uniform_constant %u32_1\n";
  6318. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  6319. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6320. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6321. EXPECT_THAT(getDiagnosticString(),
  6322. HasSubstr("OpenCL.std vload_half: expected operand P data type "
  6323. "to be 16-bit float scalar"));
  6324. }
  6325. TEST_F(ValidateExtInst, VStoreNSuccessFloatPhysical32) {
  6326. std::ostringstream ss;
  6327. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6328. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  6329. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  6330. ss << "%val2 = OpExtInst %void %extinst vstoren %f32vec4_0123 %u32_1 "
  6331. "%ptr_g\n";
  6332. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6333. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6334. }
  6335. TEST_F(ValidateExtInst, VStoreNSuccessFloatPhysical64) {
  6336. std::ostringstream ss;
  6337. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6338. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  6339. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u64_1 %ptr_g\n";
  6340. ss << "%val2 = OpExtInst %void %extinst vstoren %f32vec4_0123 %u64_1 "
  6341. "%ptr_g\n";
  6342. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  6343. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6344. }
  6345. TEST_F(ValidateExtInst, VStoreNSuccessIntPhysical32) {
  6346. std::ostringstream ss;
  6347. ss << "%ptr_w = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  6348. ss << "%ptr_g = OpPtrCastToGeneric %u32_ptr_generic %ptr_w\n";
  6349. ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u32_1 %ptr_g\n";
  6350. ss << "%val2 = OpExtInst %void %extinst vstoren %u32vec4_0123 %u32_1 "
  6351. "%ptr_g\n";
  6352. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6353. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6354. }
  6355. TEST_F(ValidateExtInst, VStoreNSuccessIntPhysical64) {
  6356. std::ostringstream ss;
  6357. ss << "%ptr_w = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  6358. ss << "%ptr_g = OpPtrCastToGeneric %u32_ptr_generic %ptr_w\n";
  6359. ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u64_1 %ptr_g\n";
  6360. ss << "%val2 = OpExtInst %void %extinst vstoren %u32vec4_0123 %u64_1 "
  6361. "%ptr_g\n";
  6362. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  6363. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6364. }
  6365. TEST_F(ValidateExtInst, VStoreNResultTypeNotVoid) {
  6366. std::ostringstream ss;
  6367. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6368. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  6369. ss << "%val1 = OpExtInst %f32 %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  6370. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6371. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6372. EXPECT_THAT(getDiagnosticString(),
  6373. HasSubstr("OpenCL.std vstoren: expected Result Type to be void"));
  6374. }
  6375. TEST_F(ValidateExtInst, VStoreNDataWrongType) {
  6376. std::ostringstream ss;
  6377. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6378. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  6379. ss << "%val1 = OpExtInst %void %extinst vstoren %f32_1 %u32_1 %ptr_g\n";
  6380. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6381. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6382. EXPECT_THAT(
  6383. getDiagnosticString(),
  6384. HasSubstr(
  6385. "OpenCL.std vstoren: expected Data to be an int or float vector"));
  6386. }
  6387. TEST_F(ValidateExtInst, VStoreNAddressingModelLogical) {
  6388. std::ostringstream ss;
  6389. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6390. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  6391. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  6392. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  6393. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6394. EXPECT_THAT(getDiagnosticString(),
  6395. HasSubstr("OpenCL.std vstoren can only be used with physical "
  6396. "addressing models"));
  6397. }
  6398. TEST_F(ValidateExtInst, VStoreNOffsetNotSizeT) {
  6399. std::ostringstream ss;
  6400. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6401. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  6402. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  6403. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  6404. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6405. EXPECT_THAT(
  6406. getDiagnosticString(),
  6407. HasSubstr(
  6408. "OpenCL.std vstoren: expected operand Offset to be of type size_t "
  6409. "(64-bit integer for the addressing model used in the module)"));
  6410. }
  6411. TEST_F(ValidateExtInst, VStoreNPNotPointer) {
  6412. std::ostringstream ss;
  6413. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 "
  6414. "%f32_ptr_generic\n";
  6415. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6416. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6417. EXPECT_THAT(getDiagnosticString(),
  6418. HasSubstr("Operand 127[%_ptr_Generic_float] cannot be a type"));
  6419. }
  6420. TEST_F(ValidateExtInst, VStoreNWrongStorageClass) {
  6421. std::ostringstream ss;
  6422. ss << "%ptr_w = OpAccessChain %f32_ptr_uniform_constant "
  6423. "%f32vec8_uniform_constant %u32_1\n";
  6424. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_w\n";
  6425. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6426. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6427. EXPECT_THAT(
  6428. getDiagnosticString(),
  6429. HasSubstr("OpenCL.std vstoren: expected operand P storage class "
  6430. "to be Generic, CrossWorkgroup, Workgroup or Function"));
  6431. }
  6432. TEST_F(ValidateExtInst, VStorePWrongDataType) {
  6433. std::ostringstream ss;
  6434. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  6435. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  6436. ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u32_1 %ptr_g\n";
  6437. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6438. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6439. EXPECT_THAT(getDiagnosticString(),
  6440. HasSubstr("OpenCL.std vstoren: expected operand P data type to "
  6441. "be equal to the type of operand Data components"));
  6442. }
  6443. TEST_F(ValidateExtInst, OpenCLStdShuffleSuccess) {
  6444. const std::string body = R"(
  6445. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec4_0123 %u32vec2_01
  6446. %val2 = OpExtInst %f32vec4 %extinst shuffle %f32vec4_0123 %u32vec4_0123
  6447. %val3 = OpExtInst %u32vec2 %extinst shuffle %u32vec4_0123 %u32vec2_01
  6448. %val4 = OpExtInst %u32vec4 %extinst shuffle %u32vec4_0123 %u32vec4_0123
  6449. )";
  6450. CompileSuccessfully(GenerateKernelCode(body));
  6451. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6452. }
  6453. TEST_F(ValidateExtInst, OpenCLStdShuffleWrongResultType) {
  6454. const std::string body = R"(
  6455. %val1 = OpExtInst %f32 %extinst shuffle %f32vec4_0123 %u32vec2_01
  6456. )";
  6457. CompileSuccessfully(GenerateKernelCode(body));
  6458. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6459. EXPECT_THAT(
  6460. getDiagnosticString(),
  6461. HasSubstr("OpenCL.std shuffle: "
  6462. "expected Result Type to be an int or float vector type"));
  6463. }
  6464. TEST_F(ValidateExtInst, OpenCLStdShuffleResultTypeInvalidNumComponents) {
  6465. const std::string body = R"(
  6466. %val1 = OpExtInst %f32vec3 %extinst shuffle %f32vec4_0123 %u32vec3_012
  6467. )";
  6468. CompileSuccessfully(GenerateKernelCode(body));
  6469. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6470. EXPECT_THAT(
  6471. getDiagnosticString(),
  6472. HasSubstr("OpenCL.std shuffle: "
  6473. "expected Result Type to have 2, 4, 8 or 16 components"));
  6474. }
  6475. TEST_F(ValidateExtInst, OpenCLStdShuffleXWrongType) {
  6476. const std::string body = R"(
  6477. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32_0 %u32vec2_01
  6478. )";
  6479. CompileSuccessfully(GenerateKernelCode(body));
  6480. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6481. EXPECT_THAT(getDiagnosticString(),
  6482. HasSubstr("OpenCL.std shuffle: "
  6483. "expected operand X to be an int or float vector"));
  6484. }
  6485. TEST_F(ValidateExtInst, OpenCLStdShuffleXInvalidNumComponents) {
  6486. const std::string body = R"(
  6487. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec3_012 %u32vec2_01
  6488. )";
  6489. CompileSuccessfully(GenerateKernelCode(body));
  6490. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6491. EXPECT_THAT(getDiagnosticString(),
  6492. HasSubstr("OpenCL.std shuffle: "
  6493. "expected operand X to have 2, 4, 8 or 16 components"));
  6494. }
  6495. TEST_F(ValidateExtInst, OpenCLStdShuffleXInvalidComponentType) {
  6496. const std::string body = R"(
  6497. %val1 = OpExtInst %f32vec2 %extinst shuffle %f64vec4_0123 %u32vec2_01
  6498. )";
  6499. CompileSuccessfully(GenerateKernelCode(body));
  6500. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6501. EXPECT_THAT(
  6502. getDiagnosticString(),
  6503. HasSubstr(
  6504. "OpenCL.std shuffle: "
  6505. "expected operand X and Result Type to have equal component types"));
  6506. }
  6507. TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskNotIntVector) {
  6508. const std::string body = R"(
  6509. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec4_0123 %f32vec2_01
  6510. )";
  6511. CompileSuccessfully(GenerateKernelCode(body));
  6512. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6513. EXPECT_THAT(getDiagnosticString(),
  6514. HasSubstr("OpenCL.std shuffle: "
  6515. "expected operand Shuffle Mask to be an int vector"));
  6516. }
  6517. TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskInvalidNumComponents) {
  6518. const std::string body = R"(
  6519. %val1 = OpExtInst %f32vec4 %extinst shuffle %f32vec4_0123 %u32vec2_01
  6520. )";
  6521. CompileSuccessfully(GenerateKernelCode(body));
  6522. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6523. EXPECT_THAT(getDiagnosticString(),
  6524. HasSubstr("OpenCL.std shuffle: "
  6525. "expected operand Shuffle Mask to have the same number "
  6526. "of components as Result Type"));
  6527. }
  6528. TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskInvalidBitWidth) {
  6529. const std::string body = R"(
  6530. %val1 = OpExtInst %f64vec2 %extinst shuffle %f64vec4_0123 %u32vec2_01
  6531. )";
  6532. CompileSuccessfully(GenerateKernelCode(body));
  6533. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6534. EXPECT_THAT(getDiagnosticString(),
  6535. HasSubstr("OpenCL.std shuffle: "
  6536. "expected operand Shuffle Mask components to have the "
  6537. "same bit width as Result Type components"));
  6538. }
  6539. TEST_F(ValidateExtInst, OpenCLStdShuffle2Success) {
  6540. const std::string body = R"(
  6541. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
  6542. %val2 = OpExtInst %f32vec4 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec4_0123
  6543. %val3 = OpExtInst %u32vec2 %extinst shuffle2 %u32vec4_0123 %u32vec4_0123 %u32vec2_01
  6544. %val4 = OpExtInst %u32vec4 %extinst shuffle2 %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
  6545. )";
  6546. CompileSuccessfully(GenerateKernelCode(body));
  6547. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6548. }
  6549. TEST_F(ValidateExtInst, OpenCLStdShuffle2WrongResultType) {
  6550. const std::string body = R"(
  6551. %val1 = OpExtInst %f32 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
  6552. )";
  6553. CompileSuccessfully(GenerateKernelCode(body));
  6554. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6555. EXPECT_THAT(
  6556. getDiagnosticString(),
  6557. HasSubstr("OpenCL.std shuffle2: "
  6558. "expected Result Type to be an int or float vector type"));
  6559. }
  6560. TEST_F(ValidateExtInst, OpenCLStdShuffle2ResultTypeInvalidNumComponents) {
  6561. const std::string body = R"(
  6562. %val1 = OpExtInst %f32vec3 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec3_012
  6563. )";
  6564. CompileSuccessfully(GenerateKernelCode(body));
  6565. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6566. EXPECT_THAT(
  6567. getDiagnosticString(),
  6568. HasSubstr("OpenCL.std shuffle2: "
  6569. "expected Result Type to have 2, 4, 8 or 16 components"));
  6570. }
  6571. TEST_F(ValidateExtInst, OpenCLStdShuffle2XWrongType) {
  6572. const std::string body = R"(
  6573. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32_0 %f32_0 %u32vec2_01
  6574. )";
  6575. CompileSuccessfully(GenerateKernelCode(body));
  6576. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6577. EXPECT_THAT(getDiagnosticString(),
  6578. HasSubstr("OpenCL.std shuffle2: "
  6579. "expected operand X to be an int or float vector"));
  6580. }
  6581. TEST_F(ValidateExtInst, OpenCLStdShuffle2YTypeDifferentFromX) {
  6582. const std::string body = R"(
  6583. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec2_01 %f32vec4_0123 %u32vec2_01
  6584. )";
  6585. CompileSuccessfully(GenerateKernelCode(body));
  6586. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6587. EXPECT_THAT(getDiagnosticString(),
  6588. HasSubstr("OpenCL.std shuffle2: "
  6589. "expected operands X and Y to be of the same type"));
  6590. }
  6591. TEST_F(ValidateExtInst, OpenCLStdShuffle2XInvalidNumComponents) {
  6592. const std::string body = R"(
  6593. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec3_012 %f32vec3_012 %u32vec2_01
  6594. )";
  6595. CompileSuccessfully(GenerateKernelCode(body));
  6596. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6597. EXPECT_THAT(getDiagnosticString(),
  6598. HasSubstr("OpenCL.std shuffle2: "
  6599. "expected operand X to have 2, 4, 8 or 16 components"));
  6600. }
  6601. TEST_F(ValidateExtInst, OpenCLStdShuffle2XInvalidComponentType) {
  6602. const std::string body = R"(
  6603. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f64vec4_0123 %f64vec4_0123 %u32vec2_01
  6604. )";
  6605. CompileSuccessfully(GenerateKernelCode(body));
  6606. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6607. EXPECT_THAT(
  6608. getDiagnosticString(),
  6609. HasSubstr(
  6610. "OpenCL.std shuffle2: "
  6611. "expected operand X and Result Type to have equal component types"));
  6612. }
  6613. TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskNotIntVector) {
  6614. const std::string body = R"(
  6615. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %f32vec2_01
  6616. )";
  6617. CompileSuccessfully(GenerateKernelCode(body));
  6618. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6619. EXPECT_THAT(getDiagnosticString(),
  6620. HasSubstr("OpenCL.std shuffle2: "
  6621. "expected operand Shuffle Mask to be an int vector"));
  6622. }
  6623. TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskInvalidNumComponents) {
  6624. const std::string body = R"(
  6625. %val1 = OpExtInst %f32vec4 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
  6626. )";
  6627. CompileSuccessfully(GenerateKernelCode(body));
  6628. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6629. EXPECT_THAT(getDiagnosticString(),
  6630. HasSubstr("OpenCL.std shuffle2: "
  6631. "expected operand Shuffle Mask to have the same number "
  6632. "of components as Result Type"));
  6633. }
  6634. TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskInvalidBitWidth) {
  6635. const std::string body = R"(
  6636. %val1 = OpExtInst %f64vec2 %extinst shuffle2 %f64vec4_0123 %f64vec4_0123 %u32vec2_01
  6637. )";
  6638. CompileSuccessfully(GenerateKernelCode(body));
  6639. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6640. EXPECT_THAT(getDiagnosticString(),
  6641. HasSubstr("OpenCL.std shuffle2: "
  6642. "expected operand Shuffle Mask components to have the "
  6643. "same bit width as Result Type components"));
  6644. }
  6645. TEST_F(ValidateExtInst, OpenCLStdPrintfSuccess) {
  6646. const std::string body = R"(
  6647. %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  6648. %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
  6649. )";
  6650. CompileSuccessfully(GenerateKernelCode(body));
  6651. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6652. }
  6653. TEST_F(ValidateExtInst, OpenCLStdPrintfBoolResultType) {
  6654. const std::string body = R"(
  6655. %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  6656. %val1 = OpExtInst %bool %extinst printf %format %u32_0 %u32_1
  6657. )";
  6658. CompileSuccessfully(GenerateKernelCode(body));
  6659. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6660. EXPECT_THAT(
  6661. getDiagnosticString(),
  6662. HasSubstr(
  6663. "OpenCL.std printf: expected Result Type to be a 32-bit int type"));
  6664. }
  6665. TEST_F(ValidateExtInst, OpenCLStdPrintfU64ResultType) {
  6666. const std::string body = R"(
  6667. %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  6668. %val1 = OpExtInst %u64 %extinst printf %format %u32_0 %u32_1
  6669. )";
  6670. CompileSuccessfully(GenerateKernelCode(body));
  6671. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6672. EXPECT_THAT(
  6673. getDiagnosticString(),
  6674. HasSubstr(
  6675. "OpenCL.std printf: expected Result Type to be a 32-bit int type"));
  6676. }
  6677. TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotPointer) {
  6678. const std::string body = R"(
  6679. %val1 = OpExtInst %u32 %extinst printf %u8_ptr_uniform_constant %u32_0 %u32_1
  6680. )";
  6681. CompileSuccessfully(GenerateKernelCode(body));
  6682. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6683. EXPECT_THAT(getDiagnosticString(),
  6684. HasSubstr("Operand 137[%_ptr_UniformConstant_uchar] cannot be a "
  6685. "type"));
  6686. }
  6687. TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotUniformConstStorageClass) {
  6688. const std::string body = R"(
  6689. %format_const = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  6690. %format = OpBitcast %u8_ptr_generic %format_const
  6691. %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
  6692. )";
  6693. CompileSuccessfully(GenerateKernelCode(body));
  6694. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6695. EXPECT_THAT(getDiagnosticString(),
  6696. HasSubstr("OpenCL.std printf: expected Format storage class to "
  6697. "be UniformConstant"));
  6698. }
  6699. TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotU8Pointer) {
  6700. const std::string body = R"(
  6701. %format = OpAccessChain %u32_ptr_uniform_constant %u32vec8_uniform_constant %u32_0
  6702. %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
  6703. )";
  6704. CompileSuccessfully(GenerateKernelCode(body));
  6705. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6706. EXPECT_THAT(
  6707. getDiagnosticString(),
  6708. HasSubstr(
  6709. "OpenCL.std printf: expected Format data type to be 8-bit int"));
  6710. }
  6711. TEST_F(ValidateExtInst, OpenCLStdPrefetchU32Success) {
  6712. const std::string body = R"(
  6713. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  6714. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  6715. )";
  6716. CompileSuccessfully(GenerateKernelCode(body));
  6717. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6718. }
  6719. TEST_F(ValidateExtInst, OpenCLStdPrefetchU32Physical64Success) {
  6720. const std::string body = R"(
  6721. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  6722. %val1 = OpExtInst %void %extinst prefetch %ptr %u64_256
  6723. )";
  6724. CompileSuccessfully(GenerateKernelCode(body, "", "Physical64"));
  6725. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6726. }
  6727. TEST_F(ValidateExtInst, OpenCLStdPrefetchF32Success) {
  6728. const std::string body = R"(
  6729. %ptr = OpAccessChain %f32_ptr_cross_workgroup %f32arr_cross_workgroup %u32_0
  6730. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  6731. )";
  6732. CompileSuccessfully(GenerateKernelCode(body));
  6733. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6734. }
  6735. TEST_F(ValidateExtInst, OpenCLStdPrefetchF32Vec2Success) {
  6736. const std::string body = R"(
  6737. %ptr = OpAccessChain %f32vec2_ptr_cross_workgroup %f32vec2arr_cross_workgroup %u32_0
  6738. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  6739. )";
  6740. CompileSuccessfully(GenerateKernelCode(body));
  6741. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6742. }
  6743. TEST_F(ValidateExtInst, OpenCLStdPrefetchResultTypeNotVoid) {
  6744. const std::string body = R"(
  6745. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  6746. %val1 = OpExtInst %u32 %extinst prefetch %ptr %u32_256
  6747. )";
  6748. CompileSuccessfully(GenerateKernelCode(body));
  6749. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6750. EXPECT_THAT(
  6751. getDiagnosticString(),
  6752. HasSubstr("OpenCL.std prefetch: expected Result Type to be void"));
  6753. }
  6754. TEST_F(ValidateExtInst, OpenCLStdPrefetchPtrNotPointer) {
  6755. const std::string body = R"(
  6756. %val1 = OpExtInst %void %extinst prefetch %u32_ptr_cross_workgroup %u32_256
  6757. )";
  6758. CompileSuccessfully(GenerateKernelCode(body));
  6759. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6760. EXPECT_THAT(getDiagnosticString(),
  6761. HasSubstr("Operand 99[%_ptr_CrossWorkgroup_uint] cannot be a "
  6762. "type"));
  6763. }
  6764. TEST_F(ValidateExtInst, OpenCLStdPrefetchPtrNotCrossWorkgroup) {
  6765. const std::string body = R"(
  6766. %ptr = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  6767. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  6768. )";
  6769. CompileSuccessfully(GenerateKernelCode(body));
  6770. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6771. EXPECT_THAT(getDiagnosticString(),
  6772. HasSubstr("OpenCL.std prefetch: expected operand Ptr storage "
  6773. "class to be CrossWorkgroup"));
  6774. }
  6775. TEST_F(ValidateExtInst, OpenCLStdPrefetchInvalidDataType) {
  6776. const std::string body = R"(
  6777. %ptr = OpAccessChain %struct_ptr_cross_workgroup %struct_arr_cross_workgroup %u32_0
  6778. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  6779. )";
  6780. CompileSuccessfully(GenerateKernelCode(body));
  6781. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6782. EXPECT_THAT(getDiagnosticString(),
  6783. HasSubstr("OpenCL.std prefetch: expected Ptr data type to be int "
  6784. "or float scalar or vector"));
  6785. }
  6786. TEST_F(ValidateExtInst, OpenCLStdPrefetchAddressingModelLogical) {
  6787. const std::string body = R"(
  6788. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  6789. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  6790. )";
  6791. CompileSuccessfully(GenerateKernelCode(body, "", "Logical"));
  6792. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6793. EXPECT_THAT(getDiagnosticString(),
  6794. HasSubstr("OpenCL.std prefetch can only be used with physical "
  6795. "addressing models"));
  6796. }
  6797. TEST_F(ValidateExtInst, OpenCLStdPrefetchNumElementsNotSizeT) {
  6798. const std::string body = R"(
  6799. %ptr = OpAccessChain %f32_ptr_cross_workgroup %f32arr_cross_workgroup %u32_0
  6800. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  6801. )";
  6802. CompileSuccessfully(GenerateKernelCode(body, "", "Physical64"));
  6803. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6804. EXPECT_THAT(getDiagnosticString(),
  6805. HasSubstr("OpenCL.std prefetch: expected operand Num Elements to "
  6806. "be of type size_t (64-bit integer for the addressing "
  6807. "model used in the module)"));
  6808. }
  6809. TEST_P(ValidateOpenCLStdFractLike, Success) {
  6810. const std::string ext_inst_name = GetParam();
  6811. std::ostringstream ss;
  6812. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  6813. ss << "%var_f32vec2 = OpVariable %f32vec2_ptr_function Function\n";
  6814. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  6815. << " %f32_0 %var_f32\n";
  6816. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  6817. << " %f32vec2_01 %var_f32vec2\n";
  6818. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6819. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6820. }
  6821. TEST_P(ValidateOpenCLStdFractLike, IntResultType) {
  6822. const std::string ext_inst_name = GetParam();
  6823. std::ostringstream ss;
  6824. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  6825. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  6826. << " %f32_0 %var_f32\n";
  6827. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6828. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6829. EXPECT_THAT(
  6830. getDiagnosticString(),
  6831. HasSubstr("OpenCL.std " + ext_inst_name +
  6832. ": expected Result Type to be a float scalar or vector type"));
  6833. }
  6834. TEST_P(ValidateOpenCLStdFractLike, XWrongType) {
  6835. const std::string ext_inst_name = GetParam();
  6836. std::ostringstream ss;
  6837. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  6838. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  6839. << " %f64_0 %var_f32\n";
  6840. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6841. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6842. EXPECT_THAT(
  6843. getDiagnosticString(),
  6844. HasSubstr("OpenCL.std " + ext_inst_name +
  6845. ": expected type of operand X to be equal to Result Type"));
  6846. }
  6847. TEST_P(ValidateOpenCLStdFractLike, NotPointer) {
  6848. const std::string ext_inst_name = GetParam();
  6849. std::ostringstream ss;
  6850. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  6851. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  6852. << " %f32_0 %f32_1\n";
  6853. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6854. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6855. EXPECT_THAT(getDiagnosticString(),
  6856. HasSubstr("OpenCL.std " + ext_inst_name +
  6857. ": expected the last operand to be a pointer"));
  6858. }
  6859. TEST_P(ValidateOpenCLStdFractLike, PointerInvalidStorageClass) {
  6860. const std::string ext_inst_name = GetParam();
  6861. std::ostringstream ss;
  6862. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  6863. "%f32vec8_uniform_constant %u32_1\n";
  6864. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0 %ptr\n";
  6865. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6866. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6867. EXPECT_THAT(getDiagnosticString(),
  6868. HasSubstr("OpenCL.std " + ext_inst_name +
  6869. ": expected storage class of the pointer to be "
  6870. "Generic, CrossWorkgroup, Workgroup or Function"));
  6871. }
  6872. TEST_P(ValidateOpenCLStdFractLike, PointerWrongDataType) {
  6873. const std::string ext_inst_name = GetParam();
  6874. std::ostringstream ss;
  6875. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  6876. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  6877. << " %f32_0 %var_u32\n";
  6878. CompileSuccessfully(GenerateKernelCode(ss.str()));
  6879. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6880. EXPECT_THAT(
  6881. getDiagnosticString(),
  6882. HasSubstr(
  6883. "OpenCL.std " + ext_inst_name +
  6884. ": expected data type of the pointer to be equal to Result Type"));
  6885. }
  6886. INSTANTIATE_TEST_SUITE_P(AllFractLike, ValidateOpenCLStdFractLike,
  6887. ::testing::ValuesIn(std::vector<std::string>{
  6888. "fract",
  6889. "modf",
  6890. "sincos",
  6891. }));
  6892. TEST_F(ValidateExtInst, OpenCLStdRemquoSuccess) {
  6893. const std::string body = R"(
  6894. %var_u32 = OpVariable %u32_ptr_function Function
  6895. %var_u32vec2 = OpVariable %u32vec2_ptr_function Function
  6896. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u32
  6897. %val2 = OpExtInst %f32vec2 %extinst remquo %f32vec2_01 %f32vec2_12 %var_u32vec2
  6898. )";
  6899. CompileSuccessfully(GenerateKernelCode(body));
  6900. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  6901. }
  6902. TEST_F(ValidateExtInst, OpenCLStdRemquoIntResultType) {
  6903. const std::string body = R"(
  6904. %var_u32 = OpVariable %u32_ptr_function Function
  6905. %val1 = OpExtInst %u32 %extinst remquo %f32_3 %f32_2 %var_u32
  6906. )";
  6907. CompileSuccessfully(GenerateKernelCode(body));
  6908. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6909. EXPECT_THAT(
  6910. getDiagnosticString(),
  6911. HasSubstr("OpenCL.std remquo: "
  6912. "expected Result Type to be a float scalar or vector type"));
  6913. }
  6914. TEST_F(ValidateExtInst, OpenCLStdRemquoXWrongType) {
  6915. const std::string body = R"(
  6916. %var_u32 = OpVariable %f32_ptr_function Function
  6917. %val1 = OpExtInst %f32 %extinst remquo %u32_3 %f32_2 %var_u32
  6918. )";
  6919. CompileSuccessfully(GenerateKernelCode(body));
  6920. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6921. EXPECT_THAT(
  6922. getDiagnosticString(),
  6923. HasSubstr("OpenCL.std remquo: "
  6924. "expected type of operand X to be equal to Result Type"));
  6925. }
  6926. TEST_F(ValidateExtInst, OpenCLStdRemquoYWrongType) {
  6927. const std::string body = R"(
  6928. %var_u32 = OpVariable %f32_ptr_function Function
  6929. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %u32_2 %var_u32
  6930. )";
  6931. CompileSuccessfully(GenerateKernelCode(body));
  6932. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6933. EXPECT_THAT(
  6934. getDiagnosticString(),
  6935. HasSubstr("OpenCL.std remquo: "
  6936. "expected type of operand Y to be equal to Result Type"));
  6937. }
  6938. TEST_F(ValidateExtInst, OpenCLStdRemquoNotPointer) {
  6939. const std::string body = R"(
  6940. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %f32_1
  6941. )";
  6942. CompileSuccessfully(GenerateKernelCode(body));
  6943. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6944. EXPECT_THAT(getDiagnosticString(),
  6945. HasSubstr("OpenCL.std remquo: "
  6946. "expected the last operand to be a pointer"));
  6947. }
  6948. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongStorageClass) {
  6949. const std::string body = R"(
  6950. %ptr = OpAccessChain %f32_ptr_uniform_constant %f32vec8_uniform_constant %u32_1
  6951. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %ptr
  6952. )";
  6953. CompileSuccessfully(GenerateKernelCode(body));
  6954. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6955. EXPECT_THAT(getDiagnosticString(),
  6956. HasSubstr("OpenCL.std remquo: "
  6957. "expected storage class of the pointer to be Generic, "
  6958. "CrossWorkgroup, Workgroup or Function"));
  6959. }
  6960. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongDataType) {
  6961. const std::string body = R"(
  6962. %var_f32 = OpVariable %f32_ptr_function Function
  6963. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_f32
  6964. )";
  6965. CompileSuccessfully(GenerateKernelCode(body));
  6966. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6967. EXPECT_THAT(getDiagnosticString(),
  6968. HasSubstr("OpenCL.std remquo: "
  6969. "expected data type of the pointer to be a 32-bit int "
  6970. "scalar or vector type"));
  6971. }
  6972. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongDataTypeWidth) {
  6973. const std::string body = R"(
  6974. %var_u64 = OpVariable %u64_ptr_function Function
  6975. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u64
  6976. )";
  6977. CompileSuccessfully(GenerateKernelCode(body));
  6978. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6979. EXPECT_THAT(getDiagnosticString(),
  6980. HasSubstr("OpenCL.std remquo: "
  6981. "expected data type of the pointer to be a 32-bit int "
  6982. "scalar or vector type"));
  6983. }
  6984. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongNumberOfComponents) {
  6985. const std::string body = R"(
  6986. %var_u32vec2 = OpVariable %u32vec2_ptr_function Function
  6987. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u32vec2
  6988. )";
  6989. CompileSuccessfully(GenerateKernelCode(body));
  6990. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  6991. EXPECT_THAT(
  6992. getDiagnosticString(),
  6993. HasSubstr("OpenCL.std remquo: "
  6994. "expected data type of the pointer to have the same number "
  6995. "of components as Result Type"));
  6996. }
  6997. TEST_P(ValidateOpenCLStdFrexpLike, Success) {
  6998. const std::string ext_inst_name = GetParam();
  6999. std::ostringstream ss;
  7000. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  7001. ss << "%var_u32vec2 = OpVariable %u32vec2_ptr_function Function\n";
  7002. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7003. << " %f32_0 %var_u32\n";
  7004. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  7005. << " %f32vec2_01 %var_u32vec2\n";
  7006. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7007. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  7008. }
  7009. TEST_P(ValidateOpenCLStdFrexpLike, IntResultType) {
  7010. const std::string ext_inst_name = GetParam();
  7011. std::ostringstream ss;
  7012. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  7013. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  7014. << " %f32_0 %var_u32\n";
  7015. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7016. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7017. EXPECT_THAT(
  7018. getDiagnosticString(),
  7019. HasSubstr("OpenCL.std " + ext_inst_name +
  7020. ": expected Result Type to be a float scalar or vector type"));
  7021. }
  7022. TEST_P(ValidateOpenCLStdFrexpLike, XWrongType) {
  7023. const std::string ext_inst_name = GetParam();
  7024. std::ostringstream ss;
  7025. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  7026. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7027. << " %f64_0 %var_u32\n";
  7028. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7029. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7030. EXPECT_THAT(
  7031. getDiagnosticString(),
  7032. HasSubstr("OpenCL.std " + ext_inst_name +
  7033. ": expected type of operand X to be equal to Result Type"));
  7034. }
  7035. TEST_P(ValidateOpenCLStdFrexpLike, NotPointer) {
  7036. const std::string ext_inst_name = GetParam();
  7037. std::ostringstream ss;
  7038. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7039. << " %f32_0 %u32_1\n";
  7040. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7041. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7042. EXPECT_THAT(getDiagnosticString(),
  7043. HasSubstr("OpenCL.std " + ext_inst_name +
  7044. ": expected the last operand to be a pointer"));
  7045. }
  7046. TEST_P(ValidateOpenCLStdFrexpLike, PointerInvalidStorageClass) {
  7047. const std::string ext_inst_name = GetParam();
  7048. std::ostringstream ss;
  7049. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  7050. "%f32vec8_uniform_constant %u32_1\n";
  7051. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0 %ptr\n";
  7052. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7053. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7054. EXPECT_THAT(getDiagnosticString(),
  7055. HasSubstr("OpenCL.std " + ext_inst_name +
  7056. ": expected storage class of the pointer to be "
  7057. "Generic, CrossWorkgroup, Workgroup or Function"));
  7058. }
  7059. TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeFloat) {
  7060. const std::string ext_inst_name = GetParam();
  7061. std::ostringstream ss;
  7062. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  7063. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7064. << " %f32_0 %var_f32\n";
  7065. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7066. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7067. EXPECT_THAT(getDiagnosticString(),
  7068. HasSubstr("OpenCL.std " + ext_inst_name +
  7069. ": expected data type of the pointer to be a 32-bit "
  7070. "int scalar or vector type"));
  7071. }
  7072. TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeU64) {
  7073. const std::string ext_inst_name = GetParam();
  7074. std::ostringstream ss;
  7075. ss << "%var_u64 = OpVariable %u64_ptr_function Function\n";
  7076. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7077. << " %f32_0 %var_u64\n";
  7078. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7079. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7080. EXPECT_THAT(getDiagnosticString(),
  7081. HasSubstr("OpenCL.std " + ext_inst_name +
  7082. ": expected data type of the pointer to be a 32-bit "
  7083. "int scalar or vector type"));
  7084. }
  7085. TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeDiffSize) {
  7086. const std::string ext_inst_name = GetParam();
  7087. std::ostringstream ss;
  7088. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  7089. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  7090. << " %f32vec2_01 %var_u32\n";
  7091. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7092. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7093. EXPECT_THAT(getDiagnosticString(),
  7094. HasSubstr("OpenCL.std " + ext_inst_name +
  7095. ": expected data type of the pointer to have the same "
  7096. "number of components as Result Type"));
  7097. }
  7098. INSTANTIATE_TEST_SUITE_P(AllFrexpLike, ValidateOpenCLStdFrexpLike,
  7099. ::testing::ValuesIn(std::vector<std::string>{
  7100. "frexp",
  7101. "lgamma_r",
  7102. }));
  7103. TEST_F(ValidateExtInst, OpenCLStdIlogbSuccess) {
  7104. const std::string body = R"(
  7105. %val1 = OpExtInst %u32 %extinst ilogb %f32_3
  7106. %val2 = OpExtInst %u32vec2 %extinst ilogb %f32vec2_12
  7107. )";
  7108. CompileSuccessfully(GenerateKernelCode(body));
  7109. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  7110. }
  7111. TEST_F(ValidateExtInst, OpenCLStdIlogbFloatResultType) {
  7112. const std::string body = R"(
  7113. %val1 = OpExtInst %f32 %extinst ilogb %f32_3
  7114. )";
  7115. CompileSuccessfully(GenerateKernelCode(body));
  7116. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7117. EXPECT_THAT(
  7118. getDiagnosticString(),
  7119. HasSubstr(
  7120. "OpenCL.std ilogb: "
  7121. "expected Result Type to be a 32-bit int scalar or vector type"));
  7122. }
  7123. TEST_F(ValidateExtInst, OpenCLStdIlogbIntX) {
  7124. const std::string body = R"(
  7125. %val1 = OpExtInst %u32 %extinst ilogb %u32_3
  7126. )";
  7127. CompileSuccessfully(GenerateKernelCode(body));
  7128. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7129. EXPECT_THAT(getDiagnosticString(),
  7130. HasSubstr("OpenCL.std ilogb: "
  7131. "expected operand X to be a float scalar or vector"));
  7132. }
  7133. TEST_F(ValidateExtInst, OpenCLStdIlogbDiffSize) {
  7134. const std::string body = R"(
  7135. %val2 = OpExtInst %u32vec2 %extinst ilogb %f32_1
  7136. )";
  7137. CompileSuccessfully(GenerateKernelCode(body));
  7138. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7139. EXPECT_THAT(getDiagnosticString(),
  7140. HasSubstr("OpenCL.std ilogb: "
  7141. "expected operand X to have the same number of "
  7142. "components as Result Type"));
  7143. }
  7144. TEST_F(ValidateExtInst, OpenCLStdNanSuccess) {
  7145. const std::string body = R"(
  7146. %val1 = OpExtInst %f32 %extinst nan %u32_3
  7147. %val2 = OpExtInst %f32vec2 %extinst nan %u32vec2_12
  7148. )";
  7149. CompileSuccessfully(GenerateKernelCode(body));
  7150. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  7151. }
  7152. TEST_F(ValidateExtInst, OpenCLStdNanIntResultType) {
  7153. const std::string body = R"(
  7154. %val1 = OpExtInst %u32 %extinst nan %u32_3
  7155. )";
  7156. CompileSuccessfully(GenerateKernelCode(body));
  7157. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7158. EXPECT_THAT(
  7159. getDiagnosticString(),
  7160. HasSubstr("OpenCL.std nan: "
  7161. "expected Result Type to be a float scalar or vector type"));
  7162. }
  7163. TEST_F(ValidateExtInst, OpenCLStdNanFloatNancode) {
  7164. const std::string body = R"(
  7165. %val1 = OpExtInst %f32 %extinst nan %f32_3
  7166. )";
  7167. CompileSuccessfully(GenerateKernelCode(body));
  7168. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7169. EXPECT_THAT(getDiagnosticString(),
  7170. HasSubstr("OpenCL.std nan: "
  7171. "expected Nancode to be an int scalar or vector type"));
  7172. }
  7173. TEST_F(ValidateExtInst, OpenCLStdNanFloatDiffSize) {
  7174. const std::string body = R"(
  7175. %val1 = OpExtInst %f32 %extinst nan %u32vec2_12
  7176. )";
  7177. CompileSuccessfully(GenerateKernelCode(body));
  7178. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7179. EXPECT_THAT(getDiagnosticString(),
  7180. HasSubstr("OpenCL.std nan: "
  7181. "expected Nancode to have the same number of "
  7182. "components as Result Type"));
  7183. }
  7184. TEST_F(ValidateExtInst, OpenCLStdNanFloatDiffBitWidth) {
  7185. const std::string body = R"(
  7186. %val1 = OpExtInst %f64 %extinst nan %u32_2
  7187. )";
  7188. CompileSuccessfully(GenerateKernelCode(body));
  7189. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7190. EXPECT_THAT(
  7191. getDiagnosticString(),
  7192. HasSubstr("OpenCL.std nan: "
  7193. "expected Nancode to have the same bit width as Result Type"));
  7194. }
  7195. TEST_P(ValidateOpenCLStdLdexpLike, Success) {
  7196. const std::string ext_inst_name = GetParam();
  7197. std::ostringstream ss;
  7198. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7199. << " %f32_0 %u32_1\n";
  7200. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  7201. << " %f32vec2_12 %u32vec2_12\n";
  7202. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7203. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  7204. }
  7205. TEST_P(ValidateOpenCLStdLdexpLike, IntResultType) {
  7206. const std::string ext_inst_name = GetParam();
  7207. std::ostringstream ss;
  7208. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  7209. << " %f32_0 %u32_1\n";
  7210. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7211. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7212. EXPECT_THAT(
  7213. getDiagnosticString(),
  7214. HasSubstr("OpenCL.std " + ext_inst_name +
  7215. ": expected Result Type to be a float scalar or vector type"));
  7216. }
  7217. TEST_P(ValidateOpenCLStdLdexpLike, XWrongType) {
  7218. const std::string ext_inst_name = GetParam();
  7219. std::ostringstream ss;
  7220. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7221. << " %u32_0 %u32_1\n";
  7222. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7223. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7224. EXPECT_THAT(
  7225. getDiagnosticString(),
  7226. HasSubstr("OpenCL.std " + ext_inst_name +
  7227. ": expected type of operand X to be equal to Result Type"));
  7228. }
  7229. TEST_P(ValidateOpenCLStdLdexpLike, ExponentNotInt) {
  7230. const std::string ext_inst_name = GetParam();
  7231. std::ostringstream ss;
  7232. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7233. << " %f32_0 %f32_1\n";
  7234. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7235. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7236. EXPECT_THAT(
  7237. getDiagnosticString(),
  7238. HasSubstr("OpenCL.std " + ext_inst_name +
  7239. ": expected the exponent to be a 32-bit int scalar or vector"));
  7240. }
  7241. TEST_P(ValidateOpenCLStdLdexpLike, ExponentNotInt32) {
  7242. const std::string ext_inst_name = GetParam();
  7243. std::ostringstream ss;
  7244. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7245. << " %f32_0 %u64_1\n";
  7246. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7247. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7248. EXPECT_THAT(
  7249. getDiagnosticString(),
  7250. HasSubstr("OpenCL.std " + ext_inst_name +
  7251. ": expected the exponent to be a 32-bit int scalar or vector"));
  7252. }
  7253. TEST_P(ValidateOpenCLStdLdexpLike, ExponentWrongSize) {
  7254. const std::string ext_inst_name = GetParam();
  7255. std::ostringstream ss;
  7256. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  7257. << " %f32_0 %u32vec2_01\n";
  7258. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7259. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7260. EXPECT_THAT(getDiagnosticString(),
  7261. HasSubstr("OpenCL.std " + ext_inst_name +
  7262. ": expected the exponent to have the same number of "
  7263. "components as Result Type"));
  7264. }
  7265. INSTANTIATE_TEST_SUITE_P(AllLdexpLike, ValidateOpenCLStdLdexpLike,
  7266. ::testing::ValuesIn(std::vector<std::string>{
  7267. "ldexp",
  7268. "pown",
  7269. "rootn",
  7270. }));
  7271. TEST_P(ValidateOpenCLStdUpsampleLike, Success) {
  7272. const std::string ext_inst_name = GetParam();
  7273. std::ostringstream ss;
  7274. ss << "%val1 = OpExtInst %u16 %extinst " << ext_inst_name << " %u8_1 %u8_2\n";
  7275. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  7276. << " %u16_1 %u16_2\n";
  7277. ss << "%val3 = OpExtInst %u64 %extinst " << ext_inst_name
  7278. << " %u32_1 %u32_2\n";
  7279. ss << "%val4 = OpExtInst %u64vec2 %extinst " << ext_inst_name
  7280. << " %u32vec2_01 %u32vec2_01\n";
  7281. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7282. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  7283. }
  7284. TEST_P(ValidateOpenCLStdUpsampleLike, FloatResultType) {
  7285. const std::string ext_inst_name = GetParam();
  7286. std::ostringstream ss;
  7287. ss << "%val1 = OpExtInst %f64 %extinst " << ext_inst_name
  7288. << " %u32_1 %u32_2\n";
  7289. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7290. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7291. EXPECT_THAT(
  7292. getDiagnosticString(),
  7293. HasSubstr("OpenCL.std " + ext_inst_name +
  7294. ": expected Result Type to be an int scalar or vector type"));
  7295. }
  7296. TEST_P(ValidateOpenCLStdUpsampleLike, InvalidResultTypeBitWidth) {
  7297. const std::string ext_inst_name = GetParam();
  7298. std::ostringstream ss;
  7299. ss << "%val1 = OpExtInst %u8 %extinst " << ext_inst_name << " %u8_1 %u8_2\n";
  7300. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7301. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7302. EXPECT_THAT(
  7303. getDiagnosticString(),
  7304. HasSubstr(
  7305. "OpenCL.std " + ext_inst_name +
  7306. ": expected bit width of Result Type components to be 16, 32 or 64"));
  7307. }
  7308. TEST_P(ValidateOpenCLStdUpsampleLike, LoHiDiffType) {
  7309. const std::string ext_inst_name = GetParam();
  7310. std::ostringstream ss;
  7311. ss << "%val1 = OpExtInst %u64 %extinst " << ext_inst_name
  7312. << " %u32_1 %u16_2\n";
  7313. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7314. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7315. EXPECT_THAT(getDiagnosticString(),
  7316. HasSubstr("OpenCL.std " + ext_inst_name +
  7317. ": expected Hi and Lo operands to have the same type"));
  7318. }
  7319. TEST_P(ValidateOpenCLStdUpsampleLike, DiffNumberOfComponents) {
  7320. const std::string ext_inst_name = GetParam();
  7321. std::ostringstream ss;
  7322. ss << "%val1 = OpExtInst %u64vec2 %extinst " << ext_inst_name
  7323. << " %u32_1 %u32_2\n";
  7324. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7325. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7326. EXPECT_THAT(getDiagnosticString(),
  7327. HasSubstr("OpenCL.std " + ext_inst_name +
  7328. ": expected Hi and Lo operands to have the same number "
  7329. "of components as Result Type"));
  7330. }
  7331. TEST_P(ValidateOpenCLStdUpsampleLike, HiLoWrongBitWidth) {
  7332. const std::string ext_inst_name = GetParam();
  7333. std::ostringstream ss;
  7334. ss << "%val1 = OpExtInst %u64 %extinst " << ext_inst_name
  7335. << " %u16_1 %u16_2\n";
  7336. CompileSuccessfully(GenerateKernelCode(ss.str()));
  7337. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7338. EXPECT_THAT(
  7339. getDiagnosticString(),
  7340. HasSubstr("OpenCL.std " + ext_inst_name +
  7341. ": expected bit width of components of Hi and Lo operands to "
  7342. "be half of the bit width of components of Result Type"));
  7343. }
  7344. INSTANTIATE_TEST_SUITE_P(AllUpsampleLike, ValidateOpenCLStdUpsampleLike,
  7345. ::testing::ValuesIn(std::vector<std::string>{
  7346. "u_upsample",
  7347. "s_upsample",
  7348. }));
  7349. TEST_F(ValidateClspvReflection, RequiresNonSemanticExtension) {
  7350. const std::string text = R"(
  7351. OpCapability Shader
  7352. OpCapability Linkage
  7353. %1 = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7354. OpMemoryModel Logical GLSL450
  7355. )";
  7356. CompileSuccessfully(text);
  7357. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7358. EXPECT_THAT(getDiagnosticString(),
  7359. HasSubstr("NonSemantic extended instruction sets cannot be "
  7360. "declared without SPV_KHR_non_semantic_info"));
  7361. }
  7362. TEST_F(ValidateClspvReflection, MissingVersion) {
  7363. const std::string text = R"(
  7364. OpCapability Shader
  7365. OpCapability Linkage
  7366. OpExtension "SPV_KHR_non_semantic_info"
  7367. %1 = OpExtInstImport "NonSemantic.ClspvReflection."
  7368. OpMemoryModel Logical GLSL450
  7369. %2 = OpTypeVoid
  7370. %3 = OpTypeInt 32 0
  7371. %4 = OpConstant %3 1
  7372. %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
  7373. )";
  7374. CompileSuccessfully(text);
  7375. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7376. EXPECT_THAT(getDiagnosticString(),
  7377. HasSubstr("Missing NonSemantic.ClspvReflection import version"));
  7378. }
  7379. TEST_F(ValidateClspvReflection, BadVersion0) {
  7380. const std::string text = R"(
  7381. OpCapability Shader
  7382. OpCapability Linkage
  7383. OpExtension "SPV_KHR_non_semantic_info"
  7384. %1 = OpExtInstImport "NonSemantic.ClspvReflection.0"
  7385. OpMemoryModel Logical GLSL450
  7386. %2 = OpTypeVoid
  7387. %3 = OpTypeInt 32 0
  7388. %4 = OpConstant %3 1
  7389. %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
  7390. )";
  7391. CompileSuccessfully(text);
  7392. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7393. EXPECT_THAT(getDiagnosticString(),
  7394. HasSubstr("Unknown NonSemantic.ClspvReflection import version"));
  7395. }
  7396. TEST_F(ValidateClspvReflection, BadVersionNotANumber) {
  7397. const std::string text = R"(
  7398. OpCapability Shader
  7399. OpCapability Linkage
  7400. OpExtension "SPV_KHR_non_semantic_info"
  7401. %1 = OpExtInstImport "NonSemantic.ClspvReflection.1a"
  7402. OpMemoryModel Logical GLSL450
  7403. %2 = OpTypeVoid
  7404. %3 = OpTypeInt 32 0
  7405. %4 = OpConstant %3 1
  7406. %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
  7407. )";
  7408. CompileSuccessfully(text);
  7409. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  7410. EXPECT_THAT(getDiagnosticString(),
  7411. HasSubstr("NonSemantic.ClspvReflection import does not encode "
  7412. "the version correctly"));
  7413. }
  7414. TEST_F(ValidateClspvReflection, Kernel) {
  7415. const std::string text = R"(
  7416. OpCapability Shader
  7417. OpExtension "SPV_KHR_non_semantic_info"
  7418. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7419. OpMemoryModel Logical GLSL450
  7420. OpEntryPoint GLCompute %foo "foo"
  7421. OpExecutionMode %foo LocalSize 1 1 1
  7422. %foo_name = OpString "foo"
  7423. %void = OpTypeVoid
  7424. %void_fn = OpTypeFunction %void
  7425. %foo = OpFunction %void None %void_fn
  7426. %entry = OpLabel
  7427. OpReturn
  7428. OpFunctionEnd
  7429. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  7430. )";
  7431. CompileSuccessfully(text);
  7432. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  7433. }
  7434. TEST_F(ValidateClspvReflection, KernelNotAFunction) {
  7435. const std::string text = R"(
  7436. OpCapability Shader
  7437. OpExtension "SPV_KHR_non_semantic_info"
  7438. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7439. OpMemoryModel Logical GLSL450
  7440. OpEntryPoint GLCompute %foo "foo"
  7441. OpExecutionMode %foo LocalSize 1 1 1
  7442. %foo_name = OpString "foo"
  7443. %void = OpTypeVoid
  7444. %void_fn = OpTypeFunction %void
  7445. %foo = OpFunction %void None %void_fn
  7446. %entry = OpLabel
  7447. OpReturn
  7448. OpFunctionEnd
  7449. %decl = OpExtInst %void %ext Kernel %foo_name %foo_name
  7450. )";
  7451. CompileSuccessfully(text);
  7452. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7453. EXPECT_THAT(getDiagnosticString(),
  7454. HasSubstr("Kernel does not reference a function"));
  7455. }
  7456. TEST_F(ValidateClspvReflection, KernelNotAnEntryPoint) {
  7457. const std::string text = R"(
  7458. OpCapability Shader
  7459. OpExtension "SPV_KHR_non_semantic_info"
  7460. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7461. OpMemoryModel Logical GLSL450
  7462. OpEntryPoint GLCompute %foo "foo"
  7463. OpExecutionMode %foo LocalSize 1 1 1
  7464. %foo_name = OpString "foo"
  7465. %void = OpTypeVoid
  7466. %void_fn = OpTypeFunction %void
  7467. %foo = OpFunction %void None %void_fn
  7468. %entry = OpLabel
  7469. OpReturn
  7470. OpFunctionEnd
  7471. %bar = OpFunction %void None %void_fn
  7472. %bar_entry = OpLabel
  7473. OpReturn
  7474. OpFunctionEnd
  7475. %decl = OpExtInst %void %ext Kernel %bar %foo_name
  7476. )";
  7477. CompileSuccessfully(text);
  7478. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7479. EXPECT_THAT(getDiagnosticString(),
  7480. HasSubstr("Kernel does not reference an entry-point"));
  7481. }
  7482. TEST_F(ValidateClspvReflection, KernelNotGLCompute) {
  7483. const std::string text = R"(
  7484. OpCapability Shader
  7485. OpExtension "SPV_KHR_non_semantic_info"
  7486. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7487. OpMemoryModel Logical GLSL450
  7488. OpEntryPoint Fragment %foo "foo"
  7489. OpExecutionMode %foo OriginUpperLeft
  7490. %foo_name = OpString "foo"
  7491. %void = OpTypeVoid
  7492. %void_fn = OpTypeFunction %void
  7493. %foo = OpFunction %void None %void_fn
  7494. %entry = OpLabel
  7495. OpReturn
  7496. OpFunctionEnd
  7497. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  7498. )";
  7499. CompileSuccessfully(text);
  7500. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7501. EXPECT_THAT(getDiagnosticString(),
  7502. HasSubstr("Kernel must refer only to GLCompute entry-points"));
  7503. }
  7504. TEST_F(ValidateClspvReflection, KernelNameMismatch) {
  7505. const std::string text = R"(
  7506. OpCapability Shader
  7507. OpExtension "SPV_KHR_non_semantic_info"
  7508. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7509. OpMemoryModel Logical GLSL450
  7510. OpEntryPoint GLCompute %foo "foo"
  7511. OpExecutionMode %foo LocalSize 1 1 1
  7512. %foo_name = OpString "bar"
  7513. %void = OpTypeVoid
  7514. %void_fn = OpTypeFunction %void
  7515. %foo = OpFunction %void None %void_fn
  7516. %entry = OpLabel
  7517. OpReturn
  7518. OpFunctionEnd
  7519. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  7520. )";
  7521. CompileSuccessfully(text);
  7522. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7523. EXPECT_THAT(getDiagnosticString(),
  7524. HasSubstr("Name must match an entry-point for Kernel"));
  7525. }
  7526. using ArgumentBasics =
  7527. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  7528. INSTANTIATE_TEST_SUITE_P(
  7529. ValidateClspvReflectionArgumentKernel, ArgumentBasics,
  7530. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  7531. std::make_pair("ArgumentStorageBuffer", "%int_0 %int_0"),
  7532. std::make_pair("ArgumentUniform", "%int_0 %int_0"),
  7533. std::make_pair("ArgumentPodStorageBuffer",
  7534. "%int_0 %int_0 %int_0 %int_4"),
  7535. std::make_pair("ArgumentPodUniform", "%int_0 %int_0 %int_0 %int_4"),
  7536. std::make_pair("ArgumentPodPushConstant", "%int_0 %int_4"),
  7537. std::make_pair("ArgumentSampledImage", "%int_0 %int_0"),
  7538. std::make_pair("ArgumentStorageImage", "%int_0 %int_0"),
  7539. std::make_pair("ArgumentSampler", "%int_0 %int_0"),
  7540. std::make_pair("ArgumentWorkgroup", "%int_0 %int_0")}));
  7541. TEST_P(ArgumentBasics, KernelNotAnExtendedInstruction) {
  7542. const std::string ext_inst = std::get<0>(GetParam());
  7543. const std::string extra = std::get<1>(GetParam());
  7544. const std::string text = R"(
  7545. OpCapability Shader
  7546. OpExtension "SPV_KHR_non_semantic_info"
  7547. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7548. OpMemoryModel Logical GLSL450
  7549. OpEntryPoint GLCompute %foo "foo"
  7550. OpExecutionMode %foo LocalSize 1 1 1
  7551. %foo_name = OpString "foo"
  7552. %void = OpTypeVoid
  7553. %int = OpTypeInt 32 0
  7554. %int_0 = OpConstant %int 0
  7555. %int_4 = OpConstant %int 4
  7556. %void_fn = OpTypeFunction %void
  7557. %foo = OpFunction %void None %void_fn
  7558. %entry = OpLabel
  7559. OpReturn
  7560. OpFunctionEnd
  7561. %in = OpExtInst %void %ext )" +
  7562. ext_inst + " %int_0 %int_0 " + extra;
  7563. CompileSuccessfully(text);
  7564. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7565. EXPECT_THAT(getDiagnosticString(),
  7566. HasSubstr("Kernel must be a Kernel extended instruction"));
  7567. }
  7568. TEST_P(ArgumentBasics, KernelFromDifferentImport) {
  7569. const std::string ext_inst = std::get<0>(GetParam());
  7570. const std::string extra = std::get<1>(GetParam());
  7571. const std::string text = R"(
  7572. OpCapability Shader
  7573. OpExtension "SPV_KHR_non_semantic_info"
  7574. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7575. %ext2 = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7576. OpMemoryModel Logical GLSL450
  7577. OpEntryPoint GLCompute %foo "foo"
  7578. OpExecutionMode %foo LocalSize 1 1 1
  7579. %foo_name = OpString "foo"
  7580. %void = OpTypeVoid
  7581. %int = OpTypeInt 32 0
  7582. %int_0 = OpConstant %int 0
  7583. %int_4 = OpConstant %int 4
  7584. %void_fn = OpTypeFunction %void
  7585. %foo = OpFunction %void None %void_fn
  7586. %entry = OpLabel
  7587. OpReturn
  7588. OpFunctionEnd
  7589. %decl = OpExtInst %void %ext2 Kernel %foo %foo_name
  7590. %in = OpExtInst %void %ext )" +
  7591. ext_inst + " %decl %int_0 " + extra;
  7592. CompileSuccessfully(text);
  7593. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7594. EXPECT_THAT(
  7595. getDiagnosticString(),
  7596. HasSubstr("Kernel must be from the same extended instruction import"));
  7597. }
  7598. TEST_P(ArgumentBasics, KernelWrongExtendedInstruction) {
  7599. const std::string ext_inst = std::get<0>(GetParam());
  7600. const std::string extra = std::get<1>(GetParam());
  7601. const std::string text = R"(
  7602. OpCapability Shader
  7603. OpExtension "SPV_KHR_non_semantic_info"
  7604. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7605. OpMemoryModel Logical GLSL450
  7606. OpEntryPoint GLCompute %foo "foo"
  7607. OpExecutionMode %foo LocalSize 1 1 1
  7608. %foo_name = OpString "foo"
  7609. %void = OpTypeVoid
  7610. %int = OpTypeInt 32 0
  7611. %int_0 = OpConstant %int 0
  7612. %int_4 = OpConstant %int 4
  7613. %void_fn = OpTypeFunction %void
  7614. %foo = OpFunction %void None %void_fn
  7615. %entry = OpLabel
  7616. OpReturn
  7617. OpFunctionEnd
  7618. %decl = OpExtInst %void %ext ArgumentInfo %foo_name
  7619. %in = OpExtInst %void %ext )" +
  7620. ext_inst + " %decl %int_0 " + extra;
  7621. CompileSuccessfully(text);
  7622. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7623. EXPECT_THAT(getDiagnosticString(),
  7624. HasSubstr("Kernel must be a Kernel extended instruction"));
  7625. }
  7626. TEST_P(ArgumentBasics, ArgumentInfo) {
  7627. const std::string ext_inst = std::get<0>(GetParam());
  7628. const std::string operands = std::get<1>(GetParam());
  7629. const std::string text = R"(
  7630. OpCapability Shader
  7631. OpExtension "SPV_KHR_non_semantic_info"
  7632. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7633. OpMemoryModel Logical GLSL450
  7634. OpEntryPoint GLCompute %foo "foo"
  7635. OpExecutionMode %foo LocalSize 1 1 1
  7636. %foo_name = OpString "foo"
  7637. %in_name = OpString "in"
  7638. %void = OpTypeVoid
  7639. %int = OpTypeInt 32 0
  7640. %int_0 = OpConstant %int 0
  7641. %int_4 = OpConstant %int 4
  7642. %void_fn = OpTypeFunction %void
  7643. %foo = OpFunction %void None %void_fn
  7644. %entry = OpLabel
  7645. OpReturn
  7646. OpFunctionEnd
  7647. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  7648. %info = OpExtInst %void %ext ArgumentInfo %in_name
  7649. %in = OpExtInst %void %ext )" +
  7650. ext_inst + " %decl %int_0 " + operands + " %info";
  7651. CompileSuccessfully(text);
  7652. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  7653. }
  7654. TEST_P(ArgumentBasics, ArgumentInfoNotAnExtendedInstruction) {
  7655. const std::string ext_inst = std::get<0>(GetParam());
  7656. const std::string operands = std::get<1>(GetParam());
  7657. const std::string text = R"(
  7658. OpCapability Shader
  7659. OpExtension "SPV_KHR_non_semantic_info"
  7660. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7661. OpMemoryModel Logical GLSL450
  7662. OpEntryPoint GLCompute %foo "foo"
  7663. OpExecutionMode %foo LocalSize 1 1 1
  7664. %foo_name = OpString "foo"
  7665. %void = OpTypeVoid
  7666. %int = OpTypeInt 32 0
  7667. %int_0 = OpConstant %int 0
  7668. %int_4 = OpConstant %int 4
  7669. %void_fn = OpTypeFunction %void
  7670. %foo = OpFunction %void None %void_fn
  7671. %entry = OpLabel
  7672. OpReturn
  7673. OpFunctionEnd
  7674. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  7675. %in = OpExtInst %void %ext )" +
  7676. ext_inst + " %decl %int_0 " + operands + " %int_0";
  7677. CompileSuccessfully(text);
  7678. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7679. EXPECT_THAT(
  7680. getDiagnosticString(),
  7681. HasSubstr("ArgInfo must be an ArgumentInfo extended instruction"));
  7682. }
  7683. TEST_P(ArgumentBasics, ArgumentInfoFromDifferentImport) {
  7684. const std::string ext_inst = std::get<0>(GetParam());
  7685. const std::string operands = std::get<1>(GetParam());
  7686. const std::string text = R"(
  7687. OpCapability Shader
  7688. OpExtension "SPV_KHR_non_semantic_info"
  7689. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7690. %ext2 = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7691. OpMemoryModel Logical GLSL450
  7692. OpEntryPoint GLCompute %foo "foo"
  7693. OpExecutionMode %foo LocalSize 1 1 1
  7694. %foo_name = OpString "foo"
  7695. %in_name = OpString "in"
  7696. %void = OpTypeVoid
  7697. %int = OpTypeInt 32 0
  7698. %int_0 = OpConstant %int 0
  7699. %int_4 = OpConstant %int 4
  7700. %void_fn = OpTypeFunction %void
  7701. %foo = OpFunction %void None %void_fn
  7702. %entry = OpLabel
  7703. OpReturn
  7704. OpFunctionEnd
  7705. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  7706. %info = OpExtInst %void %ext2 ArgumentInfo %in_name
  7707. %in = OpExtInst %void %ext )" +
  7708. ext_inst + " %decl %int_0 " + operands + " %info";
  7709. CompileSuccessfully(text);
  7710. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7711. EXPECT_THAT(
  7712. getDiagnosticString(),
  7713. HasSubstr("ArgInfo must be from the same extended instruction import"));
  7714. }
  7715. using Uint32Constant =
  7716. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  7717. INSTANTIATE_TEST_SUITE_P(
  7718. ValidateClspvReflectionUint32Constants, Uint32Constant,
  7719. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  7720. std::make_pair("ArgumentStorageBuffer %decl %float_0 %int_0 %int_0",
  7721. "Ordinal"),
  7722. std::make_pair("ArgumentStorageBuffer %decl %null %int_0 %int_0",
  7723. "Ordinal"),
  7724. std::make_pair("ArgumentStorageBuffer %decl %int_0 %float_0 %int_0",
  7725. "DescriptorSet"),
  7726. std::make_pair("ArgumentStorageBuffer %decl %int_0 %null %int_0",
  7727. "DescriptorSet"),
  7728. std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %float_0",
  7729. "Binding"),
  7730. std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %null",
  7731. "Binding"),
  7732. std::make_pair("ArgumentUniform %decl %float_0 %int_0 %int_0",
  7733. "Ordinal"),
  7734. std::make_pair("ArgumentUniform %decl %null %int_0 %int_0", "Ordinal"),
  7735. std::make_pair("ArgumentUniform %decl %int_0 %float_0 %int_0",
  7736. "DescriptorSet"),
  7737. std::make_pair("ArgumentUniform %decl %int_0 %null %int_0",
  7738. "DescriptorSet"),
  7739. std::make_pair("ArgumentUniform %decl %int_0 %int_0 %float_0",
  7740. "Binding"),
  7741. std::make_pair("ArgumentUniform %decl %int_0 %int_0 %null", "Binding"),
  7742. std::make_pair("ArgumentSampledImage %decl %float_0 %int_0 %int_0",
  7743. "Ordinal"),
  7744. std::make_pair("ArgumentSampledImage %decl %null %int_0 %int_0",
  7745. "Ordinal"),
  7746. std::make_pair("ArgumentSampledImage %decl %int_0 %float_0 %int_0",
  7747. "DescriptorSet"),
  7748. std::make_pair("ArgumentSampledImage %decl %int_0 %null %int_0",
  7749. "DescriptorSet"),
  7750. std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %float_0",
  7751. "Binding"),
  7752. std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %null",
  7753. "Binding"),
  7754. std::make_pair("ArgumentStorageImage %decl %float_0 %int_0 %int_0",
  7755. "Ordinal"),
  7756. std::make_pair("ArgumentStorageImage %decl %null %int_0 %int_0",
  7757. "Ordinal"),
  7758. std::make_pair("ArgumentStorageImage %decl %int_0 %float_0 %int_0",
  7759. "DescriptorSet"),
  7760. std::make_pair("ArgumentStorageImage %decl %int_0 %null %int_0",
  7761. "DescriptorSet"),
  7762. std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %float_0",
  7763. "Binding"),
  7764. std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %null",
  7765. "Binding"),
  7766. std::make_pair("ArgumentSampler %decl %float_0 %int_0 %int_0",
  7767. "Ordinal"),
  7768. std::make_pair("ArgumentSampler %decl %null %int_0 %int_0", "Ordinal"),
  7769. std::make_pair("ArgumentSampler %decl %int_0 %float_0 %int_0",
  7770. "DescriptorSet"),
  7771. std::make_pair("ArgumentSampler %decl %int_0 %null %int_0",
  7772. "DescriptorSet"),
  7773. std::make_pair("ArgumentSampler %decl %int_0 %int_0 %float_0",
  7774. "Binding"),
  7775. std::make_pair("ArgumentSampler %decl %int_0 %int_0 %null", "Binding"),
  7776. std::make_pair("ArgumentPodStorageBuffer %decl %float_0 %int_0 %int_0 "
  7777. "%int_0 %int_4",
  7778. "Ordinal"),
  7779. std::make_pair(
  7780. "ArgumentPodStorageBuffer %decl %null %int_0 %int_0 %int_0 %int_4",
  7781. "Ordinal"),
  7782. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %float_0 %int_0 "
  7783. "%int_0 %int_4",
  7784. "DescriptorSet"),
  7785. std::make_pair(
  7786. "ArgumentPodStorageBuffer %decl %int_0 %null %int_0 %int_0 %int_4",
  7787. "DescriptorSet"),
  7788. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %float_0 "
  7789. "%int_0 %int_4",
  7790. "Binding"),
  7791. std::make_pair(
  7792. "ArgumentPodStorageBuffer %decl %int_0 %int_0 %null %int_0 %int_4",
  7793. "Binding"),
  7794. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 "
  7795. "%float_0 %int_4",
  7796. "Offset"),
  7797. std::make_pair(
  7798. "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %null %int_4",
  7799. "Offset"),
  7800. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 "
  7801. "%int_0 %float_0",
  7802. "Size"),
  7803. std::make_pair(
  7804. "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %int_0 %null",
  7805. "Size"),
  7806. std::make_pair(
  7807. "ArgumentPodUniform %decl %float_0 %int_0 %int_0 %int_0 %int_4",
  7808. "Ordinal"),
  7809. std::make_pair(
  7810. "ArgumentPodUniform %decl %null %int_0 %int_0 %int_0 %int_4",
  7811. "Ordinal"),
  7812. std::make_pair(
  7813. "ArgumentPodUniform %decl %int_0 %float_0 %int_0 %int_0 %int_4",
  7814. "DescriptorSet"),
  7815. std::make_pair(
  7816. "ArgumentPodUniform %decl %int_0 %null %int_0 %int_0 %int_4",
  7817. "DescriptorSet"),
  7818. std::make_pair(
  7819. "ArgumentPodUniform %decl %int_0 %int_0 %float_0 %int_0 %int_4",
  7820. "Binding"),
  7821. std::make_pair(
  7822. "ArgumentPodUniform %decl %int_0 %int_0 %null %int_0 %int_4",
  7823. "Binding"),
  7824. std::make_pair(
  7825. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %float_0 %int_4",
  7826. "Offset"),
  7827. std::make_pair(
  7828. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %null %int_4",
  7829. "Offset"),
  7830. std::make_pair(
  7831. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %float_0",
  7832. "Size"),
  7833. std::make_pair(
  7834. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %null",
  7835. "Size"),
  7836. std::make_pair("ArgumentPodPushConstant %decl %float_0 %int_0 %int_4",
  7837. "Ordinal"),
  7838. std::make_pair("ArgumentPodPushConstant %decl %null %int_0 %int_4",
  7839. "Ordinal"),
  7840. std::make_pair("ArgumentPodPushConstant %decl %int_0 %float_0 %int_4",
  7841. "Offset"),
  7842. std::make_pair("ArgumentPodPushConstant %decl %int_0 %null %int_4",
  7843. "Offset"),
  7844. std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %float_0",
  7845. "Size"),
  7846. std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %null",
  7847. "Size"),
  7848. std::make_pair("ArgumentWorkgroup %decl %float_0 %int_0 %int_4",
  7849. "Ordinal"),
  7850. std::make_pair("ArgumentWorkgroup %decl %null %int_0 %int_4",
  7851. "Ordinal"),
  7852. std::make_pair("ArgumentWorkgroup %decl %int_0 %float_0 %int_4",
  7853. "SpecId"),
  7854. std::make_pair("ArgumentWorkgroup %decl %int_0 %null %int_4", "SpecId"),
  7855. std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %float_0",
  7856. "ElemSize"),
  7857. std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %null",
  7858. "ElemSize"),
  7859. std::make_pair("SpecConstantWorkgroupSize %float_0 %int_0 %int_4", "X"),
  7860. std::make_pair("SpecConstantWorkgroupSize %null %int_0 %int_4", "X"),
  7861. std::make_pair("SpecConstantWorkgroupSize %int_0 %float_0 %int_4", "Y"),
  7862. std::make_pair("SpecConstantWorkgroupSize %int_0 %null %int_4", "Y"),
  7863. std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %float_0", "Z"),
  7864. std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %null", "Z"),
  7865. std::make_pair("SpecConstantGlobalOffset %float_0 %int_0 %int_4", "X"),
  7866. std::make_pair("SpecConstantGlobalOffset %null %int_0 %int_4", "X"),
  7867. std::make_pair("SpecConstantGlobalOffset %int_0 %float_0 %int_4", "Y"),
  7868. std::make_pair("SpecConstantGlobalOffset %int_0 %null %int_4", "Y"),
  7869. std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %float_0", "Z"),
  7870. std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %null", "Z"),
  7871. std::make_pair("SpecConstantWorkDim %float_0", "Dim"),
  7872. std::make_pair("SpecConstantWorkDim %null", "Dim"),
  7873. std::make_pair("PushConstantGlobalOffset %float_0 %int_0", "Offset"),
  7874. std::make_pair("PushConstantGlobalOffset %null %int_0", "Offset"),
  7875. std::make_pair("PushConstantGlobalOffset %int_0 %float_0", "Size"),
  7876. std::make_pair("PushConstantGlobalOffset %int_0 %null", "Size"),
  7877. std::make_pair("PushConstantEnqueuedLocalSize %float_0 %int_0",
  7878. "Offset"),
  7879. std::make_pair("PushConstantEnqueuedLocalSize %null %int_0", "Offset"),
  7880. std::make_pair("PushConstantEnqueuedLocalSize %int_0 %float_0", "Size"),
  7881. std::make_pair("PushConstantEnqueuedLocalSize %int_0 %null", "Size"),
  7882. std::make_pair("PushConstantGlobalSize %float_0 %int_0", "Offset"),
  7883. std::make_pair("PushConstantGlobalSize %null %int_0", "Offset"),
  7884. std::make_pair("PushConstantGlobalSize %int_0 %float_0", "Size"),
  7885. std::make_pair("PushConstantGlobalSize %int_0 %null", "Size"),
  7886. std::make_pair("PushConstantRegionOffset %float_0 %int_0", "Offset"),
  7887. std::make_pair("PushConstantRegionOffset %null %int_0", "Offset"),
  7888. std::make_pair("PushConstantRegionOffset %int_0 %float_0", "Size"),
  7889. std::make_pair("PushConstantRegionOffset %int_0 %null", "Size"),
  7890. std::make_pair("PushConstantNumWorkgroups %float_0 %int_0", "Offset"),
  7891. std::make_pair("PushConstantNumWorkgroups %null %int_0", "Offset"),
  7892. std::make_pair("PushConstantNumWorkgroups %int_0 %float_0", "Size"),
  7893. std::make_pair("PushConstantNumWorkgroups %int_0 %null", "Size"),
  7894. std::make_pair("PushConstantRegionGroupOffset %float_0 %int_0",
  7895. "Offset"),
  7896. std::make_pair("PushConstantRegionGroupOffset %null %int_0", "Offset"),
  7897. std::make_pair("PushConstantRegionGroupOffset %int_0 %float_0", "Size"),
  7898. std::make_pair("PushConstantRegionGroupOffset %int_0 %null", "Size"),
  7899. std::make_pair("ConstantDataStorageBuffer %float_0 %int_0 %data",
  7900. "DescriptorSet"),
  7901. std::make_pair("ConstantDataStorageBuffer %null %int_0 %data",
  7902. "DescriptorSet"),
  7903. std::make_pair("ConstantDataStorageBuffer %int_0 %float_0 %data",
  7904. "Binding"),
  7905. std::make_pair("ConstantDataStorageBuffer %int_0 %null %data",
  7906. "Binding"),
  7907. std::make_pair("ConstantDataUniform %float_0 %int_0 %data",
  7908. "DescriptorSet"),
  7909. std::make_pair("ConstantDataUniform %null %int_0 %data",
  7910. "DescriptorSet"),
  7911. std::make_pair("ConstantDataUniform %int_0 %float_0 %data", "Binding"),
  7912. std::make_pair("ConstantDataUniform %int_0 %null %data", "Binding"),
  7913. std::make_pair("LiteralSampler %float_0 %int_0 %int_4",
  7914. "DescriptorSet"),
  7915. std::make_pair("LiteralSampler %null %int_0 %int_4", "DescriptorSet"),
  7916. std::make_pair("LiteralSampler %int_0 %float_0 %int_4", "Binding"),
  7917. std::make_pair("LiteralSampler %int_0 %null %int_4", "Binding"),
  7918. std::make_pair("LiteralSampler %int_0 %int_0 %float_0", "Mask"),
  7919. std::make_pair("LiteralSampler %int_0 %int_0 %null", "Mask"),
  7920. std::make_pair(
  7921. "PropertyRequiredWorkgroupSize %decl %float_0 %int_1 %int_4", "X"),
  7922. std::make_pair(
  7923. "PropertyRequiredWorkgroupSize %decl %null %int_1 %int_4", "X"),
  7924. std::make_pair(
  7925. "PropertyRequiredWorkgroupSize %decl %int_1 %float_0 %int_4", "Y"),
  7926. std::make_pair(
  7927. "PropertyRequiredWorkgroupSize %decl %int_1 %null %int_4", "Y"),
  7928. std::make_pair(
  7929. "PropertyRequiredWorkgroupSize %decl %int_1 %int_1 %float_0", "Z"),
  7930. std::make_pair(
  7931. "PropertyRequiredWorkgroupSize %decl %int_1 %int_1 %null", "Z")}));
  7932. TEST_P(Uint32Constant, Invalid) {
  7933. const std::string ext_inst = std::get<0>(GetParam());
  7934. const std::string name = std::get<1>(GetParam());
  7935. const std::string text = R"(
  7936. OpCapability Shader
  7937. OpExtension "SPV_KHR_non_semantic_info"
  7938. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7939. OpMemoryModel Logical GLSL450
  7940. OpEntryPoint GLCompute %foo "foo"
  7941. OpExecutionMode %foo LocalSize 1 1 1
  7942. %foo_name = OpString "foo"
  7943. %data = OpString "1234"
  7944. %void = OpTypeVoid
  7945. %int = OpTypeInt 32 0
  7946. %int_0 = OpConstant %int 0
  7947. %int_1 = OpConstant %int 1
  7948. %int_4 = OpConstant %int 4
  7949. %null = OpConstantNull %int
  7950. %float = OpTypeFloat 32
  7951. %float_0 = OpConstant %float 0
  7952. %void_fn = OpTypeFunction %void
  7953. %foo = OpFunction %void None %void_fn
  7954. %entry = OpLabel
  7955. OpReturn
  7956. OpFunctionEnd
  7957. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  7958. %inst = OpExtInst %void %ext )" +
  7959. ext_inst;
  7960. CompileSuccessfully(text);
  7961. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  7962. EXPECT_THAT(
  7963. getDiagnosticString(),
  7964. HasSubstr(name + " must be a 32-bit unsigned integer OpConstant"));
  7965. }
  7966. using StringOperand =
  7967. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  7968. INSTANTIATE_TEST_SUITE_P(
  7969. ValidateClspvReflectionStringOperands, StringOperand,
  7970. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  7971. std::make_pair("ConstantDataStorageBuffer %int_0 %int_0 %int_0",
  7972. "Data"),
  7973. std::make_pair("ConstantDataUniform %int_0 %int_0 %int_0", "Data")}));
  7974. TEST_P(StringOperand, Invalid) {
  7975. const std::string ext_inst = std::get<0>(GetParam());
  7976. const std::string name = std::get<1>(GetParam());
  7977. const std::string text = R"(
  7978. OpCapability Shader
  7979. OpExtension "SPV_KHR_non_semantic_info"
  7980. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  7981. OpMemoryModel Logical GLSL450
  7982. OpEntryPoint GLCompute %foo "foo"
  7983. OpExecutionMode %foo LocalSize 1 1 1
  7984. %foo_name = OpString "foo"
  7985. %data = OpString "1234"
  7986. %void = OpTypeVoid
  7987. %int = OpTypeInt 32 0
  7988. %int_0 = OpConstant %int 0
  7989. %int_1 = OpConstant %int 1
  7990. %int_4 = OpConstant %int 4
  7991. %null = OpConstantNull %int
  7992. %float = OpTypeFloat 32
  7993. %float_0 = OpConstant %float 0
  7994. %void_fn = OpTypeFunction %void
  7995. %foo = OpFunction %void None %void_fn
  7996. %entry = OpLabel
  7997. OpReturn
  7998. OpFunctionEnd
  7999. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  8000. %inst = OpExtInst %void %ext )" +
  8001. ext_inst;
  8002. CompileSuccessfully(text);
  8003. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  8004. EXPECT_THAT(getDiagnosticString(), HasSubstr(name + " must be an OpString"));
  8005. }
  8006. } // namespace
  8007. } // namespace val
  8008. } // namespace spvtools