val_ext_inst_test.cpp 286 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477
  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 ValidateGlslStd450SqrtLike = spvtest::ValidateBase<std::string>;
  31. using ValidateGlslStd450FMinLike = spvtest::ValidateBase<std::string>;
  32. using ValidateGlslStd450FClampLike = spvtest::ValidateBase<std::string>;
  33. using ValidateGlslStd450SAbsLike = spvtest::ValidateBase<std::string>;
  34. using ValidateGlslStd450UMinLike = spvtest::ValidateBase<std::string>;
  35. using ValidateGlslStd450UClampLike = spvtest::ValidateBase<std::string>;
  36. using ValidateGlslStd450SinLike = spvtest::ValidateBase<std::string>;
  37. using ValidateGlslStd450PowLike = spvtest::ValidateBase<std::string>;
  38. using ValidateGlslStd450Pack = spvtest::ValidateBase<std::string>;
  39. using ValidateGlslStd450Unpack = spvtest::ValidateBase<std::string>;
  40. using ValidateOpenCLStdSqrtLike = spvtest::ValidateBase<std::string>;
  41. using ValidateOpenCLStdFMinLike = spvtest::ValidateBase<std::string>;
  42. using ValidateOpenCLStdFClampLike = spvtest::ValidateBase<std::string>;
  43. using ValidateOpenCLStdSAbsLike = spvtest::ValidateBase<std::string>;
  44. using ValidateOpenCLStdUMinLike = spvtest::ValidateBase<std::string>;
  45. using ValidateOpenCLStdUClampLike = spvtest::ValidateBase<std::string>;
  46. using ValidateOpenCLStdUMul24Like = spvtest::ValidateBase<std::string>;
  47. using ValidateOpenCLStdUMad24Like = spvtest::ValidateBase<std::string>;
  48. using ValidateOpenCLStdLengthLike = spvtest::ValidateBase<std::string>;
  49. using ValidateOpenCLStdDistanceLike = spvtest::ValidateBase<std::string>;
  50. using ValidateOpenCLStdNormalizeLike = spvtest::ValidateBase<std::string>;
  51. using ValidateOpenCLStdVStoreHalfLike = spvtest::ValidateBase<std::string>;
  52. using ValidateOpenCLStdVLoadHalfLike = spvtest::ValidateBase<std::string>;
  53. using ValidateOpenCLStdFractLike = spvtest::ValidateBase<std::string>;
  54. using ValidateOpenCLStdFrexpLike = spvtest::ValidateBase<std::string>;
  55. using ValidateOpenCLStdLdexpLike = spvtest::ValidateBase<std::string>;
  56. using ValidateOpenCLStdUpsampleLike = spvtest::ValidateBase<std::string>;
  57. using ValidateClspvReflection = spvtest::ValidateBase<bool>;
  58. // Returns number of components in Pack/Unpack extended instructions.
  59. // |ext_inst_name| is expected to be of the format "PackHalf2x16".
  60. // Number of components is assumed to be single-digit.
  61. uint32_t GetPackedNumComponents(const std::string& ext_inst_name) {
  62. const size_t x_index = ext_inst_name.find_last_of('x');
  63. const std::string num_components_str =
  64. ext_inst_name.substr(x_index - 1, x_index);
  65. return uint32_t(std::stoul(num_components_str));
  66. }
  67. // Returns packed bit width in Pack/Unpack extended instructions.
  68. // |ext_inst_name| is expected to be of the format "PackHalf2x16".
  69. uint32_t GetPackedBitWidth(const std::string& ext_inst_name) {
  70. const size_t x_index = ext_inst_name.find_last_of('x');
  71. const std::string packed_bit_width_str = ext_inst_name.substr(x_index + 1);
  72. return uint32_t(std::stoul(packed_bit_width_str));
  73. }
  74. std::string GenerateShaderCode(
  75. const std::string& body,
  76. const std::string& capabilities_and_extensions = "",
  77. const std::string& execution_model = "Fragment") {
  78. std::ostringstream ss;
  79. ss << R"(
  80. OpCapability Shader
  81. OpCapability Float16
  82. OpCapability Float64
  83. OpCapability Int16
  84. OpCapability Int64
  85. )";
  86. ss << capabilities_and_extensions;
  87. ss << "%extinst = OpExtInstImport \"GLSL.std.450\"\n";
  88. ss << "OpMemoryModel Logical GLSL450\n";
  89. ss << "OpEntryPoint " << execution_model << " %main \"main\""
  90. << " %f32_output"
  91. << " %f32vec2_output"
  92. << " %u32_output"
  93. << " %u32vec2_output"
  94. << " %u64_output"
  95. << " %f32_input"
  96. << " %f32vec2_input"
  97. << " %u32_input"
  98. << " %u32vec2_input"
  99. << " %u64_input"
  100. << "\n";
  101. if (execution_model == "Fragment") {
  102. ss << "OpExecutionMode %main OriginUpperLeft\n";
  103. }
  104. ss << R"(
  105. %void = OpTypeVoid
  106. %func = OpTypeFunction %void
  107. %bool = OpTypeBool
  108. %f16 = OpTypeFloat 16
  109. %f32 = OpTypeFloat 32
  110. %f64 = OpTypeFloat 64
  111. %u32 = OpTypeInt 32 0
  112. %s32 = OpTypeInt 32 1
  113. %u64 = OpTypeInt 64 0
  114. %s64 = OpTypeInt 64 1
  115. %u16 = OpTypeInt 16 0
  116. %s16 = OpTypeInt 16 1
  117. %f32vec2 = OpTypeVector %f32 2
  118. %f32vec3 = OpTypeVector %f32 3
  119. %f32vec4 = OpTypeVector %f32 4
  120. %f64vec2 = OpTypeVector %f64 2
  121. %f64vec3 = OpTypeVector %f64 3
  122. %f64vec4 = OpTypeVector %f64 4
  123. %u32vec2 = OpTypeVector %u32 2
  124. %u32vec3 = OpTypeVector %u32 3
  125. %s32vec2 = OpTypeVector %s32 2
  126. %u32vec4 = OpTypeVector %u32 4
  127. %s32vec4 = OpTypeVector %s32 4
  128. %u64vec2 = OpTypeVector %u64 2
  129. %s64vec2 = OpTypeVector %s64 2
  130. %f64mat22 = OpTypeMatrix %f64vec2 2
  131. %f32mat22 = OpTypeMatrix %f32vec2 2
  132. %f32mat23 = OpTypeMatrix %f32vec2 3
  133. %f32mat32 = OpTypeMatrix %f32vec3 2
  134. %f32mat33 = OpTypeMatrix %f32vec3 3
  135. %f32_0 = OpConstant %f32 0
  136. %f32_1 = OpConstant %f32 1
  137. %f32_2 = OpConstant %f32 2
  138. %f32_3 = OpConstant %f32 3
  139. %f32_4 = OpConstant %f32 4
  140. %f32_h = OpConstant %f32 0.5
  141. %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
  142. %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
  143. %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
  144. %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
  145. %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
  146. %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
  147. %f64_0 = OpConstant %f64 0
  148. %f64_1 = OpConstant %f64 1
  149. %f64_2 = OpConstant %f64 2
  150. %f64_3 = OpConstant %f64 3
  151. %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
  152. %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
  153. %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
  154. %f16_0 = OpConstant %f16 0
  155. %f16_1 = OpConstant %f16 1
  156. %f16_h = OpConstant %f16 0.5
  157. %u32_0 = OpConstant %u32 0
  158. %u32_1 = OpConstant %u32 1
  159. %u32_2 = OpConstant %u32 2
  160. %u32_3 = OpConstant %u32 3
  161. %s32_0 = OpConstant %s32 0
  162. %s32_1 = OpConstant %s32 1
  163. %s32_2 = OpConstant %s32 2
  164. %s32_3 = OpConstant %s32 3
  165. %u64_0 = OpConstant %u64 0
  166. %u64_1 = OpConstant %u64 1
  167. %u64_2 = OpConstant %u64 2
  168. %u64_3 = OpConstant %u64 3
  169. %s64_0 = OpConstant %s64 0
  170. %s64_1 = OpConstant %s64 1
  171. %s64_2 = OpConstant %s64 2
  172. %s64_3 = OpConstant %s64 3
  173. %s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
  174. %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
  175. %s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
  176. %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
  177. %s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
  178. %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
  179. %s64vec2_01 = OpConstantComposite %s64vec2 %s64_0 %s64_1
  180. %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
  181. %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
  182. %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
  183. %f32_ptr_output = OpTypePointer Output %f32
  184. %f32vec2_ptr_output = OpTypePointer Output %f32vec2
  185. %u32_ptr_output = OpTypePointer Output %u32
  186. %u32vec2_ptr_output = OpTypePointer Output %u32vec2
  187. %u64_ptr_output = OpTypePointer Output %u64
  188. %f32_output = OpVariable %f32_ptr_output Output
  189. %f32vec2_output = OpVariable %f32vec2_ptr_output Output
  190. %u32_output = OpVariable %u32_ptr_output Output
  191. %u32vec2_output = OpVariable %u32vec2_ptr_output Output
  192. %u64_output = OpVariable %u64_ptr_output Output
  193. %f32_ptr_input = OpTypePointer Input %f32
  194. %f32vec2_ptr_input = OpTypePointer Input %f32vec2
  195. %u32_ptr_input = OpTypePointer Input %u32
  196. %u32vec2_ptr_input = OpTypePointer Input %u32vec2
  197. %u64_ptr_input = OpTypePointer Input %u64
  198. %f32_input = OpVariable %f32_ptr_input Input
  199. %f32vec2_input = OpVariable %f32vec2_ptr_input Input
  200. %u32_input = OpVariable %u32_ptr_input Input
  201. %u32vec2_input = OpVariable %u32vec2_ptr_input Input
  202. %u64_input = OpVariable %u64_ptr_input Input
  203. %struct_f16_u16 = OpTypeStruct %f16 %u16
  204. %struct_f32_f32 = OpTypeStruct %f32 %f32
  205. %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
  206. %struct_f32_u32 = OpTypeStruct %f32 %u32
  207. %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
  208. %struct_u32_f32 = OpTypeStruct %u32 %f32
  209. %struct_u32_u32 = OpTypeStruct %u32 %u32
  210. %struct_f32_f64 = OpTypeStruct %f32 %f64
  211. %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
  212. %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
  213. %main = OpFunction %void None %func
  214. %main_entry = OpLabel
  215. )";
  216. ss << body;
  217. ss << R"(
  218. OpReturn
  219. OpFunctionEnd)";
  220. return ss.str();
  221. }
  222. std::string GenerateKernelCode(
  223. const std::string& body,
  224. const std::string& capabilities_and_extensions = "",
  225. const std::string& memory_model = "Physical32") {
  226. std::ostringstream ss;
  227. ss << R"(
  228. OpCapability Addresses
  229. OpCapability Kernel
  230. OpCapability Linkage
  231. OpCapability GenericPointer
  232. OpCapability Int8
  233. OpCapability Int16
  234. OpCapability Int64
  235. OpCapability Float16
  236. OpCapability Float64
  237. OpCapability Vector16
  238. OpCapability Matrix
  239. )";
  240. ss << capabilities_and_extensions;
  241. ss << "%extinst = OpExtInstImport \"OpenCL.std\"\n";
  242. ss << "OpMemoryModel " << memory_model << " OpenCL\n";
  243. ss << R"(
  244. %void = OpTypeVoid
  245. %func = OpTypeFunction %void
  246. %bool = OpTypeBool
  247. %f16 = OpTypeFloat 16
  248. %f32 = OpTypeFloat 32
  249. %f64 = OpTypeFloat 64
  250. %u32 = OpTypeInt 32 0
  251. %u64 = OpTypeInt 64 0
  252. %u16 = OpTypeInt 16 0
  253. %u8 = OpTypeInt 8 0
  254. %f32vec2 = OpTypeVector %f32 2
  255. %f32vec3 = OpTypeVector %f32 3
  256. %f32vec4 = OpTypeVector %f32 4
  257. %f32vec8 = OpTypeVector %f32 8
  258. %f16vec8 = OpTypeVector %f16 8
  259. %f32vec16 = OpTypeVector %f32 16
  260. %f64vec2 = OpTypeVector %f64 2
  261. %f64vec3 = OpTypeVector %f64 3
  262. %f64vec4 = OpTypeVector %f64 4
  263. %u32vec2 = OpTypeVector %u32 2
  264. %u32vec3 = OpTypeVector %u32 3
  265. %u32vec4 = OpTypeVector %u32 4
  266. %u32vec8 = OpTypeVector %u32 8
  267. %u64vec2 = OpTypeVector %u64 2
  268. %f64mat22 = OpTypeMatrix %f64vec2 2
  269. %f32mat22 = OpTypeMatrix %f32vec2 2
  270. %f32mat23 = OpTypeMatrix %f32vec2 3
  271. %f32mat32 = OpTypeMatrix %f32vec3 2
  272. %f32mat33 = OpTypeMatrix %f32vec3 3
  273. %f32_0 = OpConstant %f32 0
  274. %f32_1 = OpConstant %f32 1
  275. %f32_2 = OpConstant %f32 2
  276. %f32_3 = OpConstant %f32 3
  277. %f32_4 = OpConstant %f32 4
  278. %f32_h = OpConstant %f32 0.5
  279. %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
  280. %f32vec2_12 = OpConstantComposite %f32vec2 %f32_1 %f32_2
  281. %f32vec3_012 = OpConstantComposite %f32vec3 %f32_0 %f32_1 %f32_2
  282. %f32vec3_123 = OpConstantComposite %f32vec3 %f32_1 %f32_2 %f32_3
  283. %f32vec4_0123 = OpConstantComposite %f32vec4 %f32_0 %f32_1 %f32_2 %f32_3
  284. %f32vec4_1234 = OpConstantComposite %f32vec4 %f32_1 %f32_2 %f32_3 %f32_4
  285. %f32vec8_01010101 = OpConstantComposite %f32vec8 %f32_0 %f32_1 %f32_0 %f32_1 %f32_0 %f32_1 %f32_0 %f32_1
  286. %f64_0 = OpConstant %f64 0
  287. %f64_1 = OpConstant %f64 1
  288. %f64_2 = OpConstant %f64 2
  289. %f64_3 = OpConstant %f64 3
  290. %f64vec2_01 = OpConstantComposite %f64vec2 %f64_0 %f64_1
  291. %f64vec3_012 = OpConstantComposite %f64vec3 %f64_0 %f64_1 %f64_2
  292. %f64vec4_0123 = OpConstantComposite %f64vec4 %f64_0 %f64_1 %f64_2 %f64_3
  293. %f16_0 = OpConstant %f16 0
  294. %f16_1 = OpConstant %f16 1
  295. %u8_0 = OpConstant %u8 0
  296. %u8_1 = OpConstant %u8 1
  297. %u8_2 = OpConstant %u8 2
  298. %u8_3 = OpConstant %u8 3
  299. %u16_0 = OpConstant %u16 0
  300. %u16_1 = OpConstant %u16 1
  301. %u16_2 = OpConstant %u16 2
  302. %u16_3 = OpConstant %u16 3
  303. %u32_0 = OpConstant %u32 0
  304. %u32_1 = OpConstant %u32 1
  305. %u32_2 = OpConstant %u32 2
  306. %u32_3 = OpConstant %u32 3
  307. %u32_256 = OpConstant %u32 256
  308. %u64_0 = OpConstant %u64 0
  309. %u64_1 = OpConstant %u64 1
  310. %u64_2 = OpConstant %u64 2
  311. %u64_3 = OpConstant %u64 3
  312. %u64_256 = OpConstant %u64 256
  313. %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
  314. %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
  315. %u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
  316. %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
  317. %u64vec2_01 = OpConstantComposite %u64vec2 %u64_0 %u64_1
  318. %f32mat22_1212 = OpConstantComposite %f32mat22 %f32vec2_12 %f32vec2_12
  319. %f32mat23_121212 = OpConstantComposite %f32mat23 %f32vec2_12 %f32vec2_12 %f32vec2_12
  320. %struct_f32_f32 = OpTypeStruct %f32 %f32
  321. %struct_f32_f32_f32 = OpTypeStruct %f32 %f32 %f32
  322. %struct_f32_u32 = OpTypeStruct %f32 %u32
  323. %struct_f32_u32_f32 = OpTypeStruct %f32 %u32 %f32
  324. %struct_u32_f32 = OpTypeStruct %u32 %f32
  325. %struct_u32_u32 = OpTypeStruct %u32 %u32
  326. %struct_f32_f64 = OpTypeStruct %f32 %f64
  327. %struct_f32vec2_f32vec2 = OpTypeStruct %f32vec2 %f32vec2
  328. %struct_f32vec2_u32vec2 = OpTypeStruct %f32vec2 %u32vec2
  329. %f16vec8_ptr_workgroup = OpTypePointer Workgroup %f16vec8
  330. %f16vec8_workgroup = OpVariable %f16vec8_ptr_workgroup Workgroup
  331. %f16_ptr_workgroup = OpTypePointer Workgroup %f16
  332. %u32vec8_ptr_workgroup = OpTypePointer Workgroup %u32vec8
  333. %u32vec8_workgroup = OpVariable %u32vec8_ptr_workgroup Workgroup
  334. %u32_ptr_workgroup = OpTypePointer Workgroup %u32
  335. %f32vec8_ptr_workgroup = OpTypePointer Workgroup %f32vec8
  336. %f32vec8_workgroup = OpVariable %f32vec8_ptr_workgroup Workgroup
  337. %f32_ptr_workgroup = OpTypePointer Workgroup %f32
  338. %u32arr = OpTypeArray %u32 %u32_256
  339. %u32arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %u32arr
  340. %u32arr_cross_workgroup = OpVariable %u32arr_ptr_cross_workgroup CrossWorkgroup
  341. %u32_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %u32
  342. %f32arr = OpTypeArray %f32 %u32_256
  343. %f32arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32arr
  344. %f32arr_cross_workgroup = OpVariable %f32arr_ptr_cross_workgroup CrossWorkgroup
  345. %f32_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32
  346. %f32vec2arr = OpTypeArray %f32vec2 %u32_256
  347. %f32vec2arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32vec2arr
  348. %f32vec2arr_cross_workgroup = OpVariable %f32vec2arr_ptr_cross_workgroup CrossWorkgroup
  349. %f32vec2_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %f32vec2
  350. %struct_arr = OpTypeArray %struct_f32_f32 %u32_256
  351. %struct_arr_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %struct_arr
  352. %struct_arr_cross_workgroup = OpVariable %struct_arr_ptr_cross_workgroup CrossWorkgroup
  353. %struct_ptr_cross_workgroup = OpTypePointer CrossWorkgroup %struct_f32_f32
  354. %f16vec8_ptr_uniform_constant = OpTypePointer UniformConstant %f16vec8
  355. %f16vec8_uniform_constant = OpVariable %f16vec8_ptr_uniform_constant UniformConstant
  356. %f16_ptr_uniform_constant = OpTypePointer UniformConstant %f16
  357. %u32vec8_ptr_uniform_constant = OpTypePointer UniformConstant %u32vec8
  358. %u32vec8_uniform_constant = OpVariable %u32vec8_ptr_uniform_constant UniformConstant
  359. %u32_ptr_uniform_constant = OpTypePointer UniformConstant %u32
  360. %f32vec8_ptr_uniform_constant = OpTypePointer UniformConstant %f32vec8
  361. %f32vec8_uniform_constant = OpVariable %f32vec8_ptr_uniform_constant UniformConstant
  362. %f32_ptr_uniform_constant = OpTypePointer UniformConstant %f32
  363. %f16vec8_ptr_input = OpTypePointer Input %f16vec8
  364. %f16vec8_input = OpVariable %f16vec8_ptr_input Input
  365. %f16_ptr_input = OpTypePointer Input %f16
  366. %u32vec8_ptr_input = OpTypePointer Input %u32vec8
  367. %u32vec8_input = OpVariable %u32vec8_ptr_input Input
  368. %u32_ptr_input = OpTypePointer Input %u32
  369. %f32_ptr_generic = OpTypePointer Generic %f32
  370. %u32_ptr_generic = OpTypePointer Generic %u32
  371. %f32_ptr_function = OpTypePointer Function %f32
  372. %f32vec2_ptr_function = OpTypePointer Function %f32vec2
  373. %u32_ptr_function = OpTypePointer Function %u32
  374. %u64_ptr_function = OpTypePointer Function %u64
  375. %u32vec2_ptr_function = OpTypePointer Function %u32vec2
  376. %u8arr = OpTypeArray %u8 %u32_256
  377. %u8arr_ptr_uniform_constant = OpTypePointer UniformConstant %u8arr
  378. %u8arr_uniform_constant = OpVariable %u8arr_ptr_uniform_constant UniformConstant
  379. %u8_ptr_uniform_constant = OpTypePointer UniformConstant %u8
  380. %u8_ptr_generic = OpTypePointer Generic %u8
  381. %main = OpFunction %void None %func
  382. %main_entry = OpLabel
  383. )";
  384. ss << body;
  385. ss << R"(
  386. OpReturn
  387. OpFunctionEnd)";
  388. return ss.str();
  389. }
  390. TEST_P(ValidateGlslStd450SqrtLike, Success) {
  391. const std::string ext_inst_name = GetParam();
  392. std::ostringstream ss;
  393. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
  394. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  395. << " %f32vec2_01\n";
  396. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name << " %f64_0\n";
  397. CompileSuccessfully(GenerateShaderCode(ss.str()));
  398. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  399. }
  400. TEST_P(ValidateGlslStd450SqrtLike, IntResultType) {
  401. const std::string ext_inst_name = GetParam();
  402. const std::string body =
  403. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  404. CompileSuccessfully(GenerateShaderCode(body));
  405. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  406. EXPECT_THAT(getDiagnosticString(),
  407. HasSubstr("GLSL.std.450 " + ext_inst_name +
  408. ": expected Result Type to be a float scalar "
  409. "or vector type"));
  410. }
  411. TEST_P(ValidateGlslStd450SqrtLike, IntOperand) {
  412. const std::string ext_inst_name = GetParam();
  413. const std::string body =
  414. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  415. CompileSuccessfully(GenerateShaderCode(body));
  416. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  417. EXPECT_THAT(getDiagnosticString(),
  418. HasSubstr("GLSL.std.450 " + ext_inst_name +
  419. ": expected types of all operands to be equal to "
  420. "Result Type"));
  421. }
  422. INSTANTIATE_TEST_SUITE_P(AllSqrtLike, ValidateGlslStd450SqrtLike,
  423. ::testing::ValuesIn(std::vector<std::string>{
  424. "Round",
  425. "RoundEven",
  426. "FAbs",
  427. "Trunc",
  428. "FSign",
  429. "Floor",
  430. "Ceil",
  431. "Fract",
  432. "Sqrt",
  433. "InverseSqrt",
  434. "Normalize",
  435. }));
  436. TEST_P(ValidateGlslStd450FMinLike, Success) {
  437. const std::string ext_inst_name = GetParam();
  438. std::ostringstream ss;
  439. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  440. << " %f32_0 %f32_1\n";
  441. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  442. << " %f32vec2_01 %f32vec2_12\n";
  443. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  444. << " %f64_0 %f64_0\n";
  445. CompileSuccessfully(GenerateShaderCode(ss.str()));
  446. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  447. }
  448. TEST_P(ValidateGlslStd450FMinLike, IntResultType) {
  449. const std::string ext_inst_name = GetParam();
  450. const std::string body =
  451. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %f32_1\n";
  452. CompileSuccessfully(GenerateShaderCode(body));
  453. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  454. EXPECT_THAT(getDiagnosticString(),
  455. HasSubstr("GLSL.std.450 " + ext_inst_name +
  456. ": expected Result Type to be a float scalar "
  457. "or vector type"));
  458. }
  459. TEST_P(ValidateGlslStd450FMinLike, IntOperand1) {
  460. const std::string ext_inst_name = GetParam();
  461. const std::string body =
  462. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
  463. CompileSuccessfully(GenerateShaderCode(body));
  464. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  465. EXPECT_THAT(getDiagnosticString(),
  466. HasSubstr("GLSL.std.450 " + ext_inst_name +
  467. ": expected types of all operands to be equal to "
  468. "Result Type"));
  469. }
  470. TEST_P(ValidateGlslStd450FMinLike, IntOperand2) {
  471. const std::string ext_inst_name = GetParam();
  472. const std::string body =
  473. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
  474. CompileSuccessfully(GenerateShaderCode(body));
  475. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  476. EXPECT_THAT(getDiagnosticString(),
  477. HasSubstr("GLSL.std.450 " + ext_inst_name +
  478. ": expected types of all operands to be equal to "
  479. "Result Type"));
  480. }
  481. INSTANTIATE_TEST_SUITE_P(AllFMinLike, ValidateGlslStd450FMinLike,
  482. ::testing::ValuesIn(std::vector<std::string>{
  483. "FMin",
  484. "FMax",
  485. "Step",
  486. "Reflect",
  487. "NMin",
  488. "NMax",
  489. }));
  490. TEST_P(ValidateGlslStd450FClampLike, Success) {
  491. const std::string ext_inst_name = GetParam();
  492. std::ostringstream ss;
  493. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  494. << " %f32_0 %f32_1 %f32_2\n";
  495. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  496. << " %f32vec2_01 %f32vec2_01 %f32vec2_12\n";
  497. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  498. << " %f64_0 %f64_0 %f64_1\n";
  499. CompileSuccessfully(GenerateShaderCode(ss.str()));
  500. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  501. }
  502. TEST_P(ValidateGlslStd450FClampLike, IntResultType) {
  503. const std::string ext_inst_name = GetParam();
  504. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  505. " %f32_0 %f32_1 %f32_2\n";
  506. CompileSuccessfully(GenerateShaderCode(body));
  507. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  508. EXPECT_THAT(getDiagnosticString(),
  509. HasSubstr("GLSL.std.450 " + ext_inst_name +
  510. ": expected Result Type to be a float scalar "
  511. "or vector type"));
  512. }
  513. TEST_P(ValidateGlslStd450FClampLike, IntOperand1) {
  514. const std::string ext_inst_name = GetParam();
  515. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  516. " %u32_0 %f32_0 %f32_1\n";
  517. CompileSuccessfully(GenerateShaderCode(body));
  518. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  519. EXPECT_THAT(getDiagnosticString(),
  520. HasSubstr("GLSL.std.450 " + ext_inst_name +
  521. ": expected types of all operands to be equal to "
  522. "Result Type"));
  523. }
  524. TEST_P(ValidateGlslStd450FClampLike, IntOperand2) {
  525. const std::string ext_inst_name = GetParam();
  526. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  527. " %f32_0 %u32_0 %f32_1\n";
  528. CompileSuccessfully(GenerateShaderCode(body));
  529. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  530. EXPECT_THAT(getDiagnosticString(),
  531. HasSubstr("GLSL.std.450 " + ext_inst_name +
  532. ": expected types of all operands to be equal to "
  533. "Result Type"));
  534. }
  535. TEST_P(ValidateGlslStd450FClampLike, IntOperand3) {
  536. const std::string ext_inst_name = GetParam();
  537. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  538. " %f32_1 %f32_0 %u32_2\n";
  539. CompileSuccessfully(GenerateShaderCode(body));
  540. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  541. EXPECT_THAT(getDiagnosticString(),
  542. HasSubstr("GLSL.std.450 " + ext_inst_name +
  543. ": expected types of all operands to be equal to "
  544. "Result Type"));
  545. }
  546. INSTANTIATE_TEST_SUITE_P(AllFClampLike, ValidateGlslStd450FClampLike,
  547. ::testing::ValuesIn(std::vector<std::string>{
  548. "FClamp",
  549. "FMix",
  550. "SmoothStep",
  551. "Fma",
  552. "FaceForward",
  553. "NClamp",
  554. }));
  555. TEST_P(ValidateGlslStd450SAbsLike, Success) {
  556. const std::string ext_inst_name = GetParam();
  557. std::ostringstream ss;
  558. ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name << " %u32_1\n";
  559. ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name << " %s32_1\n";
  560. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  561. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name << " %s32_1\n";
  562. ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  563. << " %s32vec2_01\n";
  564. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  565. << " %u32vec2_01\n";
  566. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  567. << " %s32vec2_01\n";
  568. ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  569. << " %u32vec2_01\n";
  570. CompileSuccessfully(GenerateShaderCode(ss.str()));
  571. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  572. }
  573. TEST_P(ValidateGlslStd450SAbsLike, FloatResultType) {
  574. const std::string ext_inst_name = GetParam();
  575. const std::string body =
  576. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  577. CompileSuccessfully(GenerateShaderCode(body));
  578. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  579. EXPECT_THAT(getDiagnosticString(),
  580. HasSubstr("GLSL.std.450 " + ext_inst_name +
  581. ": expected Result Type to be an int scalar "
  582. "or vector type"));
  583. }
  584. TEST_P(ValidateGlslStd450SAbsLike, FloatOperand) {
  585. const std::string ext_inst_name = GetParam();
  586. const std::string body =
  587. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %f32_0\n";
  588. CompileSuccessfully(GenerateShaderCode(body));
  589. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  590. EXPECT_THAT(getDiagnosticString(),
  591. HasSubstr("GLSL.std.450 " + ext_inst_name +
  592. ": expected all operands to be int scalars or "
  593. "vectors"));
  594. }
  595. TEST_P(ValidateGlslStd450SAbsLike, WrongDimOperand) {
  596. const std::string ext_inst_name = GetParam();
  597. const std::string body =
  598. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %s32vec2_01\n";
  599. CompileSuccessfully(GenerateShaderCode(body));
  600. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  601. EXPECT_THAT(getDiagnosticString(),
  602. HasSubstr("GLSL.std.450 " + ext_inst_name +
  603. ": expected all operands to have the same dimension as "
  604. "Result Type"));
  605. }
  606. TEST_P(ValidateGlslStd450SAbsLike, WrongBitWidthOperand) {
  607. const std::string ext_inst_name = GetParam();
  608. const std::string body =
  609. "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s32_0\n";
  610. CompileSuccessfully(GenerateShaderCode(body));
  611. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  612. EXPECT_THAT(getDiagnosticString(),
  613. HasSubstr("GLSL.std.450 " + ext_inst_name +
  614. ": expected all operands to have the same bit width as "
  615. "Result Type"));
  616. }
  617. TEST_P(ValidateGlslStd450SAbsLike, TypelessOperand) {
  618. const std::string ext_inst_name = GetParam();
  619. const std::string body =
  620. "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %main_entry\n";
  621. CompileSuccessfully(GenerateShaderCode(body));
  622. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  623. EXPECT_THAT(
  624. getDiagnosticString(),
  625. HasSubstr("GLSL.std.450 " + ext_inst_name +
  626. ": expected all operands to be int scalars or vectors"));
  627. }
  628. INSTANTIATE_TEST_SUITE_P(AllSAbsLike, ValidateGlslStd450SAbsLike,
  629. ::testing::ValuesIn(std::vector<std::string>{
  630. "SAbs",
  631. "SSign",
  632. "FindILsb",
  633. "FindUMsb",
  634. "FindSMsb",
  635. }));
  636. TEST_F(ValidateExtInst, FindUMsbNot32Bit) {
  637. const std::string body = R"(
  638. %val1 = OpExtInst %s64 %extinst FindUMsb %u64_1
  639. )";
  640. CompileSuccessfully(GenerateShaderCode(body));
  641. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  642. EXPECT_THAT(getDiagnosticString(),
  643. HasSubstr("GLSL.std.450 FindUMsb: this instruction is currently "
  644. "limited to 32-bit width components"));
  645. }
  646. TEST_F(ValidateExtInst, FindSMsbNot32Bit) {
  647. const std::string body = R"(
  648. %val1 = OpExtInst %s64 %extinst FindSMsb %u64_1
  649. )";
  650. CompileSuccessfully(GenerateShaderCode(body));
  651. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  652. EXPECT_THAT(getDiagnosticString(),
  653. HasSubstr("GLSL.std.450 FindSMsb: this instruction is currently "
  654. "limited to 32-bit width components"));
  655. }
  656. TEST_P(ValidateGlslStd450UMinLike, Success) {
  657. const std::string ext_inst_name = GetParam();
  658. std::ostringstream ss;
  659. ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name
  660. << " %u32_1 %s32_2\n";
  661. ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name
  662. << " %s32_1 %u32_2\n";
  663. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  664. << " %u32_1 %s32_2\n";
  665. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  666. << " %s32_1 %u32_2\n";
  667. ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  668. << " %s32vec2_01 %u32vec2_01\n";
  669. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  670. << " %u32vec2_01 %s32vec2_01\n";
  671. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  672. << " %s32vec2_01 %u32vec2_01\n";
  673. ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  674. << " %u32vec2_01 %s32vec2_01\n";
  675. ss << "%val9 = OpExtInst %s64 %extinst " << ext_inst_name
  676. << " %u64_1 %s64_0\n";
  677. CompileSuccessfully(GenerateShaderCode(ss.str()));
  678. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  679. }
  680. TEST_P(ValidateGlslStd450UMinLike, FloatResultType) {
  681. const std::string ext_inst_name = GetParam();
  682. const std::string body =
  683. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
  684. CompileSuccessfully(GenerateShaderCode(body));
  685. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  686. EXPECT_THAT(getDiagnosticString(),
  687. HasSubstr("GLSL.std.450 " + ext_inst_name +
  688. ": expected Result Type to be an int scalar "
  689. "or vector type"));
  690. }
  691. TEST_P(ValidateGlslStd450UMinLike, FloatOperand1) {
  692. const std::string ext_inst_name = GetParam();
  693. const std::string body =
  694. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
  695. CompileSuccessfully(GenerateShaderCode(body));
  696. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  697. EXPECT_THAT(getDiagnosticString(),
  698. HasSubstr("GLSL.std.450 " + ext_inst_name +
  699. ": expected all operands to be int scalars or "
  700. "vectors"));
  701. }
  702. TEST_P(ValidateGlslStd450UMinLike, FloatOperand2) {
  703. const std::string ext_inst_name = GetParam();
  704. const std::string body =
  705. "%val1 = OpExtInst %s32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
  706. CompileSuccessfully(GenerateShaderCode(body));
  707. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  708. EXPECT_THAT(getDiagnosticString(),
  709. HasSubstr("GLSL.std.450 " + ext_inst_name +
  710. ": expected all operands to be int scalars or "
  711. "vectors"));
  712. }
  713. TEST_P(ValidateGlslStd450UMinLike, WrongDimOperand1) {
  714. const std::string ext_inst_name = GetParam();
  715. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  716. " %s32vec2_01 %s32_0\n";
  717. CompileSuccessfully(GenerateShaderCode(body));
  718. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  719. EXPECT_THAT(getDiagnosticString(),
  720. HasSubstr("GLSL.std.450 " + ext_inst_name +
  721. ": expected all operands to have the same dimension as "
  722. "Result Type"));
  723. }
  724. TEST_P(ValidateGlslStd450UMinLike, WrongDimOperand2) {
  725. const std::string ext_inst_name = GetParam();
  726. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  727. " %s32_0 %s32vec2_01\n";
  728. CompileSuccessfully(GenerateShaderCode(body));
  729. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  730. EXPECT_THAT(getDiagnosticString(),
  731. HasSubstr("GLSL.std.450 " + ext_inst_name +
  732. ": expected all operands to have the same dimension as "
  733. "Result Type"));
  734. }
  735. TEST_P(ValidateGlslStd450UMinLike, WrongBitWidthOperand1) {
  736. const std::string ext_inst_name = GetParam();
  737. const std::string body =
  738. "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s32_0 %s64_0\n";
  739. CompileSuccessfully(GenerateShaderCode(body));
  740. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  741. EXPECT_THAT(getDiagnosticString(),
  742. HasSubstr("GLSL.std.450 " + ext_inst_name +
  743. ": expected all operands to have the same bit width as "
  744. "Result Type"));
  745. }
  746. TEST_P(ValidateGlslStd450UMinLike, WrongBitWidthOperand2) {
  747. const std::string ext_inst_name = GetParam();
  748. const std::string body =
  749. "%val1 = OpExtInst %s64 %extinst " + ext_inst_name + " %s64_0 %s32_0\n";
  750. CompileSuccessfully(GenerateShaderCode(body));
  751. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  752. EXPECT_THAT(getDiagnosticString(),
  753. HasSubstr("GLSL.std.450 " + ext_inst_name +
  754. ": expected all operands to have the same bit width as "
  755. "Result Type"));
  756. }
  757. TEST_P(ValidateGlslStd450UMinLike, TypelessOperand) {
  758. const std::string ext_inst_name = GetParam();
  759. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  760. " %s64_0 %main_entry\n";
  761. CompileSuccessfully(GenerateShaderCode(body));
  762. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  763. EXPECT_THAT(
  764. getDiagnosticString(),
  765. HasSubstr("GLSL.std.450 " + ext_inst_name +
  766. ": expected all operands to be int scalars or vectors"));
  767. }
  768. INSTANTIATE_TEST_SUITE_P(AllUMinLike, ValidateGlslStd450UMinLike,
  769. ::testing::ValuesIn(std::vector<std::string>{
  770. "UMin",
  771. "SMin",
  772. "UMax",
  773. "SMax",
  774. }));
  775. TEST_P(ValidateGlslStd450UClampLike, Success) {
  776. const std::string ext_inst_name = GetParam();
  777. std::ostringstream ss;
  778. ss << "%val1 = OpExtInst %s32 %extinst " << ext_inst_name
  779. << " %s32_0 %u32_1 %s32_2\n";
  780. ss << "%val2 = OpExtInst %s32 %extinst " << ext_inst_name
  781. << " %u32_0 %s32_1 %u32_2\n";
  782. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  783. << " %s32_0 %u32_1 %s32_2\n";
  784. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  785. << " %u32_0 %s32_1 %u32_2\n";
  786. ss << "%val5 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  787. << " %s32vec2_01 %u32vec2_01 %u32vec2_12\n";
  788. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  789. << " %u32vec2_01 %s32vec2_01 %s32vec2_12\n";
  790. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  791. << " %s32vec2_01 %u32vec2_01 %u32vec2_12\n";
  792. ss << "%val8 = OpExtInst %s32vec2 %extinst " << ext_inst_name
  793. << " %u32vec2_01 %s32vec2_01 %s32vec2_12\n";
  794. ss << "%val9 = OpExtInst %s64 %extinst " << ext_inst_name
  795. << " %u64_1 %s64_0 %s64_1\n";
  796. CompileSuccessfully(GenerateShaderCode(ss.str()));
  797. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  798. }
  799. TEST_P(ValidateGlslStd450UClampLike, FloatResultType) {
  800. const std::string ext_inst_name = GetParam();
  801. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  802. " %u32_0 %u32_0 %u32_1\n";
  803. CompileSuccessfully(GenerateShaderCode(body));
  804. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  805. EXPECT_THAT(getDiagnosticString(),
  806. HasSubstr("GLSL.std.450 " + ext_inst_name +
  807. ": expected Result Type to be an int scalar "
  808. "or vector type"));
  809. }
  810. TEST_P(ValidateGlslStd450UClampLike, FloatOperand1) {
  811. const std::string ext_inst_name = GetParam();
  812. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  813. " %f32_0 %u32_0 %u32_1\n";
  814. CompileSuccessfully(GenerateShaderCode(body));
  815. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  816. EXPECT_THAT(getDiagnosticString(),
  817. HasSubstr("GLSL.std.450 " + ext_inst_name +
  818. ": expected all operands to be int scalars or "
  819. "vectors"));
  820. }
  821. TEST_P(ValidateGlslStd450UClampLike, FloatOperand2) {
  822. const std::string ext_inst_name = GetParam();
  823. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  824. " %u32_0 %f32_0 %u32_1\n";
  825. CompileSuccessfully(GenerateShaderCode(body));
  826. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  827. EXPECT_THAT(getDiagnosticString(),
  828. HasSubstr("GLSL.std.450 " + ext_inst_name +
  829. ": expected all operands to be int scalars or "
  830. "vectors"));
  831. }
  832. TEST_P(ValidateGlslStd450UClampLike, FloatOperand3) {
  833. const std::string ext_inst_name = GetParam();
  834. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  835. " %u32_0 %u32_0 %f32_1\n";
  836. CompileSuccessfully(GenerateShaderCode(body));
  837. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  838. EXPECT_THAT(getDiagnosticString(),
  839. HasSubstr("GLSL.std.450 " + ext_inst_name +
  840. ": expected all operands to be int scalars or "
  841. "vectors"));
  842. }
  843. TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand1) {
  844. const std::string ext_inst_name = GetParam();
  845. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  846. " %s32vec2_01 %s32_0 %u32_1\n";
  847. CompileSuccessfully(GenerateShaderCode(body));
  848. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  849. EXPECT_THAT(getDiagnosticString(),
  850. HasSubstr("GLSL.std.450 " + ext_inst_name +
  851. ": expected all operands to have the same dimension as "
  852. "Result Type"));
  853. }
  854. TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand2) {
  855. const std::string ext_inst_name = GetParam();
  856. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  857. " %s32_0 %s32vec2_01 %u32_1\n";
  858. CompileSuccessfully(GenerateShaderCode(body));
  859. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  860. EXPECT_THAT(getDiagnosticString(),
  861. HasSubstr("GLSL.std.450 " + ext_inst_name +
  862. ": expected all operands to have the same dimension as "
  863. "Result Type"));
  864. }
  865. TEST_P(ValidateGlslStd450UClampLike, WrongDimOperand3) {
  866. const std::string ext_inst_name = GetParam();
  867. const std::string body = "%val1 = OpExtInst %s32 %extinst " + ext_inst_name +
  868. " %s32_0 %u32_1 %s32vec2_01\n";
  869. CompileSuccessfully(GenerateShaderCode(body));
  870. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  871. EXPECT_THAT(getDiagnosticString(),
  872. HasSubstr("GLSL.std.450 " + ext_inst_name +
  873. ": expected all operands to have the same dimension as "
  874. "Result Type"));
  875. }
  876. TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand1) {
  877. const std::string ext_inst_name = GetParam();
  878. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  879. " %s32_0 %s64_0 %s64_1\n";
  880. CompileSuccessfully(GenerateShaderCode(body));
  881. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  882. EXPECT_THAT(getDiagnosticString(),
  883. HasSubstr("GLSL.std.450 " + ext_inst_name +
  884. ": expected all operands to have the same bit width as "
  885. "Result Type"));
  886. }
  887. TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand2) {
  888. const std::string ext_inst_name = GetParam();
  889. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  890. " %s64_0 %s32_0 %s64_1\n";
  891. CompileSuccessfully(GenerateShaderCode(body));
  892. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  893. EXPECT_THAT(getDiagnosticString(),
  894. HasSubstr("GLSL.std.450 " + ext_inst_name +
  895. ": expected all operands to have the same bit width as "
  896. "Result Type"));
  897. }
  898. TEST_P(ValidateGlslStd450UClampLike, WrongBitWidthOperand3) {
  899. const std::string ext_inst_name = GetParam();
  900. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  901. " %s64_0 %s64_0 %s32_1\n";
  902. CompileSuccessfully(GenerateShaderCode(body));
  903. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  904. EXPECT_THAT(getDiagnosticString(),
  905. HasSubstr("GLSL.std.450 " + ext_inst_name +
  906. ": expected all operands to have the same bit width as "
  907. "Result Type"));
  908. }
  909. TEST_P(ValidateGlslStd450UClampLike, TypelessOperand) {
  910. const std::string ext_inst_name = GetParam();
  911. const std::string body = "%val1 = OpExtInst %s64 %extinst " + ext_inst_name +
  912. " %main_entry %s64_0 %s64_0\n";
  913. CompileSuccessfully(GenerateShaderCode(body));
  914. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  915. EXPECT_THAT(
  916. getDiagnosticString(),
  917. HasSubstr("GLSL.std.450 " + ext_inst_name +
  918. ": expected all operands to be int scalars or vectors"));
  919. }
  920. INSTANTIATE_TEST_SUITE_P(AllUClampLike, ValidateGlslStd450UClampLike,
  921. ::testing::ValuesIn(std::vector<std::string>{
  922. "UClamp",
  923. "SClamp",
  924. }));
  925. TEST_P(ValidateGlslStd450SinLike, Success) {
  926. const std::string ext_inst_name = GetParam();
  927. std::ostringstream ss;
  928. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
  929. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  930. << " %f32vec2_01\n";
  931. CompileSuccessfully(GenerateShaderCode(ss.str()));
  932. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  933. }
  934. TEST_P(ValidateGlslStd450SinLike, IntResultType) {
  935. const std::string ext_inst_name = GetParam();
  936. const std::string body =
  937. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  938. CompileSuccessfully(GenerateShaderCode(body));
  939. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  940. EXPECT_THAT(getDiagnosticString(),
  941. HasSubstr("GLSL.std.450 " + ext_inst_name +
  942. ": expected Result Type to be a 16 or 32-bit scalar "
  943. "or vector float type"));
  944. }
  945. TEST_P(ValidateGlslStd450SinLike, F64ResultType) {
  946. const std::string ext_inst_name = GetParam();
  947. const std::string body =
  948. "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32_0\n";
  949. CompileSuccessfully(GenerateShaderCode(body));
  950. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  951. EXPECT_THAT(getDiagnosticString(),
  952. HasSubstr("GLSL.std.450 " + ext_inst_name +
  953. ": expected Result Type to be a 16 or 32-bit scalar "
  954. "or vector float type"));
  955. }
  956. TEST_P(ValidateGlslStd450SinLike, IntOperand) {
  957. const std::string ext_inst_name = GetParam();
  958. const std::string body =
  959. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  960. CompileSuccessfully(GenerateShaderCode(body));
  961. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  962. EXPECT_THAT(getDiagnosticString(),
  963. HasSubstr("GLSL.std.450 " + ext_inst_name +
  964. ": expected types of all operands to be equal to "
  965. "Result Type"));
  966. }
  967. INSTANTIATE_TEST_SUITE_P(AllSinLike, ValidateGlslStd450SinLike,
  968. ::testing::ValuesIn(std::vector<std::string>{
  969. "Radians",
  970. "Degrees",
  971. "Sin",
  972. "Cos",
  973. "Tan",
  974. "Asin",
  975. "Acos",
  976. "Atan",
  977. "Sinh",
  978. "Cosh",
  979. "Tanh",
  980. "Asinh",
  981. "Acosh",
  982. "Atanh",
  983. "Exp",
  984. "Exp2",
  985. "Log",
  986. "Log2",
  987. }));
  988. TEST_P(ValidateGlslStd450PowLike, Success) {
  989. const std::string ext_inst_name = GetParam();
  990. std::ostringstream ss;
  991. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  992. << " %f32_1 %f32_1\n";
  993. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  994. << " %f32vec2_01 %f32vec2_12\n";
  995. CompileSuccessfully(GenerateShaderCode(ss.str()));
  996. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  997. }
  998. TEST_P(ValidateGlslStd450PowLike, IntResultType) {
  999. const std::string ext_inst_name = GetParam();
  1000. const std::string body =
  1001. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_1 %f32_0\n";
  1002. CompileSuccessfully(GenerateShaderCode(body));
  1003. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1004. EXPECT_THAT(getDiagnosticString(),
  1005. HasSubstr("GLSL.std.450 " + ext_inst_name +
  1006. ": expected Result Type to be a 16 or 32-bit scalar "
  1007. "or vector float type"));
  1008. }
  1009. TEST_P(ValidateGlslStd450PowLike, F64ResultType) {
  1010. const std::string ext_inst_name = GetParam();
  1011. const std::string body =
  1012. "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32_1 %f32_0\n";
  1013. CompileSuccessfully(GenerateShaderCode(body));
  1014. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1015. EXPECT_THAT(getDiagnosticString(),
  1016. HasSubstr("GLSL.std.450 " + ext_inst_name +
  1017. ": expected Result Type to be a 16 or 32-bit scalar "
  1018. "or vector float type"));
  1019. }
  1020. TEST_P(ValidateGlslStd450PowLike, IntOperand1) {
  1021. const std::string ext_inst_name = GetParam();
  1022. const std::string body =
  1023. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
  1024. CompileSuccessfully(GenerateShaderCode(body));
  1025. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1026. EXPECT_THAT(getDiagnosticString(),
  1027. HasSubstr("GLSL.std.450 " + ext_inst_name +
  1028. ": expected types of all operands to be equal to "
  1029. "Result Type"));
  1030. }
  1031. TEST_P(ValidateGlslStd450PowLike, IntOperand2) {
  1032. const std::string ext_inst_name = GetParam();
  1033. const std::string body =
  1034. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
  1035. CompileSuccessfully(GenerateShaderCode(body));
  1036. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1037. EXPECT_THAT(getDiagnosticString(),
  1038. HasSubstr("GLSL.std.450 " + ext_inst_name +
  1039. ": expected types of all operands to be equal to "
  1040. "Result Type"));
  1041. }
  1042. INSTANTIATE_TEST_SUITE_P(AllPowLike, ValidateGlslStd450PowLike,
  1043. ::testing::ValuesIn(std::vector<std::string>{
  1044. "Atan2",
  1045. "Pow",
  1046. }));
  1047. TEST_F(ValidateExtInst, GlslStd450DeterminantSuccess) {
  1048. const std::string body = R"(
  1049. %val1 = OpExtInst %f32 %extinst Determinant %f32mat22_1212
  1050. )";
  1051. CompileSuccessfully(GenerateShaderCode(body));
  1052. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1053. }
  1054. TEST_F(ValidateExtInst, GlslStd450DeterminantIncompatibleResultType) {
  1055. const std::string body = R"(
  1056. %val1 = OpExtInst %f64 %extinst Determinant %f32mat22_1212
  1057. )";
  1058. CompileSuccessfully(GenerateShaderCode(body));
  1059. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1060. EXPECT_THAT(getDiagnosticString(),
  1061. HasSubstr("GLSL.std.450 Determinant: "
  1062. "expected operand X component type to be equal to "
  1063. "Result Type"));
  1064. }
  1065. TEST_F(ValidateExtInst, GlslStd450DeterminantNotMatrix) {
  1066. const std::string body = R"(
  1067. %val1 = OpExtInst %f32 %extinst Determinant %f32_1
  1068. )";
  1069. CompileSuccessfully(GenerateShaderCode(body));
  1070. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1071. EXPECT_THAT(getDiagnosticString(),
  1072. HasSubstr("GLSL.std.450 Determinant: "
  1073. "expected operand X to be a square matrix"));
  1074. }
  1075. TEST_F(ValidateExtInst, GlslStd450DeterminantMatrixNotSquare) {
  1076. const std::string body = R"(
  1077. %val1 = OpExtInst %f32 %extinst Determinant %f32mat23_121212
  1078. )";
  1079. CompileSuccessfully(GenerateShaderCode(body));
  1080. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1081. EXPECT_THAT(getDiagnosticString(),
  1082. HasSubstr("GLSL.std.450 Determinant: "
  1083. "expected operand X to be a square matrix"));
  1084. }
  1085. TEST_F(ValidateExtInst, GlslStd450MatrixInverseSuccess) {
  1086. const std::string body = R"(
  1087. %val1 = OpExtInst %f32mat22 %extinst MatrixInverse %f32mat22_1212
  1088. )";
  1089. CompileSuccessfully(GenerateShaderCode(body));
  1090. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1091. }
  1092. TEST_F(ValidateExtInst, GlslStd450MatrixInverseIncompatibleResultType) {
  1093. const std::string body = R"(
  1094. %val1 = OpExtInst %f32mat33 %extinst MatrixInverse %f32mat22_1212
  1095. )";
  1096. CompileSuccessfully(GenerateShaderCode(body));
  1097. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1098. EXPECT_THAT(getDiagnosticString(),
  1099. HasSubstr("GLSL.std.450 MatrixInverse: "
  1100. "expected operand X type to be equal to "
  1101. "Result Type"));
  1102. }
  1103. TEST_F(ValidateExtInst, GlslStd450MatrixInverseNotMatrix) {
  1104. const std::string body = R"(
  1105. %val1 = OpExtInst %f32 %extinst MatrixInverse %f32mat22_1212
  1106. )";
  1107. CompileSuccessfully(GenerateShaderCode(body));
  1108. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1109. EXPECT_THAT(getDiagnosticString(),
  1110. HasSubstr("GLSL.std.450 MatrixInverse: "
  1111. "expected Result Type to be a square matrix"));
  1112. }
  1113. TEST_F(ValidateExtInst, GlslStd450MatrixInverseMatrixNotSquare) {
  1114. const std::string body = R"(
  1115. %val1 = OpExtInst %f32mat23 %extinst MatrixInverse %f32mat23_121212
  1116. )";
  1117. CompileSuccessfully(GenerateShaderCode(body));
  1118. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1119. EXPECT_THAT(getDiagnosticString(),
  1120. HasSubstr("GLSL.std.450 MatrixInverse: "
  1121. "expected Result Type to be a square matrix"));
  1122. }
  1123. TEST_F(ValidateExtInst, GlslStd450ModfSuccess) {
  1124. const std::string body = R"(
  1125. %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32_output
  1126. %val2 = OpExtInst %f32vec2 %extinst Modf %f32vec2_01 %f32vec2_output
  1127. )";
  1128. CompileSuccessfully(GenerateShaderCode(body));
  1129. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1130. }
  1131. TEST_F(ValidateExtInst, GlslStd450ModfIntResultType) {
  1132. const std::string body = R"(
  1133. %val1 = OpExtInst %u32 %extinst Modf %f32_h %f32_output
  1134. )";
  1135. CompileSuccessfully(GenerateShaderCode(body));
  1136. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1137. EXPECT_THAT(getDiagnosticString(),
  1138. HasSubstr("GLSL.std.450 Modf: "
  1139. "expected Result Type to be a scalar or vector "
  1140. "float type"));
  1141. }
  1142. TEST_F(ValidateExtInst, GlslStd450ModfXNotOfResultType) {
  1143. const std::string body = R"(
  1144. %val1 = OpExtInst %f32 %extinst Modf %f64_0 %f32_output
  1145. )";
  1146. CompileSuccessfully(GenerateShaderCode(body));
  1147. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1148. EXPECT_THAT(getDiagnosticString(),
  1149. HasSubstr("GLSL.std.450 Modf: "
  1150. "expected operand X type to be equal to Result Type"));
  1151. }
  1152. TEST_F(ValidateExtInst, GlslStd450ModfINotPointer) {
  1153. const std::string body = R"(
  1154. %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32_1
  1155. )";
  1156. CompileSuccessfully(GenerateShaderCode(body));
  1157. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1158. EXPECT_THAT(getDiagnosticString(),
  1159. HasSubstr("GLSL.std.450 Modf: "
  1160. "expected operand I to be a pointer"));
  1161. }
  1162. TEST_F(ValidateExtInst, GlslStd450ModfIDataNotOfResultType) {
  1163. const std::string body = R"(
  1164. %val1 = OpExtInst %f32 %extinst Modf %f32_h %f32vec2_output
  1165. )";
  1166. CompileSuccessfully(GenerateShaderCode(body));
  1167. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1168. EXPECT_THAT(getDiagnosticString(),
  1169. HasSubstr("GLSL.std.450 Modf: "
  1170. "expected operand I data type to be equal to "
  1171. "Result Type"));
  1172. }
  1173. TEST_F(ValidateExtInst, GlslStd450ModfStructSuccess) {
  1174. const std::string body = R"(
  1175. %val1 = OpExtInst %struct_f32_f32 %extinst ModfStruct %f32_h
  1176. %val2 = OpExtInst %struct_f32vec2_f32vec2 %extinst ModfStruct %f32vec2_01
  1177. )";
  1178. CompileSuccessfully(GenerateShaderCode(body));
  1179. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1180. }
  1181. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeNotStruct) {
  1182. const std::string body = R"(
  1183. %val1 = OpExtInst %f32 %extinst ModfStruct %f32_h
  1184. )";
  1185. CompileSuccessfully(GenerateShaderCode(body));
  1186. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1187. EXPECT_THAT(getDiagnosticString(),
  1188. HasSubstr("GLSL.std.450 ModfStruct: "
  1189. "expected Result Type to be a struct with two "
  1190. "identical scalar or vector float type members"));
  1191. }
  1192. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructWrongSize) {
  1193. const std::string body = R"(
  1194. %val1 = OpExtInst %struct_f32_f32_f32 %extinst ModfStruct %f32_h
  1195. )";
  1196. CompileSuccessfully(GenerateShaderCode(body));
  1197. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1198. EXPECT_THAT(getDiagnosticString(),
  1199. HasSubstr("GLSL.std.450 ModfStruct: "
  1200. "expected Result Type to be a struct with two "
  1201. "identical scalar or vector float type members"));
  1202. }
  1203. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructWrongFirstMember) {
  1204. const std::string body = R"(
  1205. %val1 = OpExtInst %struct_u32_f32 %extinst ModfStruct %f32_h
  1206. )";
  1207. CompileSuccessfully(GenerateShaderCode(body));
  1208. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1209. EXPECT_THAT(getDiagnosticString(),
  1210. HasSubstr("GLSL.std.450 ModfStruct: "
  1211. "expected Result Type to be a struct with two "
  1212. "identical scalar or vector float type members"));
  1213. }
  1214. TEST_F(ValidateExtInst, GlslStd450ModfStructResultTypeStructMembersNotEqual) {
  1215. const std::string body = R"(
  1216. %val1 = OpExtInst %struct_f32_f64 %extinst ModfStruct %f32_h
  1217. )";
  1218. CompileSuccessfully(GenerateShaderCode(body));
  1219. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1220. EXPECT_THAT(getDiagnosticString(),
  1221. HasSubstr("GLSL.std.450 ModfStruct: "
  1222. "expected Result Type to be a struct with two "
  1223. "identical scalar or vector float type members"));
  1224. }
  1225. TEST_F(ValidateExtInst, GlslStd450ModfStructXWrongType) {
  1226. const std::string body = R"(
  1227. %val1 = OpExtInst %struct_f32_f32 %extinst ModfStruct %f64_0
  1228. )";
  1229. CompileSuccessfully(GenerateShaderCode(body));
  1230. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1231. EXPECT_THAT(getDiagnosticString(),
  1232. HasSubstr("GLSL.std.450 ModfStruct: "
  1233. "expected operand X type to be equal to members of "
  1234. "Result Type struct"));
  1235. }
  1236. TEST_F(ValidateExtInst, GlslStd450FrexpSuccess) {
  1237. const std::string body = R"(
  1238. %val1 = OpExtInst %f32 %extinst Frexp %f32_h %u32_output
  1239. %val2 = OpExtInst %f32vec2 %extinst Frexp %f32vec2_01 %u32vec2_output
  1240. )";
  1241. CompileSuccessfully(GenerateShaderCode(body));
  1242. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1243. }
  1244. TEST_F(ValidateExtInst, GlslStd450FrexpIntResultType) {
  1245. const std::string body = R"(
  1246. %val1 = OpExtInst %u32 %extinst Frexp %f32_h %u32_output
  1247. )";
  1248. CompileSuccessfully(GenerateShaderCode(body));
  1249. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1250. EXPECT_THAT(getDiagnosticString(),
  1251. HasSubstr("GLSL.std.450 Frexp: "
  1252. "expected Result Type to be a scalar or vector "
  1253. "float type"));
  1254. }
  1255. TEST_F(ValidateExtInst, GlslStd450FrexpWrongXType) {
  1256. const std::string body = R"(
  1257. %val1 = OpExtInst %f32 %extinst Frexp %u32_1 %u32_output
  1258. )";
  1259. CompileSuccessfully(GenerateShaderCode(body));
  1260. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1261. EXPECT_THAT(getDiagnosticString(),
  1262. HasSubstr("GLSL.std.450 Frexp: "
  1263. "expected operand X type to be equal to Result Type"));
  1264. }
  1265. TEST_F(ValidateExtInst, GlslStd450FrexpExpNotPointer) {
  1266. const std::string body = R"(
  1267. %val1 = OpExtInst %f32 %extinst Frexp %f32_1 %u32_1
  1268. )";
  1269. CompileSuccessfully(GenerateShaderCode(body));
  1270. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1271. EXPECT_THAT(getDiagnosticString(),
  1272. HasSubstr("GLSL.std.450 Frexp: "
  1273. "expected operand Exp to be a pointer"));
  1274. }
  1275. TEST_F(ValidateExtInst, GlslStd450FrexpExpNotInt32Pointer) {
  1276. const std::string body = R"(
  1277. %val1 = OpExtInst %f32 %extinst Frexp %f32_1 %f32_output
  1278. )";
  1279. CompileSuccessfully(GenerateShaderCode(body));
  1280. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1281. EXPECT_THAT(getDiagnosticString(),
  1282. HasSubstr("GLSL.std.450 Frexp: "
  1283. "expected operand Exp data type to be a 32-bit int "
  1284. "scalar or vector type"));
  1285. }
  1286. TEST_F(ValidateExtInst, GlslStd450FrexpExpWrongComponentNumber) {
  1287. const std::string body = R"(
  1288. %val1 = OpExtInst %f32vec2 %extinst Frexp %f32vec2_01 %u32_output
  1289. )";
  1290. CompileSuccessfully(GenerateShaderCode(body));
  1291. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1292. EXPECT_THAT(getDiagnosticString(),
  1293. HasSubstr("GLSL.std.450 Frexp: "
  1294. "expected operand Exp data type to have the same "
  1295. "component number as Result Type"));
  1296. }
  1297. TEST_F(ValidateExtInst, GlslStd450LdexpSuccess) {
  1298. const std::string body = R"(
  1299. %val1 = OpExtInst %f32 %extinst Ldexp %f32_h %u32_2
  1300. %val2 = OpExtInst %f32vec2 %extinst Ldexp %f32vec2_01 %u32vec2_12
  1301. %val3 = OpExtInst %f32 %extinst Ldexp %f32_h %u64_1
  1302. )";
  1303. CompileSuccessfully(GenerateShaderCode(body));
  1304. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1305. }
  1306. TEST_F(ValidateExtInst, GlslStd450LdexpIntResultType) {
  1307. const std::string body = R"(
  1308. %val1 = OpExtInst %u32 %extinst Ldexp %f32_h %u32_2
  1309. )";
  1310. CompileSuccessfully(GenerateShaderCode(body));
  1311. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1312. EXPECT_THAT(getDiagnosticString(),
  1313. HasSubstr("GLSL.std.450 Ldexp: "
  1314. "expected Result Type to be a scalar or vector "
  1315. "float type"));
  1316. }
  1317. TEST_F(ValidateExtInst, GlslStd450LdexpWrongXType) {
  1318. const std::string body = R"(
  1319. %val1 = OpExtInst %f32 %extinst Ldexp %u32_1 %u32_2
  1320. )";
  1321. CompileSuccessfully(GenerateShaderCode(body));
  1322. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1323. EXPECT_THAT(getDiagnosticString(),
  1324. HasSubstr("GLSL.std.450 Ldexp: "
  1325. "expected operand X type to be equal to Result Type"));
  1326. }
  1327. TEST_F(ValidateExtInst, GlslStd450LdexpFloatExp) {
  1328. const std::string body = R"(
  1329. %val1 = OpExtInst %f32 %extinst Ldexp %f32_1 %f32_2
  1330. )";
  1331. CompileSuccessfully(GenerateShaderCode(body));
  1332. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1333. EXPECT_THAT(getDiagnosticString(),
  1334. HasSubstr("GLSL.std.450 Ldexp: "
  1335. "expected operand Exp to be a 32-bit int scalar "
  1336. "or vector type"));
  1337. }
  1338. TEST_F(ValidateExtInst, GlslStd450LdexpExpWrongSize) {
  1339. const std::string body = R"(
  1340. %val1 = OpExtInst %f32vec2 %extinst Ldexp %f32vec2_12 %u32_2
  1341. )";
  1342. CompileSuccessfully(GenerateShaderCode(body));
  1343. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1344. EXPECT_THAT(getDiagnosticString(),
  1345. HasSubstr("GLSL.std.450 Ldexp: "
  1346. "expected operand Exp to have the same component "
  1347. "number as Result Type"));
  1348. }
  1349. TEST_F(ValidateExtInst, GlslStd450LdexpExpNoType) {
  1350. const std::string body = R"(
  1351. %val1 = OpExtInst %f32 %extinst Ldexp %f32_1 %main_entry
  1352. )";
  1353. CompileSuccessfully(GenerateShaderCode(body));
  1354. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1355. EXPECT_THAT(getDiagnosticString(),
  1356. HasSubstr("GLSL.std.450 Ldexp: "
  1357. "expected operand Exp to be a 32-bit int scalar "
  1358. "or vector type"));
  1359. }
  1360. TEST_F(ValidateExtInst, GlslStd450FrexpStructSuccess) {
  1361. const std::string body = R"(
  1362. %val1 = OpExtInst %struct_f32_u32 %extinst FrexpStruct %f32_h
  1363. %val2 = OpExtInst %struct_f32vec2_u32vec2 %extinst FrexpStruct %f32vec2_01
  1364. )";
  1365. CompileSuccessfully(GenerateShaderCode(body));
  1366. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1367. }
  1368. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeNotStruct) {
  1369. const std::string body = R"(
  1370. %val1 = OpExtInst %f32 %extinst FrexpStruct %f32_h
  1371. )";
  1372. CompileSuccessfully(GenerateShaderCode(body));
  1373. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1374. EXPECT_THAT(getDiagnosticString(),
  1375. HasSubstr("GLSL.std.450 FrexpStruct: "
  1376. "expected Result Type to be a struct with two members, "
  1377. "first member a float scalar or vector, second member "
  1378. "a 32-bit int scalar or vector with the same number of "
  1379. "components as the first member"));
  1380. }
  1381. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongSize) {
  1382. const std::string body = R"(
  1383. %val1 = OpExtInst %struct_f32_u32_f32 %extinst FrexpStruct %f32_h
  1384. )";
  1385. CompileSuccessfully(GenerateShaderCode(body));
  1386. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1387. EXPECT_THAT(getDiagnosticString(),
  1388. HasSubstr("GLSL.std.450 FrexpStruct: "
  1389. "expected Result Type to be a struct with two members, "
  1390. "first member a float scalar or vector, second member "
  1391. "a 32-bit int scalar or vector with the same number of "
  1392. "components as the first member"));
  1393. }
  1394. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongMember1) {
  1395. const std::string body = R"(
  1396. %val1 = OpExtInst %struct_u32_u32 %extinst FrexpStruct %f32_h
  1397. )";
  1398. CompileSuccessfully(GenerateShaderCode(body));
  1399. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1400. EXPECT_THAT(getDiagnosticString(),
  1401. HasSubstr("GLSL.std.450 FrexpStruct: "
  1402. "expected Result Type to be a struct with two members, "
  1403. "first member a float scalar or vector, second member "
  1404. "a 32-bit int scalar or vector with the same number of "
  1405. "components as the first member"));
  1406. }
  1407. TEST_F(ValidateExtInst, GlslStd450FrexpStructResultTypeStructWrongMember2) {
  1408. const std::string body = R"(
  1409. %val1 = OpExtInst %struct_f32_f32 %extinst FrexpStruct %f32_h
  1410. )";
  1411. CompileSuccessfully(GenerateShaderCode(body));
  1412. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1413. EXPECT_THAT(getDiagnosticString(),
  1414. HasSubstr("GLSL.std.450 FrexpStruct: "
  1415. "expected Result Type to be a struct with two members, "
  1416. "first member a float scalar or vector, second member "
  1417. "a 32-bit int scalar or vector with the same number of "
  1418. "components as the first member"));
  1419. }
  1420. TEST_F(ValidateExtInst, GlslStd450FrexpStructXWrongType) {
  1421. const std::string body = R"(
  1422. %val1 = OpExtInst %struct_f32_u32 %extinst FrexpStruct %f64_0
  1423. )";
  1424. CompileSuccessfully(GenerateShaderCode(body));
  1425. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1426. EXPECT_THAT(getDiagnosticString(),
  1427. HasSubstr("GLSL.std.450 FrexpStruct: "
  1428. "expected operand X type to be equal to the first "
  1429. "member of Result Type struct"));
  1430. }
  1431. TEST_F(ValidateExtInst,
  1432. GlslStd450FrexpStructResultTypeStructRightInt16Member2) {
  1433. const std::string body = R"(
  1434. %val1 = OpExtInst %struct_f16_u16 %extinst FrexpStruct %f16_h
  1435. )";
  1436. const std::string extension = R"(
  1437. OpExtension "SPV_AMD_gpu_shader_int16"
  1438. )";
  1439. CompileSuccessfully(GenerateShaderCode(body, extension));
  1440. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1441. }
  1442. TEST_F(ValidateExtInst,
  1443. GlslStd450FrexpStructResultTypeStructWrongInt16Member2) {
  1444. const std::string body = R"(
  1445. %val1 = OpExtInst %struct_f16_u16 %extinst FrexpStruct %f16_h
  1446. )";
  1447. CompileSuccessfully(GenerateShaderCode(body));
  1448. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1449. EXPECT_THAT(getDiagnosticString(),
  1450. HasSubstr("GLSL.std.450 FrexpStruct: "
  1451. "expected Result Type to be a struct with two members, "
  1452. "first member a float scalar or vector, second member "
  1453. "a 32-bit int scalar or vector with the same number of "
  1454. "components as the first member"));
  1455. }
  1456. TEST_P(ValidateGlslStd450Pack, Success) {
  1457. const std::string ext_inst_name = GetParam();
  1458. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1459. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1460. const uint32_t total_bit_width = num_components * packed_bit_width;
  1461. const std::string vec_str =
  1462. num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  1463. std::ostringstream body;
  1464. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  1465. << ext_inst_name << vec_str;
  1466. body << "%val2 = OpExtInst %s" << total_bit_width << " %extinst "
  1467. << ext_inst_name << vec_str;
  1468. CompileSuccessfully(GenerateShaderCode(body.str()));
  1469. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1470. }
  1471. TEST_P(ValidateGlslStd450Pack, Float32ResultType) {
  1472. const std::string ext_inst_name = GetParam();
  1473. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1474. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1475. const uint32_t total_bit_width = num_components * packed_bit_width;
  1476. const std::string vec_str =
  1477. num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  1478. std::ostringstream body;
  1479. body << "%val1 = OpExtInst %f" << total_bit_width << " %extinst "
  1480. << ext_inst_name << vec_str;
  1481. std::ostringstream expected;
  1482. expected << "GLSL.std.450 " << ext_inst_name
  1483. << ": expected Result Type to be " << total_bit_width
  1484. << "-bit int scalar type";
  1485. CompileSuccessfully(GenerateShaderCode(body.str()));
  1486. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1487. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1488. }
  1489. TEST_P(ValidateGlslStd450Pack, Int16ResultType) {
  1490. const std::string ext_inst_name = GetParam();
  1491. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1492. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1493. const uint32_t total_bit_width = num_components * packed_bit_width;
  1494. const std::string vec_str =
  1495. num_components == 2 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  1496. std::ostringstream body;
  1497. body << "%val1 = OpExtInst %u16 %extinst " << ext_inst_name << vec_str;
  1498. std::ostringstream expected;
  1499. expected << "GLSL.std.450 " << ext_inst_name
  1500. << ": expected Result Type to be " << total_bit_width
  1501. << "-bit int scalar type";
  1502. CompileSuccessfully(GenerateShaderCode(body.str()));
  1503. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1504. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1505. }
  1506. TEST_P(ValidateGlslStd450Pack, VNotVector) {
  1507. const std::string ext_inst_name = GetParam();
  1508. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1509. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1510. const uint32_t total_bit_width = num_components * packed_bit_width;
  1511. std::ostringstream body;
  1512. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  1513. << ext_inst_name << " %f32_1\n";
  1514. std::ostringstream expected;
  1515. expected << "GLSL.std.450 " << ext_inst_name
  1516. << ": expected operand V to be a 32-bit float vector of size "
  1517. << num_components;
  1518. CompileSuccessfully(GenerateShaderCode(body.str()));
  1519. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1520. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1521. }
  1522. TEST_P(ValidateGlslStd450Pack, VNotFloatVector) {
  1523. const std::string ext_inst_name = GetParam();
  1524. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1525. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1526. const uint32_t total_bit_width = num_components * packed_bit_width;
  1527. const std::string vec_str =
  1528. num_components == 2 ? " %u32vec2_01\n" : " %u32vec4_0123\n";
  1529. std::ostringstream body;
  1530. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  1531. << ext_inst_name << vec_str;
  1532. std::ostringstream expected;
  1533. expected << "GLSL.std.450 " << ext_inst_name
  1534. << ": expected operand V to be a 32-bit float vector of size "
  1535. << num_components;
  1536. CompileSuccessfully(GenerateShaderCode(body.str()));
  1537. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1538. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1539. }
  1540. TEST_P(ValidateGlslStd450Pack, VNotFloat32Vector) {
  1541. const std::string ext_inst_name = GetParam();
  1542. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1543. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1544. const uint32_t total_bit_width = num_components * packed_bit_width;
  1545. const std::string vec_str =
  1546. num_components == 2 ? " %f64vec2_01\n" : " %f64vec4_0123\n";
  1547. std::ostringstream body;
  1548. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  1549. << ext_inst_name << vec_str;
  1550. std::ostringstream expected;
  1551. expected << "GLSL.std.450 " << ext_inst_name
  1552. << ": expected operand V to be a 32-bit float vector of size "
  1553. << num_components;
  1554. CompileSuccessfully(GenerateShaderCode(body.str()));
  1555. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1556. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1557. }
  1558. TEST_P(ValidateGlslStd450Pack, VWrongSizeVector) {
  1559. const std::string ext_inst_name = GetParam();
  1560. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1561. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1562. const uint32_t total_bit_width = num_components * packed_bit_width;
  1563. const std::string vec_str =
  1564. num_components == 4 ? " %f32vec2_01\n" : " %f32vec4_0123\n";
  1565. std::ostringstream body;
  1566. body << "%val1 = OpExtInst %u" << total_bit_width << " %extinst "
  1567. << ext_inst_name << vec_str;
  1568. std::ostringstream expected;
  1569. expected << "GLSL.std.450 " << ext_inst_name
  1570. << ": expected operand V to be a 32-bit float vector of size "
  1571. << num_components;
  1572. CompileSuccessfully(GenerateShaderCode(body.str()));
  1573. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1574. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1575. }
  1576. INSTANTIATE_TEST_SUITE_P(AllPack, ValidateGlslStd450Pack,
  1577. ::testing::ValuesIn(std::vector<std::string>{
  1578. "PackSnorm4x8",
  1579. "PackUnorm4x8",
  1580. "PackSnorm2x16",
  1581. "PackUnorm2x16",
  1582. "PackHalf2x16",
  1583. }));
  1584. TEST_F(ValidateExtInst, PackDouble2x32Success) {
  1585. const std::string body = R"(
  1586. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u32vec2_01
  1587. )";
  1588. CompileSuccessfully(GenerateShaderCode(body));
  1589. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1590. }
  1591. TEST_F(ValidateExtInst, PackDouble2x32Float32ResultType) {
  1592. const std::string body = R"(
  1593. %val1 = OpExtInst %f32 %extinst PackDouble2x32 %u32vec2_01
  1594. )";
  1595. CompileSuccessfully(GenerateShaderCode(body));
  1596. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1597. EXPECT_THAT(getDiagnosticString(),
  1598. HasSubstr("GLSL.std.450 PackDouble2x32: expected Result Type to "
  1599. "be 64-bit float scalar type"));
  1600. }
  1601. TEST_F(ValidateExtInst, PackDouble2x32Int64ResultType) {
  1602. const std::string body = R"(
  1603. %val1 = OpExtInst %u64 %extinst PackDouble2x32 %u32vec2_01
  1604. )";
  1605. CompileSuccessfully(GenerateShaderCode(body));
  1606. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1607. EXPECT_THAT(getDiagnosticString(),
  1608. HasSubstr("GLSL.std.450 PackDouble2x32: expected Result Type to "
  1609. "be 64-bit float scalar type"));
  1610. }
  1611. TEST_F(ValidateExtInst, PackDouble2x32VNotVector) {
  1612. const std::string body = R"(
  1613. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u64_1
  1614. )";
  1615. CompileSuccessfully(GenerateShaderCode(body));
  1616. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1617. EXPECT_THAT(getDiagnosticString(),
  1618. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  1619. "a 32-bit int vector of size 2"));
  1620. }
  1621. TEST_F(ValidateExtInst, PackDouble2x32VNotIntVector) {
  1622. const std::string body = R"(
  1623. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %f32vec2_01
  1624. )";
  1625. CompileSuccessfully(GenerateShaderCode(body));
  1626. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1627. EXPECT_THAT(getDiagnosticString(),
  1628. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  1629. "a 32-bit int vector of size 2"));
  1630. }
  1631. TEST_F(ValidateExtInst, PackDouble2x32VNotInt32Vector) {
  1632. const std::string body = R"(
  1633. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u64vec2_01
  1634. )";
  1635. CompileSuccessfully(GenerateShaderCode(body));
  1636. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1637. EXPECT_THAT(getDiagnosticString(),
  1638. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  1639. "a 32-bit int vector of size 2"));
  1640. }
  1641. TEST_F(ValidateExtInst, PackDouble2x32VWrongSize) {
  1642. const std::string body = R"(
  1643. %val1 = OpExtInst %f64 %extinst PackDouble2x32 %u32vec4_0123
  1644. )";
  1645. CompileSuccessfully(GenerateShaderCode(body));
  1646. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1647. EXPECT_THAT(getDiagnosticString(),
  1648. HasSubstr("GLSL.std.450 PackDouble2x32: expected operand V to be "
  1649. "a 32-bit int vector of size 2"));
  1650. }
  1651. TEST_P(ValidateGlslStd450Unpack, Success) {
  1652. const std::string ext_inst_name = GetParam();
  1653. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1654. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1655. const uint32_t total_bit_width = num_components * packed_bit_width;
  1656. const std::string result_type_str =
  1657. num_components == 2 ? "%f32vec2" : " %f32vec4";
  1658. std::ostringstream body;
  1659. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  1660. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  1661. body << "%val2 = OpExtInst " << result_type_str << " %extinst "
  1662. << ext_inst_name << " %s" << total_bit_width << "_1\n";
  1663. CompileSuccessfully(GenerateShaderCode(body.str()));
  1664. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1665. }
  1666. TEST_P(ValidateGlslStd450Unpack, ResultTypeNotVector) {
  1667. const std::string ext_inst_name = GetParam();
  1668. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1669. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1670. const uint32_t total_bit_width = num_components * packed_bit_width;
  1671. const std::string result_type_str = "%f32";
  1672. std::ostringstream body;
  1673. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  1674. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  1675. std::ostringstream expected;
  1676. expected << "GLSL.std.450 " << ext_inst_name
  1677. << ": expected Result Type to be a 32-bit float vector of size "
  1678. << num_components;
  1679. CompileSuccessfully(GenerateShaderCode(body.str()));
  1680. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1681. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1682. }
  1683. TEST_P(ValidateGlslStd450Unpack, ResultTypeNotFloatVector) {
  1684. const std::string ext_inst_name = GetParam();
  1685. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1686. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1687. const uint32_t total_bit_width = num_components * packed_bit_width;
  1688. const std::string result_type_str =
  1689. num_components == 2 ? "%u32vec2" : " %u32vec4";
  1690. std::ostringstream body;
  1691. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  1692. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  1693. std::ostringstream expected;
  1694. expected << "GLSL.std.450 " << ext_inst_name
  1695. << ": expected Result Type to be a 32-bit float vector of size "
  1696. << num_components;
  1697. CompileSuccessfully(GenerateShaderCode(body.str()));
  1698. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1699. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1700. }
  1701. TEST_P(ValidateGlslStd450Unpack, ResultTypeNotFloat32Vector) {
  1702. const std::string ext_inst_name = GetParam();
  1703. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1704. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1705. const uint32_t total_bit_width = num_components * packed_bit_width;
  1706. const std::string result_type_str =
  1707. num_components == 2 ? "%f64vec2" : " %f64vec4";
  1708. std::ostringstream body;
  1709. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  1710. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  1711. std::ostringstream expected;
  1712. expected << "GLSL.std.450 " << ext_inst_name
  1713. << ": expected Result Type to be a 32-bit float vector of size "
  1714. << num_components;
  1715. CompileSuccessfully(GenerateShaderCode(body.str()));
  1716. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1717. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1718. }
  1719. TEST_P(ValidateGlslStd450Unpack, ResultTypeWrongSize) {
  1720. const std::string ext_inst_name = GetParam();
  1721. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1722. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1723. const uint32_t total_bit_width = num_components * packed_bit_width;
  1724. const std::string result_type_str =
  1725. num_components == 4 ? "%f32vec2" : " %f32vec4";
  1726. std::ostringstream body;
  1727. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  1728. << ext_inst_name << " %u" << total_bit_width << "_1\n";
  1729. std::ostringstream expected;
  1730. expected << "GLSL.std.450 " << ext_inst_name
  1731. << ": expected Result Type to be a 32-bit float vector of size "
  1732. << num_components;
  1733. CompileSuccessfully(GenerateShaderCode(body.str()));
  1734. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1735. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1736. }
  1737. TEST_P(ValidateGlslStd450Unpack, ResultPNotInt) {
  1738. const std::string ext_inst_name = GetParam();
  1739. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1740. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1741. const uint32_t total_bit_width = num_components * packed_bit_width;
  1742. const std::string result_type_str =
  1743. num_components == 2 ? "%f32vec2" : " %f32vec4";
  1744. std::ostringstream body;
  1745. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  1746. << ext_inst_name << " %f" << total_bit_width << "_1\n";
  1747. std::ostringstream expected;
  1748. expected << "GLSL.std.450 " << ext_inst_name
  1749. << ": expected operand P to be a " << total_bit_width
  1750. << "-bit int scalar";
  1751. CompileSuccessfully(GenerateShaderCode(body.str()));
  1752. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1753. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1754. }
  1755. TEST_P(ValidateGlslStd450Unpack, ResultPWrongBitWidth) {
  1756. const std::string ext_inst_name = GetParam();
  1757. const uint32_t num_components = GetPackedNumComponents(ext_inst_name);
  1758. const uint32_t packed_bit_width = GetPackedBitWidth(ext_inst_name);
  1759. const uint32_t total_bit_width = num_components * packed_bit_width;
  1760. const uint32_t wrong_bit_width = total_bit_width == 32 ? 64 : 32;
  1761. const std::string result_type_str =
  1762. num_components == 2 ? "%f32vec2" : " %f32vec4";
  1763. std::ostringstream body;
  1764. body << "%val1 = OpExtInst " << result_type_str << " %extinst "
  1765. << ext_inst_name << " %u" << wrong_bit_width << "_1\n";
  1766. std::ostringstream expected;
  1767. expected << "GLSL.std.450 " << ext_inst_name
  1768. << ": expected operand P to be a " << total_bit_width
  1769. << "-bit int scalar";
  1770. CompileSuccessfully(GenerateShaderCode(body.str()));
  1771. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1772. EXPECT_THAT(getDiagnosticString(), HasSubstr(expected.str()));
  1773. }
  1774. INSTANTIATE_TEST_SUITE_P(AllUnpack, ValidateGlslStd450Unpack,
  1775. ::testing::ValuesIn(std::vector<std::string>{
  1776. "UnpackSnorm4x8",
  1777. "UnpackUnorm4x8",
  1778. "UnpackSnorm2x16",
  1779. "UnpackUnorm2x16",
  1780. "UnpackHalf2x16",
  1781. }));
  1782. TEST_F(ValidateExtInst, UnpackDouble2x32Success) {
  1783. const std::string body = R"(
  1784. %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %f64_1
  1785. )";
  1786. CompileSuccessfully(GenerateShaderCode(body));
  1787. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1788. }
  1789. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotVector) {
  1790. const std::string body = R"(
  1791. %val1 = OpExtInst %u64 %extinst UnpackDouble2x32 %f64_1
  1792. )";
  1793. CompileSuccessfully(GenerateShaderCode(body));
  1794. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1795. EXPECT_THAT(getDiagnosticString(),
  1796. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  1797. "to be a 32-bit int vector of size 2"));
  1798. }
  1799. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotIntVector) {
  1800. const std::string body = R"(
  1801. %val1 = OpExtInst %f32vec2 %extinst UnpackDouble2x32 %f64_1
  1802. )";
  1803. CompileSuccessfully(GenerateShaderCode(body));
  1804. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1805. EXPECT_THAT(getDiagnosticString(),
  1806. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  1807. "to be a 32-bit int vector of size 2"));
  1808. }
  1809. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeNotInt32Vector) {
  1810. const std::string body = R"(
  1811. %val1 = OpExtInst %u64vec2 %extinst UnpackDouble2x32 %f64_1
  1812. )";
  1813. CompileSuccessfully(GenerateShaderCode(body));
  1814. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1815. EXPECT_THAT(getDiagnosticString(),
  1816. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  1817. "to be a 32-bit int vector of size 2"));
  1818. }
  1819. TEST_F(ValidateExtInst, UnpackDouble2x32ResultTypeWrongSize) {
  1820. const std::string body = R"(
  1821. %val1 = OpExtInst %u32vec4 %extinst UnpackDouble2x32 %f64_1
  1822. )";
  1823. CompileSuccessfully(GenerateShaderCode(body));
  1824. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1825. EXPECT_THAT(getDiagnosticString(),
  1826. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected Result Type "
  1827. "to be a 32-bit int vector of size 2"));
  1828. }
  1829. TEST_F(ValidateExtInst, UnpackDouble2x32VNotFloat) {
  1830. const std::string body = R"(
  1831. %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %u64_1
  1832. )";
  1833. CompileSuccessfully(GenerateShaderCode(body));
  1834. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1835. EXPECT_THAT(getDiagnosticString(),
  1836. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected operand V to "
  1837. "be a 64-bit float scalar"));
  1838. }
  1839. TEST_F(ValidateExtInst, UnpackDouble2x32VNotFloat64) {
  1840. const std::string body = R"(
  1841. %val1 = OpExtInst %u32vec2 %extinst UnpackDouble2x32 %f32_1
  1842. )";
  1843. CompileSuccessfully(GenerateShaderCode(body));
  1844. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1845. EXPECT_THAT(getDiagnosticString(),
  1846. HasSubstr("GLSL.std.450 UnpackDouble2x32: expected operand V to "
  1847. "be a 64-bit float scalar"));
  1848. }
  1849. TEST_F(ValidateExtInst, GlslStd450LengthSuccess) {
  1850. const std::string body = R"(
  1851. %val1 = OpExtInst %f32 %extinst Length %f32_1
  1852. %val2 = OpExtInst %f32 %extinst Length %f32vec2_01
  1853. %val3 = OpExtInst %f32 %extinst Length %f32vec4_0123
  1854. )";
  1855. CompileSuccessfully(GenerateShaderCode(body));
  1856. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1857. }
  1858. TEST_F(ValidateExtInst, GlslStd450LengthIntResultType) {
  1859. const std::string body = R"(
  1860. %val1 = OpExtInst %u32 %extinst Length %f32vec2_01
  1861. )";
  1862. CompileSuccessfully(GenerateShaderCode(body));
  1863. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1864. EXPECT_THAT(getDiagnosticString(),
  1865. HasSubstr("GLSL.std.450 Length: "
  1866. "expected Result Type to be a float scalar type"));
  1867. }
  1868. TEST_F(ValidateExtInst, GlslStd450LengthIntX) {
  1869. const std::string body = R"(
  1870. %val1 = OpExtInst %f32 %extinst Length %u32vec2_01
  1871. )";
  1872. CompileSuccessfully(GenerateShaderCode(body));
  1873. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1874. EXPECT_THAT(getDiagnosticString(),
  1875. HasSubstr("GLSL.std.450 Length: "
  1876. "expected operand X to be of float scalar or "
  1877. "vector type"));
  1878. }
  1879. TEST_F(ValidateExtInst, GlslStd450LengthDifferentType) {
  1880. const std::string body = R"(
  1881. %val1 = OpExtInst %f64 %extinst Length %f32vec2_01
  1882. )";
  1883. CompileSuccessfully(GenerateShaderCode(body));
  1884. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1885. EXPECT_THAT(getDiagnosticString(),
  1886. HasSubstr("GLSL.std.450 Length: "
  1887. "expected operand X component type to be equal to "
  1888. "Result Type"));
  1889. }
  1890. TEST_F(ValidateExtInst, GlslStd450DistanceSuccess) {
  1891. const std::string body = R"(
  1892. %val1 = OpExtInst %f32 %extinst Distance %f32_0 %f32_1
  1893. %val2 = OpExtInst %f32 %extinst Distance %f32vec2_01 %f32vec2_12
  1894. %val3 = OpExtInst %f32 %extinst Distance %f32vec4_0123 %f32vec4_1234
  1895. )";
  1896. CompileSuccessfully(GenerateShaderCode(body));
  1897. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1898. }
  1899. TEST_F(ValidateExtInst, GlslStd450DistanceIntResultType) {
  1900. const std::string body = R"(
  1901. %val1 = OpExtInst %u32 %extinst Distance %f32vec2_01 %f32vec2_12
  1902. )";
  1903. CompileSuccessfully(GenerateShaderCode(body));
  1904. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1905. EXPECT_THAT(getDiagnosticString(),
  1906. HasSubstr("GLSL.std.450 Distance: "
  1907. "expected Result Type to be a float scalar type"));
  1908. }
  1909. TEST_F(ValidateExtInst, GlslStd450DistanceIntP0) {
  1910. const std::string body = R"(
  1911. %val1 = OpExtInst %f32 %extinst Distance %u32_0 %f32_1
  1912. )";
  1913. CompileSuccessfully(GenerateShaderCode(body));
  1914. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1915. EXPECT_THAT(getDiagnosticString(),
  1916. HasSubstr("GLSL.std.450 Distance: "
  1917. "expected operand P0 to be of float scalar or "
  1918. "vector type"));
  1919. }
  1920. TEST_F(ValidateExtInst, GlslStd450DistanceF64VectorP0) {
  1921. const std::string body = R"(
  1922. %val1 = OpExtInst %f32 %extinst Distance %f64vec2_01 %f32vec2_12
  1923. )";
  1924. CompileSuccessfully(GenerateShaderCode(body));
  1925. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1926. EXPECT_THAT(getDiagnosticString(),
  1927. HasSubstr("GLSL.std.450 Distance: "
  1928. "expected operand P0 component type to be equal to "
  1929. "Result Type"));
  1930. }
  1931. TEST_F(ValidateExtInst, GlslStd450DistanceIntP1) {
  1932. const std::string body = R"(
  1933. %val1 = OpExtInst %f32 %extinst Distance %f32_0 %u32_1
  1934. )";
  1935. CompileSuccessfully(GenerateShaderCode(body));
  1936. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1937. EXPECT_THAT(getDiagnosticString(),
  1938. HasSubstr("GLSL.std.450 Distance: "
  1939. "expected operand P1 to be of float scalar or "
  1940. "vector type"));
  1941. }
  1942. TEST_F(ValidateExtInst, GlslStd450DistanceF64VectorP1) {
  1943. const std::string body = R"(
  1944. %val1 = OpExtInst %f32 %extinst Distance %f32vec2_12 %f64vec2_01
  1945. )";
  1946. CompileSuccessfully(GenerateShaderCode(body));
  1947. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1948. EXPECT_THAT(getDiagnosticString(),
  1949. HasSubstr("GLSL.std.450 Distance: "
  1950. "expected operand P1 component type to be equal to "
  1951. "Result Type"));
  1952. }
  1953. TEST_F(ValidateExtInst, GlslStd450DistanceDifferentSize) {
  1954. const std::string body = R"(
  1955. %val1 = OpExtInst %f32 %extinst Distance %f32vec2_01 %f32vec4_0123
  1956. )";
  1957. CompileSuccessfully(GenerateShaderCode(body));
  1958. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1959. EXPECT_THAT(getDiagnosticString(),
  1960. HasSubstr("GLSL.std.450 Distance: "
  1961. "expected operands P0 and P1 to have the same number "
  1962. "of components"));
  1963. }
  1964. TEST_F(ValidateExtInst, GlslStd450CrossSuccess) {
  1965. const std::string body = R"(
  1966. %val1 = OpExtInst %f32vec3 %extinst Cross %f32vec3_012 %f32vec3_123
  1967. )";
  1968. CompileSuccessfully(GenerateShaderCode(body));
  1969. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  1970. }
  1971. TEST_F(ValidateExtInst, GlslStd450CrossIntVectorResultType) {
  1972. const std::string body = R"(
  1973. %val1 = OpExtInst %u32vec3 %extinst Cross %f32vec3_012 %f32vec3_123
  1974. )";
  1975. CompileSuccessfully(GenerateShaderCode(body));
  1976. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1977. EXPECT_THAT(getDiagnosticString(),
  1978. HasSubstr("GLSL.std.450 Cross: "
  1979. "expected Result Type to be a float vector type"));
  1980. }
  1981. TEST_F(ValidateExtInst, GlslStd450CrossResultTypeWrongSize) {
  1982. const std::string body = R"(
  1983. %val1 = OpExtInst %f32vec2 %extinst Cross %f32vec3_012 %f32vec3_123
  1984. )";
  1985. CompileSuccessfully(GenerateShaderCode(body));
  1986. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1987. EXPECT_THAT(getDiagnosticString(),
  1988. HasSubstr("GLSL.std.450 Cross: "
  1989. "expected Result Type to have 3 components"));
  1990. }
  1991. TEST_F(ValidateExtInst, GlslStd450CrossXWrongType) {
  1992. const std::string body = R"(
  1993. %val1 = OpExtInst %f32vec3 %extinst Cross %f64vec3_012 %f32vec3_123
  1994. )";
  1995. CompileSuccessfully(GenerateShaderCode(body));
  1996. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  1997. EXPECT_THAT(getDiagnosticString(),
  1998. HasSubstr("GLSL.std.450 Cross: "
  1999. "expected operand X type to be equal to Result Type"));
  2000. }
  2001. TEST_F(ValidateExtInst, GlslStd450CrossYWrongType) {
  2002. const std::string body = R"(
  2003. %val1 = OpExtInst %f32vec3 %extinst Cross %f32vec3_123 %f64vec3_012
  2004. )";
  2005. CompileSuccessfully(GenerateShaderCode(body));
  2006. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2007. EXPECT_THAT(getDiagnosticString(),
  2008. HasSubstr("GLSL.std.450 Cross: "
  2009. "expected operand Y type to be equal to Result Type"));
  2010. }
  2011. TEST_F(ValidateExtInst, GlslStd450RefractSuccess) {
  2012. const std::string body = R"(
  2013. %val1 = OpExtInst %f32 %extinst Refract %f32_1 %f32_1 %f32_1
  2014. %val2 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f16_1
  2015. )";
  2016. CompileSuccessfully(GenerateShaderCode(body));
  2017. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2018. }
  2019. TEST_F(ValidateExtInst, GlslStd450RefractIntVectorResultType) {
  2020. const std::string body = R"(
  2021. %val1 = OpExtInst %u32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f32_1
  2022. )";
  2023. CompileSuccessfully(GenerateShaderCode(body));
  2024. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2025. EXPECT_THAT(getDiagnosticString(),
  2026. HasSubstr("GLSL.std.450 Refract: "
  2027. "expected Result Type to be a float scalar or "
  2028. "vector type"));
  2029. }
  2030. TEST_F(ValidateExtInst, GlslStd450RefractIntVectorI) {
  2031. const std::string body = R"(
  2032. %val1 = OpExtInst %f32vec2 %extinst Refract %u32vec2_01 %f32vec2_01 %f32_1
  2033. )";
  2034. CompileSuccessfully(GenerateShaderCode(body));
  2035. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2036. EXPECT_THAT(getDiagnosticString(),
  2037. HasSubstr("GLSL.std.450 Refract: "
  2038. "expected operand I to be of type equal to "
  2039. "Result Type"));
  2040. }
  2041. TEST_F(ValidateExtInst, GlslStd450RefractIntVectorN) {
  2042. const std::string body = R"(
  2043. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %u32vec2_01 %f32_1
  2044. )";
  2045. CompileSuccessfully(GenerateShaderCode(body));
  2046. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2047. EXPECT_THAT(getDiagnosticString(),
  2048. HasSubstr("GLSL.std.450 Refract: "
  2049. "expected operand N to be of type equal to "
  2050. "Result Type"));
  2051. }
  2052. TEST_F(ValidateExtInst, GlslStd450RefractIntEta) {
  2053. const std::string body = R"(
  2054. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %u32_1
  2055. )";
  2056. CompileSuccessfully(GenerateShaderCode(body));
  2057. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2058. EXPECT_THAT(getDiagnosticString(),
  2059. HasSubstr("GLSL.std.450 Refract: "
  2060. "expected operand Eta to be a float scalar"));
  2061. }
  2062. TEST_F(ValidateExtInst, GlslStd450RefractFloat64Eta) {
  2063. // SPIR-V issue 337: Eta can be 64-bit float scalar.
  2064. const std::string body = R"(
  2065. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f64_1
  2066. )";
  2067. CompileSuccessfully(GenerateShaderCode(body));
  2068. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2069. EXPECT_THAT(getDiagnosticString(), Eq(""));
  2070. }
  2071. TEST_F(ValidateExtInst, GlslStd450RefractVectorEta) {
  2072. const std::string body = R"(
  2073. %val1 = OpExtInst %f32vec2 %extinst Refract %f32vec2_01 %f32vec2_01 %f32vec2_01
  2074. )";
  2075. CompileSuccessfully(GenerateShaderCode(body));
  2076. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2077. EXPECT_THAT(getDiagnosticString(),
  2078. HasSubstr("GLSL.std.450 Refract: "
  2079. "expected operand Eta to be a float scalar"));
  2080. }
  2081. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidSuccess) {
  2082. const std::string body = R"(
  2083. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
  2084. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtCentroid %f32vec2_input
  2085. )";
  2086. CompileSuccessfully(
  2087. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2088. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2089. }
  2090. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidInternalSuccess) {
  2091. const std::string body = R"(
  2092. %ld1 = OpLoad %f32 %f32_input
  2093. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %ld1
  2094. %ld2 = OpLoad %f32vec2 %f32vec2_input
  2095. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtCentroid %ld2
  2096. )";
  2097. CompileSuccessfully(
  2098. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2099. getValidatorOptions()->before_hlsl_legalization = true;
  2100. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2101. }
  2102. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidInternalInvalidDataF32) {
  2103. const std::string body = R"(
  2104. %ld1 = OpLoad %f32 %f32_input
  2105. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %ld1
  2106. )";
  2107. CompileSuccessfully(
  2108. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2109. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2110. EXPECT_THAT(getDiagnosticString(),
  2111. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  2112. "expected Interpolant to be a pointer"));
  2113. }
  2114. TEST_F(ValidateExtInst,
  2115. GlslStd450InterpolateAtCentroidInternalInvalidDataF32Vec2) {
  2116. const std::string body = R"(
  2117. %ld2 = OpLoad %f32vec2 %f32vec2_input
  2118. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtCentroid %ld2
  2119. )";
  2120. CompileSuccessfully(
  2121. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2122. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2123. EXPECT_THAT(getDiagnosticString(),
  2124. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  2125. "expected Interpolant to be a pointer"));
  2126. }
  2127. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidNoCapability) {
  2128. const std::string body = R"(
  2129. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
  2130. )";
  2131. CompileSuccessfully(GenerateShaderCode(body));
  2132. ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
  2133. EXPECT_THAT(getDiagnosticString(),
  2134. HasSubstr("GLSL.std.450 InterpolateAtCentroid requires "
  2135. "capability InterpolationFunction"));
  2136. }
  2137. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidIntResultType) {
  2138. const std::string body = R"(
  2139. %val1 = OpExtInst %u32 %extinst InterpolateAtCentroid %f32_input
  2140. )";
  2141. CompileSuccessfully(
  2142. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2143. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2144. EXPECT_THAT(getDiagnosticString(),
  2145. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  2146. "expected Result Type to be a 32-bit float scalar "
  2147. "or vector type"));
  2148. }
  2149. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidF64ResultType) {
  2150. const std::string body = R"(
  2151. %val1 = OpExtInst %f64 %extinst InterpolateAtCentroid %f32_input
  2152. )";
  2153. CompileSuccessfully(
  2154. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2155. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2156. EXPECT_THAT(getDiagnosticString(),
  2157. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  2158. "expected Result Type to be a 32-bit float scalar "
  2159. "or vector type"));
  2160. }
  2161. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidNotPointer) {
  2162. const std::string body = R"(
  2163. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_1
  2164. )";
  2165. CompileSuccessfully(
  2166. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2167. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2168. EXPECT_THAT(getDiagnosticString(),
  2169. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  2170. "expected Interpolant to be a pointer"));
  2171. }
  2172. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongDataType) {
  2173. const std::string body = R"(
  2174. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32vec2_input
  2175. )";
  2176. CompileSuccessfully(
  2177. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2178. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2179. EXPECT_THAT(getDiagnosticString(),
  2180. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  2181. "expected Interpolant data type to be equal to "
  2182. "Result Type"));
  2183. }
  2184. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongStorageClass) {
  2185. const std::string body = R"(
  2186. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_output
  2187. )";
  2188. CompileSuccessfully(
  2189. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2190. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2191. EXPECT_THAT(getDiagnosticString(),
  2192. HasSubstr("GLSL.std.450 InterpolateAtCentroid: "
  2193. "expected Interpolant storage class to be Input"));
  2194. }
  2195. TEST_F(ValidateExtInst, GlslStd450InterpolateAtCentroidWrongExecutionModel) {
  2196. const std::string body = R"(
  2197. %val1 = OpExtInst %f32 %extinst InterpolateAtCentroid %f32_input
  2198. )";
  2199. CompileSuccessfully(GenerateShaderCode(
  2200. body, "OpCapability InterpolationFunction\n", "Vertex"));
  2201. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  2202. EXPECT_THAT(getDiagnosticString(),
  2203. HasSubstr("GLSL.std.450 InterpolateAtCentroid requires "
  2204. "Fragment execution model"));
  2205. }
  2206. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleSuccess) {
  2207. const std::string body = R"(
  2208. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
  2209. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtSample %f32vec2_input %u32_1
  2210. )";
  2211. CompileSuccessfully(
  2212. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2213. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2214. }
  2215. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleInternalSuccess) {
  2216. const std::string body = R"(
  2217. %ld1 = OpLoad %f32 %f32_input
  2218. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %ld1 %u32_1
  2219. %ld2 = OpLoad %f32vec2 %f32vec2_input
  2220. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtSample %ld2 %u32_1
  2221. )";
  2222. CompileSuccessfully(
  2223. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2224. getValidatorOptions()->before_hlsl_legalization = true;
  2225. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2226. }
  2227. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleInternalInvalidDataF32) {
  2228. const std::string body = R"(
  2229. %ld1 = OpLoad %f32 %f32_input
  2230. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %ld1 %u32_1
  2231. )";
  2232. CompileSuccessfully(
  2233. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2234. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2235. EXPECT_THAT(getDiagnosticString(),
  2236. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2237. "expected Interpolant to be a pointer"));
  2238. }
  2239. TEST_F(ValidateExtInst,
  2240. GlslStd450InterpolateAtSampleInternalInvalidDataF32Vec2) {
  2241. const std::string body = R"(
  2242. %ld2 = OpLoad %f32vec2 %f32vec2_input
  2243. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtSample %ld2 %u32_1
  2244. )";
  2245. CompileSuccessfully(
  2246. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2247. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2248. EXPECT_THAT(getDiagnosticString(),
  2249. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2250. "expected Interpolant to be a pointer"));
  2251. }
  2252. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleNoCapability) {
  2253. const std::string body = R"(
  2254. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
  2255. )";
  2256. CompileSuccessfully(GenerateShaderCode(body));
  2257. ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
  2258. EXPECT_THAT(getDiagnosticString(),
  2259. HasSubstr("GLSL.std.450 InterpolateAtSample requires "
  2260. "capability InterpolationFunction"));
  2261. }
  2262. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleIntResultType) {
  2263. const std::string body = R"(
  2264. %val1 = OpExtInst %u32 %extinst InterpolateAtSample %f32_input %u32_1
  2265. )";
  2266. CompileSuccessfully(
  2267. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2268. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2269. EXPECT_THAT(getDiagnosticString(),
  2270. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2271. "expected Result Type to be a 32-bit float scalar "
  2272. "or vector type"));
  2273. }
  2274. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleF64ResultType) {
  2275. const std::string body = R"(
  2276. %val1 = OpExtInst %f64 %extinst InterpolateAtSample %f32_input %u32_1
  2277. )";
  2278. CompileSuccessfully(
  2279. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2280. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2281. EXPECT_THAT(getDiagnosticString(),
  2282. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2283. "expected Result Type to be a 32-bit float scalar "
  2284. "or vector type"));
  2285. }
  2286. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleNotPointer) {
  2287. const std::string body = R"(
  2288. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_1 %u32_1
  2289. )";
  2290. CompileSuccessfully(
  2291. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2292. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2293. EXPECT_THAT(getDiagnosticString(),
  2294. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2295. "expected Interpolant to be a pointer"));
  2296. }
  2297. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongDataType) {
  2298. const std::string body = R"(
  2299. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32vec2_input %u32_1
  2300. )";
  2301. CompileSuccessfully(
  2302. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2303. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2304. EXPECT_THAT(getDiagnosticString(),
  2305. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2306. "expected Interpolant data type to be equal to "
  2307. "Result Type"));
  2308. }
  2309. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongStorageClass) {
  2310. const std::string body = R"(
  2311. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_output %u32_1
  2312. )";
  2313. CompileSuccessfully(
  2314. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2315. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2316. EXPECT_THAT(getDiagnosticString(),
  2317. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2318. "expected Interpolant storage class to be Input"));
  2319. }
  2320. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleFloatSample) {
  2321. const std::string body = R"(
  2322. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %f32_1
  2323. )";
  2324. CompileSuccessfully(
  2325. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2326. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2327. EXPECT_THAT(getDiagnosticString(),
  2328. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2329. "expected Sample to be 32-bit integer"));
  2330. }
  2331. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleU64Sample) {
  2332. const std::string body = R"(
  2333. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u64_1
  2334. )";
  2335. CompileSuccessfully(
  2336. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2337. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2338. EXPECT_THAT(getDiagnosticString(),
  2339. HasSubstr("GLSL.std.450 InterpolateAtSample: "
  2340. "expected Sample to be 32-bit integer"));
  2341. }
  2342. TEST_F(ValidateExtInst, GlslStd450InterpolateAtSampleWrongExecutionModel) {
  2343. const std::string body = R"(
  2344. %val1 = OpExtInst %f32 %extinst InterpolateAtSample %f32_input %u32_1
  2345. )";
  2346. CompileSuccessfully(GenerateShaderCode(
  2347. body, "OpCapability InterpolationFunction\n", "Vertex"));
  2348. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  2349. EXPECT_THAT(getDiagnosticString(),
  2350. HasSubstr("GLSL.std.450 InterpolateAtSample requires "
  2351. "Fragment execution model"));
  2352. }
  2353. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetSuccess) {
  2354. const std::string body = R"(
  2355. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  2356. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtOffset %f32vec2_input %f32vec2_01
  2357. )";
  2358. CompileSuccessfully(
  2359. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2360. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2361. }
  2362. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetInternalSuccess) {
  2363. const std::string body = R"(
  2364. %ld1 = OpLoad %f32 %f32_input
  2365. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %ld1 %f32vec2_01
  2366. %ld2 = OpLoad %f32vec2 %f32vec2_input
  2367. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtOffset %ld2 %f32vec2_01
  2368. )";
  2369. CompileSuccessfully(
  2370. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2371. getValidatorOptions()->before_hlsl_legalization = true;
  2372. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2373. }
  2374. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetInternalInvalidDataF32) {
  2375. const std::string body = R"(
  2376. %ld1 = OpLoad %f32 %f32_input
  2377. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %ld1 %f32vec2_01
  2378. )";
  2379. CompileSuccessfully(
  2380. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2381. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2382. EXPECT_THAT(getDiagnosticString(),
  2383. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2384. "expected Interpolant to be a pointer"));
  2385. }
  2386. TEST_F(ValidateExtInst,
  2387. GlslStd450InterpolateAtOffsetInternalInvalidDataF32Vec2) {
  2388. const std::string body = R"(
  2389. %ld2 = OpLoad %f32vec2 %f32vec2_input
  2390. %val2 = OpExtInst %f32vec2 %extinst InterpolateAtOffset %ld2 %f32vec2_01
  2391. )";
  2392. CompileSuccessfully(
  2393. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2394. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2395. EXPECT_THAT(getDiagnosticString(),
  2396. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2397. "expected Interpolant to be a pointer"));
  2398. }
  2399. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetNoCapability) {
  2400. const std::string body = R"(
  2401. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  2402. )";
  2403. CompileSuccessfully(GenerateShaderCode(body));
  2404. ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
  2405. EXPECT_THAT(getDiagnosticString(),
  2406. HasSubstr("GLSL.std.450 InterpolateAtOffset requires "
  2407. "capability InterpolationFunction"));
  2408. }
  2409. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetIntResultType) {
  2410. const std::string body = R"(
  2411. %val1 = OpExtInst %u32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  2412. )";
  2413. CompileSuccessfully(
  2414. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2415. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2416. EXPECT_THAT(getDiagnosticString(),
  2417. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2418. "expected Result Type to be a 32-bit float scalar "
  2419. "or vector type"));
  2420. }
  2421. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetF64ResultType) {
  2422. const std::string body = R"(
  2423. %val1 = OpExtInst %f64 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  2424. )";
  2425. CompileSuccessfully(
  2426. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2427. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2428. EXPECT_THAT(getDiagnosticString(),
  2429. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2430. "expected Result Type to be a 32-bit float scalar "
  2431. "or vector type"));
  2432. }
  2433. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetNotPointer) {
  2434. const std::string body = R"(
  2435. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_1 %f32vec2_01
  2436. )";
  2437. CompileSuccessfully(
  2438. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2439. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2440. EXPECT_THAT(getDiagnosticString(),
  2441. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2442. "expected Interpolant to be a pointer"));
  2443. }
  2444. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongDataType) {
  2445. const std::string body = R"(
  2446. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32vec2_input %f32vec2_01
  2447. )";
  2448. CompileSuccessfully(
  2449. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2450. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2451. EXPECT_THAT(getDiagnosticString(),
  2452. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2453. "expected Interpolant data type to be equal to "
  2454. "Result Type"));
  2455. }
  2456. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongStorageClass) {
  2457. const std::string body = R"(
  2458. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_output %f32vec2_01
  2459. )";
  2460. CompileSuccessfully(
  2461. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2462. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2463. EXPECT_THAT(getDiagnosticString(),
  2464. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2465. "expected Interpolant storage class to be Input"));
  2466. }
  2467. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotVector) {
  2468. const std::string body = R"(
  2469. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32_0
  2470. )";
  2471. CompileSuccessfully(
  2472. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2473. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2474. EXPECT_THAT(getDiagnosticString(),
  2475. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2476. "expected Offset to be a vector of 2 32-bit floats"));
  2477. }
  2478. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotVector2) {
  2479. const std::string body = R"(
  2480. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec3_012
  2481. )";
  2482. CompileSuccessfully(
  2483. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2484. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2485. EXPECT_THAT(getDiagnosticString(),
  2486. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2487. "expected Offset to be a vector of 2 32-bit floats"));
  2488. }
  2489. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotFloatVector) {
  2490. const std::string body = R"(
  2491. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %u32vec2_01
  2492. )";
  2493. CompileSuccessfully(
  2494. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2495. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2496. EXPECT_THAT(getDiagnosticString(),
  2497. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2498. "expected Offset to be a vector of 2 32-bit floats"));
  2499. }
  2500. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetOffsetNotFloat32Vector) {
  2501. const std::string body = R"(
  2502. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f64vec2_01
  2503. )";
  2504. CompileSuccessfully(
  2505. GenerateShaderCode(body, "OpCapability InterpolationFunction\n"));
  2506. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2507. EXPECT_THAT(getDiagnosticString(),
  2508. HasSubstr("GLSL.std.450 InterpolateAtOffset: "
  2509. "expected Offset to be a vector of 2 32-bit floats"));
  2510. }
  2511. TEST_F(ValidateExtInst, GlslStd450InterpolateAtOffsetWrongExecutionModel) {
  2512. const std::string body = R"(
  2513. %val1 = OpExtInst %f32 %extinst InterpolateAtOffset %f32_input %f32vec2_01
  2514. )";
  2515. CompileSuccessfully(GenerateShaderCode(
  2516. body, "OpCapability InterpolationFunction\n", "Vertex"));
  2517. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  2518. EXPECT_THAT(getDiagnosticString(),
  2519. HasSubstr("GLSL.std.450 InterpolateAtOffset requires "
  2520. "Fragment execution model"));
  2521. }
  2522. TEST_P(ValidateOpenCLStdSqrtLike, Success) {
  2523. const std::string ext_inst_name = GetParam();
  2524. std::ostringstream ss;
  2525. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0\n";
  2526. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  2527. << " %f32vec2_01\n";
  2528. ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  2529. << " %f32vec4_0123\n";
  2530. ss << "%val4 = OpExtInst %f64 %extinst " << ext_inst_name << " %f64_0\n";
  2531. CompileSuccessfully(GenerateKernelCode(ss.str()));
  2532. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2533. }
  2534. TEST_P(ValidateOpenCLStdSqrtLike, IntResultType) {
  2535. const std::string ext_inst_name = GetParam();
  2536. const std::string body =
  2537. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  2538. CompileSuccessfully(GenerateKernelCode(body));
  2539. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2540. EXPECT_THAT(getDiagnosticString(),
  2541. HasSubstr("OpenCL.std " + ext_inst_name +
  2542. ": expected Result Type to be a float scalar "
  2543. "or vector type"));
  2544. }
  2545. TEST_P(ValidateOpenCLStdSqrtLike, IntOperand) {
  2546. const std::string ext_inst_name = GetParam();
  2547. const std::string body =
  2548. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  2549. CompileSuccessfully(GenerateKernelCode(body));
  2550. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2551. EXPECT_THAT(getDiagnosticString(),
  2552. HasSubstr("OpenCL.std " + ext_inst_name +
  2553. ": expected types of all operands to be equal to "
  2554. "Result Type"));
  2555. }
  2556. INSTANTIATE_TEST_SUITE_P(
  2557. AllSqrtLike, ValidateOpenCLStdSqrtLike,
  2558. ::testing::ValuesIn(std::vector<std::string>{
  2559. "acos", "acosh", "acospi", "asin",
  2560. "asinh", "asinpi", "atan", "atanh",
  2561. "atanpi", "cbrt", "ceil", "cos",
  2562. "cosh", "cospi", "erfc", "erf",
  2563. "exp", "exp2", "exp10", "expm1",
  2564. "fabs", "floor", "log", "log2",
  2565. "log10", "log1p", "logb", "rint",
  2566. "round", "rsqrt", "sin", "sinh",
  2567. "sinpi", "sqrt", "tan", "tanh",
  2568. "tanpi", "tgamma", "trunc", "half_cos",
  2569. "half_exp", "half_exp2", "half_exp10", "half_log",
  2570. "half_log2", "half_log10", "half_recip", "half_rsqrt",
  2571. "half_sin", "half_sqrt", "half_tan", "lgamma",
  2572. "native_cos", "native_exp", "native_exp2", "native_exp10",
  2573. "native_log", "native_log2", "native_log10", "native_recip",
  2574. "native_rsqrt", "native_sin", "native_sqrt", "native_tan",
  2575. "degrees", "radians", "sign",
  2576. }));
  2577. TEST_P(ValidateOpenCLStdFMinLike, Success) {
  2578. const std::string ext_inst_name = GetParam();
  2579. std::ostringstream ss;
  2580. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  2581. << " %f32_0 %f32_1\n";
  2582. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  2583. << " %f32vec2_01 %f32vec2_12\n";
  2584. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  2585. << " %f64_0 %f64_0\n";
  2586. CompileSuccessfully(GenerateKernelCode(ss.str()));
  2587. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2588. }
  2589. TEST_P(ValidateOpenCLStdFMinLike, IntResultType) {
  2590. const std::string ext_inst_name = GetParam();
  2591. const std::string body =
  2592. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %f32_1\n";
  2593. CompileSuccessfully(GenerateKernelCode(body));
  2594. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2595. EXPECT_THAT(getDiagnosticString(),
  2596. HasSubstr("OpenCL.std " + ext_inst_name +
  2597. ": expected Result Type to be a float scalar "
  2598. "or vector type"));
  2599. }
  2600. TEST_P(ValidateOpenCLStdFMinLike, IntOperand1) {
  2601. const std::string ext_inst_name = GetParam();
  2602. const std::string body =
  2603. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %f32_1\n";
  2604. CompileSuccessfully(GenerateKernelCode(body));
  2605. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2606. EXPECT_THAT(getDiagnosticString(),
  2607. HasSubstr("OpenCL.std " + ext_inst_name +
  2608. ": expected types of all operands to be equal to "
  2609. "Result Type"));
  2610. }
  2611. TEST_P(ValidateOpenCLStdFMinLike, IntOperand2) {
  2612. const std::string ext_inst_name = GetParam();
  2613. const std::string body =
  2614. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %f32_0 %u32_1\n";
  2615. CompileSuccessfully(GenerateKernelCode(body));
  2616. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2617. EXPECT_THAT(getDiagnosticString(),
  2618. HasSubstr("OpenCL.std " + ext_inst_name +
  2619. ": expected types of all operands to be equal to "
  2620. "Result Type"));
  2621. }
  2622. INSTANTIATE_TEST_SUITE_P(AllFMinLike, ValidateOpenCLStdFMinLike,
  2623. ::testing::ValuesIn(std::vector<std::string>{
  2624. "atan2", "atan2pi", "copysign",
  2625. "fdim", "fmax", "fmin",
  2626. "fmod", "maxmag", "minmag",
  2627. "hypot", "nextafter", "pow",
  2628. "powr", "remainder", "half_divide",
  2629. "half_powr", "native_divide", "native_powr",
  2630. "step", "fmax_common", "fmin_common",
  2631. }));
  2632. TEST_P(ValidateOpenCLStdFClampLike, Success) {
  2633. const std::string ext_inst_name = GetParam();
  2634. std::ostringstream ss;
  2635. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  2636. << " %f32_0 %f32_1 %f32_2\n";
  2637. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  2638. << " %f32vec2_01 %f32vec2_01 %f32vec2_12\n";
  2639. ss << "%val3 = OpExtInst %f64 %extinst " << ext_inst_name
  2640. << " %f64_0 %f64_0 %f64_1\n";
  2641. CompileSuccessfully(GenerateKernelCode(ss.str()));
  2642. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2643. }
  2644. TEST_P(ValidateOpenCLStdFClampLike, IntResultType) {
  2645. const std::string ext_inst_name = GetParam();
  2646. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2647. " %f32_0 %f32_1 %f32_2\n";
  2648. CompileSuccessfully(GenerateKernelCode(body));
  2649. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2650. EXPECT_THAT(getDiagnosticString(),
  2651. HasSubstr("OpenCL.std " + ext_inst_name +
  2652. ": expected Result Type to be a float scalar "
  2653. "or vector type"));
  2654. }
  2655. TEST_P(ValidateOpenCLStdFClampLike, IntOperand1) {
  2656. const std::string ext_inst_name = GetParam();
  2657. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  2658. " %u32_0 %f32_0 %f32_1\n";
  2659. CompileSuccessfully(GenerateKernelCode(body));
  2660. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2661. EXPECT_THAT(getDiagnosticString(),
  2662. HasSubstr("OpenCL.std " + ext_inst_name +
  2663. ": expected types of all operands to be equal to "
  2664. "Result Type"));
  2665. }
  2666. TEST_P(ValidateOpenCLStdFClampLike, IntOperand2) {
  2667. const std::string ext_inst_name = GetParam();
  2668. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  2669. " %f32_0 %u32_0 %f32_1\n";
  2670. CompileSuccessfully(GenerateKernelCode(body));
  2671. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2672. EXPECT_THAT(getDiagnosticString(),
  2673. HasSubstr("OpenCL.std " + ext_inst_name +
  2674. ": expected types of all operands to be equal to "
  2675. "Result Type"));
  2676. }
  2677. TEST_P(ValidateOpenCLStdFClampLike, IntOperand3) {
  2678. const std::string ext_inst_name = GetParam();
  2679. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  2680. " %f32_1 %f32_0 %u32_2\n";
  2681. CompileSuccessfully(GenerateKernelCode(body));
  2682. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2683. EXPECT_THAT(getDiagnosticString(),
  2684. HasSubstr("OpenCL.std " + ext_inst_name +
  2685. ": expected types of all operands to be equal to "
  2686. "Result Type"));
  2687. }
  2688. INSTANTIATE_TEST_SUITE_P(AllFClampLike, ValidateOpenCLStdFClampLike,
  2689. ::testing::ValuesIn(std::vector<std::string>{
  2690. "fma",
  2691. "mad",
  2692. "fclamp",
  2693. "mix",
  2694. "smoothstep",
  2695. }));
  2696. TEST_P(ValidateOpenCLStdSAbsLike, Success) {
  2697. const std::string ext_inst_name = GetParam();
  2698. std::ostringstream ss;
  2699. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  2700. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  2701. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  2702. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name << " %u32_1\n";
  2703. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2704. << " %u32vec2_01\n";
  2705. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2706. << " %u32vec2_01\n";
  2707. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2708. << " %u32vec2_01\n";
  2709. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2710. << " %u32vec2_01\n";
  2711. CompileSuccessfully(GenerateKernelCode(ss.str()));
  2712. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2713. }
  2714. TEST_P(ValidateOpenCLStdSAbsLike, FloatResultType) {
  2715. const std::string ext_inst_name = GetParam();
  2716. const std::string body =
  2717. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0\n";
  2718. CompileSuccessfully(GenerateKernelCode(body));
  2719. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2720. EXPECT_THAT(getDiagnosticString(),
  2721. HasSubstr("OpenCL.std " + ext_inst_name +
  2722. ": expected Result Type to be an int scalar "
  2723. "or vector type"));
  2724. }
  2725. TEST_P(ValidateOpenCLStdSAbsLike, FloatOperand) {
  2726. const std::string ext_inst_name = GetParam();
  2727. const std::string body =
  2728. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0\n";
  2729. CompileSuccessfully(GenerateKernelCode(body));
  2730. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2731. EXPECT_THAT(
  2732. getDiagnosticString(),
  2733. HasSubstr("OpenCL.std " + ext_inst_name +
  2734. ": expected types of all operands to be equal to Result Type"));
  2735. }
  2736. TEST_P(ValidateOpenCLStdSAbsLike, U64Operand) {
  2737. const std::string ext_inst_name = GetParam();
  2738. const std::string body =
  2739. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0\n";
  2740. CompileSuccessfully(GenerateKernelCode(body));
  2741. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2742. EXPECT_THAT(
  2743. getDiagnosticString(),
  2744. HasSubstr("OpenCL.std " + ext_inst_name +
  2745. ": expected types of all operands to be equal to Result Type"));
  2746. }
  2747. INSTANTIATE_TEST_SUITE_P(AllSAbsLike, ValidateOpenCLStdSAbsLike,
  2748. ::testing::ValuesIn(std::vector<std::string>{
  2749. "s_abs",
  2750. "clz",
  2751. "ctz",
  2752. "popcount",
  2753. "u_abs",
  2754. }));
  2755. TEST_P(ValidateOpenCLStdUMinLike, Success) {
  2756. const std::string ext_inst_name = GetParam();
  2757. std::ostringstream ss;
  2758. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  2759. << " %u32_1 %u32_2\n";
  2760. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  2761. << " %u32_1 %u32_2\n";
  2762. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  2763. << " %u32_1 %u32_2\n";
  2764. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  2765. << " %u32_1 %u32_2\n";
  2766. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2767. << " %u32vec2_01 %u32vec2_01\n";
  2768. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2769. << " %u32vec2_01 %u32vec2_01\n";
  2770. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2771. << " %u32vec2_01 %u32vec2_01\n";
  2772. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2773. << " %u32vec2_01 %u32vec2_01\n";
  2774. ss << "%val9 = OpExtInst %u64 %extinst " << ext_inst_name
  2775. << " %u64_1 %u64_0\n";
  2776. CompileSuccessfully(GenerateKernelCode(ss.str()));
  2777. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2778. }
  2779. TEST_P(ValidateOpenCLStdUMinLike, FloatResultType) {
  2780. const std::string ext_inst_name = GetParam();
  2781. const std::string body =
  2782. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
  2783. CompileSuccessfully(GenerateKernelCode(body));
  2784. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2785. EXPECT_THAT(getDiagnosticString(),
  2786. HasSubstr("OpenCL.std " + ext_inst_name +
  2787. ": expected Result Type to be an int scalar "
  2788. "or vector type"));
  2789. }
  2790. TEST_P(ValidateOpenCLStdUMinLike, FloatOperand1) {
  2791. const std::string ext_inst_name = GetParam();
  2792. const std::string body =
  2793. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
  2794. CompileSuccessfully(GenerateKernelCode(body));
  2795. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2796. EXPECT_THAT(
  2797. getDiagnosticString(),
  2798. HasSubstr("OpenCL.std " + ext_inst_name +
  2799. ": expected types of all operands to be equal to Result Type"));
  2800. }
  2801. TEST_P(ValidateOpenCLStdUMinLike, FloatOperand2) {
  2802. const std::string ext_inst_name = GetParam();
  2803. const std::string body =
  2804. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
  2805. CompileSuccessfully(GenerateKernelCode(body));
  2806. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2807. EXPECT_THAT(
  2808. getDiagnosticString(),
  2809. HasSubstr("OpenCL.std " + ext_inst_name +
  2810. ": expected types of all operands to be equal to Result Type"));
  2811. }
  2812. TEST_P(ValidateOpenCLStdUMinLike, U64Operand1) {
  2813. const std::string ext_inst_name = GetParam();
  2814. const std::string body =
  2815. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0 %u32_0\n";
  2816. CompileSuccessfully(GenerateKernelCode(body));
  2817. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2818. EXPECT_THAT(
  2819. getDiagnosticString(),
  2820. HasSubstr("OpenCL.std " + ext_inst_name +
  2821. ": expected types of all operands to be equal to Result Type"));
  2822. }
  2823. TEST_P(ValidateOpenCLStdUMinLike, U64Operand2) {
  2824. const std::string ext_inst_name = GetParam();
  2825. const std::string body =
  2826. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %u64_0\n";
  2827. CompileSuccessfully(GenerateKernelCode(body));
  2828. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2829. EXPECT_THAT(
  2830. getDiagnosticString(),
  2831. HasSubstr("OpenCL.std " + ext_inst_name +
  2832. ": expected types of all operands to be equal to Result Type"));
  2833. }
  2834. INSTANTIATE_TEST_SUITE_P(AllUMinLike, ValidateOpenCLStdUMinLike,
  2835. ::testing::ValuesIn(std::vector<std::string>{
  2836. "s_max",
  2837. "u_max",
  2838. "s_min",
  2839. "u_min",
  2840. "s_abs_diff",
  2841. "s_add_sat",
  2842. "u_add_sat",
  2843. "s_mul_hi",
  2844. "rotate",
  2845. "s_sub_sat",
  2846. "u_sub_sat",
  2847. "s_hadd",
  2848. "u_hadd",
  2849. "s_rhadd",
  2850. "u_rhadd",
  2851. "u_abs_diff",
  2852. "u_mul_hi",
  2853. }));
  2854. TEST_P(ValidateOpenCLStdUClampLike, Success) {
  2855. const std::string ext_inst_name = GetParam();
  2856. std::ostringstream ss;
  2857. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  2858. << " %u32_0 %u32_1 %u32_2\n";
  2859. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  2860. << " %u32_0 %u32_1 %u32_2\n";
  2861. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  2862. << " %u32_0 %u32_1 %u32_2\n";
  2863. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  2864. << " %u32_0 %u32_1 %u32_2\n";
  2865. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2866. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  2867. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2868. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  2869. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2870. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  2871. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2872. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  2873. ss << "%val9 = OpExtInst %u64 %extinst " << ext_inst_name
  2874. << " %u64_1 %u64_0 %u64_1\n";
  2875. CompileSuccessfully(GenerateKernelCode(ss.str()));
  2876. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2877. }
  2878. TEST_P(ValidateOpenCLStdUClampLike, FloatResultType) {
  2879. const std::string ext_inst_name = GetParam();
  2880. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  2881. " %u32_0 %u32_0 %u32_1\n";
  2882. CompileSuccessfully(GenerateKernelCode(body));
  2883. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2884. EXPECT_THAT(getDiagnosticString(),
  2885. HasSubstr("OpenCL.std " + ext_inst_name +
  2886. ": expected Result Type to be an int scalar "
  2887. "or vector type"));
  2888. }
  2889. TEST_P(ValidateOpenCLStdUClampLike, FloatOperand1) {
  2890. const std::string ext_inst_name = GetParam();
  2891. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2892. " %f32_0 %u32_0 %u32_1\n";
  2893. CompileSuccessfully(GenerateKernelCode(body));
  2894. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2895. EXPECT_THAT(
  2896. getDiagnosticString(),
  2897. HasSubstr("OpenCL.std " + ext_inst_name +
  2898. ": expected types of all operands to be equal to Result Type"));
  2899. }
  2900. TEST_P(ValidateOpenCLStdUClampLike, FloatOperand2) {
  2901. const std::string ext_inst_name = GetParam();
  2902. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2903. " %u32_0 %f32_0 %u32_1\n";
  2904. CompileSuccessfully(GenerateKernelCode(body));
  2905. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2906. EXPECT_THAT(
  2907. getDiagnosticString(),
  2908. HasSubstr("OpenCL.std " + ext_inst_name +
  2909. ": expected types of all operands to be equal to Result Type"));
  2910. }
  2911. TEST_P(ValidateOpenCLStdUClampLike, FloatOperand3) {
  2912. const std::string ext_inst_name = GetParam();
  2913. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2914. " %u32_0 %u32_0 %f32_1\n";
  2915. CompileSuccessfully(GenerateKernelCode(body));
  2916. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2917. EXPECT_THAT(
  2918. getDiagnosticString(),
  2919. HasSubstr("OpenCL.std " + ext_inst_name +
  2920. ": expected types of all operands to be equal to Result Type"));
  2921. }
  2922. TEST_P(ValidateOpenCLStdUClampLike, U64Operand1) {
  2923. const std::string ext_inst_name = GetParam();
  2924. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2925. " %f32_0 %u32_0 %u64_1\n";
  2926. CompileSuccessfully(GenerateKernelCode(body));
  2927. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2928. EXPECT_THAT(
  2929. getDiagnosticString(),
  2930. HasSubstr("OpenCL.std " + ext_inst_name +
  2931. ": expected types of all operands to be equal to Result Type"));
  2932. }
  2933. TEST_P(ValidateOpenCLStdUClampLike, U64Operand2) {
  2934. const std::string ext_inst_name = GetParam();
  2935. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2936. " %u32_0 %f32_0 %u64_1\n";
  2937. CompileSuccessfully(GenerateKernelCode(body));
  2938. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2939. EXPECT_THAT(
  2940. getDiagnosticString(),
  2941. HasSubstr("OpenCL.std " + ext_inst_name +
  2942. ": expected types of all operands to be equal to Result Type"));
  2943. }
  2944. TEST_P(ValidateOpenCLStdUClampLike, U64Operand3) {
  2945. const std::string ext_inst_name = GetParam();
  2946. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  2947. " %u32_0 %u32_0 %u64_1\n";
  2948. CompileSuccessfully(GenerateKernelCode(body));
  2949. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2950. EXPECT_THAT(
  2951. getDiagnosticString(),
  2952. HasSubstr("OpenCL.std " + ext_inst_name +
  2953. ": expected types of all operands to be equal to Result Type"));
  2954. }
  2955. INSTANTIATE_TEST_SUITE_P(AllUClampLike, ValidateOpenCLStdUClampLike,
  2956. ::testing::ValuesIn(std::vector<std::string>{
  2957. "s_clamp",
  2958. "u_clamp",
  2959. "s_mad_hi",
  2960. "u_mad_sat",
  2961. "s_mad_sat",
  2962. "u_mad_hi",
  2963. }));
  2964. // -------------------------------------------------------------
  2965. TEST_P(ValidateOpenCLStdUMul24Like, Success) {
  2966. const std::string ext_inst_name = GetParam();
  2967. std::ostringstream ss;
  2968. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  2969. << " %u32_1 %u32_2\n";
  2970. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  2971. << " %u32_1 %u32_2\n";
  2972. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  2973. << " %u32_1 %u32_2\n";
  2974. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  2975. << " %u32_1 %u32_2\n";
  2976. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2977. << " %u32vec2_01 %u32vec2_01\n";
  2978. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2979. << " %u32vec2_01 %u32vec2_01\n";
  2980. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2981. << " %u32vec2_01 %u32vec2_01\n";
  2982. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  2983. << " %u32vec2_01 %u32vec2_01\n";
  2984. CompileSuccessfully(GenerateKernelCode(ss.str()));
  2985. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  2986. }
  2987. TEST_P(ValidateOpenCLStdUMul24Like, FloatResultType) {
  2988. const std::string ext_inst_name = GetParam();
  2989. const std::string body =
  2990. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32_0 %u32_0\n";
  2991. CompileSuccessfully(GenerateKernelCode(body));
  2992. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  2993. EXPECT_THAT(
  2994. getDiagnosticString(),
  2995. HasSubstr(
  2996. "OpenCL.std " + ext_inst_name +
  2997. ": expected Result Type to be a 32-bit int scalar or vector type"));
  2998. }
  2999. TEST_P(ValidateOpenCLStdUMul24Like, U64ResultType) {
  3000. const std::string ext_inst_name = GetParam();
  3001. const std::string body =
  3002. "%val1 = OpExtInst %u64 %extinst " + ext_inst_name + " %u64_0 %u64_0\n";
  3003. CompileSuccessfully(GenerateKernelCode(body));
  3004. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3005. EXPECT_THAT(
  3006. getDiagnosticString(),
  3007. HasSubstr(
  3008. "OpenCL.std " + ext_inst_name +
  3009. ": expected Result Type to be a 32-bit int scalar or vector type"));
  3010. }
  3011. TEST_P(ValidateOpenCLStdUMul24Like, FloatOperand1) {
  3012. const std::string ext_inst_name = GetParam();
  3013. const std::string body =
  3014. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_0 %u32_0\n";
  3015. CompileSuccessfully(GenerateKernelCode(body));
  3016. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3017. EXPECT_THAT(
  3018. getDiagnosticString(),
  3019. HasSubstr("OpenCL.std " + ext_inst_name +
  3020. ": expected types of all operands to be equal to Result Type"));
  3021. }
  3022. TEST_P(ValidateOpenCLStdUMul24Like, FloatOperand2) {
  3023. const std::string ext_inst_name = GetParam();
  3024. const std::string body =
  3025. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %f32_0\n";
  3026. CompileSuccessfully(GenerateKernelCode(body));
  3027. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3028. EXPECT_THAT(
  3029. getDiagnosticString(),
  3030. HasSubstr("OpenCL.std " + ext_inst_name +
  3031. ": expected types of all operands to be equal to Result Type"));
  3032. }
  3033. TEST_P(ValidateOpenCLStdUMul24Like, U64Operand1) {
  3034. const std::string ext_inst_name = GetParam();
  3035. const std::string body =
  3036. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u64_0 %u32_0\n";
  3037. CompileSuccessfully(GenerateKernelCode(body));
  3038. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3039. EXPECT_THAT(
  3040. getDiagnosticString(),
  3041. HasSubstr("OpenCL.std " + ext_inst_name +
  3042. ": expected types of all operands to be equal to Result Type"));
  3043. }
  3044. TEST_P(ValidateOpenCLStdUMul24Like, U64Operand2) {
  3045. const std::string ext_inst_name = GetParam();
  3046. const std::string body =
  3047. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %u32_0 %u64_0\n";
  3048. CompileSuccessfully(GenerateKernelCode(body));
  3049. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3050. EXPECT_THAT(
  3051. getDiagnosticString(),
  3052. HasSubstr("OpenCL.std " + ext_inst_name +
  3053. ": expected types of all operands to be equal to Result Type"));
  3054. }
  3055. INSTANTIATE_TEST_SUITE_P(AllUMul24Like, ValidateOpenCLStdUMul24Like,
  3056. ::testing::ValuesIn(std::vector<std::string>{
  3057. "s_mul24",
  3058. "u_mul24",
  3059. }));
  3060. TEST_P(ValidateOpenCLStdUMad24Like, Success) {
  3061. const std::string ext_inst_name = GetParam();
  3062. std::ostringstream ss;
  3063. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  3064. << " %u32_0 %u32_1 %u32_2\n";
  3065. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  3066. << " %u32_0 %u32_1 %u32_2\n";
  3067. ss << "%val3 = OpExtInst %u32 %extinst " << ext_inst_name
  3068. << " %u32_0 %u32_1 %u32_2\n";
  3069. ss << "%val4 = OpExtInst %u32 %extinst " << ext_inst_name
  3070. << " %u32_0 %u32_1 %u32_2\n";
  3071. ss << "%val5 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3072. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  3073. ss << "%val6 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3074. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  3075. ss << "%val7 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3076. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  3077. ss << "%val8 = OpExtInst %u32vec2 %extinst " << ext_inst_name
  3078. << " %u32vec2_01 %u32vec2_01 %u32vec2_12\n";
  3079. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3080. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3081. }
  3082. TEST_P(ValidateOpenCLStdUMad24Like, FloatResultType) {
  3083. const std::string ext_inst_name = GetParam();
  3084. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  3085. " %u32_0 %u32_0 %u32_1\n";
  3086. CompileSuccessfully(GenerateKernelCode(body));
  3087. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3088. EXPECT_THAT(
  3089. getDiagnosticString(),
  3090. HasSubstr(
  3091. "OpenCL.std " + ext_inst_name +
  3092. ": expected Result Type to be a 32-bit int scalar or vector type"));
  3093. }
  3094. TEST_P(ValidateOpenCLStdUMad24Like, U64ResultType) {
  3095. const std::string ext_inst_name = GetParam();
  3096. const std::string body = "%val1 = OpExtInst %u64 %extinst " + ext_inst_name +
  3097. " %u64_0 %u64_0 %u64_1\n";
  3098. CompileSuccessfully(GenerateKernelCode(body));
  3099. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3100. EXPECT_THAT(
  3101. getDiagnosticString(),
  3102. HasSubstr(
  3103. "OpenCL.std " + ext_inst_name +
  3104. ": expected Result Type to be a 32-bit int scalar or vector type"));
  3105. }
  3106. TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand1) {
  3107. const std::string ext_inst_name = GetParam();
  3108. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  3109. " %f32_0 %u32_0 %u32_1\n";
  3110. CompileSuccessfully(GenerateKernelCode(body));
  3111. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3112. EXPECT_THAT(
  3113. getDiagnosticString(),
  3114. HasSubstr("OpenCL.std " + ext_inst_name +
  3115. ": expected types of all operands to be equal to Result Type"));
  3116. }
  3117. TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand2) {
  3118. const std::string ext_inst_name = GetParam();
  3119. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  3120. " %u32_0 %f32_0 %u32_1\n";
  3121. CompileSuccessfully(GenerateKernelCode(body));
  3122. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3123. EXPECT_THAT(
  3124. getDiagnosticString(),
  3125. HasSubstr("OpenCL.std " + ext_inst_name +
  3126. ": expected types of all operands to be equal to Result Type"));
  3127. }
  3128. TEST_P(ValidateOpenCLStdUMad24Like, FloatOperand3) {
  3129. const std::string ext_inst_name = GetParam();
  3130. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  3131. " %u32_0 %u32_0 %f32_1\n";
  3132. CompileSuccessfully(GenerateKernelCode(body));
  3133. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3134. EXPECT_THAT(
  3135. getDiagnosticString(),
  3136. HasSubstr("OpenCL.std " + ext_inst_name +
  3137. ": expected types of all operands to be equal to Result Type"));
  3138. }
  3139. TEST_P(ValidateOpenCLStdUMad24Like, U64Operand1) {
  3140. const std::string ext_inst_name = GetParam();
  3141. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  3142. " %f32_0 %u32_0 %u64_1\n";
  3143. CompileSuccessfully(GenerateKernelCode(body));
  3144. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3145. EXPECT_THAT(
  3146. getDiagnosticString(),
  3147. HasSubstr("OpenCL.std " + ext_inst_name +
  3148. ": expected types of all operands to be equal to Result Type"));
  3149. }
  3150. TEST_P(ValidateOpenCLStdUMad24Like, U64Operand2) {
  3151. const std::string ext_inst_name = GetParam();
  3152. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  3153. " %u32_0 %f32_0 %u64_1\n";
  3154. CompileSuccessfully(GenerateKernelCode(body));
  3155. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3156. EXPECT_THAT(
  3157. getDiagnosticString(),
  3158. HasSubstr("OpenCL.std " + ext_inst_name +
  3159. ": expected types of all operands to be equal to Result Type"));
  3160. }
  3161. TEST_P(ValidateOpenCLStdUMad24Like, U64Operand3) {
  3162. const std::string ext_inst_name = GetParam();
  3163. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  3164. " %u32_0 %u32_0 %u64_1\n";
  3165. CompileSuccessfully(GenerateKernelCode(body));
  3166. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3167. EXPECT_THAT(
  3168. getDiagnosticString(),
  3169. HasSubstr("OpenCL.std " + ext_inst_name +
  3170. ": expected types of all operands to be equal to Result Type"));
  3171. }
  3172. INSTANTIATE_TEST_SUITE_P(AllUMad24Like, ValidateOpenCLStdUMad24Like,
  3173. ::testing::ValuesIn(std::vector<std::string>{
  3174. "s_mad24",
  3175. "u_mad24",
  3176. }));
  3177. TEST_F(ValidateExtInst, OpenCLStdCrossSuccess) {
  3178. const std::string body = R"(
  3179. %val1 = OpExtInst %f32vec3 %extinst cross %f32vec3_012 %f32vec3_123
  3180. %val2 = OpExtInst %f32vec4 %extinst cross %f32vec4_0123 %f32vec4_0123
  3181. )";
  3182. CompileSuccessfully(GenerateKernelCode(body));
  3183. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3184. }
  3185. TEST_F(ValidateExtInst, OpenCLStdCrossIntVectorResultType) {
  3186. const std::string body = R"(
  3187. %val1 = OpExtInst %u32vec3 %extinst cross %f32vec3_012 %f32vec3_123
  3188. )";
  3189. CompileSuccessfully(GenerateKernelCode(body));
  3190. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3191. EXPECT_THAT(getDiagnosticString(),
  3192. HasSubstr("OpenCL.std cross: "
  3193. "expected Result Type to be a float vector type"));
  3194. }
  3195. TEST_F(ValidateExtInst, OpenCLStdCrossResultTypeWrongSize) {
  3196. const std::string body = R"(
  3197. %val1 = OpExtInst %f32vec2 %extinst cross %f32vec3_012 %f32vec3_123
  3198. )";
  3199. CompileSuccessfully(GenerateKernelCode(body));
  3200. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3201. EXPECT_THAT(getDiagnosticString(),
  3202. HasSubstr("OpenCL.std cross: "
  3203. "expected Result Type to have 3 or 4 components"));
  3204. }
  3205. TEST_F(ValidateExtInst, OpenCLStdCrossXWrongType) {
  3206. const std::string body = R"(
  3207. %val1 = OpExtInst %f32vec3 %extinst cross %f64vec3_012 %f32vec3_123
  3208. )";
  3209. CompileSuccessfully(GenerateKernelCode(body));
  3210. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3211. EXPECT_THAT(getDiagnosticString(),
  3212. HasSubstr("OpenCL.std cross: "
  3213. "expected operand X type to be equal to Result Type"));
  3214. }
  3215. TEST_F(ValidateExtInst, OpenCLStdCrossYWrongType) {
  3216. const std::string body = R"(
  3217. %val1 = OpExtInst %f32vec3 %extinst cross %f32vec3_123 %f64vec3_012
  3218. )";
  3219. CompileSuccessfully(GenerateKernelCode(body));
  3220. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3221. EXPECT_THAT(getDiagnosticString(),
  3222. HasSubstr("OpenCL.std cross: "
  3223. "expected operand Y type to be equal to Result Type"));
  3224. }
  3225. TEST_P(ValidateOpenCLStdLengthLike, Success) {
  3226. const std::string ext_inst_name = GetParam();
  3227. std::ostringstream ss;
  3228. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32vec2_01\n";
  3229. ss << "%val2 = OpExtInst %f32 %extinst " << ext_inst_name
  3230. << " %f32vec4_0123\n";
  3231. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3232. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3233. }
  3234. TEST_P(ValidateOpenCLStdLengthLike, IntResultType) {
  3235. const std::string ext_inst_name = GetParam();
  3236. const std::string body =
  3237. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32vec2_01\n";
  3238. CompileSuccessfully(GenerateKernelCode(body));
  3239. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3240. EXPECT_THAT(getDiagnosticString(),
  3241. HasSubstr("OpenCL.std " + ext_inst_name +
  3242. ": "
  3243. "expected Result Type to be a float scalar type"));
  3244. }
  3245. TEST_P(ValidateOpenCLStdLengthLike, IntX) {
  3246. const std::string ext_inst_name = GetParam();
  3247. const std::string body =
  3248. "%val1 = OpExtInst %f32 %extinst " + ext_inst_name + " %u32vec2_01\n";
  3249. CompileSuccessfully(GenerateKernelCode(body));
  3250. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3251. EXPECT_THAT(getDiagnosticString(),
  3252. HasSubstr("OpenCL.std " + ext_inst_name +
  3253. ": "
  3254. "expected operand P to be a float scalar or vector"));
  3255. }
  3256. TEST_P(ValidateOpenCLStdLengthLike, VectorTooBig) {
  3257. const std::string ext_inst_name = GetParam();
  3258. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  3259. " %f32vec8_01010101\n";
  3260. CompileSuccessfully(GenerateKernelCode(body));
  3261. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3262. EXPECT_THAT(
  3263. getDiagnosticString(),
  3264. HasSubstr("OpenCL.std " + ext_inst_name +
  3265. ": "
  3266. "expected operand P to have no more than 4 components"));
  3267. }
  3268. TEST_P(ValidateOpenCLStdLengthLike, DifferentType) {
  3269. const std::string ext_inst_name = GetParam();
  3270. const std::string body =
  3271. "%val1 = OpExtInst %f64 %extinst " + ext_inst_name + " %f32vec2_01\n";
  3272. CompileSuccessfully(GenerateKernelCode(body));
  3273. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3274. EXPECT_THAT(getDiagnosticString(),
  3275. HasSubstr("OpenCL.std " + ext_inst_name +
  3276. ": "
  3277. "expected operand P component type to be equal to "
  3278. "Result Type"));
  3279. }
  3280. INSTANTIATE_TEST_SUITE_P(AllLengthLike, ValidateOpenCLStdLengthLike,
  3281. ::testing::ValuesIn(std::vector<std::string>{
  3282. "length",
  3283. "fast_length",
  3284. }));
  3285. TEST_P(ValidateOpenCLStdDistanceLike, Success) {
  3286. const std::string ext_inst_name = GetParam();
  3287. std::ostringstream ss;
  3288. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  3289. << " %f32vec2_01 %f32vec2_01\n";
  3290. ss << "%val2 = OpExtInst %f32 %extinst " << ext_inst_name
  3291. << " %f32vec4_0123 %f32vec4_1234\n";
  3292. ss << "%val3 = OpExtInst %f32 %extinst " << ext_inst_name
  3293. << " %f32_0 %f32_1\n";
  3294. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3295. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3296. }
  3297. TEST_P(ValidateOpenCLStdDistanceLike, IntResultType) {
  3298. const std::string ext_inst_name = GetParam();
  3299. const std::string body = "%val1 = OpExtInst %u32 %extinst " + ext_inst_name +
  3300. " %f32vec2_01 %f32vec2_12\n";
  3301. CompileSuccessfully(GenerateKernelCode(body));
  3302. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3303. EXPECT_THAT(getDiagnosticString(),
  3304. HasSubstr("OpenCL.std " + ext_inst_name +
  3305. ": "
  3306. "expected Result Type to be a float scalar type"));
  3307. }
  3308. TEST_P(ValidateOpenCLStdDistanceLike, IntP0) {
  3309. const std::string ext_inst_name = GetParam();
  3310. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  3311. " %u32vec2_01 %f32vec2_12\n";
  3312. CompileSuccessfully(GenerateKernelCode(body));
  3313. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3314. EXPECT_THAT(
  3315. getDiagnosticString(),
  3316. HasSubstr("OpenCL.std " + ext_inst_name +
  3317. ": "
  3318. "expected operand P0 to be of float scalar or vector type"));
  3319. }
  3320. TEST_P(ValidateOpenCLStdDistanceLike, VectorTooBig) {
  3321. const std::string ext_inst_name = GetParam();
  3322. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  3323. " %f32vec8_01010101 %f32vec8_01010101\n";
  3324. CompileSuccessfully(GenerateKernelCode(body));
  3325. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3326. EXPECT_THAT(
  3327. getDiagnosticString(),
  3328. HasSubstr("OpenCL.std " + ext_inst_name +
  3329. ": "
  3330. "expected operand P0 to have no more than 4 components"));
  3331. }
  3332. TEST_P(ValidateOpenCLStdDistanceLike, F64P0) {
  3333. const std::string ext_inst_name = GetParam();
  3334. const std::string body = "%val1 = OpExtInst %f32 %extinst " + ext_inst_name +
  3335. " %f64vec2_01 %f32vec2_12\n";
  3336. CompileSuccessfully(GenerateKernelCode(body));
  3337. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3338. EXPECT_THAT(
  3339. getDiagnosticString(),
  3340. HasSubstr(
  3341. "OpenCL.std " + ext_inst_name +
  3342. ": "
  3343. "expected operand P0 component type to be equal to Result Type"));
  3344. }
  3345. TEST_P(ValidateOpenCLStdDistanceLike, DifferentOperands) {
  3346. const std::string ext_inst_name = GetParam();
  3347. const std::string body = "%val1 = OpExtInst %f64 %extinst " + ext_inst_name +
  3348. " %f64vec2_01 %f32vec2_12\n";
  3349. CompileSuccessfully(GenerateKernelCode(body));
  3350. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3351. EXPECT_THAT(getDiagnosticString(),
  3352. HasSubstr("OpenCL.std " + ext_inst_name +
  3353. ": "
  3354. "expected operands P0 and P1 to be of the same type"));
  3355. }
  3356. INSTANTIATE_TEST_SUITE_P(AllDistanceLike, ValidateOpenCLStdDistanceLike,
  3357. ::testing::ValuesIn(std::vector<std::string>{
  3358. "distance",
  3359. "fast_distance",
  3360. }));
  3361. TEST_P(ValidateOpenCLStdNormalizeLike, Success) {
  3362. const std::string ext_inst_name = GetParam();
  3363. std::ostringstream ss;
  3364. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3365. << " %f32vec2_01\n";
  3366. ss << "%val2 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  3367. << " %f32vec4_0123\n";
  3368. ss << "%val3 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_2\n";
  3369. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3370. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3371. }
  3372. TEST_P(ValidateOpenCLStdNormalizeLike, IntResultType) {
  3373. const std::string ext_inst_name = GetParam();
  3374. const std::string body =
  3375. "%val1 = OpExtInst %u32 %extinst " + ext_inst_name + " %f32_2\n";
  3376. CompileSuccessfully(GenerateKernelCode(body));
  3377. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3378. EXPECT_THAT(
  3379. getDiagnosticString(),
  3380. HasSubstr("OpenCL.std " + ext_inst_name +
  3381. ": "
  3382. "expected Result Type to be a float scalar or vector type"));
  3383. }
  3384. TEST_P(ValidateOpenCLStdNormalizeLike, VectorTooBig) {
  3385. const std::string ext_inst_name = GetParam();
  3386. const std::string body = "%val1 = OpExtInst %f32vec8 %extinst " +
  3387. ext_inst_name + " %f32vec8_01010101\n";
  3388. CompileSuccessfully(GenerateKernelCode(body));
  3389. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3390. EXPECT_THAT(
  3391. getDiagnosticString(),
  3392. HasSubstr("OpenCL.std " + ext_inst_name +
  3393. ": "
  3394. "expected Result Type to have no more than 4 components"));
  3395. }
  3396. TEST_P(ValidateOpenCLStdNormalizeLike, DifferentType) {
  3397. const std::string ext_inst_name = GetParam();
  3398. const std::string body =
  3399. "%val1 = OpExtInst %f64vec2 %extinst " + ext_inst_name + " %f32vec2_01\n";
  3400. CompileSuccessfully(GenerateKernelCode(body));
  3401. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3402. EXPECT_THAT(getDiagnosticString(),
  3403. HasSubstr("OpenCL.std " + ext_inst_name +
  3404. ": "
  3405. "expected operand P type to be equal to Result Type"));
  3406. }
  3407. INSTANTIATE_TEST_SUITE_P(AllNormalizeLike, ValidateOpenCLStdNormalizeLike,
  3408. ::testing::ValuesIn(std::vector<std::string>{
  3409. "normalize",
  3410. "fast_normalize",
  3411. }));
  3412. TEST_F(ValidateExtInst, OpenCLStdBitselectSuccess) {
  3413. const std::string body = R"(
  3414. %val1 = OpExtInst %f32 %extinst bitselect %f32_2 %f32_1 %f32_1
  3415. %val2 = OpExtInst %f32vec4 %extinst bitselect %f32vec4_0123 %f32vec4_1234 %f32vec4_0123
  3416. %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %u32_1 %u32_1
  3417. %val4 = OpExtInst %u32vec4 %extinst bitselect %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
  3418. %val5 = OpExtInst %u64 %extinst bitselect %u64_2 %u64_1 %u64_1
  3419. )";
  3420. CompileSuccessfully(GenerateKernelCode(body));
  3421. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3422. }
  3423. TEST_F(ValidateExtInst, OpenCLStdBitselectWrongResultType) {
  3424. const std::string body = R"(
  3425. %val3 = OpExtInst %struct_f32_f32 %extinst bitselect %u32_2 %u32_1 %u32_1
  3426. )";
  3427. CompileSuccessfully(GenerateKernelCode(body));
  3428. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3429. EXPECT_THAT(
  3430. getDiagnosticString(),
  3431. HasSubstr(
  3432. "OpenCL.std bitselect: "
  3433. "expected Result Type to be an int or float scalar or vector type"));
  3434. }
  3435. TEST_F(ValidateExtInst, OpenCLStdBitselectAWrongType) {
  3436. const std::string body = R"(
  3437. %val3 = OpExtInst %u32 %extinst bitselect %f32_2 %u32_1 %u32_1
  3438. )";
  3439. CompileSuccessfully(GenerateKernelCode(body));
  3440. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3441. EXPECT_THAT(
  3442. getDiagnosticString(),
  3443. HasSubstr("OpenCL.std bitselect: "
  3444. "expected types of all operands to be equal to Result Type"));
  3445. }
  3446. TEST_F(ValidateExtInst, OpenCLStdBitselectBWrongType) {
  3447. const std::string body = R"(
  3448. %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %f32_1 %u32_1
  3449. )";
  3450. CompileSuccessfully(GenerateKernelCode(body));
  3451. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3452. EXPECT_THAT(
  3453. getDiagnosticString(),
  3454. HasSubstr("OpenCL.std bitselect: "
  3455. "expected types of all operands to be equal to Result Type"));
  3456. }
  3457. TEST_F(ValidateExtInst, OpenCLStdBitselectCWrongType) {
  3458. const std::string body = R"(
  3459. %val3 = OpExtInst %u32 %extinst bitselect %u32_2 %u32_1 %f32_1
  3460. )";
  3461. CompileSuccessfully(GenerateKernelCode(body));
  3462. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3463. EXPECT_THAT(
  3464. getDiagnosticString(),
  3465. HasSubstr("OpenCL.std bitselect: "
  3466. "expected types of all operands to be equal to Result Type"));
  3467. }
  3468. TEST_F(ValidateExtInst, OpenCLStdSelectSuccess) {
  3469. const std::string body = R"(
  3470. %val1 = OpExtInst %f32 %extinst select %f32_2 %f32_1 %u32_1
  3471. %val2 = OpExtInst %f32vec4 %extinst select %f32vec4_0123 %f32vec4_1234 %u32vec4_0123
  3472. %val3 = OpExtInst %u32 %extinst select %u32_2 %u32_1 %u32_1
  3473. %val4 = OpExtInst %u32vec4 %extinst select %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
  3474. %val5 = OpExtInst %u64 %extinst select %u64_2 %u64_1 %u64_1
  3475. )";
  3476. CompileSuccessfully(GenerateKernelCode(body));
  3477. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3478. }
  3479. TEST_F(ValidateExtInst, OpenCLStdSelectWrongResultType) {
  3480. const std::string body = R"(
  3481. %val3 = OpExtInst %struct_f32_f32 %extinst select %u32_2 %u32_1 %u32_1
  3482. )";
  3483. CompileSuccessfully(GenerateKernelCode(body));
  3484. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3485. EXPECT_THAT(
  3486. getDiagnosticString(),
  3487. HasSubstr(
  3488. "OpenCL.std select: "
  3489. "expected Result Type to be an int or float scalar or vector type"));
  3490. }
  3491. TEST_F(ValidateExtInst, OpenCLStdSelectAWrongType) {
  3492. const std::string body = R"(
  3493. %val3 = OpExtInst %u32 %extinst select %f32_2 %u32_1 %u32_1
  3494. )";
  3495. CompileSuccessfully(GenerateKernelCode(body));
  3496. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3497. EXPECT_THAT(getDiagnosticString(),
  3498. HasSubstr("OpenCL.std select: "
  3499. "expected operand A type to be equal to Result Type"));
  3500. }
  3501. TEST_F(ValidateExtInst, OpenCLStdSelectBWrongType) {
  3502. const std::string body = R"(
  3503. %val3 = OpExtInst %u32 %extinst select %u32_2 %f32_1 %u32_1
  3504. )";
  3505. CompileSuccessfully(GenerateKernelCode(body));
  3506. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3507. EXPECT_THAT(getDiagnosticString(),
  3508. HasSubstr("OpenCL.std select: "
  3509. "expected operand B type to be equal to Result Type"));
  3510. }
  3511. TEST_F(ValidateExtInst, OpenCLStdSelectCWrongType) {
  3512. const std::string body = R"(
  3513. %val3 = OpExtInst %f32 %extinst select %f32_2 %f32_1 %f32_1
  3514. )";
  3515. CompileSuccessfully(GenerateKernelCode(body));
  3516. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3517. EXPECT_THAT(getDiagnosticString(),
  3518. HasSubstr("OpenCL.std select: "
  3519. "expected operand C to be an int scalar or vector"));
  3520. }
  3521. TEST_F(ValidateExtInst, OpenCLStdSelectCWrongComponentNumber) {
  3522. const std::string body = R"(
  3523. %val3 = OpExtInst %f32vec2 %extinst select %f32vec2_12 %f32vec2_01 %u32_1
  3524. )";
  3525. CompileSuccessfully(GenerateKernelCode(body));
  3526. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3527. EXPECT_THAT(getDiagnosticString(),
  3528. HasSubstr("OpenCL.std select: "
  3529. "expected operand C to have the same number of "
  3530. "components as Result Type"));
  3531. }
  3532. TEST_F(ValidateExtInst, OpenCLStdSelectCWrongBitWidth) {
  3533. const std::string body = R"(
  3534. %val3 = OpExtInst %f32vec2 %extinst select %f32vec2_12 %f32vec2_01 %u64vec2_01
  3535. )";
  3536. CompileSuccessfully(GenerateKernelCode(body));
  3537. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3538. EXPECT_THAT(
  3539. getDiagnosticString(),
  3540. HasSubstr(
  3541. "OpenCL.std select: "
  3542. "expected operand C to have the same bit width as Result Type"));
  3543. }
  3544. TEST_P(ValidateOpenCLStdVStoreHalfLike, SuccessPhysical32) {
  3545. const std::string ext_inst_name = GetParam();
  3546. const std::string rounding_mode =
  3547. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3548. std::ostringstream ss;
  3549. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3550. if (std::string::npos == ext_inst_name.find("halfn")) {
  3551. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3552. << " %f32_1 %u32_1 %ptr" << rounding_mode << "\n";
  3553. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  3554. << " %f64_0 %u32_2 %ptr" << rounding_mode << "\n";
  3555. } else {
  3556. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3557. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3558. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  3559. << " %f32vec4_0123 %u32_0 %ptr" << rounding_mode << "\n";
  3560. ss << "%val3 = OpExtInst %void %extinst " << ext_inst_name
  3561. << " %f64vec2_01 %u32_2 %ptr" << rounding_mode << "\n";
  3562. }
  3563. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3564. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3565. }
  3566. TEST_P(ValidateOpenCLStdVStoreHalfLike, SuccessPhysical64) {
  3567. const std::string ext_inst_name = GetParam();
  3568. const std::string rounding_mode =
  3569. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3570. std::ostringstream ss;
  3571. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3572. if (std::string::npos == ext_inst_name.find("halfn")) {
  3573. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3574. << " %f32_1 %u64_1 %ptr" << rounding_mode << "\n";
  3575. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  3576. << " %f64_0 %u64_2 %ptr" << rounding_mode << "\n";
  3577. } else {
  3578. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3579. << " %f32vec2_01 %u64_1 %ptr" << rounding_mode << "\n";
  3580. ss << "%val2 = OpExtInst %void %extinst " << ext_inst_name
  3581. << " %f32vec4_0123 %u64_0 %ptr" << rounding_mode << "\n";
  3582. ss << "%val3 = OpExtInst %void %extinst " << ext_inst_name
  3583. << " %f64vec2_01 %u64_2 %ptr" << rounding_mode << "\n";
  3584. }
  3585. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  3586. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3587. }
  3588. TEST_P(ValidateOpenCLStdVStoreHalfLike, NonVoidResultType) {
  3589. const std::string ext_inst_name = GetParam();
  3590. const std::string rounding_mode =
  3591. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3592. std::ostringstream ss;
  3593. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3594. if (std::string::npos == ext_inst_name.find("halfn")) {
  3595. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  3596. << " %f32_1 %u32_1 %ptr" << rounding_mode << "\n";
  3597. } else {
  3598. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  3599. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3600. }
  3601. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3602. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3603. EXPECT_THAT(getDiagnosticString(),
  3604. HasSubstr("OpenCL.std " + ext_inst_name +
  3605. ": expected Result Type to be void"));
  3606. }
  3607. TEST_P(ValidateOpenCLStdVStoreHalfLike, WrongDataType) {
  3608. const std::string ext_inst_name = GetParam();
  3609. const std::string rounding_mode =
  3610. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3611. std::ostringstream ss;
  3612. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3613. if (std::string::npos == ext_inst_name.find("halfn")) {
  3614. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3615. << " %f64vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3616. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3617. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3618. EXPECT_THAT(getDiagnosticString(),
  3619. HasSubstr("OpenCL.std " + ext_inst_name +
  3620. ": expected Data to be a 32 or 64-bit float scalar"));
  3621. } else {
  3622. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3623. << " %f64_0 %u32_1 %ptr" << rounding_mode << "\n";
  3624. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3625. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3626. EXPECT_THAT(getDiagnosticString(),
  3627. HasSubstr("OpenCL.std " + ext_inst_name +
  3628. ": expected Data to be a 32 or 64-bit float vector"));
  3629. }
  3630. }
  3631. TEST_P(ValidateOpenCLStdVStoreHalfLike, AddressingModelLogical) {
  3632. const std::string ext_inst_name = GetParam();
  3633. const std::string rounding_mode =
  3634. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3635. std::ostringstream ss;
  3636. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3637. if (std::string::npos == ext_inst_name.find("halfn")) {
  3638. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3639. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  3640. } else {
  3641. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3642. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3643. }
  3644. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  3645. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3646. EXPECT_THAT(getDiagnosticString(),
  3647. HasSubstr("OpenCL.std " + ext_inst_name +
  3648. " can only be used with physical addressing models"));
  3649. }
  3650. TEST_P(ValidateOpenCLStdVStoreHalfLike, OffsetNotSizeT) {
  3651. const std::string ext_inst_name = GetParam();
  3652. const std::string rounding_mode =
  3653. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3654. std::ostringstream ss;
  3655. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3656. if (std::string::npos == ext_inst_name.find("halfn")) {
  3657. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3658. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  3659. } else {
  3660. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3661. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3662. }
  3663. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  3664. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3665. EXPECT_THAT(
  3666. getDiagnosticString(),
  3667. HasSubstr("OpenCL.std " + ext_inst_name +
  3668. ": "
  3669. "expected operand Offset to be of type size_t (64-bit integer "
  3670. "for the addressing model used in the module)"));
  3671. }
  3672. TEST_P(ValidateOpenCLStdVStoreHalfLike, PNotPointer) {
  3673. const std::string ext_inst_name = GetParam();
  3674. const std::string rounding_mode =
  3675. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3676. std::ostringstream ss;
  3677. if (std::string::npos == ext_inst_name.find("halfn")) {
  3678. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3679. << " %f32_0 %u32_1 %f16_ptr_workgroup" << rounding_mode << "\n";
  3680. } else {
  3681. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3682. << " %f32vec2_01 %u32_1 %f16_ptr_workgroup" << rounding_mode << "\n";
  3683. }
  3684. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3685. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  3686. EXPECT_THAT(getDiagnosticString(),
  3687. HasSubstr("Operand '89[%_ptr_Workgroup_half]' cannot be a type"));
  3688. }
  3689. TEST_P(ValidateOpenCLStdVStoreHalfLike, ConstPointer) {
  3690. const std::string ext_inst_name = GetParam();
  3691. const std::string rounding_mode =
  3692. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3693. std::ostringstream ss;
  3694. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  3695. "%f16vec8_uniform_constant %u32_1\n";
  3696. if (std::string::npos == ext_inst_name.find("halfn")) {
  3697. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3698. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  3699. } else {
  3700. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3701. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3702. }
  3703. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3704. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3705. EXPECT_THAT(getDiagnosticString(),
  3706. HasSubstr("OpenCL.std " + ext_inst_name +
  3707. ": expected operand P storage class to be Generic, "
  3708. "CrossWorkgroup, Workgroup or Function"));
  3709. }
  3710. TEST_P(ValidateOpenCLStdVStoreHalfLike, PDataTypeInt) {
  3711. const std::string ext_inst_name = GetParam();
  3712. const std::string rounding_mode =
  3713. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3714. std::ostringstream ss;
  3715. ss << "%ptr = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  3716. if (std::string::npos == ext_inst_name.find("halfn")) {
  3717. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3718. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  3719. } else {
  3720. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3721. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3722. }
  3723. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3724. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3725. EXPECT_THAT(
  3726. getDiagnosticString(),
  3727. HasSubstr("OpenCL.std " + ext_inst_name +
  3728. ": expected operand P data type to be 16-bit float scalar"));
  3729. }
  3730. TEST_P(ValidateOpenCLStdVStoreHalfLike, PDataTypeFloat32) {
  3731. const std::string ext_inst_name = GetParam();
  3732. const std::string rounding_mode =
  3733. ext_inst_name.substr(ext_inst_name.length() - 2) == "_r" ? " RTE" : "";
  3734. std::ostringstream ss;
  3735. ss << "%ptr = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  3736. if (std::string::npos == ext_inst_name.find("halfn")) {
  3737. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3738. << " %f32_0 %u32_1 %ptr" << rounding_mode << "\n";
  3739. } else {
  3740. ss << "%val1 = OpExtInst %void %extinst " << ext_inst_name
  3741. << " %f32vec2_01 %u32_1 %ptr" << rounding_mode << "\n";
  3742. }
  3743. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3744. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3745. EXPECT_THAT(
  3746. getDiagnosticString(),
  3747. HasSubstr("OpenCL.std " + ext_inst_name +
  3748. ": expected operand P data type to be 16-bit float scalar"));
  3749. }
  3750. INSTANTIATE_TEST_SUITE_P(AllVStoreHalfLike, ValidateOpenCLStdVStoreHalfLike,
  3751. ::testing::ValuesIn(std::vector<std::string>{
  3752. "vstore_half",
  3753. "vstore_half_r",
  3754. "vstore_halfn",
  3755. "vstore_halfn_r",
  3756. "vstorea_halfn",
  3757. "vstorea_halfn_r",
  3758. }));
  3759. TEST_P(ValidateOpenCLStdVLoadHalfLike, SuccessPhysical32) {
  3760. const std::string ext_inst_name = GetParam();
  3761. std::ostringstream ss;
  3762. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3763. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3764. << " %u32_1 %ptr 2\n";
  3765. ss << "%val2 = OpExtInst %f32vec3 %extinst " << ext_inst_name
  3766. << " %u32_1 %ptr 3\n";
  3767. ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  3768. << " %u32_1 %ptr 4\n";
  3769. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3770. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3771. }
  3772. TEST_P(ValidateOpenCLStdVLoadHalfLike, SuccessPhysical64) {
  3773. const std::string ext_inst_name = GetParam();
  3774. std::ostringstream ss;
  3775. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3776. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3777. << " %u64_1 %ptr 2\n";
  3778. ss << "%val2 = OpExtInst %f32vec3 %extinst " << ext_inst_name
  3779. << " %u64_1 %ptr 3\n";
  3780. ss << "%val3 = OpExtInst %f32vec4 %extinst " << ext_inst_name
  3781. << " %u64_1 %ptr 4\n";
  3782. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  3783. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3784. }
  3785. TEST_P(ValidateOpenCLStdVLoadHalfLike, ResultTypeNotFloatVector) {
  3786. const std::string ext_inst_name = GetParam();
  3787. std::ostringstream ss;
  3788. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3789. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  3790. << " %u32_1 %ptr 1\n";
  3791. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3792. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3793. EXPECT_THAT(getDiagnosticString(),
  3794. HasSubstr("OpenCL.std " + ext_inst_name +
  3795. ": expected Result Type to be a float vector type"));
  3796. }
  3797. TEST_P(ValidateOpenCLStdVLoadHalfLike, AddressingModelLogical) {
  3798. const std::string ext_inst_name = GetParam();
  3799. std::ostringstream ss;
  3800. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3801. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3802. << " %u32_1 %ptr 2\n";
  3803. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  3804. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3805. EXPECT_THAT(getDiagnosticString(),
  3806. HasSubstr("OpenCL.std " + ext_inst_name +
  3807. " can only be used with physical addressing models"));
  3808. }
  3809. TEST_P(ValidateOpenCLStdVLoadHalfLike, OffsetNotSizeT) {
  3810. const std::string ext_inst_name = GetParam();
  3811. std::ostringstream ss;
  3812. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3813. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3814. << " %u64_1 %ptr 2\n";
  3815. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3816. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3817. EXPECT_THAT(
  3818. getDiagnosticString(),
  3819. HasSubstr("OpenCL.std " + ext_inst_name +
  3820. ": expected operand Offset to be of type size_t (32-bit "
  3821. "integer for the addressing model used in the module)"));
  3822. }
  3823. TEST_P(ValidateOpenCLStdVLoadHalfLike, PNotPointer) {
  3824. const std::string ext_inst_name = GetParam();
  3825. std::ostringstream ss;
  3826. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3827. << " %u32_1 %f16_ptr_workgroup 2\n";
  3828. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3829. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  3830. EXPECT_THAT(getDiagnosticString(),
  3831. HasSubstr("Operand '89[%_ptr_Workgroup_half]' cannot be a type"));
  3832. }
  3833. TEST_P(ValidateOpenCLStdVLoadHalfLike, OffsetWrongStorageType) {
  3834. const std::string ext_inst_name = GetParam();
  3835. std::ostringstream ss;
  3836. ss << "%ptr = OpAccessChain %f16_ptr_input %f16vec8_input %u32_1\n";
  3837. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3838. << " %u32_1 %ptr 2\n";
  3839. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3840. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3841. EXPECT_THAT(
  3842. getDiagnosticString(),
  3843. HasSubstr("OpenCL.std " + ext_inst_name +
  3844. ": expected operand P storage class to be UniformConstant, "
  3845. "Generic, CrossWorkgroup, Workgroup or Function"));
  3846. }
  3847. TEST_P(ValidateOpenCLStdVLoadHalfLike, PDataTypeInt) {
  3848. const std::string ext_inst_name = GetParam();
  3849. std::ostringstream ss;
  3850. ss << "%ptr = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  3851. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3852. << " %u32_1 %ptr 2\n";
  3853. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3854. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3855. EXPECT_THAT(
  3856. getDiagnosticString(),
  3857. HasSubstr("OpenCL.std " + ext_inst_name +
  3858. ": expected operand P data type to be 16-bit float scalar"));
  3859. }
  3860. TEST_P(ValidateOpenCLStdVLoadHalfLike, PDataTypeFloat32) {
  3861. const std::string ext_inst_name = GetParam();
  3862. std::ostringstream ss;
  3863. ss << "%ptr = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  3864. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3865. << " %u32_1 %ptr 2\n";
  3866. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3867. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3868. EXPECT_THAT(
  3869. getDiagnosticString(),
  3870. HasSubstr("OpenCL.std " + ext_inst_name +
  3871. ": expected operand P data type to be 16-bit float scalar"));
  3872. }
  3873. TEST_P(ValidateOpenCLStdVLoadHalfLike, WrongN) {
  3874. const std::string ext_inst_name = GetParam();
  3875. std::ostringstream ss;
  3876. ss << "%ptr = OpAccessChain %f16_ptr_workgroup %f16vec8_workgroup %u32_1\n";
  3877. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  3878. << " %u32_1 %ptr 3\n";
  3879. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3880. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3881. EXPECT_THAT(getDiagnosticString(),
  3882. HasSubstr("OpenCL.std " + ext_inst_name +
  3883. ": expected literal N to be equal to the number of "
  3884. "components of Result Type"));
  3885. }
  3886. INSTANTIATE_TEST_SUITE_P(AllVLoadHalfLike, ValidateOpenCLStdVLoadHalfLike,
  3887. ::testing::ValuesIn(std::vector<std::string>{
  3888. "vload_halfn",
  3889. "vloada_halfn",
  3890. }));
  3891. TEST_F(ValidateExtInst, VLoadNSuccessFloatPhysical32) {
  3892. std::ostringstream ss;
  3893. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  3894. "%f32vec8_uniform_constant %u32_1\n";
  3895. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  3896. ss << "%val2 = OpExtInst %f32vec3 %extinst vloadn %u32_1 %ptr 3\n";
  3897. ss << "%val3 = OpExtInst %f32vec4 %extinst vloadn %u32_1 %ptr 4\n";
  3898. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3899. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3900. }
  3901. TEST_F(ValidateExtInst, VLoadNSuccessIntPhysical32) {
  3902. std::ostringstream ss;
  3903. ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
  3904. "%u32vec8_uniform_constant %u32_1\n";
  3905. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  3906. ss << "%val2 = OpExtInst %u32vec3 %extinst vloadn %u32_1 %ptr 3\n";
  3907. ss << "%val3 = OpExtInst %u32vec4 %extinst vloadn %u32_1 %ptr 4\n";
  3908. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3909. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3910. }
  3911. TEST_F(ValidateExtInst, VLoadNSuccessFloatPhysical64) {
  3912. std::ostringstream ss;
  3913. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  3914. "%f32vec8_uniform_constant %u32_1\n";
  3915. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u64_1 %ptr 2\n";
  3916. ss << "%val2 = OpExtInst %f32vec3 %extinst vloadn %u64_1 %ptr 3\n";
  3917. ss << "%val3 = OpExtInst %f32vec4 %extinst vloadn %u64_1 %ptr 4\n";
  3918. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  3919. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3920. }
  3921. TEST_F(ValidateExtInst, VLoadNSuccessIntPhysical64) {
  3922. std::ostringstream ss;
  3923. ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
  3924. "%u32vec8_uniform_constant %u32_1\n";
  3925. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u64_1 %ptr 2\n";
  3926. ss << "%val2 = OpExtInst %u32vec3 %extinst vloadn %u64_1 %ptr 3\n";
  3927. ss << "%val3 = OpExtInst %u32vec4 %extinst vloadn %u64_1 %ptr 4\n";
  3928. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  3929. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  3930. }
  3931. TEST_F(ValidateExtInst, VLoadNWrongResultType) {
  3932. std::ostringstream ss;
  3933. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  3934. "%f32vec8_uniform_constant %u32_1\n";
  3935. ss << "%val1 = OpExtInst %f32 %extinst vloadn %u32_1 %ptr 2\n";
  3936. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3937. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3938. EXPECT_THAT(
  3939. getDiagnosticString(),
  3940. HasSubstr("OpenCL.std vloadn: "
  3941. "expected Result Type to be an int or float vector type"));
  3942. }
  3943. TEST_F(ValidateExtInst, VLoadNAddressingModelLogical) {
  3944. std::ostringstream ss;
  3945. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  3946. "%f32vec8_uniform_constant %u32_1\n";
  3947. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  3948. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  3949. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3950. EXPECT_THAT(getDiagnosticString(),
  3951. HasSubstr("OpenCL.std vloadn can only be used with physical "
  3952. "addressing models"));
  3953. }
  3954. TEST_F(ValidateExtInst, VLoadNOffsetNotSizeT) {
  3955. std::ostringstream ss;
  3956. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  3957. "%f32vec8_uniform_constant %u32_1\n";
  3958. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u64_1 %ptr 2\n";
  3959. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3960. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3961. EXPECT_THAT(
  3962. getDiagnosticString(),
  3963. HasSubstr(
  3964. "OpenCL.std vloadn: expected operand Offset to be of type size_t "
  3965. "(32-bit integer for the addressing model used in the module)"));
  3966. }
  3967. TEST_F(ValidateExtInst, VLoadNPNotPointer) {
  3968. std::ostringstream ss;
  3969. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 "
  3970. "%f32_ptr_uniform_constant 2\n";
  3971. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3972. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  3973. EXPECT_THAT(
  3974. getDiagnosticString(),
  3975. HasSubstr("Operand '120[%_ptr_UniformConstant_float]' cannot be a "
  3976. "type"));
  3977. }
  3978. TEST_F(ValidateExtInst, VLoadNWrongStorageClass) {
  3979. std::ostringstream ss;
  3980. ss << "%ptr = OpAccessChain %u32_ptr_input %u32vec8_input %u32_1\n";
  3981. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  3982. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3983. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3984. EXPECT_THAT(getDiagnosticString(),
  3985. HasSubstr("OpenCL.std vloadn: expected operand P storage class "
  3986. "to be UniformConstant, Generic, CrossWorkgroup, "
  3987. "Workgroup or Function"));
  3988. }
  3989. TEST_F(ValidateExtInst, VLoadNWrongComponentType) {
  3990. std::ostringstream ss;
  3991. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  3992. "%f32vec8_uniform_constant %u32_1\n";
  3993. ss << "%val1 = OpExtInst %u32vec2 %extinst vloadn %u32_1 %ptr 2\n";
  3994. CompileSuccessfully(GenerateKernelCode(ss.str()));
  3995. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  3996. EXPECT_THAT(getDiagnosticString(),
  3997. HasSubstr("OpenCL.std vloadn: expected operand P data type to be "
  3998. "equal to component type of Result Type"));
  3999. }
  4000. TEST_F(ValidateExtInst, VLoadNWrongN) {
  4001. std::ostringstream ss;
  4002. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  4003. "%f32vec8_uniform_constant %u32_1\n";
  4004. ss << "%val1 = OpExtInst %f32vec2 %extinst vloadn %u32_1 %ptr 3\n";
  4005. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4006. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4007. EXPECT_THAT(getDiagnosticString(),
  4008. HasSubstr("OpenCL.std vloadn: expected literal N to be equal to "
  4009. "the number of components of Result Type"));
  4010. }
  4011. TEST_F(ValidateExtInst, VLoadHalfSuccessPhysical32) {
  4012. std::ostringstream ss;
  4013. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  4014. "%f16vec8_uniform_constant %u32_1\n";
  4015. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  4016. ss << "%val2 = OpExtInst %f64 %extinst vload_half %u32_1 %ptr\n";
  4017. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4018. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4019. }
  4020. TEST_F(ValidateExtInst, VLoadHalfSuccessPhysical64) {
  4021. std::ostringstream ss;
  4022. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  4023. "%f16vec8_uniform_constant %u32_1\n";
  4024. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u64_1 %ptr\n";
  4025. ss << "%val2 = OpExtInst %f64 %extinst vload_half %u64_1 %ptr\n";
  4026. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  4027. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4028. }
  4029. TEST_F(ValidateExtInst, VLoadHalfWrongResultType) {
  4030. std::ostringstream ss;
  4031. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  4032. "%f16vec8_uniform_constant %u32_1\n";
  4033. ss << "%val1 = OpExtInst %u32 %extinst vload_half %u32_1 %ptr\n";
  4034. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4035. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4036. EXPECT_THAT(getDiagnosticString(),
  4037. HasSubstr("OpenCL.std vload_half: "
  4038. "expected Result Type to be a float scalar type"));
  4039. }
  4040. TEST_F(ValidateExtInst, VLoadHalfAddressingModelLogical) {
  4041. std::ostringstream ss;
  4042. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  4043. "%f16vec8_uniform_constant %u32_1\n";
  4044. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  4045. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  4046. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4047. EXPECT_THAT(getDiagnosticString(),
  4048. HasSubstr("OpenCL.std vload_half can only be used with physical "
  4049. "addressing models"));
  4050. }
  4051. TEST_F(ValidateExtInst, VLoadHalfOffsetNotSizeT) {
  4052. std::ostringstream ss;
  4053. ss << "%ptr = OpAccessChain %f16_ptr_uniform_constant "
  4054. "%f16vec8_uniform_constant %u32_1\n";
  4055. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u64_1 %ptr\n";
  4056. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4057. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4058. EXPECT_THAT(
  4059. getDiagnosticString(),
  4060. HasSubstr(
  4061. "OpenCL.std vload_half: expected operand Offset to be of type size_t "
  4062. "(32-bit integer for the addressing model used in the module)"));
  4063. }
  4064. TEST_F(ValidateExtInst, VLoadHalfPNotPointer) {
  4065. std::ostringstream ss;
  4066. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 "
  4067. "%f16_ptr_uniform_constant\n";
  4068. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4069. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  4070. EXPECT_THAT(getDiagnosticString(),
  4071. HasSubstr("Operand '114[%_ptr_UniformConstant_half]' cannot be a "
  4072. "type"));
  4073. }
  4074. TEST_F(ValidateExtInst, VLoadHalfWrongStorageClass) {
  4075. std::ostringstream ss;
  4076. ss << "%ptr = OpAccessChain %f16_ptr_input %f16vec8_input %u32_1\n";
  4077. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  4078. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4079. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4080. EXPECT_THAT(
  4081. getDiagnosticString(),
  4082. HasSubstr(
  4083. "OpenCL.std vload_half: expected operand P storage class to be "
  4084. "UniformConstant, Generic, CrossWorkgroup, Workgroup or Function"));
  4085. }
  4086. TEST_F(ValidateExtInst, VLoadHalfPDataTypeInt) {
  4087. std::ostringstream ss;
  4088. ss << "%ptr = OpAccessChain %u32_ptr_uniform_constant "
  4089. "%u32vec8_uniform_constant %u32_1\n";
  4090. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  4091. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4092. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4093. EXPECT_THAT(getDiagnosticString(),
  4094. HasSubstr("OpenCL.std vload_half: expected operand P data type "
  4095. "to be 16-bit float scalar"));
  4096. }
  4097. TEST_F(ValidateExtInst, VLoadHalfPDataTypeFloat32) {
  4098. std::ostringstream ss;
  4099. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  4100. "%f32vec8_uniform_constant %u32_1\n";
  4101. ss << "%val1 = OpExtInst %f32 %extinst vload_half %u32_1 %ptr\n";
  4102. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4103. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4104. EXPECT_THAT(getDiagnosticString(),
  4105. HasSubstr("OpenCL.std vload_half: expected operand P data type "
  4106. "to be 16-bit float scalar"));
  4107. }
  4108. TEST_F(ValidateExtInst, VStoreNSuccessFloatPhysical32) {
  4109. std::ostringstream ss;
  4110. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  4111. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  4112. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  4113. ss << "%val2 = OpExtInst %void %extinst vstoren %f32vec4_0123 %u32_1 "
  4114. "%ptr_g\n";
  4115. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4116. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4117. }
  4118. TEST_F(ValidateExtInst, VStoreNSuccessFloatPhysical64) {
  4119. std::ostringstream ss;
  4120. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  4121. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  4122. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u64_1 %ptr_g\n";
  4123. ss << "%val2 = OpExtInst %void %extinst vstoren %f32vec4_0123 %u64_1 "
  4124. "%ptr_g\n";
  4125. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  4126. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4127. }
  4128. TEST_F(ValidateExtInst, VStoreNSuccessIntPhysical32) {
  4129. std::ostringstream ss;
  4130. ss << "%ptr_w = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  4131. ss << "%ptr_g = OpPtrCastToGeneric %u32_ptr_generic %ptr_w\n";
  4132. ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u32_1 %ptr_g\n";
  4133. ss << "%val2 = OpExtInst %void %extinst vstoren %u32vec4_0123 %u32_1 "
  4134. "%ptr_g\n";
  4135. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4136. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4137. }
  4138. TEST_F(ValidateExtInst, VStoreNSuccessIntPhysical64) {
  4139. std::ostringstream ss;
  4140. ss << "%ptr_w = OpAccessChain %u32_ptr_workgroup %u32vec8_workgroup %u32_1\n";
  4141. ss << "%ptr_g = OpPtrCastToGeneric %u32_ptr_generic %ptr_w\n";
  4142. ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u64_1 %ptr_g\n";
  4143. ss << "%val2 = OpExtInst %void %extinst vstoren %u32vec4_0123 %u64_1 "
  4144. "%ptr_g\n";
  4145. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  4146. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4147. }
  4148. TEST_F(ValidateExtInst, VStoreNResultTypeNotVoid) {
  4149. std::ostringstream ss;
  4150. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  4151. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  4152. ss << "%val1 = OpExtInst %f32 %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  4153. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4154. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4155. EXPECT_THAT(getDiagnosticString(),
  4156. HasSubstr("OpenCL.std vstoren: expected Result Type to be void"));
  4157. }
  4158. TEST_F(ValidateExtInst, VStoreNDataWrongType) {
  4159. std::ostringstream ss;
  4160. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  4161. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  4162. ss << "%val1 = OpExtInst %void %extinst vstoren %f32_1 %u32_1 %ptr_g\n";
  4163. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4164. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4165. EXPECT_THAT(
  4166. getDiagnosticString(),
  4167. HasSubstr(
  4168. "OpenCL.std vstoren: expected Data to be an int or float vector"));
  4169. }
  4170. TEST_F(ValidateExtInst, VStoreNAddressingModelLogical) {
  4171. std::ostringstream ss;
  4172. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  4173. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  4174. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  4175. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Logical"));
  4176. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4177. EXPECT_THAT(getDiagnosticString(),
  4178. HasSubstr("OpenCL.std vstoren can only be used with physical "
  4179. "addressing models"));
  4180. }
  4181. TEST_F(ValidateExtInst, VStoreNOffsetNotSizeT) {
  4182. std::ostringstream ss;
  4183. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  4184. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  4185. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_g\n";
  4186. CompileSuccessfully(GenerateKernelCode(ss.str(), "", "Physical64"));
  4187. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4188. EXPECT_THAT(
  4189. getDiagnosticString(),
  4190. HasSubstr(
  4191. "OpenCL.std vstoren: expected operand Offset to be of type size_t "
  4192. "(64-bit integer for the addressing model used in the module)"));
  4193. }
  4194. TEST_F(ValidateExtInst, VStoreNPNotPointer) {
  4195. std::ostringstream ss;
  4196. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 "
  4197. "%f32_ptr_generic\n";
  4198. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4199. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  4200. EXPECT_THAT(getDiagnosticString(),
  4201. HasSubstr("Operand '127[%_ptr_Generic_float]' cannot be a type"));
  4202. }
  4203. TEST_F(ValidateExtInst, VStoreNWrongStorageClass) {
  4204. std::ostringstream ss;
  4205. ss << "%ptr_w = OpAccessChain %f32_ptr_uniform_constant "
  4206. "%f32vec8_uniform_constant %u32_1\n";
  4207. ss << "%val1 = OpExtInst %void %extinst vstoren %f32vec2_01 %u32_1 %ptr_w\n";
  4208. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4209. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4210. EXPECT_THAT(
  4211. getDiagnosticString(),
  4212. HasSubstr("OpenCL.std vstoren: expected operand P storage class "
  4213. "to be Generic, CrossWorkgroup, Workgroup or Function"));
  4214. }
  4215. TEST_F(ValidateExtInst, VStorePWrongDataType) {
  4216. std::ostringstream ss;
  4217. ss << "%ptr_w = OpAccessChain %f32_ptr_workgroup %f32vec8_workgroup %u32_1\n";
  4218. ss << "%ptr_g = OpPtrCastToGeneric %f32_ptr_generic %ptr_w\n";
  4219. ss << "%val1 = OpExtInst %void %extinst vstoren %u32vec2_01 %u32_1 %ptr_g\n";
  4220. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4221. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4222. EXPECT_THAT(getDiagnosticString(),
  4223. HasSubstr("OpenCL.std vstoren: expected operand P data type to "
  4224. "be equal to the type of operand Data components"));
  4225. }
  4226. TEST_F(ValidateExtInst, OpenCLStdShuffleSuccess) {
  4227. const std::string body = R"(
  4228. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec4_0123 %u32vec2_01
  4229. %val2 = OpExtInst %f32vec4 %extinst shuffle %f32vec4_0123 %u32vec4_0123
  4230. %val3 = OpExtInst %u32vec2 %extinst shuffle %u32vec4_0123 %u32vec2_01
  4231. %val4 = OpExtInst %u32vec4 %extinst shuffle %u32vec4_0123 %u32vec4_0123
  4232. )";
  4233. CompileSuccessfully(GenerateKernelCode(body));
  4234. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4235. }
  4236. TEST_F(ValidateExtInst, OpenCLStdShuffleWrongResultType) {
  4237. const std::string body = R"(
  4238. %val1 = OpExtInst %f32 %extinst shuffle %f32vec4_0123 %u32vec2_01
  4239. )";
  4240. CompileSuccessfully(GenerateKernelCode(body));
  4241. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4242. EXPECT_THAT(
  4243. getDiagnosticString(),
  4244. HasSubstr("OpenCL.std shuffle: "
  4245. "expected Result Type to be an int or float vector type"));
  4246. }
  4247. TEST_F(ValidateExtInst, OpenCLStdShuffleResultTypeInvalidNumComponents) {
  4248. const std::string body = R"(
  4249. %val1 = OpExtInst %f32vec3 %extinst shuffle %f32vec4_0123 %u32vec3_012
  4250. )";
  4251. CompileSuccessfully(GenerateKernelCode(body));
  4252. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4253. EXPECT_THAT(
  4254. getDiagnosticString(),
  4255. HasSubstr("OpenCL.std shuffle: "
  4256. "expected Result Type to have 2, 4, 8 or 16 components"));
  4257. }
  4258. TEST_F(ValidateExtInst, OpenCLStdShuffleXWrongType) {
  4259. const std::string body = R"(
  4260. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32_0 %u32vec2_01
  4261. )";
  4262. CompileSuccessfully(GenerateKernelCode(body));
  4263. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4264. EXPECT_THAT(getDiagnosticString(),
  4265. HasSubstr("OpenCL.std shuffle: "
  4266. "expected operand X to be an int or float vector"));
  4267. }
  4268. TEST_F(ValidateExtInst, OpenCLStdShuffleXInvalidNumComponents) {
  4269. const std::string body = R"(
  4270. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec3_012 %u32vec2_01
  4271. )";
  4272. CompileSuccessfully(GenerateKernelCode(body));
  4273. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4274. EXPECT_THAT(getDiagnosticString(),
  4275. HasSubstr("OpenCL.std shuffle: "
  4276. "expected operand X to have 2, 4, 8 or 16 components"));
  4277. }
  4278. TEST_F(ValidateExtInst, OpenCLStdShuffleXInvalidComponentType) {
  4279. const std::string body = R"(
  4280. %val1 = OpExtInst %f32vec2 %extinst shuffle %f64vec4_0123 %u32vec2_01
  4281. )";
  4282. CompileSuccessfully(GenerateKernelCode(body));
  4283. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4284. EXPECT_THAT(
  4285. getDiagnosticString(),
  4286. HasSubstr(
  4287. "OpenCL.std shuffle: "
  4288. "expected operand X and Result Type to have equal component types"));
  4289. }
  4290. TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskNotIntVector) {
  4291. const std::string body = R"(
  4292. %val1 = OpExtInst %f32vec2 %extinst shuffle %f32vec4_0123 %f32vec2_01
  4293. )";
  4294. CompileSuccessfully(GenerateKernelCode(body));
  4295. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4296. EXPECT_THAT(getDiagnosticString(),
  4297. HasSubstr("OpenCL.std shuffle: "
  4298. "expected operand Shuffle Mask to be an int vector"));
  4299. }
  4300. TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskInvalidNumComponents) {
  4301. const std::string body = R"(
  4302. %val1 = OpExtInst %f32vec4 %extinst shuffle %f32vec4_0123 %u32vec2_01
  4303. )";
  4304. CompileSuccessfully(GenerateKernelCode(body));
  4305. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4306. EXPECT_THAT(getDiagnosticString(),
  4307. HasSubstr("OpenCL.std shuffle: "
  4308. "expected operand Shuffle Mask to have the same number "
  4309. "of components as Result Type"));
  4310. }
  4311. TEST_F(ValidateExtInst, OpenCLStdShuffleShuffleMaskInvalidBitWidth) {
  4312. const std::string body = R"(
  4313. %val1 = OpExtInst %f64vec2 %extinst shuffle %f64vec4_0123 %u32vec2_01
  4314. )";
  4315. CompileSuccessfully(GenerateKernelCode(body));
  4316. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4317. EXPECT_THAT(getDiagnosticString(),
  4318. HasSubstr("OpenCL.std shuffle: "
  4319. "expected operand Shuffle Mask components to have the "
  4320. "same bit width as Result Type components"));
  4321. }
  4322. TEST_F(ValidateExtInst, OpenCLStdShuffle2Success) {
  4323. const std::string body = R"(
  4324. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
  4325. %val2 = OpExtInst %f32vec4 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec4_0123
  4326. %val3 = OpExtInst %u32vec2 %extinst shuffle2 %u32vec4_0123 %u32vec4_0123 %u32vec2_01
  4327. %val4 = OpExtInst %u32vec4 %extinst shuffle2 %u32vec4_0123 %u32vec4_0123 %u32vec4_0123
  4328. )";
  4329. CompileSuccessfully(GenerateKernelCode(body));
  4330. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4331. }
  4332. TEST_F(ValidateExtInst, OpenCLStdShuffle2WrongResultType) {
  4333. const std::string body = R"(
  4334. %val1 = OpExtInst %f32 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
  4335. )";
  4336. CompileSuccessfully(GenerateKernelCode(body));
  4337. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4338. EXPECT_THAT(
  4339. getDiagnosticString(),
  4340. HasSubstr("OpenCL.std shuffle2: "
  4341. "expected Result Type to be an int or float vector type"));
  4342. }
  4343. TEST_F(ValidateExtInst, OpenCLStdShuffle2ResultTypeInvalidNumComponents) {
  4344. const std::string body = R"(
  4345. %val1 = OpExtInst %f32vec3 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec3_012
  4346. )";
  4347. CompileSuccessfully(GenerateKernelCode(body));
  4348. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4349. EXPECT_THAT(
  4350. getDiagnosticString(),
  4351. HasSubstr("OpenCL.std shuffle2: "
  4352. "expected Result Type to have 2, 4, 8 or 16 components"));
  4353. }
  4354. TEST_F(ValidateExtInst, OpenCLStdShuffle2XWrongType) {
  4355. const std::string body = R"(
  4356. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32_0 %f32_0 %u32vec2_01
  4357. )";
  4358. CompileSuccessfully(GenerateKernelCode(body));
  4359. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4360. EXPECT_THAT(getDiagnosticString(),
  4361. HasSubstr("OpenCL.std shuffle2: "
  4362. "expected operand X to be an int or float vector"));
  4363. }
  4364. TEST_F(ValidateExtInst, OpenCLStdShuffle2YTypeDifferentFromX) {
  4365. const std::string body = R"(
  4366. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec2_01 %f32vec4_0123 %u32vec2_01
  4367. )";
  4368. CompileSuccessfully(GenerateKernelCode(body));
  4369. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4370. EXPECT_THAT(getDiagnosticString(),
  4371. HasSubstr("OpenCL.std shuffle2: "
  4372. "expected operands X and Y to be of the same type"));
  4373. }
  4374. TEST_F(ValidateExtInst, OpenCLStdShuffle2XInvalidNumComponents) {
  4375. const std::string body = R"(
  4376. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec3_012 %f32vec3_012 %u32vec2_01
  4377. )";
  4378. CompileSuccessfully(GenerateKernelCode(body));
  4379. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4380. EXPECT_THAT(getDiagnosticString(),
  4381. HasSubstr("OpenCL.std shuffle2: "
  4382. "expected operand X to have 2, 4, 8 or 16 components"));
  4383. }
  4384. TEST_F(ValidateExtInst, OpenCLStdShuffle2XInvalidComponentType) {
  4385. const std::string body = R"(
  4386. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f64vec4_0123 %f64vec4_0123 %u32vec2_01
  4387. )";
  4388. CompileSuccessfully(GenerateKernelCode(body));
  4389. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4390. EXPECT_THAT(
  4391. getDiagnosticString(),
  4392. HasSubstr(
  4393. "OpenCL.std shuffle2: "
  4394. "expected operand X and Result Type to have equal component types"));
  4395. }
  4396. TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskNotIntVector) {
  4397. const std::string body = R"(
  4398. %val1 = OpExtInst %f32vec2 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %f32vec2_01
  4399. )";
  4400. CompileSuccessfully(GenerateKernelCode(body));
  4401. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4402. EXPECT_THAT(getDiagnosticString(),
  4403. HasSubstr("OpenCL.std shuffle2: "
  4404. "expected operand Shuffle Mask to be an int vector"));
  4405. }
  4406. TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskInvalidNumComponents) {
  4407. const std::string body = R"(
  4408. %val1 = OpExtInst %f32vec4 %extinst shuffle2 %f32vec4_0123 %f32vec4_0123 %u32vec2_01
  4409. )";
  4410. CompileSuccessfully(GenerateKernelCode(body));
  4411. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4412. EXPECT_THAT(getDiagnosticString(),
  4413. HasSubstr("OpenCL.std shuffle2: "
  4414. "expected operand Shuffle Mask to have the same number "
  4415. "of components as Result Type"));
  4416. }
  4417. TEST_F(ValidateExtInst, OpenCLStdShuffle2ShuffleMaskInvalidBitWidth) {
  4418. const std::string body = R"(
  4419. %val1 = OpExtInst %f64vec2 %extinst shuffle2 %f64vec4_0123 %f64vec4_0123 %u32vec2_01
  4420. )";
  4421. CompileSuccessfully(GenerateKernelCode(body));
  4422. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4423. EXPECT_THAT(getDiagnosticString(),
  4424. HasSubstr("OpenCL.std shuffle2: "
  4425. "expected operand Shuffle Mask components to have the "
  4426. "same bit width as Result Type components"));
  4427. }
  4428. TEST_F(ValidateExtInst, OpenCLStdPrintfSuccess) {
  4429. const std::string body = R"(
  4430. %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  4431. %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
  4432. )";
  4433. CompileSuccessfully(GenerateKernelCode(body));
  4434. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4435. }
  4436. TEST_F(ValidateExtInst, OpenCLStdPrintfBoolResultType) {
  4437. const std::string body = R"(
  4438. %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  4439. %val1 = OpExtInst %bool %extinst printf %format %u32_0 %u32_1
  4440. )";
  4441. CompileSuccessfully(GenerateKernelCode(body));
  4442. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4443. EXPECT_THAT(
  4444. getDiagnosticString(),
  4445. HasSubstr(
  4446. "OpenCL.std printf: expected Result Type to be a 32-bit int type"));
  4447. }
  4448. TEST_F(ValidateExtInst, OpenCLStdPrintfU64ResultType) {
  4449. const std::string body = R"(
  4450. %format = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  4451. %val1 = OpExtInst %u64 %extinst printf %format %u32_0 %u32_1
  4452. )";
  4453. CompileSuccessfully(GenerateKernelCode(body));
  4454. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4455. EXPECT_THAT(
  4456. getDiagnosticString(),
  4457. HasSubstr(
  4458. "OpenCL.std printf: expected Result Type to be a 32-bit int type"));
  4459. }
  4460. TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotPointer) {
  4461. const std::string body = R"(
  4462. %val1 = OpExtInst %u32 %extinst printf %u8_ptr_uniform_constant %u32_0 %u32_1
  4463. )";
  4464. CompileSuccessfully(GenerateKernelCode(body));
  4465. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  4466. EXPECT_THAT(
  4467. getDiagnosticString(),
  4468. HasSubstr("Operand '137[%_ptr_UniformConstant_uchar]' cannot be a "
  4469. "type"));
  4470. }
  4471. TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotUniformConstStorageClass) {
  4472. const std::string body = R"(
  4473. %format_const = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  4474. %format = OpBitcast %u8_ptr_generic %format_const
  4475. %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
  4476. )";
  4477. CompileSuccessfully(GenerateKernelCode(body));
  4478. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4479. EXPECT_THAT(getDiagnosticString(),
  4480. HasSubstr("OpenCL.std printf: expected Format storage class to "
  4481. "be UniformConstant"));
  4482. }
  4483. TEST_F(ValidateExtInst, OpenCLStdPrintfFormatNotU8Pointer) {
  4484. const std::string body = R"(
  4485. %format = OpAccessChain %u32_ptr_uniform_constant %u32vec8_uniform_constant %u32_0
  4486. %val1 = OpExtInst %u32 %extinst printf %format %u32_0 %u32_1
  4487. )";
  4488. CompileSuccessfully(GenerateKernelCode(body));
  4489. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4490. EXPECT_THAT(
  4491. getDiagnosticString(),
  4492. HasSubstr(
  4493. "OpenCL.std printf: expected Format data type to be 8-bit int"));
  4494. }
  4495. TEST_F(ValidateExtInst, OpenCLStdPrefetchU32Success) {
  4496. const std::string body = R"(
  4497. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  4498. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  4499. )";
  4500. CompileSuccessfully(GenerateKernelCode(body));
  4501. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4502. }
  4503. TEST_F(ValidateExtInst, OpenCLStdPrefetchU32Physical64Success) {
  4504. const std::string body = R"(
  4505. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  4506. %val1 = OpExtInst %void %extinst prefetch %ptr %u64_256
  4507. )";
  4508. CompileSuccessfully(GenerateKernelCode(body, "", "Physical64"));
  4509. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4510. }
  4511. TEST_F(ValidateExtInst, OpenCLStdPrefetchF32Success) {
  4512. const std::string body = R"(
  4513. %ptr = OpAccessChain %f32_ptr_cross_workgroup %f32arr_cross_workgroup %u32_0
  4514. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  4515. )";
  4516. CompileSuccessfully(GenerateKernelCode(body));
  4517. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4518. }
  4519. TEST_F(ValidateExtInst, OpenCLStdPrefetchF32Vec2Success) {
  4520. const std::string body = R"(
  4521. %ptr = OpAccessChain %f32vec2_ptr_cross_workgroup %f32vec2arr_cross_workgroup %u32_0
  4522. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  4523. )";
  4524. CompileSuccessfully(GenerateKernelCode(body));
  4525. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4526. }
  4527. TEST_F(ValidateExtInst, OpenCLStdPrefetchResultTypeNotVoid) {
  4528. const std::string body = R"(
  4529. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  4530. %val1 = OpExtInst %u32 %extinst prefetch %ptr %u32_256
  4531. )";
  4532. CompileSuccessfully(GenerateKernelCode(body));
  4533. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4534. EXPECT_THAT(
  4535. getDiagnosticString(),
  4536. HasSubstr("OpenCL.std prefetch: expected Result Type to be void"));
  4537. }
  4538. TEST_F(ValidateExtInst, OpenCLStdPrefetchPtrNotPointer) {
  4539. const std::string body = R"(
  4540. %val1 = OpExtInst %void %extinst prefetch %u32_ptr_cross_workgroup %u32_256
  4541. )";
  4542. CompileSuccessfully(GenerateKernelCode(body));
  4543. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  4544. EXPECT_THAT(getDiagnosticString(),
  4545. HasSubstr("Operand '99[%_ptr_CrossWorkgroup_uint]' cannot be a "
  4546. "type"));
  4547. }
  4548. TEST_F(ValidateExtInst, OpenCLStdPrefetchPtrNotCrossWorkgroup) {
  4549. const std::string body = R"(
  4550. %ptr = OpAccessChain %u8_ptr_uniform_constant %u8arr_uniform_constant %u32_0
  4551. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  4552. )";
  4553. CompileSuccessfully(GenerateKernelCode(body));
  4554. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4555. EXPECT_THAT(getDiagnosticString(),
  4556. HasSubstr("OpenCL.std prefetch: expected operand Ptr storage "
  4557. "class to be CrossWorkgroup"));
  4558. }
  4559. TEST_F(ValidateExtInst, OpenCLStdPrefetchInvalidDataType) {
  4560. const std::string body = R"(
  4561. %ptr = OpAccessChain %struct_ptr_cross_workgroup %struct_arr_cross_workgroup %u32_0
  4562. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  4563. )";
  4564. CompileSuccessfully(GenerateKernelCode(body));
  4565. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4566. EXPECT_THAT(getDiagnosticString(),
  4567. HasSubstr("OpenCL.std prefetch: expected Ptr data type to be int "
  4568. "or float scalar or vector"));
  4569. }
  4570. TEST_F(ValidateExtInst, OpenCLStdPrefetchAddressingModelLogical) {
  4571. const std::string body = R"(
  4572. %ptr = OpAccessChain %u32_ptr_cross_workgroup %u32arr_cross_workgroup %u32_0
  4573. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  4574. )";
  4575. CompileSuccessfully(GenerateKernelCode(body, "", "Logical"));
  4576. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4577. EXPECT_THAT(getDiagnosticString(),
  4578. HasSubstr("OpenCL.std prefetch can only be used with physical "
  4579. "addressing models"));
  4580. }
  4581. TEST_F(ValidateExtInst, OpenCLStdPrefetchNumElementsNotSizeT) {
  4582. const std::string body = R"(
  4583. %ptr = OpAccessChain %f32_ptr_cross_workgroup %f32arr_cross_workgroup %u32_0
  4584. %val1 = OpExtInst %void %extinst prefetch %ptr %u32_256
  4585. )";
  4586. CompileSuccessfully(GenerateKernelCode(body, "", "Physical64"));
  4587. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4588. EXPECT_THAT(getDiagnosticString(),
  4589. HasSubstr("OpenCL.std prefetch: expected operand Num Elements to "
  4590. "be of type size_t (64-bit integer for the addressing "
  4591. "model used in the module)"));
  4592. }
  4593. TEST_P(ValidateOpenCLStdFractLike, Success) {
  4594. const std::string ext_inst_name = GetParam();
  4595. std::ostringstream ss;
  4596. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  4597. ss << "%var_f32vec2 = OpVariable %f32vec2_ptr_function Function\n";
  4598. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4599. << " %f32_0 %var_f32\n";
  4600. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  4601. << " %f32vec2_01 %var_f32vec2\n";
  4602. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4603. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4604. }
  4605. TEST_P(ValidateOpenCLStdFractLike, IntResultType) {
  4606. const std::string ext_inst_name = GetParam();
  4607. std::ostringstream ss;
  4608. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  4609. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  4610. << " %f32_0 %var_f32\n";
  4611. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4612. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4613. EXPECT_THAT(
  4614. getDiagnosticString(),
  4615. HasSubstr("OpenCL.std " + ext_inst_name +
  4616. ": expected Result Type to be a float scalar or vector type"));
  4617. }
  4618. TEST_P(ValidateOpenCLStdFractLike, XWrongType) {
  4619. const std::string ext_inst_name = GetParam();
  4620. std::ostringstream ss;
  4621. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  4622. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4623. << " %f64_0 %var_f32\n";
  4624. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4625. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4626. EXPECT_THAT(
  4627. getDiagnosticString(),
  4628. HasSubstr("OpenCL.std " + ext_inst_name +
  4629. ": expected type of operand X to be equal to Result Type"));
  4630. }
  4631. TEST_P(ValidateOpenCLStdFractLike, NotPointer) {
  4632. const std::string ext_inst_name = GetParam();
  4633. std::ostringstream ss;
  4634. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  4635. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4636. << " %f32_0 %f32_1\n";
  4637. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4638. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4639. EXPECT_THAT(getDiagnosticString(),
  4640. HasSubstr("OpenCL.std " + ext_inst_name +
  4641. ": expected the last operand to be a pointer"));
  4642. }
  4643. TEST_P(ValidateOpenCLStdFractLike, PointerInvalidStorageClass) {
  4644. const std::string ext_inst_name = GetParam();
  4645. std::ostringstream ss;
  4646. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  4647. "%f32vec8_uniform_constant %u32_1\n";
  4648. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0 %ptr\n";
  4649. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4650. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4651. EXPECT_THAT(getDiagnosticString(),
  4652. HasSubstr("OpenCL.std " + ext_inst_name +
  4653. ": expected storage class of the pointer to be "
  4654. "Generic, CrossWorkgroup, Workgroup or Function"));
  4655. }
  4656. TEST_P(ValidateOpenCLStdFractLike, PointerWrongDataType) {
  4657. const std::string ext_inst_name = GetParam();
  4658. std::ostringstream ss;
  4659. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  4660. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4661. << " %f32_0 %var_u32\n";
  4662. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4663. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4664. EXPECT_THAT(
  4665. getDiagnosticString(),
  4666. HasSubstr(
  4667. "OpenCL.std " + ext_inst_name +
  4668. ": expected data type of the pointer to be equal to Result Type"));
  4669. }
  4670. INSTANTIATE_TEST_SUITE_P(AllFractLike, ValidateOpenCLStdFractLike,
  4671. ::testing::ValuesIn(std::vector<std::string>{
  4672. "fract",
  4673. "modf",
  4674. "sincos",
  4675. }));
  4676. TEST_F(ValidateExtInst, OpenCLStdRemquoSuccess) {
  4677. const std::string body = R"(
  4678. %var_u32 = OpVariable %u32_ptr_function Function
  4679. %var_u32vec2 = OpVariable %u32vec2_ptr_function Function
  4680. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u32
  4681. %val2 = OpExtInst %f32vec2 %extinst remquo %f32vec2_01 %f32vec2_12 %var_u32vec2
  4682. )";
  4683. CompileSuccessfully(GenerateKernelCode(body));
  4684. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4685. }
  4686. TEST_F(ValidateExtInst, OpenCLStdRemquoIntResultType) {
  4687. const std::string body = R"(
  4688. %var_u32 = OpVariable %u32_ptr_function Function
  4689. %val1 = OpExtInst %u32 %extinst remquo %f32_3 %f32_2 %var_u32
  4690. )";
  4691. CompileSuccessfully(GenerateKernelCode(body));
  4692. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4693. EXPECT_THAT(
  4694. getDiagnosticString(),
  4695. HasSubstr("OpenCL.std remquo: "
  4696. "expected Result Type to be a float scalar or vector type"));
  4697. }
  4698. TEST_F(ValidateExtInst, OpenCLStdRemquoXWrongType) {
  4699. const std::string body = R"(
  4700. %var_u32 = OpVariable %f32_ptr_function Function
  4701. %val1 = OpExtInst %f32 %extinst remquo %u32_3 %f32_2 %var_u32
  4702. )";
  4703. CompileSuccessfully(GenerateKernelCode(body));
  4704. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4705. EXPECT_THAT(
  4706. getDiagnosticString(),
  4707. HasSubstr("OpenCL.std remquo: "
  4708. "expected type of operand X to be equal to Result Type"));
  4709. }
  4710. TEST_F(ValidateExtInst, OpenCLStdRemquoYWrongType) {
  4711. const std::string body = R"(
  4712. %var_u32 = OpVariable %f32_ptr_function Function
  4713. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %u32_2 %var_u32
  4714. )";
  4715. CompileSuccessfully(GenerateKernelCode(body));
  4716. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4717. EXPECT_THAT(
  4718. getDiagnosticString(),
  4719. HasSubstr("OpenCL.std remquo: "
  4720. "expected type of operand Y to be equal to Result Type"));
  4721. }
  4722. TEST_F(ValidateExtInst, OpenCLStdRemquoNotPointer) {
  4723. const std::string body = R"(
  4724. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %f32_1
  4725. )";
  4726. CompileSuccessfully(GenerateKernelCode(body));
  4727. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4728. EXPECT_THAT(getDiagnosticString(),
  4729. HasSubstr("OpenCL.std remquo: "
  4730. "expected the last operand to be a pointer"));
  4731. }
  4732. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongStorageClass) {
  4733. const std::string body = R"(
  4734. %ptr = OpAccessChain %f32_ptr_uniform_constant %f32vec8_uniform_constant %u32_1
  4735. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %ptr
  4736. )";
  4737. CompileSuccessfully(GenerateKernelCode(body));
  4738. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4739. EXPECT_THAT(getDiagnosticString(),
  4740. HasSubstr("OpenCL.std remquo: "
  4741. "expected storage class of the pointer to be Generic, "
  4742. "CrossWorkgroup, Workgroup or Function"));
  4743. }
  4744. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongDataType) {
  4745. const std::string body = R"(
  4746. %var_f32 = OpVariable %f32_ptr_function Function
  4747. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_f32
  4748. )";
  4749. CompileSuccessfully(GenerateKernelCode(body));
  4750. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4751. EXPECT_THAT(getDiagnosticString(),
  4752. HasSubstr("OpenCL.std remquo: "
  4753. "expected data type of the pointer to be a 32-bit int "
  4754. "scalar or vector type"));
  4755. }
  4756. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongDataTypeWidth) {
  4757. const std::string body = R"(
  4758. %var_u64 = OpVariable %u64_ptr_function Function
  4759. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u64
  4760. )";
  4761. CompileSuccessfully(GenerateKernelCode(body));
  4762. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4763. EXPECT_THAT(getDiagnosticString(),
  4764. HasSubstr("OpenCL.std remquo: "
  4765. "expected data type of the pointer to be a 32-bit int "
  4766. "scalar or vector type"));
  4767. }
  4768. TEST_F(ValidateExtInst, OpenCLStdRemquoPointerWrongNumberOfComponents) {
  4769. const std::string body = R"(
  4770. %var_u32vec2 = OpVariable %u32vec2_ptr_function Function
  4771. %val1 = OpExtInst %f32 %extinst remquo %f32_3 %f32_2 %var_u32vec2
  4772. )";
  4773. CompileSuccessfully(GenerateKernelCode(body));
  4774. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4775. EXPECT_THAT(
  4776. getDiagnosticString(),
  4777. HasSubstr("OpenCL.std remquo: "
  4778. "expected data type of the pointer to have the same number "
  4779. "of components as Result Type"));
  4780. }
  4781. TEST_P(ValidateOpenCLStdFrexpLike, Success) {
  4782. const std::string ext_inst_name = GetParam();
  4783. std::ostringstream ss;
  4784. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  4785. ss << "%var_u32vec2 = OpVariable %u32vec2_ptr_function Function\n";
  4786. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4787. << " %f32_0 %var_u32\n";
  4788. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  4789. << " %f32vec2_01 %var_u32vec2\n";
  4790. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4791. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4792. }
  4793. TEST_P(ValidateOpenCLStdFrexpLike, IntResultType) {
  4794. const std::string ext_inst_name = GetParam();
  4795. std::ostringstream ss;
  4796. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  4797. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  4798. << " %f32_0 %var_u32\n";
  4799. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4800. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4801. EXPECT_THAT(
  4802. getDiagnosticString(),
  4803. HasSubstr("OpenCL.std " + ext_inst_name +
  4804. ": expected Result Type to be a float scalar or vector type"));
  4805. }
  4806. TEST_P(ValidateOpenCLStdFrexpLike, XWrongType) {
  4807. const std::string ext_inst_name = GetParam();
  4808. std::ostringstream ss;
  4809. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  4810. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4811. << " %f64_0 %var_u32\n";
  4812. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4813. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4814. EXPECT_THAT(
  4815. getDiagnosticString(),
  4816. HasSubstr("OpenCL.std " + ext_inst_name +
  4817. ": expected type of operand X to be equal to Result Type"));
  4818. }
  4819. TEST_P(ValidateOpenCLStdFrexpLike, NotPointer) {
  4820. const std::string ext_inst_name = GetParam();
  4821. std::ostringstream ss;
  4822. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4823. << " %f32_0 %u32_1\n";
  4824. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4825. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4826. EXPECT_THAT(getDiagnosticString(),
  4827. HasSubstr("OpenCL.std " + ext_inst_name +
  4828. ": expected the last operand to be a pointer"));
  4829. }
  4830. TEST_P(ValidateOpenCLStdFrexpLike, PointerInvalidStorageClass) {
  4831. const std::string ext_inst_name = GetParam();
  4832. std::ostringstream ss;
  4833. ss << "%ptr = OpAccessChain %f32_ptr_uniform_constant "
  4834. "%f32vec8_uniform_constant %u32_1\n";
  4835. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name << " %f32_0 %ptr\n";
  4836. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4837. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4838. EXPECT_THAT(getDiagnosticString(),
  4839. HasSubstr("OpenCL.std " + ext_inst_name +
  4840. ": expected storage class of the pointer to be "
  4841. "Generic, CrossWorkgroup, Workgroup or Function"));
  4842. }
  4843. TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeFloat) {
  4844. const std::string ext_inst_name = GetParam();
  4845. std::ostringstream ss;
  4846. ss << "%var_f32 = OpVariable %f32_ptr_function Function\n";
  4847. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4848. << " %f32_0 %var_f32\n";
  4849. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4850. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4851. EXPECT_THAT(getDiagnosticString(),
  4852. HasSubstr("OpenCL.std " + ext_inst_name +
  4853. ": expected data type of the pointer to be a 32-bit "
  4854. "int scalar or vector type"));
  4855. }
  4856. TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeU64) {
  4857. const std::string ext_inst_name = GetParam();
  4858. std::ostringstream ss;
  4859. ss << "%var_u64 = OpVariable %u64_ptr_function Function\n";
  4860. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4861. << " %f32_0 %var_u64\n";
  4862. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4863. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4864. EXPECT_THAT(getDiagnosticString(),
  4865. HasSubstr("OpenCL.std " + ext_inst_name +
  4866. ": expected data type of the pointer to be a 32-bit "
  4867. "int scalar or vector type"));
  4868. }
  4869. TEST_P(ValidateOpenCLStdFrexpLike, PointerDataTypeDiffSize) {
  4870. const std::string ext_inst_name = GetParam();
  4871. std::ostringstream ss;
  4872. ss << "%var_u32 = OpVariable %u32_ptr_function Function\n";
  4873. ss << "%val1 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  4874. << " %f32vec2_01 %var_u32\n";
  4875. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4876. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4877. EXPECT_THAT(getDiagnosticString(),
  4878. HasSubstr("OpenCL.std " + ext_inst_name +
  4879. ": expected data type of the pointer to have the same "
  4880. "number of components as Result Type"));
  4881. }
  4882. INSTANTIATE_TEST_SUITE_P(AllFrexpLike, ValidateOpenCLStdFrexpLike,
  4883. ::testing::ValuesIn(std::vector<std::string>{
  4884. "frexp",
  4885. "lgamma_r",
  4886. }));
  4887. TEST_F(ValidateExtInst, OpenCLStdIlogbSuccess) {
  4888. const std::string body = R"(
  4889. %val1 = OpExtInst %u32 %extinst ilogb %f32_3
  4890. %val2 = OpExtInst %u32vec2 %extinst ilogb %f32vec2_12
  4891. )";
  4892. CompileSuccessfully(GenerateKernelCode(body));
  4893. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4894. }
  4895. TEST_F(ValidateExtInst, OpenCLStdIlogbFloatResultType) {
  4896. const std::string body = R"(
  4897. %val1 = OpExtInst %f32 %extinst ilogb %f32_3
  4898. )";
  4899. CompileSuccessfully(GenerateKernelCode(body));
  4900. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4901. EXPECT_THAT(
  4902. getDiagnosticString(),
  4903. HasSubstr(
  4904. "OpenCL.std ilogb: "
  4905. "expected Result Type to be a 32-bit int scalar or vector type"));
  4906. }
  4907. TEST_F(ValidateExtInst, OpenCLStdIlogbIntX) {
  4908. const std::string body = R"(
  4909. %val1 = OpExtInst %u32 %extinst ilogb %u32_3
  4910. )";
  4911. CompileSuccessfully(GenerateKernelCode(body));
  4912. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4913. EXPECT_THAT(getDiagnosticString(),
  4914. HasSubstr("OpenCL.std ilogb: "
  4915. "expected operand X to be a float scalar or vector"));
  4916. }
  4917. TEST_F(ValidateExtInst, OpenCLStdIlogbDiffSize) {
  4918. const std::string body = R"(
  4919. %val2 = OpExtInst %u32vec2 %extinst ilogb %f32_1
  4920. )";
  4921. CompileSuccessfully(GenerateKernelCode(body));
  4922. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4923. EXPECT_THAT(getDiagnosticString(),
  4924. HasSubstr("OpenCL.std ilogb: "
  4925. "expected operand X to have the same number of "
  4926. "components as Result Type"));
  4927. }
  4928. TEST_F(ValidateExtInst, OpenCLStdNanSuccess) {
  4929. const std::string body = R"(
  4930. %val1 = OpExtInst %f32 %extinst nan %u32_3
  4931. %val2 = OpExtInst %f32vec2 %extinst nan %u32vec2_12
  4932. )";
  4933. CompileSuccessfully(GenerateKernelCode(body));
  4934. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4935. }
  4936. TEST_F(ValidateExtInst, OpenCLStdNanIntResultType) {
  4937. const std::string body = R"(
  4938. %val1 = OpExtInst %u32 %extinst nan %u32_3
  4939. )";
  4940. CompileSuccessfully(GenerateKernelCode(body));
  4941. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4942. EXPECT_THAT(
  4943. getDiagnosticString(),
  4944. HasSubstr("OpenCL.std nan: "
  4945. "expected Result Type to be a float scalar or vector type"));
  4946. }
  4947. TEST_F(ValidateExtInst, OpenCLStdNanFloatNancode) {
  4948. const std::string body = R"(
  4949. %val1 = OpExtInst %f32 %extinst nan %f32_3
  4950. )";
  4951. CompileSuccessfully(GenerateKernelCode(body));
  4952. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4953. EXPECT_THAT(getDiagnosticString(),
  4954. HasSubstr("OpenCL.std nan: "
  4955. "expected Nancode to be an int scalar or vector type"));
  4956. }
  4957. TEST_F(ValidateExtInst, OpenCLStdNanFloatDiffSize) {
  4958. const std::string body = R"(
  4959. %val1 = OpExtInst %f32 %extinst nan %u32vec2_12
  4960. )";
  4961. CompileSuccessfully(GenerateKernelCode(body));
  4962. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4963. EXPECT_THAT(getDiagnosticString(),
  4964. HasSubstr("OpenCL.std nan: "
  4965. "expected Nancode to have the same number of "
  4966. "components as Result Type"));
  4967. }
  4968. TEST_F(ValidateExtInst, OpenCLStdNanFloatDiffBitWidth) {
  4969. const std::string body = R"(
  4970. %val1 = OpExtInst %f64 %extinst nan %u32_2
  4971. )";
  4972. CompileSuccessfully(GenerateKernelCode(body));
  4973. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4974. EXPECT_THAT(
  4975. getDiagnosticString(),
  4976. HasSubstr("OpenCL.std nan: "
  4977. "expected Nancode to have the same bit width as Result Type"));
  4978. }
  4979. TEST_P(ValidateOpenCLStdLdexpLike, Success) {
  4980. const std::string ext_inst_name = GetParam();
  4981. std::ostringstream ss;
  4982. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  4983. << " %f32_0 %u32_1\n";
  4984. ss << "%val2 = OpExtInst %f32vec2 %extinst " << ext_inst_name
  4985. << " %f32vec2_12 %u32vec2_12\n";
  4986. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4987. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  4988. }
  4989. TEST_P(ValidateOpenCLStdLdexpLike, IntResultType) {
  4990. const std::string ext_inst_name = GetParam();
  4991. std::ostringstream ss;
  4992. ss << "%val1 = OpExtInst %u32 %extinst " << ext_inst_name
  4993. << " %f32_0 %u32_1\n";
  4994. CompileSuccessfully(GenerateKernelCode(ss.str()));
  4995. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  4996. EXPECT_THAT(
  4997. getDiagnosticString(),
  4998. HasSubstr("OpenCL.std " + ext_inst_name +
  4999. ": expected Result Type to be a float scalar or vector type"));
  5000. }
  5001. TEST_P(ValidateOpenCLStdLdexpLike, XWrongType) {
  5002. const std::string ext_inst_name = GetParam();
  5003. std::ostringstream ss;
  5004. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  5005. << " %u32_0 %u32_1\n";
  5006. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5007. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5008. EXPECT_THAT(
  5009. getDiagnosticString(),
  5010. HasSubstr("OpenCL.std " + ext_inst_name +
  5011. ": expected type of operand X to be equal to Result Type"));
  5012. }
  5013. TEST_P(ValidateOpenCLStdLdexpLike, ExponentNotInt) {
  5014. const std::string ext_inst_name = GetParam();
  5015. std::ostringstream ss;
  5016. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  5017. << " %f32_0 %f32_1\n";
  5018. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5019. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5020. EXPECT_THAT(
  5021. getDiagnosticString(),
  5022. HasSubstr("OpenCL.std " + ext_inst_name +
  5023. ": expected the exponent to be a 32-bit int scalar or vector"));
  5024. }
  5025. TEST_P(ValidateOpenCLStdLdexpLike, ExponentNotInt32) {
  5026. const std::string ext_inst_name = GetParam();
  5027. std::ostringstream ss;
  5028. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  5029. << " %f32_0 %u64_1\n";
  5030. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5031. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5032. EXPECT_THAT(
  5033. getDiagnosticString(),
  5034. HasSubstr("OpenCL.std " + ext_inst_name +
  5035. ": expected the exponent to be a 32-bit int scalar or vector"));
  5036. }
  5037. TEST_P(ValidateOpenCLStdLdexpLike, ExponentWrongSize) {
  5038. const std::string ext_inst_name = GetParam();
  5039. std::ostringstream ss;
  5040. ss << "%val1 = OpExtInst %f32 %extinst " << ext_inst_name
  5041. << " %f32_0 %u32vec2_01\n";
  5042. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5043. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5044. EXPECT_THAT(getDiagnosticString(),
  5045. HasSubstr("OpenCL.std " + ext_inst_name +
  5046. ": expected the exponent to have the same number of "
  5047. "components as Result Type"));
  5048. }
  5049. INSTANTIATE_TEST_SUITE_P(AllLdexpLike, ValidateOpenCLStdLdexpLike,
  5050. ::testing::ValuesIn(std::vector<std::string>{
  5051. "ldexp",
  5052. "pown",
  5053. "rootn",
  5054. }));
  5055. TEST_P(ValidateOpenCLStdUpsampleLike, Success) {
  5056. const std::string ext_inst_name = GetParam();
  5057. std::ostringstream ss;
  5058. ss << "%val1 = OpExtInst %u16 %extinst " << ext_inst_name << " %u8_1 %u8_2\n";
  5059. ss << "%val2 = OpExtInst %u32 %extinst " << ext_inst_name
  5060. << " %u16_1 %u16_2\n";
  5061. ss << "%val3 = OpExtInst %u64 %extinst " << ext_inst_name
  5062. << " %u32_1 %u32_2\n";
  5063. ss << "%val4 = OpExtInst %u64vec2 %extinst " << ext_inst_name
  5064. << " %u32vec2_01 %u32vec2_01\n";
  5065. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5066. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5067. }
  5068. TEST_P(ValidateOpenCLStdUpsampleLike, FloatResultType) {
  5069. const std::string ext_inst_name = GetParam();
  5070. std::ostringstream ss;
  5071. ss << "%val1 = OpExtInst %f64 %extinst " << ext_inst_name
  5072. << " %u32_1 %u32_2\n";
  5073. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5074. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5075. EXPECT_THAT(
  5076. getDiagnosticString(),
  5077. HasSubstr("OpenCL.std " + ext_inst_name +
  5078. ": expected Result Type to be an int scalar or vector type"));
  5079. }
  5080. TEST_P(ValidateOpenCLStdUpsampleLike, InvalidResultTypeBitWidth) {
  5081. const std::string ext_inst_name = GetParam();
  5082. std::ostringstream ss;
  5083. ss << "%val1 = OpExtInst %u8 %extinst " << ext_inst_name << " %u8_1 %u8_2\n";
  5084. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5085. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5086. EXPECT_THAT(
  5087. getDiagnosticString(),
  5088. HasSubstr(
  5089. "OpenCL.std " + ext_inst_name +
  5090. ": expected bit width of Result Type components to be 16, 32 or 64"));
  5091. }
  5092. TEST_P(ValidateOpenCLStdUpsampleLike, LoHiDiffType) {
  5093. const std::string ext_inst_name = GetParam();
  5094. std::ostringstream ss;
  5095. ss << "%val1 = OpExtInst %u64 %extinst " << ext_inst_name
  5096. << " %u32_1 %u16_2\n";
  5097. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5098. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5099. EXPECT_THAT(getDiagnosticString(),
  5100. HasSubstr("OpenCL.std " + ext_inst_name +
  5101. ": expected Hi and Lo operands to have the same type"));
  5102. }
  5103. TEST_P(ValidateOpenCLStdUpsampleLike, DiffNumberOfComponents) {
  5104. const std::string ext_inst_name = GetParam();
  5105. std::ostringstream ss;
  5106. ss << "%val1 = OpExtInst %u64vec2 %extinst " << ext_inst_name
  5107. << " %u32_1 %u32_2\n";
  5108. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5109. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5110. EXPECT_THAT(getDiagnosticString(),
  5111. HasSubstr("OpenCL.std " + ext_inst_name +
  5112. ": expected Hi and Lo operands to have the same number "
  5113. "of components as Result Type"));
  5114. }
  5115. TEST_P(ValidateOpenCLStdUpsampleLike, HiLoWrongBitWidth) {
  5116. const std::string ext_inst_name = GetParam();
  5117. std::ostringstream ss;
  5118. ss << "%val1 = OpExtInst %u64 %extinst " << ext_inst_name
  5119. << " %u16_1 %u16_2\n";
  5120. CompileSuccessfully(GenerateKernelCode(ss.str()));
  5121. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5122. EXPECT_THAT(
  5123. getDiagnosticString(),
  5124. HasSubstr("OpenCL.std " + ext_inst_name +
  5125. ": expected bit width of components of Hi and Lo operands to "
  5126. "be half of the bit width of components of Result Type"));
  5127. }
  5128. INSTANTIATE_TEST_SUITE_P(AllUpsampleLike, ValidateOpenCLStdUpsampleLike,
  5129. ::testing::ValuesIn(std::vector<std::string>{
  5130. "u_upsample",
  5131. "s_upsample",
  5132. }));
  5133. TEST_F(ValidateClspvReflection, RequiresNonSemanticExtension) {
  5134. const std::string text = R"(
  5135. OpCapability Shader
  5136. OpCapability Linkage
  5137. %1 = OpExtInstImport "NonSemantic.ClspvReflection.1"
  5138. OpMemoryModel Logical GLSL450
  5139. )";
  5140. CompileSuccessfully(text);
  5141. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5142. EXPECT_THAT(getDiagnosticString(),
  5143. HasSubstr("NonSemantic extended instruction sets cannot be "
  5144. "declared without SPV_KHR_non_semantic_info"));
  5145. }
  5146. TEST_F(ValidateClspvReflection, DoesNotRequiresNonSemanticExtensionPost1p6) {
  5147. const std::string text = R"(
  5148. OpCapability Shader
  5149. OpCapability Linkage
  5150. %1 = OpExtInstImport "NonSemantic.ClspvReflection.1"
  5151. OpMemoryModel Logical GLSL450
  5152. )";
  5153. CompileSuccessfully(text, SPV_ENV_UNIVERSAL_1_6);
  5154. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_6));
  5155. }
  5156. TEST_F(ValidateClspvReflection, MissingVersion) {
  5157. const std::string text = R"(
  5158. OpCapability Shader
  5159. OpCapability Linkage
  5160. OpExtension "SPV_KHR_non_semantic_info"
  5161. %1 = OpExtInstImport "NonSemantic.ClspvReflection."
  5162. OpMemoryModel Logical GLSL450
  5163. %2 = OpTypeVoid
  5164. %3 = OpTypeInt 32 0
  5165. %4 = OpConstant %3 1
  5166. %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
  5167. )";
  5168. CompileSuccessfully(text);
  5169. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5170. EXPECT_THAT(getDiagnosticString(),
  5171. HasSubstr("Missing NonSemantic.ClspvReflection import version"));
  5172. }
  5173. TEST_F(ValidateClspvReflection, BadVersion0) {
  5174. const std::string text = R"(
  5175. OpCapability Shader
  5176. OpCapability Linkage
  5177. OpExtension "SPV_KHR_non_semantic_info"
  5178. %1 = OpExtInstImport "NonSemantic.ClspvReflection.0"
  5179. OpMemoryModel Logical GLSL450
  5180. %2 = OpTypeVoid
  5181. %3 = OpTypeInt 32 0
  5182. %4 = OpConstant %3 1
  5183. %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
  5184. )";
  5185. CompileSuccessfully(text);
  5186. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5187. EXPECT_THAT(getDiagnosticString(),
  5188. HasSubstr("Unknown NonSemantic.ClspvReflection import version"));
  5189. }
  5190. TEST_F(ValidateClspvReflection, BadVersionNotANumber) {
  5191. const std::string text = R"(
  5192. OpCapability Shader
  5193. OpCapability Linkage
  5194. OpExtension "SPV_KHR_non_semantic_info"
  5195. %1 = OpExtInstImport "NonSemantic.ClspvReflection.1a"
  5196. OpMemoryModel Logical GLSL450
  5197. %2 = OpTypeVoid
  5198. %3 = OpTypeInt 32 0
  5199. %4 = OpConstant %3 1
  5200. %5 = OpExtInst %2 %1 SpecConstantWorkDim %4
  5201. )";
  5202. CompileSuccessfully(text);
  5203. ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
  5204. EXPECT_THAT(getDiagnosticString(),
  5205. HasSubstr("NonSemantic.ClspvReflection import does not encode "
  5206. "the version correctly"));
  5207. }
  5208. TEST_F(ValidateClspvReflection, Kernel) {
  5209. const std::string text = R"(
  5210. OpCapability Shader
  5211. OpExtension "SPV_KHR_non_semantic_info"
  5212. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  5213. OpMemoryModel Logical GLSL450
  5214. OpEntryPoint GLCompute %foo "foo"
  5215. OpExecutionMode %foo LocalSize 1 1 1
  5216. %foo_name = OpString "foo"
  5217. %void = OpTypeVoid
  5218. %void_fn = OpTypeFunction %void
  5219. %foo = OpFunction %void None %void_fn
  5220. %entry = OpLabel
  5221. OpReturn
  5222. OpFunctionEnd
  5223. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  5224. )";
  5225. CompileSuccessfully(text);
  5226. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5227. }
  5228. TEST_F(ValidateClspvReflection, KernelNotAFunction) {
  5229. const std::string text = R"(
  5230. OpCapability Shader
  5231. OpExtension "SPV_KHR_non_semantic_info"
  5232. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  5233. OpMemoryModel Logical GLSL450
  5234. OpEntryPoint GLCompute %foo "foo"
  5235. OpExecutionMode %foo LocalSize 1 1 1
  5236. %foo_name = OpString "foo"
  5237. %void = OpTypeVoid
  5238. %void_fn = OpTypeFunction %void
  5239. %foo = OpFunction %void None %void_fn
  5240. %entry = OpLabel
  5241. OpReturn
  5242. OpFunctionEnd
  5243. %decl = OpExtInst %void %ext Kernel %foo_name %foo_name
  5244. )";
  5245. CompileSuccessfully(text);
  5246. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5247. EXPECT_THAT(getDiagnosticString(),
  5248. HasSubstr("Kernel does not reference a function"));
  5249. }
  5250. TEST_F(ValidateClspvReflection, KernelNotAnEntryPoint) {
  5251. const std::string text = R"(
  5252. OpCapability Shader
  5253. OpExtension "SPV_KHR_non_semantic_info"
  5254. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  5255. OpMemoryModel Logical GLSL450
  5256. OpEntryPoint GLCompute %foo "foo"
  5257. OpExecutionMode %foo LocalSize 1 1 1
  5258. %foo_name = OpString "foo"
  5259. %void = OpTypeVoid
  5260. %void_fn = OpTypeFunction %void
  5261. %foo = OpFunction %void None %void_fn
  5262. %entry = OpLabel
  5263. OpReturn
  5264. OpFunctionEnd
  5265. %bar = OpFunction %void None %void_fn
  5266. %bar_entry = OpLabel
  5267. OpReturn
  5268. OpFunctionEnd
  5269. %decl = OpExtInst %void %ext Kernel %bar %foo_name
  5270. )";
  5271. CompileSuccessfully(text);
  5272. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5273. EXPECT_THAT(getDiagnosticString(),
  5274. HasSubstr("Kernel does not reference an entry-point"));
  5275. }
  5276. TEST_F(ValidateClspvReflection, KernelNotGLCompute) {
  5277. const std::string text = R"(
  5278. OpCapability Shader
  5279. OpExtension "SPV_KHR_non_semantic_info"
  5280. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  5281. OpMemoryModel Logical GLSL450
  5282. OpEntryPoint Fragment %foo "foo"
  5283. OpExecutionMode %foo OriginUpperLeft
  5284. %foo_name = OpString "foo"
  5285. %void = OpTypeVoid
  5286. %void_fn = OpTypeFunction %void
  5287. %foo = OpFunction %void None %void_fn
  5288. %entry = OpLabel
  5289. OpReturn
  5290. OpFunctionEnd
  5291. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  5292. )";
  5293. CompileSuccessfully(text);
  5294. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5295. EXPECT_THAT(getDiagnosticString(),
  5296. HasSubstr("Kernel must refer only to GLCompute entry-points"));
  5297. }
  5298. TEST_F(ValidateClspvReflection, KernelNameMismatch) {
  5299. const std::string text = R"(
  5300. OpCapability Shader
  5301. OpExtension "SPV_KHR_non_semantic_info"
  5302. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  5303. OpMemoryModel Logical GLSL450
  5304. OpEntryPoint GLCompute %foo "foo"
  5305. OpExecutionMode %foo LocalSize 1 1 1
  5306. %foo_name = OpString "bar"
  5307. %void = OpTypeVoid
  5308. %void_fn = OpTypeFunction %void
  5309. %foo = OpFunction %void None %void_fn
  5310. %entry = OpLabel
  5311. OpReturn
  5312. OpFunctionEnd
  5313. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  5314. )";
  5315. CompileSuccessfully(text);
  5316. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5317. EXPECT_THAT(getDiagnosticString(),
  5318. HasSubstr("Name must match an entry-point for Kernel"));
  5319. }
  5320. TEST_F(ValidateClspvReflection, KernelArgumentsVersionGood) {
  5321. const std::string text = R"(
  5322. OpCapability Shader
  5323. OpExtension "SPV_KHR_non_semantic_info"
  5324. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5325. OpMemoryModel Logical GLSL450
  5326. OpEntryPoint GLCompute %foo "foo"
  5327. OpExecutionMode %foo LocalSize 1 1 1
  5328. %foo_name = OpString "foo"
  5329. %void = OpTypeVoid
  5330. %void_fn = OpTypeFunction %void
  5331. %int = OpTypeInt 32 0
  5332. %int_1 = OpConstant %int 1
  5333. %foo = OpFunction %void None %void_fn
  5334. %entry = OpLabel
  5335. OpReturn
  5336. OpFunctionEnd
  5337. %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_1
  5338. )";
  5339. CompileSuccessfully(text);
  5340. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5341. }
  5342. TEST_F(ValidateClspvReflection, KernelArgumentsVersionBad) {
  5343. const std::string text = R"(
  5344. OpCapability Shader
  5345. OpExtension "SPV_KHR_non_semantic_info"
  5346. %ext = OpExtInstImport "NonSemantic.ClspvReflection.4"
  5347. OpMemoryModel Logical GLSL450
  5348. OpEntryPoint GLCompute %foo "foo"
  5349. OpExecutionMode %foo LocalSize 1 1 1
  5350. %foo_name = OpString "foo"
  5351. %void = OpTypeVoid
  5352. %void_fn = OpTypeFunction %void
  5353. %int = OpTypeInt 32 0
  5354. %int_1 = OpConstant %int 1
  5355. %foo = OpFunction %void None %void_fn
  5356. %entry = OpLabel
  5357. OpReturn
  5358. OpFunctionEnd
  5359. %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_1
  5360. )";
  5361. CompileSuccessfully(text);
  5362. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5363. EXPECT_THAT(getDiagnosticString(),
  5364. HasSubstr("Version 4 of the Kernel instruction can only have 2 "
  5365. "additional operands"));
  5366. }
  5367. TEST_F(ValidateClspvReflection, KernelNumArgumentsNotInt) {
  5368. const std::string text = R"(
  5369. OpCapability Shader
  5370. OpExtension "SPV_KHR_non_semantic_info"
  5371. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5372. OpMemoryModel Logical GLSL450
  5373. OpEntryPoint GLCompute %foo "foo"
  5374. OpExecutionMode %foo LocalSize 1 1 1
  5375. %foo_name = OpString "foo"
  5376. %void = OpTypeVoid
  5377. %void_fn = OpTypeFunction %void
  5378. %int = OpTypeInt 32 0
  5379. %int_0 = OpConstant %int 0
  5380. %float = OpTypeFloat 32
  5381. %float_0 = OpConstant %float 0
  5382. %foo = OpFunction %void None %void_fn
  5383. %entry = OpLabel
  5384. OpReturn
  5385. OpFunctionEnd
  5386. %decl = OpExtInst %void %ext Kernel %foo %foo_name %float_0
  5387. )";
  5388. CompileSuccessfully(text);
  5389. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5390. EXPECT_THAT(
  5391. getDiagnosticString(),
  5392. HasSubstr("NumArguments must be a 32-bit unsigned integer OpConstant"));
  5393. }
  5394. TEST_F(ValidateClspvReflection, KernelNumArgumentsNotConstant) {
  5395. const std::string text = R"(
  5396. OpCapability Shader
  5397. OpExtension "SPV_KHR_non_semantic_info"
  5398. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5399. OpMemoryModel Logical GLSL450
  5400. OpEntryPoint GLCompute %foo "foo"
  5401. OpExecutionMode %foo LocalSize 1 1 1
  5402. %foo_name = OpString "foo"
  5403. %void = OpTypeVoid
  5404. %void_fn = OpTypeFunction %void
  5405. %int = OpTypeInt 32 0
  5406. %int_0 = OpConstant %int 0
  5407. %null = OpConstantNull %int
  5408. %foo = OpFunction %void None %void_fn
  5409. %entry = OpLabel
  5410. OpReturn
  5411. OpFunctionEnd
  5412. %decl = OpExtInst %void %ext Kernel %foo %foo_name %null
  5413. )";
  5414. CompileSuccessfully(text);
  5415. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5416. EXPECT_THAT(
  5417. getDiagnosticString(),
  5418. HasSubstr("NumArguments must be a 32-bit unsigned integer OpConstant"));
  5419. }
  5420. TEST_F(ValidateClspvReflection, KernelFlagsNotInt) {
  5421. const std::string text = R"(
  5422. OpCapability Shader
  5423. OpExtension "SPV_KHR_non_semantic_info"
  5424. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5425. OpMemoryModel Logical GLSL450
  5426. OpEntryPoint GLCompute %foo "foo"
  5427. OpExecutionMode %foo LocalSize 1 1 1
  5428. %foo_name = OpString "foo"
  5429. %void = OpTypeVoid
  5430. %void_fn = OpTypeFunction %void
  5431. %int = OpTypeInt 32 0
  5432. %int_0 = OpConstant %int 0
  5433. %float = OpTypeFloat 32
  5434. %float_0 = OpConstant %float 0
  5435. %foo = OpFunction %void None %void_fn
  5436. %entry = OpLabel
  5437. OpReturn
  5438. OpFunctionEnd
  5439. %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_0 %float_0
  5440. )";
  5441. CompileSuccessfully(text);
  5442. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5443. EXPECT_THAT(getDiagnosticString(),
  5444. HasSubstr("Flags must be a 32-bit unsigned integer OpConstant"));
  5445. }
  5446. TEST_F(ValidateClspvReflection, KernelFlagsNotConstant) {
  5447. const std::string text = R"(
  5448. OpCapability Shader
  5449. OpExtension "SPV_KHR_non_semantic_info"
  5450. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5451. OpMemoryModel Logical GLSL450
  5452. OpEntryPoint GLCompute %foo "foo"
  5453. OpExecutionMode %foo LocalSize 1 1 1
  5454. %foo_name = OpString "foo"
  5455. %void = OpTypeVoid
  5456. %void_fn = OpTypeFunction %void
  5457. %int = OpTypeInt 32 0
  5458. %int_0 = OpConstant %int 0
  5459. %null = OpConstantNull %int
  5460. %foo = OpFunction %void None %void_fn
  5461. %entry = OpLabel
  5462. OpReturn
  5463. OpFunctionEnd
  5464. %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_0 %null
  5465. )";
  5466. CompileSuccessfully(text);
  5467. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5468. EXPECT_THAT(getDiagnosticString(),
  5469. HasSubstr("Flags must be a 32-bit unsigned integer OpConstant"));
  5470. }
  5471. TEST_F(ValidateClspvReflection, KernelAttributesNotString) {
  5472. const std::string text = R"(
  5473. OpCapability Shader
  5474. OpExtension "SPV_KHR_non_semantic_info"
  5475. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5476. OpMemoryModel Logical GLSL450
  5477. OpEntryPoint GLCompute %foo "foo"
  5478. OpExecutionMode %foo LocalSize 1 1 1
  5479. %foo_name = OpString "foo"
  5480. %void = OpTypeVoid
  5481. %void_fn = OpTypeFunction %void
  5482. %int = OpTypeInt 32 0
  5483. %int_0 = OpConstant %int 0
  5484. %float = OpTypeFloat 32
  5485. %float_0 = OpConstant %float 0
  5486. %foo = OpFunction %void None %void_fn
  5487. %entry = OpLabel
  5488. OpReturn
  5489. OpFunctionEnd
  5490. %decl = OpExtInst %void %ext Kernel %foo %foo_name %int_0 %int_0 %int_0
  5491. )";
  5492. CompileSuccessfully(text);
  5493. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5494. EXPECT_THAT(getDiagnosticString(),
  5495. HasSubstr("Attributes must be an OpString"));
  5496. }
  5497. using ArgumentBasics =
  5498. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  5499. INSTANTIATE_TEST_SUITE_P(
  5500. ValidateClspvReflectionArgumentKernel, ArgumentBasics,
  5501. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  5502. std::make_pair("ArgumentStorageBuffer", "%int_0 %int_0"),
  5503. std::make_pair("ArgumentUniform", "%int_0 %int_0"),
  5504. std::make_pair("ArgumentPodStorageBuffer",
  5505. "%int_0 %int_0 %int_0 %int_4"),
  5506. std::make_pair("ArgumentPodUniform", "%int_0 %int_0 %int_0 %int_4"),
  5507. std::make_pair("ArgumentPodPushConstant", "%int_0 %int_4"),
  5508. std::make_pair("ArgumentSampledImage", "%int_0 %int_0"),
  5509. std::make_pair("ArgumentStorageImage", "%int_0 %int_0"),
  5510. std::make_pair("ArgumentSampler", "%int_0 %int_0"),
  5511. std::make_pair("ArgumentWorkgroup", "%int_0 %int_0"),
  5512. std::make_pair("ArgumentPointerPushConstant", "%int_0 %int_4"),
  5513. std::make_pair("ArgumentPointerUniform", "%int_0 %int_0 %int_0 %int_4"),
  5514. std::make_pair("ArgumentStorageTexelBuffer", "%int_0 %int_0"),
  5515. std::make_pair("ArgumentUniformTexelBuffer", "%int_0 %int_0")}));
  5516. TEST_P(ArgumentBasics, KernelNotAnExtendedInstruction) {
  5517. const std::string ext_inst = std::get<0>(GetParam());
  5518. const std::string extra = std::get<1>(GetParam());
  5519. const std::string text = R"(
  5520. OpCapability Shader
  5521. OpExtension "SPV_KHR_non_semantic_info"
  5522. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5523. OpMemoryModel Logical GLSL450
  5524. OpEntryPoint GLCompute %foo "foo"
  5525. OpExecutionMode %foo LocalSize 1 1 1
  5526. %foo_name = OpString "foo"
  5527. %void = OpTypeVoid
  5528. %int = OpTypeInt 32 0
  5529. %int_0 = OpConstant %int 0
  5530. %int_4 = OpConstant %int 4
  5531. %void_fn = OpTypeFunction %void
  5532. %foo = OpFunction %void None %void_fn
  5533. %entry = OpLabel
  5534. OpReturn
  5535. OpFunctionEnd
  5536. %in = OpExtInst %void %ext )" +
  5537. ext_inst + " %int_0 %int_0 " + extra;
  5538. CompileSuccessfully(text);
  5539. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5540. EXPECT_THAT(getDiagnosticString(),
  5541. HasSubstr("Kernel must be a Kernel extended instruction"));
  5542. }
  5543. TEST_P(ArgumentBasics, KernelFromDifferentImport) {
  5544. const std::string ext_inst = std::get<0>(GetParam());
  5545. const std::string extra = std::get<1>(GetParam());
  5546. const std::string text = R"(
  5547. OpCapability Shader
  5548. OpExtension "SPV_KHR_non_semantic_info"
  5549. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5550. %ext2 = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5551. OpMemoryModel Logical GLSL450
  5552. OpEntryPoint GLCompute %foo "foo"
  5553. OpExecutionMode %foo LocalSize 1 1 1
  5554. %foo_name = OpString "foo"
  5555. %void = OpTypeVoid
  5556. %int = OpTypeInt 32 0
  5557. %int_0 = OpConstant %int 0
  5558. %int_4 = OpConstant %int 4
  5559. %void_fn = OpTypeFunction %void
  5560. %foo = OpFunction %void None %void_fn
  5561. %entry = OpLabel
  5562. OpReturn
  5563. OpFunctionEnd
  5564. %decl = OpExtInst %void %ext2 Kernel %foo %foo_name
  5565. %in = OpExtInst %void %ext )" +
  5566. ext_inst + " %decl %int_0 " + extra;
  5567. CompileSuccessfully(text);
  5568. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5569. EXPECT_THAT(
  5570. getDiagnosticString(),
  5571. HasSubstr("Kernel must be from the same extended instruction import"));
  5572. }
  5573. TEST_P(ArgumentBasics, KernelWrongExtendedInstruction) {
  5574. const std::string ext_inst = std::get<0>(GetParam());
  5575. const std::string extra = std::get<1>(GetParam());
  5576. const std::string text = R"(
  5577. OpCapability Shader
  5578. OpExtension "SPV_KHR_non_semantic_info"
  5579. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5580. OpMemoryModel Logical GLSL450
  5581. OpEntryPoint GLCompute %foo "foo"
  5582. OpExecutionMode %foo LocalSize 1 1 1
  5583. %foo_name = OpString "foo"
  5584. %void = OpTypeVoid
  5585. %int = OpTypeInt 32 0
  5586. %int_0 = OpConstant %int 0
  5587. %int_4 = OpConstant %int 4
  5588. %void_fn = OpTypeFunction %void
  5589. %foo = OpFunction %void None %void_fn
  5590. %entry = OpLabel
  5591. OpReturn
  5592. OpFunctionEnd
  5593. %decl = OpExtInst %void %ext ArgumentInfo %foo_name
  5594. %in = OpExtInst %void %ext )" +
  5595. ext_inst + " %decl %int_0 " + extra;
  5596. CompileSuccessfully(text);
  5597. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5598. EXPECT_THAT(getDiagnosticString(),
  5599. HasSubstr("Kernel must be a Kernel extended instruction"));
  5600. }
  5601. TEST_P(ArgumentBasics, ArgumentInfo) {
  5602. const std::string ext_inst = std::get<0>(GetParam());
  5603. const std::string operands = std::get<1>(GetParam());
  5604. const std::string text = R"(
  5605. OpCapability Shader
  5606. OpExtension "SPV_KHR_non_semantic_info"
  5607. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5608. OpMemoryModel Logical GLSL450
  5609. OpEntryPoint GLCompute %foo "foo"
  5610. OpExecutionMode %foo LocalSize 1 1 1
  5611. %foo_name = OpString "foo"
  5612. %in_name = OpString "in"
  5613. %void = OpTypeVoid
  5614. %int = OpTypeInt 32 0
  5615. %int_0 = OpConstant %int 0
  5616. %int_4 = OpConstant %int 4
  5617. %void_fn = OpTypeFunction %void
  5618. %foo = OpFunction %void None %void_fn
  5619. %entry = OpLabel
  5620. OpReturn
  5621. OpFunctionEnd
  5622. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  5623. %info = OpExtInst %void %ext ArgumentInfo %in_name
  5624. %in = OpExtInst %void %ext )" +
  5625. ext_inst + " %decl %int_0 " + operands + " %info";
  5626. CompileSuccessfully(text);
  5627. ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
  5628. }
  5629. TEST_P(ArgumentBasics, ArgumentInfoNotAnExtendedInstruction) {
  5630. const std::string ext_inst = std::get<0>(GetParam());
  5631. const std::string operands = std::get<1>(GetParam());
  5632. const std::string text = R"(
  5633. OpCapability Shader
  5634. OpExtension "SPV_KHR_non_semantic_info"
  5635. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5636. OpMemoryModel Logical GLSL450
  5637. OpEntryPoint GLCompute %foo "foo"
  5638. OpExecutionMode %foo LocalSize 1 1 1
  5639. %foo_name = OpString "foo"
  5640. %void = OpTypeVoid
  5641. %int = OpTypeInt 32 0
  5642. %int_0 = OpConstant %int 0
  5643. %int_4 = OpConstant %int 4
  5644. %void_fn = OpTypeFunction %void
  5645. %foo = OpFunction %void None %void_fn
  5646. %entry = OpLabel
  5647. OpReturn
  5648. OpFunctionEnd
  5649. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  5650. %in = OpExtInst %void %ext )" +
  5651. ext_inst + " %decl %int_0 " + operands + " %int_0";
  5652. CompileSuccessfully(text);
  5653. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5654. EXPECT_THAT(
  5655. getDiagnosticString(),
  5656. HasSubstr("ArgInfo must be an ArgumentInfo extended instruction"));
  5657. }
  5658. TEST_P(ArgumentBasics, ArgumentInfoFromDifferentImport) {
  5659. const std::string ext_inst = std::get<0>(GetParam());
  5660. const std::string operands = std::get<1>(GetParam());
  5661. const std::string text = R"(
  5662. OpCapability Shader
  5663. OpExtension "SPV_KHR_non_semantic_info"
  5664. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5665. %ext2 = OpExtInstImport "NonSemantic.ClspvReflection.5"
  5666. OpMemoryModel Logical GLSL450
  5667. OpEntryPoint GLCompute %foo "foo"
  5668. OpExecutionMode %foo LocalSize 1 1 1
  5669. %foo_name = OpString "foo"
  5670. %in_name = OpString "in"
  5671. %void = OpTypeVoid
  5672. %int = OpTypeInt 32 0
  5673. %int_0 = OpConstant %int 0
  5674. %int_4 = OpConstant %int 4
  5675. %void_fn = OpTypeFunction %void
  5676. %foo = OpFunction %void None %void_fn
  5677. %entry = OpLabel
  5678. OpReturn
  5679. OpFunctionEnd
  5680. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  5681. %info = OpExtInst %void %ext2 ArgumentInfo %in_name
  5682. %in = OpExtInst %void %ext )" +
  5683. ext_inst + " %decl %int_0 " + operands + " %info";
  5684. CompileSuccessfully(text);
  5685. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  5686. EXPECT_THAT(
  5687. getDiagnosticString(),
  5688. HasSubstr("ArgInfo must be from the same extended instruction import"));
  5689. }
  5690. using Uint32Constant =
  5691. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  5692. INSTANTIATE_TEST_SUITE_P(
  5693. ValidateClspvReflectionUint32Constants, Uint32Constant,
  5694. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  5695. std::make_pair("ArgumentStorageBuffer %decl %float_0 %int_0 %int_0",
  5696. "Ordinal"),
  5697. std::make_pair("ArgumentStorageBuffer %decl %null %int_0 %int_0",
  5698. "Ordinal"),
  5699. std::make_pair("ArgumentStorageBuffer %decl %int_0 %float_0 %int_0",
  5700. "DescriptorSet"),
  5701. std::make_pair("ArgumentStorageBuffer %decl %int_0 %null %int_0",
  5702. "DescriptorSet"),
  5703. std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %float_0",
  5704. "Binding"),
  5705. std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %null",
  5706. "Binding"),
  5707. std::make_pair("ArgumentUniform %decl %float_0 %int_0 %int_0",
  5708. "Ordinal"),
  5709. std::make_pair("ArgumentUniform %decl %null %int_0 %int_0", "Ordinal"),
  5710. std::make_pair("ArgumentUniform %decl %int_0 %float_0 %int_0",
  5711. "DescriptorSet"),
  5712. std::make_pair("ArgumentUniform %decl %int_0 %null %int_0",
  5713. "DescriptorSet"),
  5714. std::make_pair("ArgumentUniform %decl %int_0 %int_0 %float_0",
  5715. "Binding"),
  5716. std::make_pair("ArgumentUniform %decl %int_0 %int_0 %null", "Binding"),
  5717. std::make_pair("ArgumentSampledImage %decl %float_0 %int_0 %int_0",
  5718. "Ordinal"),
  5719. std::make_pair("ArgumentSampledImage %decl %null %int_0 %int_0",
  5720. "Ordinal"),
  5721. std::make_pair("ArgumentSampledImage %decl %int_0 %float_0 %int_0",
  5722. "DescriptorSet"),
  5723. std::make_pair("ArgumentSampledImage %decl %int_0 %null %int_0",
  5724. "DescriptorSet"),
  5725. std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %float_0",
  5726. "Binding"),
  5727. std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %null",
  5728. "Binding"),
  5729. std::make_pair("ArgumentStorageImage %decl %float_0 %int_0 %int_0",
  5730. "Ordinal"),
  5731. std::make_pair("ArgumentStorageImage %decl %null %int_0 %int_0",
  5732. "Ordinal"),
  5733. std::make_pair("ArgumentStorageImage %decl %int_0 %float_0 %int_0",
  5734. "DescriptorSet"),
  5735. std::make_pair("ArgumentStorageImage %decl %int_0 %null %int_0",
  5736. "DescriptorSet"),
  5737. std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %float_0",
  5738. "Binding"),
  5739. std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %null",
  5740. "Binding"),
  5741. std::make_pair("ArgumentSampler %decl %float_0 %int_0 %int_0",
  5742. "Ordinal"),
  5743. std::make_pair("ArgumentSampler %decl %null %int_0 %int_0", "Ordinal"),
  5744. std::make_pair("ArgumentSampler %decl %int_0 %float_0 %int_0",
  5745. "DescriptorSet"),
  5746. std::make_pair("ArgumentSampler %decl %int_0 %null %int_0",
  5747. "DescriptorSet"),
  5748. std::make_pair("ArgumentSampler %decl %int_0 %int_0 %float_0",
  5749. "Binding"),
  5750. std::make_pair("ArgumentSampler %decl %int_0 %int_0 %null", "Binding"),
  5751. std::make_pair("ArgumentPodStorageBuffer %decl %float_0 %int_0 %int_0 "
  5752. "%int_0 %int_4",
  5753. "Ordinal"),
  5754. std::make_pair(
  5755. "ArgumentPodStorageBuffer %decl %null %int_0 %int_0 %int_0 %int_4",
  5756. "Ordinal"),
  5757. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %float_0 %int_0 "
  5758. "%int_0 %int_4",
  5759. "DescriptorSet"),
  5760. std::make_pair(
  5761. "ArgumentPodStorageBuffer %decl %int_0 %null %int_0 %int_0 %int_4",
  5762. "DescriptorSet"),
  5763. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %float_0 "
  5764. "%int_0 %int_4",
  5765. "Binding"),
  5766. std::make_pair(
  5767. "ArgumentPodStorageBuffer %decl %int_0 %int_0 %null %int_0 %int_4",
  5768. "Binding"),
  5769. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 "
  5770. "%float_0 %int_4",
  5771. "Offset"),
  5772. std::make_pair(
  5773. "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %null %int_4",
  5774. "Offset"),
  5775. std::make_pair("ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 "
  5776. "%int_0 %float_0",
  5777. "Size"),
  5778. std::make_pair(
  5779. "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %int_0 %null",
  5780. "Size"),
  5781. std::make_pair(
  5782. "ArgumentPodUniform %decl %float_0 %int_0 %int_0 %int_0 %int_4",
  5783. "Ordinal"),
  5784. std::make_pair(
  5785. "ArgumentPodUniform %decl %null %int_0 %int_0 %int_0 %int_4",
  5786. "Ordinal"),
  5787. std::make_pair(
  5788. "ArgumentPodUniform %decl %int_0 %float_0 %int_0 %int_0 %int_4",
  5789. "DescriptorSet"),
  5790. std::make_pair(
  5791. "ArgumentPodUniform %decl %int_0 %null %int_0 %int_0 %int_4",
  5792. "DescriptorSet"),
  5793. std::make_pair(
  5794. "ArgumentPodUniform %decl %int_0 %int_0 %float_0 %int_0 %int_4",
  5795. "Binding"),
  5796. std::make_pair(
  5797. "ArgumentPodUniform %decl %int_0 %int_0 %null %int_0 %int_4",
  5798. "Binding"),
  5799. std::make_pair(
  5800. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %float_0 %int_4",
  5801. "Offset"),
  5802. std::make_pair(
  5803. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %null %int_4",
  5804. "Offset"),
  5805. std::make_pair(
  5806. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %float_0",
  5807. "Size"),
  5808. std::make_pair(
  5809. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %null",
  5810. "Size"),
  5811. std::make_pair("ArgumentPodPushConstant %decl %float_0 %int_0 %int_4",
  5812. "Ordinal"),
  5813. std::make_pair("ArgumentPodPushConstant %decl %null %int_0 %int_4",
  5814. "Ordinal"),
  5815. std::make_pair("ArgumentPodPushConstant %decl %int_0 %float_0 %int_4",
  5816. "Offset"),
  5817. std::make_pair("ArgumentPodPushConstant %decl %int_0 %null %int_4",
  5818. "Offset"),
  5819. std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %float_0",
  5820. "Size"),
  5821. std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %null",
  5822. "Size"),
  5823. std::make_pair("ArgumentWorkgroup %decl %float_0 %int_0 %int_4",
  5824. "Ordinal"),
  5825. std::make_pair("ArgumentWorkgroup %decl %null %int_0 %int_4",
  5826. "Ordinal"),
  5827. std::make_pair("ArgumentWorkgroup %decl %int_0 %float_0 %int_4",
  5828. "SpecId"),
  5829. std::make_pair("ArgumentWorkgroup %decl %int_0 %null %int_4", "SpecId"),
  5830. std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %float_0",
  5831. "ElemSize"),
  5832. std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %null",
  5833. "ElemSize"),
  5834. std::make_pair("SpecConstantWorkgroupSize %float_0 %int_0 %int_4", "X"),
  5835. std::make_pair("SpecConstantWorkgroupSize %null %int_0 %int_4", "X"),
  5836. std::make_pair("SpecConstantWorkgroupSize %int_0 %float_0 %int_4", "Y"),
  5837. std::make_pair("SpecConstantWorkgroupSize %int_0 %null %int_4", "Y"),
  5838. std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %float_0", "Z"),
  5839. std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %null", "Z"),
  5840. std::make_pair("SpecConstantGlobalOffset %float_0 %int_0 %int_4", "X"),
  5841. std::make_pair("SpecConstantGlobalOffset %null %int_0 %int_4", "X"),
  5842. std::make_pair("SpecConstantGlobalOffset %int_0 %float_0 %int_4", "Y"),
  5843. std::make_pair("SpecConstantGlobalOffset %int_0 %null %int_4", "Y"),
  5844. std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %float_0", "Z"),
  5845. std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %null", "Z"),
  5846. std::make_pair("SpecConstantWorkDim %float_0", "Dim"),
  5847. std::make_pair("SpecConstantWorkDim %null", "Dim"),
  5848. std::make_pair("PushConstantGlobalOffset %float_0 %int_0", "Offset"),
  5849. std::make_pair("PushConstantGlobalOffset %null %int_0", "Offset"),
  5850. std::make_pair("PushConstantGlobalOffset %int_0 %float_0", "Size"),
  5851. std::make_pair("PushConstantGlobalOffset %int_0 %null", "Size"),
  5852. std::make_pair("PushConstantEnqueuedLocalSize %float_0 %int_0",
  5853. "Offset"),
  5854. std::make_pair("PushConstantEnqueuedLocalSize %null %int_0", "Offset"),
  5855. std::make_pair("PushConstantEnqueuedLocalSize %int_0 %float_0", "Size"),
  5856. std::make_pair("PushConstantEnqueuedLocalSize %int_0 %null", "Size"),
  5857. std::make_pair("PushConstantGlobalSize %float_0 %int_0", "Offset"),
  5858. std::make_pair("PushConstantGlobalSize %null %int_0", "Offset"),
  5859. std::make_pair("PushConstantGlobalSize %int_0 %float_0", "Size"),
  5860. std::make_pair("PushConstantGlobalSize %int_0 %null", "Size"),
  5861. std::make_pair("PushConstantRegionOffset %float_0 %int_0", "Offset"),
  5862. std::make_pair("PushConstantRegionOffset %null %int_0", "Offset"),
  5863. std::make_pair("PushConstantRegionOffset %int_0 %float_0", "Size"),
  5864. std::make_pair("PushConstantRegionOffset %int_0 %null", "Size"),
  5865. std::make_pair("PushConstantNumWorkgroups %float_0 %int_0", "Offset"),
  5866. std::make_pair("PushConstantNumWorkgroups %null %int_0", "Offset"),
  5867. std::make_pair("PushConstantNumWorkgroups %int_0 %float_0", "Size"),
  5868. std::make_pair("PushConstantNumWorkgroups %int_0 %null", "Size"),
  5869. std::make_pair("PushConstantRegionGroupOffset %float_0 %int_0",
  5870. "Offset"),
  5871. std::make_pair("PushConstantRegionGroupOffset %null %int_0", "Offset"),
  5872. std::make_pair("PushConstantRegionGroupOffset %int_0 %float_0", "Size"),
  5873. std::make_pair("PushConstantRegionGroupOffset %int_0 %null", "Size"),
  5874. std::make_pair("ConstantDataStorageBuffer %float_0 %int_0 %data",
  5875. "DescriptorSet"),
  5876. std::make_pair("ConstantDataStorageBuffer %null %int_0 %data",
  5877. "DescriptorSet"),
  5878. std::make_pair("ConstantDataStorageBuffer %int_0 %float_0 %data",
  5879. "Binding"),
  5880. std::make_pair("ConstantDataStorageBuffer %int_0 %null %data",
  5881. "Binding"),
  5882. std::make_pair("ConstantDataUniform %float_0 %int_0 %data",
  5883. "DescriptorSet"),
  5884. std::make_pair("ConstantDataUniform %null %int_0 %data",
  5885. "DescriptorSet"),
  5886. std::make_pair("ConstantDataUniform %int_0 %float_0 %data", "Binding"),
  5887. std::make_pair("ConstantDataUniform %int_0 %null %data", "Binding"),
  5888. std::make_pair("LiteralSampler %float_0 %int_0 %int_4",
  5889. "DescriptorSet"),
  5890. std::make_pair("LiteralSampler %null %int_0 %int_4", "DescriptorSet"),
  5891. std::make_pair("LiteralSampler %int_0 %float_0 %int_4", "Binding"),
  5892. std::make_pair("LiteralSampler %int_0 %null %int_4", "Binding"),
  5893. std::make_pair("LiteralSampler %int_0 %int_0 %float_0", "Mask"),
  5894. std::make_pair("LiteralSampler %int_0 %int_0 %null", "Mask"),
  5895. std::make_pair(
  5896. "PropertyRequiredWorkgroupSize %decl %float_0 %int_1 %int_4", "X"),
  5897. std::make_pair(
  5898. "PropertyRequiredWorkgroupSize %decl %null %int_1 %int_4", "X"),
  5899. std::make_pair(
  5900. "PropertyRequiredWorkgroupSize %decl %int_1 %float_0 %int_4", "Y"),
  5901. std::make_pair(
  5902. "PropertyRequiredWorkgroupSize %decl %int_1 %null %int_4", "Y"),
  5903. std::make_pair(
  5904. "PropertyRequiredWorkgroupSize %decl %int_1 %int_1 %float_0", "Z"),
  5905. std::make_pair(
  5906. "PropertyRequiredWorkgroupSize %decl %int_1 %int_1 %null", "Z"),
  5907. std::make_pair("SpecConstantSubgroupMaxSize %float_0", "Size"),
  5908. std::make_pair("SpecConstantSubgroupMaxSize %null", "Size"),
  5909. std::make_pair(
  5910. "ArgumentPointerPushConstant %decl %float_0 %int_0 %int_0",
  5911. "Ordinal"),
  5912. std::make_pair("ArgumentPointerPushConstant %decl %null %int_0 %int_0",
  5913. "Ordinal"),
  5914. std::make_pair(
  5915. "ArgumentPointerPushConstant %decl %int_0 %float_0 %int_0",
  5916. "Offset"),
  5917. std::make_pair("ArgumentPointerPushConstant %decl %int_0 %null %int_0",
  5918. "Offset"),
  5919. std::make_pair(
  5920. "ArgumentPointerPushConstant %decl %int_0 %int_0 %float_0", "Size"),
  5921. std::make_pair("ArgumentPointerPushConstant %decl %int_0 %int_0 %null",
  5922. "Size"),
  5923. std::make_pair(
  5924. "ArgumentPointerUniform %decl %float_0 %int_0 %int_0 %int_0 %int_4",
  5925. "Ordinal"),
  5926. std::make_pair(
  5927. "ArgumentPointerUniform %decl %null %int_0 %int_0 %int_0 %int_4",
  5928. "Ordinal"),
  5929. std::make_pair(
  5930. "ArgumentPointerUniform %decl %int_0 %float_0 %int_0 %int_0 %int_4",
  5931. "DescriptorSet"),
  5932. std::make_pair(
  5933. "ArgumentPointerUniform %decl %int_0 %null %int_0 %int_0 %int_4",
  5934. "DescriptorSet"),
  5935. std::make_pair(
  5936. "ArgumentPointerUniform %decl %int_0 %int_0 %float_0 %int_0 %int_4",
  5937. "Binding"),
  5938. std::make_pair(
  5939. "ArgumentPointerUniform %decl %int_0 %int_0 %null %int_0 %int_4",
  5940. "Binding"),
  5941. std::make_pair(
  5942. "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %float_0 %int_4",
  5943. "Offset"),
  5944. std::make_pair(
  5945. "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %null %int_4",
  5946. "Offset"),
  5947. std::make_pair(
  5948. "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %int_0 %float_0",
  5949. "Size"),
  5950. std::make_pair(
  5951. "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %int_0 %null",
  5952. "Size"),
  5953. std::make_pair(
  5954. "ProgramScopeVariablesStorageBuffer %float_0 %int_0 %data",
  5955. "DescriptorSet"),
  5956. std::make_pair("ProgramScopeVariablesStorageBuffer %null %int_0 %data",
  5957. "DescriptorSet"),
  5958. std::make_pair(
  5959. "ProgramScopeVariablesStorageBuffer %int_0 %float_0 %data",
  5960. "Binding"),
  5961. std::make_pair("ProgramScopeVariablesStorageBuffer %int_0 %null %data",
  5962. "Binding"),
  5963. std::make_pair(
  5964. "ProgramScopeVariablePointerRelocation %float_0 %int_0 %int_4",
  5965. "ObjectOffset"),
  5966. std::make_pair(
  5967. "ProgramScopeVariablePointerRelocation %null %int_0 %int_4",
  5968. "ObjectOffset"),
  5969. std::make_pair(
  5970. "ProgramScopeVariablePointerRelocation %int_0 %float_0 %int_4",
  5971. "PointerOffset"),
  5972. std::make_pair(
  5973. "ProgramScopeVariablePointerRelocation %int_0 %null %int_4",
  5974. "PointerOffset"),
  5975. std::make_pair(
  5976. "ProgramScopeVariablePointerRelocation %int_0 %int_0 %float_0",
  5977. "PointerSize"),
  5978. std::make_pair(
  5979. "ProgramScopeVariablePointerRelocation %int_0 %int_0 %null",
  5980. "PointerSize"),
  5981. std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl "
  5982. "%float_0 %int_0 %int_4",
  5983. "Ordinal"),
  5984. std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %null "
  5985. "%int_0 %int_4",
  5986. "Ordinal"),
  5987. std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
  5988. "%float_0 %int_4",
  5989. "Offset"),
  5990. std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
  5991. "%null %int_4",
  5992. "Offset"),
  5993. std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
  5994. "%int_0 %float_0",
  5995. "Size"),
  5996. std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
  5997. "%int_0 %null",
  5998. "Size"),
  5999. std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
  6000. "%float_0 %int_0 %int_4",
  6001. "Ordinal"),
  6002. std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
  6003. "%null %int_0 %int_4",
  6004. "Ordinal"),
  6005. std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
  6006. "%int_0 %float_0 %int_4",
  6007. "Offset"),
  6008. std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
  6009. "%int_0 %null %int_4",
  6010. "Offset"),
  6011. std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
  6012. "%int_0 %int_0 %float_0",
  6013. "Size"),
  6014. std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
  6015. "%int_0 %int_0 %null",
  6016. "Size"),
  6017. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %float_0 "
  6018. "%int_0 %int_0 %int_0 %int_4",
  6019. "Ordinal"),
  6020. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %null "
  6021. "%int_0 %int_0 %int_0 %int_4",
  6022. "Ordinal"),
  6023. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6024. "%float_0 %int_0 %int_0 %int_4",
  6025. "DescriptorSet"),
  6026. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6027. "%null %int_0 %int_0 %int_4",
  6028. "DescriptorSet"),
  6029. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6030. "%int_0 %float_0 %int_0 %int_4",
  6031. "Binding"),
  6032. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6033. "%int_0 %null %int_0 %int_4",
  6034. "Binding"),
  6035. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6036. "%int_0 %int_0 %float_0 %int_4",
  6037. "Offset"),
  6038. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6039. "%int_0 %int_0 %null %int_4",
  6040. "Offset"),
  6041. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6042. "%int_0 %int_0 %int_0 %float_0",
  6043. "Size"),
  6044. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6045. "%int_0 %int_0 %int_0 %null",
  6046. "Size"),
  6047. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %float_0 "
  6048. "%int_0 %int_0 %int_0 %int_4",
  6049. "Ordinal"),
  6050. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %null "
  6051. "%int_0 %int_0 %int_0 %int_4",
  6052. "Ordinal"),
  6053. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6054. "%float_0 %int_0 %int_0 %int_4",
  6055. "DescriptorSet"),
  6056. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6057. "%null %int_0 %int_0 %int_4",
  6058. "DescriptorSet"),
  6059. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6060. "%int_0 %float_0 %int_0 %int_4",
  6061. "Binding"),
  6062. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6063. "%int_0 %null %int_0 %int_4",
  6064. "Binding"),
  6065. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6066. "%int_0 %int_0 %float_0 %int_4",
  6067. "Offset"),
  6068. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6069. "%int_0 %int_0 %null %int_4",
  6070. "Offset"),
  6071. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6072. "%int_0 %int_0 %int_0 %float_0",
  6073. "Size"),
  6074. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6075. "%int_0 %int_0 %int_0 %null",
  6076. "Size"),
  6077. std::make_pair(
  6078. "ArgumentStorageTexelBuffer %decl %float_0 %int_0 %int_0",
  6079. "Ordinal"),
  6080. std::make_pair("ArgumentStorageTexelBuffer %decl %null %int_0 %int_0",
  6081. "Ordinal"),
  6082. std::make_pair(
  6083. "ArgumentStorageTexelBuffer %decl %int_0 %float_0 %int_0",
  6084. "DescriptorSet"),
  6085. std::make_pair("ArgumentStorageTexelBuffer %decl %int_0 %null %int_0",
  6086. "DescriptorSet"),
  6087. std::make_pair(
  6088. "ArgumentStorageTexelBuffer %decl %int_0 %int_0 %float_0",
  6089. "Binding"),
  6090. std::make_pair("ArgumentStorageTexelBuffer %decl %int_0 %int_0 %null",
  6091. "Binding"),
  6092. std::make_pair(
  6093. "ArgumentUniformTexelBuffer %decl %float_0 %int_0 %int_0",
  6094. "Ordinal"),
  6095. std::make_pair("ArgumentUniformTexelBuffer %decl %null %int_0 %int_0",
  6096. "Ordinal"),
  6097. std::make_pair(
  6098. "ArgumentUniformTexelBuffer %decl %int_0 %float_0 %int_0",
  6099. "DescriptorSet"),
  6100. std::make_pair("ArgumentUniformTexelBuffer %decl %int_0 %null %int_0",
  6101. "DescriptorSet"),
  6102. std::make_pair(
  6103. "ArgumentUniformTexelBuffer %decl %int_0 %int_0 %float_0",
  6104. "Binding"),
  6105. std::make_pair("ArgumentUniformTexelBuffer %decl %int_0 %int_0 %null",
  6106. "Binding"),
  6107. std::make_pair("ConstantDataPointerPushConstant %float_0 %int_4 %data",
  6108. "Offset"),
  6109. std::make_pair("ConstantDataPointerPushConstant %null %int_4 %data",
  6110. "Offset"),
  6111. std::make_pair("ConstantDataPointerPushConstant %int_0 %float_0 %data",
  6112. "Size"),
  6113. std::make_pair("ConstantDataPointerPushConstant %int_0 %null %data",
  6114. "Size"),
  6115. std::make_pair(
  6116. "ProgramScopeVariablePointerPushConstant %float_0 %int_4 %data",
  6117. "Offset"),
  6118. std::make_pair(
  6119. "ProgramScopeVariablePointerPushConstant %null %int_4 %data",
  6120. "Offset"),
  6121. std::make_pair(
  6122. "ProgramScopeVariablePointerPushConstant %int_0 %float_0 %data",
  6123. "Size"),
  6124. std::make_pair(
  6125. "ProgramScopeVariablePointerPushConstant %int_0 %null %data",
  6126. "Size"),
  6127. std::make_pair("PrintfInfo %float_0 %data %int_0 %int_0 %int_0",
  6128. "PrintfID"),
  6129. std::make_pair("PrintfInfo %null %data %int_0 %int_0 %int_0",
  6130. "PrintfID"),
  6131. std::make_pair("PrintfInfo %int_0 %data %float_0 %int_0 %int_0",
  6132. "ArgumentSizes"),
  6133. std::make_pair("PrintfInfo %int_0 %data %null %int_0 %int_0",
  6134. "ArgumentSizes"),
  6135. std::make_pair("PrintfInfo %int_0 %data %int_0 %float_0 %int_0",
  6136. "ArgumentSizes"),
  6137. std::make_pair("PrintfInfo %int_0 %data %int_0 %null %int_0",
  6138. "ArgumentSizes"),
  6139. std::make_pair("PrintfInfo %int_0 %data %int_0 %int_0 %null",
  6140. "ArgumentSizes"),
  6141. std::make_pair("PrintfInfo %int_0 %data %int_0 %int_0 %float_0",
  6142. "ArgumentSizes"),
  6143. std::make_pair("PrintfInfo %int_0 %data %int_0 %float_0",
  6144. "ArgumentSizes"),
  6145. std::make_pair("PrintfInfo %int_0 %data %int_0 %null", "ArgumentSizes"),
  6146. std::make_pair("PrintfBufferStorageBuffer %float_0 %int_0 %int_4",
  6147. "DescriptorSet"),
  6148. std::make_pair("PrintfBufferStorageBuffer %null %int_0 %int_4",
  6149. "DescriptorSet"),
  6150. std::make_pair("PrintfBufferStorageBuffer %int_0 %float_0 %int_4",
  6151. "Binding"),
  6152. std::make_pair("PrintfBufferStorageBuffer %int_0 %null %int_4",
  6153. "Binding"),
  6154. std::make_pair("PrintfBufferStorageBuffer %int_0 %int_0 %float_0",
  6155. "Size"),
  6156. std::make_pair("PrintfBufferStorageBuffer %int_0 %int_0 %null", "Size"),
  6157. std::make_pair("PrintfBufferPointerPushConstant %float_0 %int_0 %int_4",
  6158. "Offset"),
  6159. std::make_pair("PrintfBufferPointerPushConstant %null %int_0 %int_4",
  6160. "Offset"),
  6161. std::make_pair("PrintfBufferPointerPushConstant %int_0 %float_0 %int_4",
  6162. "Size"),
  6163. std::make_pair("PrintfBufferPointerPushConstant %int_0 %null %int_4",
  6164. "Size"),
  6165. std::make_pair("PrintfBufferPointerPushConstant %int_0 %int_0 %float_0",
  6166. "BufferSize"),
  6167. std::make_pair("PrintfBufferPointerPushConstant %int_0 %int_0 %null",
  6168. "BufferSize")}));
  6169. TEST_P(Uint32Constant, Invalid) {
  6170. const std::string ext_inst = std::get<0>(GetParam());
  6171. const std::string name = std::get<1>(GetParam());
  6172. const std::string text = R"(
  6173. OpCapability Shader
  6174. OpExtension "SPV_KHR_non_semantic_info"
  6175. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  6176. OpMemoryModel Logical GLSL450
  6177. OpEntryPoint GLCompute %foo "foo"
  6178. OpExecutionMode %foo LocalSize 1 1 1
  6179. %foo_name = OpString "foo"
  6180. %data = OpString "1234"
  6181. %void = OpTypeVoid
  6182. %int = OpTypeInt 32 0
  6183. %int_0 = OpConstant %int 0
  6184. %int_1 = OpConstant %int 1
  6185. %int_4 = OpConstant %int 4
  6186. %null = OpConstantNull %int
  6187. %float = OpTypeFloat 32
  6188. %float_0 = OpConstant %float 0
  6189. %void_fn = OpTypeFunction %void
  6190. %foo = OpFunction %void None %void_fn
  6191. %entry = OpLabel
  6192. OpReturn
  6193. OpFunctionEnd
  6194. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  6195. %inst = OpExtInst %void %ext )" +
  6196. ext_inst;
  6197. CompileSuccessfully(text);
  6198. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6199. EXPECT_THAT(
  6200. getDiagnosticString(),
  6201. HasSubstr(name + " must be a 32-bit unsigned integer OpConstant"));
  6202. }
  6203. using StringOperand =
  6204. spvtest::ValidateBase<std::pair<std::string, std::string>>;
  6205. INSTANTIATE_TEST_SUITE_P(
  6206. ValidateClspvReflectionStringOperands, StringOperand,
  6207. ::testing::ValuesIn(std::vector<std::pair<std::string, std::string>>{
  6208. std::make_pair("ConstantDataStorageBuffer %int_0 %int_0 %int_0",
  6209. "Data"),
  6210. std::make_pair("ConstantDataUniform %int_0 %int_0 %int_0", "Data"),
  6211. std::make_pair(
  6212. "ProgramScopeVariablesStorageBuffer %int_0 %int_0 %int_0", "Data"),
  6213. std::make_pair("ConstantDataPointerPushConstant %int_0 %int_0 %int_0",
  6214. "Data"),
  6215. std::make_pair(
  6216. "ProgramScopeVariablePointerPushConstant %int_0 %int_0 %int_0",
  6217. "Data"),
  6218. std::make_pair("PrintfInfo %int_0 %int_0", "FormatString")}));
  6219. TEST_P(StringOperand, Invalid) {
  6220. const std::string ext_inst = std::get<0>(GetParam());
  6221. const std::string name = std::get<1>(GetParam());
  6222. const std::string text = R"(
  6223. OpCapability Shader
  6224. OpExtension "SPV_KHR_non_semantic_info"
  6225. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  6226. OpMemoryModel Logical GLSL450
  6227. OpEntryPoint GLCompute %foo "foo"
  6228. OpExecutionMode %foo LocalSize 1 1 1
  6229. %foo_name = OpString "foo"
  6230. %data = OpString "1234"
  6231. %void = OpTypeVoid
  6232. %int = OpTypeInt 32 0
  6233. %int_0 = OpConstant %int 0
  6234. %int_1 = OpConstant %int 1
  6235. %int_4 = OpConstant %int 4
  6236. %null = OpConstantNull %int
  6237. %float = OpTypeFloat 32
  6238. %float_0 = OpConstant %float 0
  6239. %void_fn = OpTypeFunction %void
  6240. %foo = OpFunction %void None %void_fn
  6241. %entry = OpLabel
  6242. OpReturn
  6243. OpFunctionEnd
  6244. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  6245. %inst = OpExtInst %void %ext )" +
  6246. ext_inst;
  6247. CompileSuccessfully(text);
  6248. ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6249. EXPECT_THAT(getDiagnosticString(), HasSubstr(name + " must be an OpString"));
  6250. }
  6251. using VersionCheck = spvtest::ValidateBase<std::pair<std::string, uint32_t>>;
  6252. INSTANTIATE_TEST_SUITE_P(
  6253. ValidateClspvReflectionVersionCheck, VersionCheck,
  6254. ::testing::ValuesIn(std::vector<std::pair<std::string, uint32_t>>{
  6255. std::make_pair("ArgumentStorageBuffer %decl %int_0 %int_0 %int_0", 1),
  6256. std::make_pair("ArgumentUniform %decl %int_0 %int_0 %int_0", 1),
  6257. std::make_pair(
  6258. "ArgumentPodStorageBuffer %decl %int_0 %int_0 %int_0 %int_0 %int_0",
  6259. 1),
  6260. std::make_pair(
  6261. "ArgumentPodUniform %decl %int_0 %int_0 %int_0 %int_0 %int_0", 1),
  6262. std::make_pair("ArgumentPodPushConstant %decl %int_0 %int_0 %int_0", 1),
  6263. std::make_pair("ArgumentSampledImage %decl %int_0 %int_0 %int_0", 1),
  6264. std::make_pair("ArgumentStorageImage %decl %int_0 %int_0 %int_0", 1),
  6265. std::make_pair("ArgumentSampler %decl %int_0 %int_0 %int_0", 1),
  6266. std::make_pair("ArgumentWorkgroup %decl %int_0 %int_0 %int_0", 1),
  6267. std::make_pair("SpecConstantWorkgroupSize %int_0 %int_0 %int_0", 1),
  6268. std::make_pair("SpecConstantGlobalOffset %int_0 %int_0 %int_0", 1),
  6269. std::make_pair("SpecConstantWorkDim %int_0", 1),
  6270. std::make_pair("PushConstantGlobalOffset %int_0 %int_0", 1),
  6271. std::make_pair("PushConstantEnqueuedLocalSize %int_0 %int_0", 1),
  6272. std::make_pair("PushConstantGlobalSize %int_0 %int_0", 1),
  6273. std::make_pair("PushConstantRegionOffset %int_0 %int_0", 1),
  6274. std::make_pair("PushConstantNumWorkgroups %int_0 %int_0", 1),
  6275. std::make_pair("PushConstantRegionGroupOffset %int_0 %int_0", 1),
  6276. std::make_pair("ConstantDataStorageBuffer %int_0 %int_0 %data", 1),
  6277. std::make_pair("ConstantDataUniform %int_0 %int_0 %data", 1),
  6278. std::make_pair("LiteralSampler %int_0 %int_0 %int_0", 1),
  6279. std::make_pair(
  6280. "PropertyRequiredWorkgroupSize %decl %int_0 %int_0 %int_0", 1),
  6281. std::make_pair("SpecConstantSubgroupMaxSize %int_0", 2),
  6282. std::make_pair("ArgumentPointerPushConstant %decl %int_0 %int_0 %int_0",
  6283. 3),
  6284. std::make_pair(
  6285. "ArgumentPointerUniform %decl %int_0 %int_0 %int_0 %int_0 %int_0",
  6286. 3),
  6287. std::make_pair("ProgramScopeVariablesStorageBuffer %int_0 %int_0 %data",
  6288. 3),
  6289. std::make_pair(
  6290. "ProgramScopeVariablePointerRelocation %int_0 %int_0 %int_0", 3),
  6291. std::make_pair("ImageArgumentInfoChannelOrderPushConstant %decl %int_0 "
  6292. "%int_0 %int_0",
  6293. 3),
  6294. std::make_pair("ImageArgumentInfoChannelDataTypePushConstant %decl "
  6295. "%int_0 %int_0 %int_0",
  6296. 3),
  6297. std::make_pair("ImageArgumentInfoChannelOrderUniform %decl %int_0 "
  6298. "%int_0 %int_0 %int_0 %int_0",
  6299. 3),
  6300. std::make_pair("ImageArgumentInfoChannelDataTypeUniform %decl %int_0 "
  6301. "%int_0 %int_0 %int_0 %int_0",
  6302. 3),
  6303. std::make_pair("ArgumentStorageTexelBuffer %decl %int_0 %int_0 %int_0",
  6304. 4),
  6305. std::make_pair("ArgumentUniformTexelBuffer %decl %int_0 %int_0 %int_0",
  6306. 4),
  6307. std::make_pair("ConstantDataPointerPushConstant %int_0 %int_0 %data",
  6308. 5),
  6309. std::make_pair(
  6310. "ProgramScopeVariablePointerPushConstant %int_0 %int_0 %data", 5),
  6311. std::make_pair("PrintfInfo %int_0 %data", 5),
  6312. std::make_pair("PrintfBufferStorageBuffer %int_0 %int_0 %int_0", 5),
  6313. std::make_pair("PrintfBufferPointerPushConstant %int_0 %int_0 %int_0",
  6314. 5)}));
  6315. TEST_P(VersionCheck, V1) {
  6316. const std::string ext_inst = std::get<0>(GetParam());
  6317. const uint32_t version = std::get<1>(GetParam());
  6318. const std::string text = R"(
  6319. OpCapability Shader
  6320. OpExtension "SPV_KHR_non_semantic_info"
  6321. %ext = OpExtInstImport "NonSemantic.ClspvReflection.1"
  6322. OpMemoryModel Logical GLSL450
  6323. OpEntryPoint GLCompute %foo "foo"
  6324. OpExecutionMode %foo LocalSize 1 1 1
  6325. %foo_name = OpString "foo"
  6326. %data = OpString "1234"
  6327. %void = OpTypeVoid
  6328. %int = OpTypeInt 32 0
  6329. %int_0 = OpConstant %int 0
  6330. %int_1 = OpConstant %int 1
  6331. %int_4 = OpConstant %int 4
  6332. %null = OpConstantNull %int
  6333. %float = OpTypeFloat 32
  6334. %float_0 = OpConstant %float 0
  6335. %void_fn = OpTypeFunction %void
  6336. %foo = OpFunction %void None %void_fn
  6337. %entry = OpLabel
  6338. OpReturn
  6339. OpFunctionEnd
  6340. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  6341. %inst = OpExtInst %void %ext )" +
  6342. ext_inst;
  6343. CompileSuccessfully(text);
  6344. if (version <= 1) {
  6345. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  6346. } else {
  6347. EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6348. EXPECT_THAT(getDiagnosticString(),
  6349. HasSubstr("requires version " + std::to_string(version) +
  6350. ", but parsed version is 1"));
  6351. }
  6352. }
  6353. TEST_P(VersionCheck, V2) {
  6354. const std::string ext_inst = std::get<0>(GetParam());
  6355. const uint32_t version = std::get<1>(GetParam());
  6356. const std::string text = R"(
  6357. OpCapability Shader
  6358. OpExtension "SPV_KHR_non_semantic_info"
  6359. %ext = OpExtInstImport "NonSemantic.ClspvReflection.2"
  6360. OpMemoryModel Logical GLSL450
  6361. OpEntryPoint GLCompute %foo "foo"
  6362. OpExecutionMode %foo LocalSize 1 1 1
  6363. %foo_name = OpString "foo"
  6364. %data = OpString "1234"
  6365. %void = OpTypeVoid
  6366. %int = OpTypeInt 32 0
  6367. %int_0 = OpConstant %int 0
  6368. %int_1 = OpConstant %int 1
  6369. %int_4 = OpConstant %int 4
  6370. %null = OpConstantNull %int
  6371. %float = OpTypeFloat 32
  6372. %float_0 = OpConstant %float 0
  6373. %void_fn = OpTypeFunction %void
  6374. %foo = OpFunction %void None %void_fn
  6375. %entry = OpLabel
  6376. OpReturn
  6377. OpFunctionEnd
  6378. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  6379. %inst = OpExtInst %void %ext )" +
  6380. ext_inst;
  6381. CompileSuccessfully(text);
  6382. if (version <= 2) {
  6383. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  6384. } else {
  6385. EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6386. EXPECT_THAT(getDiagnosticString(),
  6387. HasSubstr("requires version " + std::to_string(version) +
  6388. ", but parsed version is 2"));
  6389. }
  6390. }
  6391. TEST_P(VersionCheck, V3) {
  6392. const std::string ext_inst = std::get<0>(GetParam());
  6393. const uint32_t version = std::get<1>(GetParam());
  6394. const std::string text = R"(
  6395. OpCapability Shader
  6396. OpExtension "SPV_KHR_non_semantic_info"
  6397. %ext = OpExtInstImport "NonSemantic.ClspvReflection.3"
  6398. OpMemoryModel Logical GLSL450
  6399. OpEntryPoint GLCompute %foo "foo"
  6400. OpExecutionMode %foo LocalSize 1 1 1
  6401. %foo_name = OpString "foo"
  6402. %data = OpString "1234"
  6403. %void = OpTypeVoid
  6404. %int = OpTypeInt 32 0
  6405. %int_0 = OpConstant %int 0
  6406. %int_1 = OpConstant %int 1
  6407. %int_4 = OpConstant %int 4
  6408. %null = OpConstantNull %int
  6409. %float = OpTypeFloat 32
  6410. %float_0 = OpConstant %float 0
  6411. %void_fn = OpTypeFunction %void
  6412. %foo = OpFunction %void None %void_fn
  6413. %entry = OpLabel
  6414. OpReturn
  6415. OpFunctionEnd
  6416. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  6417. %inst = OpExtInst %void %ext )" +
  6418. ext_inst;
  6419. CompileSuccessfully(text);
  6420. if (version <= 3) {
  6421. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  6422. } else {
  6423. EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6424. EXPECT_THAT(getDiagnosticString(),
  6425. HasSubstr("requires version " + std::to_string(version) +
  6426. ", but parsed version is 3"));
  6427. }
  6428. }
  6429. TEST_P(VersionCheck, V4) {
  6430. const std::string ext_inst = std::get<0>(GetParam());
  6431. const uint32_t version = std::get<1>(GetParam());
  6432. const std::string text = R"(
  6433. OpCapability Shader
  6434. OpExtension "SPV_KHR_non_semantic_info"
  6435. %ext = OpExtInstImport "NonSemantic.ClspvReflection.4"
  6436. OpMemoryModel Logical GLSL450
  6437. OpEntryPoint GLCompute %foo "foo"
  6438. OpExecutionMode %foo LocalSize 1 1 1
  6439. %foo_name = OpString "foo"
  6440. %data = OpString "1234"
  6441. %void = OpTypeVoid
  6442. %int = OpTypeInt 32 0
  6443. %int_0 = OpConstant %int 0
  6444. %int_1 = OpConstant %int 1
  6445. %int_4 = OpConstant %int 4
  6446. %null = OpConstantNull %int
  6447. %float = OpTypeFloat 32
  6448. %float_0 = OpConstant %float 0
  6449. %void_fn = OpTypeFunction %void
  6450. %foo = OpFunction %void None %void_fn
  6451. %entry = OpLabel
  6452. OpReturn
  6453. OpFunctionEnd
  6454. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  6455. %inst = OpExtInst %void %ext )" +
  6456. ext_inst;
  6457. CompileSuccessfully(text);
  6458. if (version <= 4) {
  6459. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  6460. } else {
  6461. EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6462. EXPECT_THAT(getDiagnosticString(),
  6463. HasSubstr("requires version " + std::to_string(version) +
  6464. ", but parsed version is 4"));
  6465. }
  6466. }
  6467. TEST_P(VersionCheck, V5) {
  6468. const std::string ext_inst = std::get<0>(GetParam());
  6469. const uint32_t version = std::get<1>(GetParam());
  6470. const std::string text = R"(
  6471. OpCapability Shader
  6472. OpExtension "SPV_KHR_non_semantic_info"
  6473. %ext = OpExtInstImport "NonSemantic.ClspvReflection.5"
  6474. OpMemoryModel Logical GLSL450
  6475. OpEntryPoint GLCompute %foo "foo"
  6476. OpExecutionMode %foo LocalSize 1 1 1
  6477. %foo_name = OpString "foo"
  6478. %data = OpString "1234"
  6479. %void = OpTypeVoid
  6480. %int = OpTypeInt 32 0
  6481. %int_0 = OpConstant %int 0
  6482. %int_1 = OpConstant %int 1
  6483. %int_4 = OpConstant %int 4
  6484. %null = OpConstantNull %int
  6485. %float = OpTypeFloat 32
  6486. %float_0 = OpConstant %float 0
  6487. %void_fn = OpTypeFunction %void
  6488. %foo = OpFunction %void None %void_fn
  6489. %entry = OpLabel
  6490. OpReturn
  6491. OpFunctionEnd
  6492. %decl = OpExtInst %void %ext Kernel %foo %foo_name
  6493. %inst = OpExtInst %void %ext )" +
  6494. ext_inst;
  6495. CompileSuccessfully(text);
  6496. if (version <= 5) {
  6497. EXPECT_EQ(SPV_SUCCESS, ValidateInstructions());
  6498. } else {
  6499. EXPECT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
  6500. EXPECT_THAT(getDiagnosticString(),
  6501. HasSubstr("requires version " + std::to_string(version) +
  6502. ", but parsed version is 1"));
  6503. }
  6504. }
  6505. } // namespace
  6506. } // namespace val
  6507. } // namespace spvtools