| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999 |
- // Copyright (c) 2017 Google Inc.
- // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights
- // reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // Tests for unique type declaration rules validator.
- #include <sstream>
- #include <string>
- #include "gmock/gmock.h"
- #include "test/unit_spirv.h"
- #include "test/val/val_fixtures.h"
- namespace spvtools {
- namespace val {
- namespace {
- using ::testing::Eq;
- using ::testing::HasSubstr;
- using ::testing::Not;
- using ValidateImage = spvtest::ValidateBase<bool>;
- std::string GenerateShaderCode(
- const std::string& body,
- const std::string& capabilities_and_extensions = "",
- const std::string& execution_model = "Fragment",
- const std::string& execution_mode = "",
- const spv_target_env env = SPV_ENV_UNIVERSAL_1_0,
- const std::string& memory_model = "GLSL450",
- const std::string& declarations = "") {
- std::ostringstream ss;
- ss << R"(
- OpCapability Shader
- OpCapability InputAttachment
- OpCapability ImageGatherExtended
- OpCapability MinLod
- OpCapability Sampled1D
- OpCapability ImageQuery
- OpCapability Int64
- OpCapability Float64
- OpCapability SparseResidency
- OpCapability ImageBuffer
- )";
- if (env == SPV_ENV_UNIVERSAL_1_0) {
- ss << "OpCapability SampledRect\n";
- }
- // In 1.4, the entry point must list all module-scope variables used. Just
- // list all of them.
- std::string interface_vars = (env != SPV_ENV_UNIVERSAL_1_4) ? "" :
- R"(
- %uniform_image_f32_1d_0001
- %uniform_image_f32_1d_0002_rgba32f
- %uniform_image_f32_2d_0001
- %uniform_image_f32_2d_0011 ; multisampled sampled
- %uniform_image_u32_2d_0001
- %uniform_image_u32_2d_0002
- %uniform_image_s32_3d_0001
- %uniform_image_f32_2d_0002
- %uniform_image_s32_2d_0002
- %uniform_image_f32_spd_0002
- %uniform_image_f32_3d_0111
- %uniform_image_f32_cube_0101
- %uniform_image_f32_cube_0102_rgba32f
- %uniform_sampler
- %private_image_u32_buffer_0002_r32ui
- %private_image_u32_spd_0002
- %private_image_f32_buffer_0002_r32ui
- )";
- ss << capabilities_and_extensions;
- ss << "OpMemoryModel Logical " << memory_model << "\n";
- ss << "OpEntryPoint " << execution_model
- << " %main \"main\" " + interface_vars + "\n";
- if (execution_model == "Fragment") {
- ss << "OpExecutionMode %main OriginUpperLeft\n";
- }
- ss << execution_mode;
- if (env == SPV_ENV_VULKAN_1_0) {
- ss << R"(
- OpDecorate %uniform_image_f32_1d_0001 DescriptorSet 0
- OpDecorate %uniform_image_f32_1d_0001 Binding 0
- OpDecorate %uniform_image_f32_1d_0002_rgba32f DescriptorSet 0
- OpDecorate %uniform_image_f32_1d_0002_rgba32f Binding 1
- OpDecorate %uniform_image_f32_2d_0001 DescriptorSet 0
- OpDecorate %uniform_image_f32_2d_0001 Binding 2
- OpDecorate %uniform_image_f32_2d_0011 DescriptorSet 0
- OpDecorate %uniform_image_f32_2d_0011 Binding 3
- OpDecorate %uniform_image_u32_2d_0001 DescriptorSet 1
- OpDecorate %uniform_image_u32_2d_0001 Binding 0
- OpDecorate %uniform_image_u32_2d_0002 DescriptorSet 1
- OpDecorate %uniform_image_u32_2d_0002 Binding 1
- OpDecorate %uniform_image_s32_3d_0001 DescriptorSet 1
- OpDecorate %uniform_image_s32_3d_0001 Binding 2
- OpDecorate %uniform_image_f32_2d_0002 DescriptorSet 1
- OpDecorate %uniform_image_f32_2d_0002 Binding 3
- OpDecorate %uniform_image_s32_2d_0002 DescriptorSet 1
- OpDecorate %uniform_image_s32_2d_0002 Binding 4
- OpDecorate %uniform_image_f32_spd_0002 DescriptorSet 2
- OpDecorate %uniform_image_f32_spd_0002 Binding 0
- OpDecorate %uniform_image_f32_3d_0111 DescriptorSet 2
- OpDecorate %uniform_image_f32_3d_0111 Binding 1
- OpDecorate %uniform_image_f32_cube_0101 DescriptorSet 2
- OpDecorate %uniform_image_f32_cube_0101 Binding 2
- OpDecorate %uniform_image_f32_cube_0102_rgba32f DescriptorSet 2
- OpDecorate %uniform_image_f32_cube_0102_rgba32f Binding 3
- OpDecorate %uniform_sampler DescriptorSet 3
- OpDecorate %uniform_sampler Binding 0
- )";
- }
- ss << R"(
- %void = OpTypeVoid
- %func = OpTypeFunction %void
- %bool = OpTypeBool
- %f32 = OpTypeFloat 32
- %f64 = OpTypeFloat 64
- %u32 = OpTypeInt 32 0
- %s32 = OpTypeInt 32 1
- %u64 = OpTypeInt 64 0
- %s64 = OpTypeInt 64 1
- %s32vec2 = OpTypeVector %s32 2
- %u32vec2 = OpTypeVector %u32 2
- %f32vec2 = OpTypeVector %f32 2
- %u32vec3 = OpTypeVector %u32 3
- %s32vec3 = OpTypeVector %s32 3
- %f32vec3 = OpTypeVector %f32 3
- %u32vec4 = OpTypeVector %u32 4
- %s32vec4 = OpTypeVector %s32 4
- %f32vec4 = OpTypeVector %f32 4
- %f32_0 = OpConstant %f32 0
- %f32_1 = OpConstant %f32 1
- %f32_0_5 = OpConstant %f32 0.5
- %f32_0_25 = OpConstant %f32 0.25
- %f32_0_75 = OpConstant %f32 0.75
- %f64_0 = OpConstant %f64 0
- %f64_1 = OpConstant %f64 1
- %s32_0 = OpConstant %s32 0
- %s32_1 = OpConstant %s32 1
- %s32_2 = OpConstant %s32 2
- %s32_3 = OpConstant %s32 3
- %s32_4 = OpConstant %s32 4
- %s32_m1 = OpConstant %s32 -1
- %u32_0 = OpConstant %u32 0
- %u32_1 = OpConstant %u32 1
- %u32_2 = OpConstant %u32 2
- %u32_3 = OpConstant %u32 3
- %u32_4 = OpConstant %u32 4
- %u64_0 = OpConstant %u64 0
- %u64_1 = OpConstant %u64 1
- %u32vec2arr4 = OpTypeArray %u32vec2 %u32_4
- %u32vec2arr3 = OpTypeArray %u32vec2 %u32_3
- %u32arr4 = OpTypeArray %u32 %u32_4
- %u32vec3arr4 = OpTypeArray %u32vec3 %u32_4
- %struct_u32_f32vec4 = OpTypeStruct %u32 %f32vec4
- %struct_u64_f32vec4 = OpTypeStruct %u64 %f32vec4
- %struct_u32_u32vec4 = OpTypeStruct %u32 %u32vec4
- %struct_u32_f32vec3 = OpTypeStruct %u32 %f32vec3
- %struct_f32_f32vec4 = OpTypeStruct %f32 %f32vec4
- %struct_u32_u32 = OpTypeStruct %u32 %u32
- %struct_f32_f32 = OpTypeStruct %f32 %f32
- %struct_u32 = OpTypeStruct %u32
- %struct_u32_f32_u32 = OpTypeStruct %u32 %f32 %u32
- %struct_u32_f32vec4_u32 = OpTypeStruct %u32 %f32vec4 %u32
- %struct_u32_u32arr4 = OpTypeStruct %u32 %u32arr4
- %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
- %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
- %u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
- %u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3
- %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
- %u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4
- %s32vec2_01 = OpConstantComposite %s32vec2 %s32_0 %s32_1
- %s32vec2_12 = OpConstantComposite %s32vec2 %s32_1 %s32_2
- %s32vec3_012 = OpConstantComposite %s32vec3 %s32_0 %s32_1 %s32_2
- %s32vec3_123 = OpConstantComposite %s32vec3 %s32_1 %s32_2 %s32_3
- %s32vec4_0123 = OpConstantComposite %s32vec4 %s32_0 %s32_1 %s32_2 %s32_3
- %s32vec4_1234 = OpConstantComposite %s32vec4 %s32_1 %s32_2 %s32_3 %s32_4
- %f32vec2_00 = OpConstantComposite %f32vec2 %f32_0 %f32_0
- %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
- %f32vec2_10 = OpConstantComposite %f32vec2 %f32_1 %f32_0
- %f32vec2_11 = OpConstantComposite %f32vec2 %f32_1 %f32_1
- %f32vec2_hh = OpConstantComposite %f32vec2 %f32_0_5 %f32_0_5
- %f32vec3_000 = OpConstantComposite %f32vec3 %f32_0 %f32_0 %f32_0
- %f32vec3_hhh = OpConstantComposite %f32vec3 %f32_0_5 %f32_0_5 %f32_0_5
- %f32vec4_0000 = OpConstantComposite %f32vec4 %f32_0 %f32_0 %f32_0 %f32_0
- %const_offsets = OpConstantComposite %u32vec2arr4 %u32vec2_01 %u32vec2_12 %u32vec2_01 %u32vec2_12
- %const_offsets3x2 = OpConstantComposite %u32vec2arr3 %u32vec2_01 %u32vec2_12 %u32vec2_01
- %const_offsets4xu = OpConstantComposite %u32arr4 %u32_0 %u32_0 %u32_0 %u32_0
- %const_offsets4x3 = OpConstantComposite %u32vec3arr4 %u32vec3_012 %u32vec3_012 %u32vec3_012 %u32vec3_012
- %type_image_f32_1d_0001 = OpTypeImage %f32 1D 0 0 0 1 Unknown
- %ptr_image_f32_1d_0001 = OpTypePointer UniformConstant %type_image_f32_1d_0001
- %uniform_image_f32_1d_0001 = OpVariable %ptr_image_f32_1d_0001 UniformConstant
- %type_sampled_image_f32_1d_0001 = OpTypeSampledImage %type_image_f32_1d_0001
- %type_image_f32_1d_0002_rgba32f = OpTypeImage %f32 1D 0 0 0 2 Rgba32f
- %ptr_image_f32_1d_0002_rgba32f = OpTypePointer UniformConstant %type_image_f32_1d_0002_rgba32f
- %uniform_image_f32_1d_0002_rgba32f = OpVariable %ptr_image_f32_1d_0002_rgba32f UniformConstant
- %type_image_f32_2d_0001 = OpTypeImage %f32 2D 0 0 0 1 Unknown
- %ptr_image_f32_2d_0001 = OpTypePointer UniformConstant %type_image_f32_2d_0001
- %uniform_image_f32_2d_0001 = OpVariable %ptr_image_f32_2d_0001 UniformConstant
- %type_sampled_image_f32_2d_0001 = OpTypeSampledImage %type_image_f32_2d_0001
- %type_image_f32_2d_0011 = OpTypeImage %f32 2D 0 0 1 1 Unknown
- %ptr_image_f32_2d_0011 = OpTypePointer UniformConstant %type_image_f32_2d_0011
- %uniform_image_f32_2d_0011 = OpVariable %ptr_image_f32_2d_0011 UniformConstant
- %type_sampled_image_f32_2d_0011 = OpTypeSampledImage %type_image_f32_2d_0011
- %type_image_u32_2d_0001 = OpTypeImage %u32 2D 0 0 0 1 Unknown
- %ptr_image_u32_2d_0001 = OpTypePointer UniformConstant %type_image_u32_2d_0001
- %uniform_image_u32_2d_0001 = OpVariable %ptr_image_u32_2d_0001 UniformConstant
- %type_sampled_image_u32_2d_0001 = OpTypeSampledImage %type_image_u32_2d_0001
- %type_image_u32_2d_0002 = OpTypeImage %u32 2D 0 0 0 2 Unknown
- %ptr_image_u32_2d_0002 = OpTypePointer UniformConstant %type_image_u32_2d_0002
- %uniform_image_u32_2d_0002 = OpVariable %ptr_image_u32_2d_0002 UniformConstant
- %type_image_s32_3d_0001 = OpTypeImage %s32 3D 0 0 0 1 Unknown
- %ptr_image_s32_3d_0001 = OpTypePointer UniformConstant %type_image_s32_3d_0001
- %uniform_image_s32_3d_0001 = OpVariable %ptr_image_s32_3d_0001 UniformConstant
- %type_sampled_image_s32_3d_0001 = OpTypeSampledImage %type_image_s32_3d_0001
- %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Unknown
- %ptr_image_f32_2d_0002 = OpTypePointer UniformConstant %type_image_f32_2d_0002
- %uniform_image_f32_2d_0002 = OpVariable %ptr_image_f32_2d_0002 UniformConstant
- %type_image_s32_2d_0002 = OpTypeImage %s32 2D 0 0 0 2 Unknown
- %ptr_image_s32_2d_0002 = OpTypePointer UniformConstant %type_image_s32_2d_0002
- %uniform_image_s32_2d_0002 = OpVariable %ptr_image_s32_2d_0002 UniformConstant
- %type_image_f32_spd_0002 = OpTypeImage %f32 SubpassData 0 0 0 2 Unknown
- %ptr_image_f32_spd_0002 = OpTypePointer UniformConstant %type_image_f32_spd_0002
- %uniform_image_f32_spd_0002 = OpVariable %ptr_image_f32_spd_0002 UniformConstant
- %type_image_f32_3d_0111 = OpTypeImage %f32 3D 0 1 1 1 Unknown
- %ptr_image_f32_3d_0111 = OpTypePointer UniformConstant %type_image_f32_3d_0111
- %uniform_image_f32_3d_0111 = OpVariable %ptr_image_f32_3d_0111 UniformConstant
- %type_sampled_image_f32_3d_0111 = OpTypeSampledImage %type_image_f32_3d_0111
- %type_image_f32_cube_0101 = OpTypeImage %f32 Cube 0 1 0 1 Unknown
- %ptr_image_f32_cube_0101 = OpTypePointer UniformConstant %type_image_f32_cube_0101
- %uniform_image_f32_cube_0101 = OpVariable %ptr_image_f32_cube_0101 UniformConstant
- %type_sampled_image_f32_cube_0101 = OpTypeSampledImage %type_image_f32_cube_0101
- %type_image_f32_cube_0102_rgba32f = OpTypeImage %f32 Cube 0 1 0 2 Rgba32f
- %ptr_image_f32_cube_0102_rgba32f = OpTypePointer UniformConstant %type_image_f32_cube_0102_rgba32f
- %uniform_image_f32_cube_0102_rgba32f = OpVariable %ptr_image_f32_cube_0102_rgba32f UniformConstant
- %type_sampler = OpTypeSampler
- %ptr_sampler = OpTypePointer UniformConstant %type_sampler
- %uniform_sampler = OpVariable %ptr_sampler UniformConstant
- %type_image_u32_buffer_0002_r32ui = OpTypeImage %u32 Buffer 0 0 0 2 R32ui
- %ptr_Image_u32 = OpTypePointer Image %u32
- %ptr_image_u32_buffer_0002_r32ui = OpTypePointer Private %type_image_u32_buffer_0002_r32ui
- %private_image_u32_buffer_0002_r32ui = OpVariable %ptr_image_u32_buffer_0002_r32ui Private
- %ptr_Image_u32arr4 = OpTypePointer Image %u32arr4
- %type_image_u32_spd_0002 = OpTypeImage %u32 SubpassData 0 0 0 2 Unknown
- %ptr_image_u32_spd_0002 = OpTypePointer Private %type_image_u32_spd_0002
- %private_image_u32_spd_0002 = OpVariable %ptr_image_u32_spd_0002 Private
- %type_image_f32_buffer_0002_r32ui = OpTypeImage %f32 Buffer 0 0 0 2 R32ui
- %ptr_Image_f32 = OpTypePointer Image %f32
- %ptr_image_f32_buffer_0002_r32ui = OpTypePointer Private %type_image_f32_buffer_0002_r32ui
- %private_image_f32_buffer_0002_r32ui = OpVariable %ptr_image_f32_buffer_0002_r32ui Private
- )";
- if (env == SPV_ENV_UNIVERSAL_1_0) {
- ss << R"(
- %type_image_void_2d_0001 = OpTypeImage %void 2D 0 0 0 1 Unknown
- %ptr_image_void_2d_0001 = OpTypePointer UniformConstant %type_image_void_2d_0001
- %uniform_image_void_2d_0001 = OpVariable %ptr_image_void_2d_0001 UniformConstant
- %type_sampled_image_void_2d_0001 = OpTypeSampledImage %type_image_void_2d_0001
- %type_image_void_2d_0002 = OpTypeImage %void 2D 0 0 0 2 Unknown
- %ptr_image_void_2d_0002 = OpTypePointer UniformConstant %type_image_void_2d_0002
- %uniform_image_void_2d_0002 = OpVariable %ptr_image_void_2d_0002 UniformConstant
- %type_image_f32_rect_0001 = OpTypeImage %f32 Rect 0 0 0 1 Unknown
- %ptr_image_f32_rect_0001 = OpTypePointer UniformConstant %type_image_f32_rect_0001
- %uniform_image_f32_rect_0001 = OpVariable %ptr_image_f32_rect_0001 UniformConstant
- %type_sampled_image_f32_rect_0001 = OpTypeSampledImage %type_image_f32_rect_0001
- )";
- }
- ss << declarations;
- ss << R"(
- %main = OpFunction %void None %func
- %main_entry = OpLabel
- )";
- ss << body;
- ss << R"(
- OpReturn
- OpFunctionEnd)";
- return ss.str();
- }
- std::string GenerateKernelCode(
- const std::string& body,
- const std::string& capabilities_and_extensions = "") {
- std::ostringstream ss;
- ss << R"(
- OpCapability Addresses
- OpCapability Kernel
- OpCapability Linkage
- OpCapability ImageQuery
- OpCapability ImageGatherExtended
- OpCapability InputAttachment
- OpCapability SampledRect
- )";
- ss << capabilities_and_extensions;
- ss << R"(
- OpMemoryModel Physical32 OpenCL
- %void = OpTypeVoid
- %func = OpTypeFunction %void
- %bool = OpTypeBool
- %f32 = OpTypeFloat 32
- %u32 = OpTypeInt 32 0
- %u32vec2 = OpTypeVector %u32 2
- %f32vec2 = OpTypeVector %f32 2
- %u32vec3 = OpTypeVector %u32 3
- %f32vec3 = OpTypeVector %f32 3
- %u32vec4 = OpTypeVector %u32 4
- %f32vec4 = OpTypeVector %f32 4
- %f32_0 = OpConstant %f32 0
- %f32_1 = OpConstant %f32 1
- %f32_0_5 = OpConstant %f32 0.5
- %f32_0_25 = OpConstant %f32 0.25
- %f32_0_75 = OpConstant %f32 0.75
- %u32_0 = OpConstant %u32 0
- %u32_1 = OpConstant %u32 1
- %u32_2 = OpConstant %u32 2
- %u32_3 = OpConstant %u32 3
- %u32_4 = OpConstant %u32 4
- %u32vec2_01 = OpConstantComposite %u32vec2 %u32_0 %u32_1
- %u32vec2_12 = OpConstantComposite %u32vec2 %u32_1 %u32_2
- %u32vec3_012 = OpConstantComposite %u32vec3 %u32_0 %u32_1 %u32_2
- %u32vec3_123 = OpConstantComposite %u32vec3 %u32_1 %u32_2 %u32_3
- %u32vec4_0123 = OpConstantComposite %u32vec4 %u32_0 %u32_1 %u32_2 %u32_3
- %u32vec4_1234 = OpConstantComposite %u32vec4 %u32_1 %u32_2 %u32_3 %u32_4
- %f32vec2_00 = OpConstantComposite %f32vec2 %f32_0 %f32_0
- %f32vec2_01 = OpConstantComposite %f32vec2 %f32_0 %f32_1
- %f32vec2_10 = OpConstantComposite %f32vec2 %f32_1 %f32_0
- %f32vec2_11 = OpConstantComposite %f32vec2 %f32_1 %f32_1
- %f32vec2_hh = OpConstantComposite %f32vec2 %f32_0_5 %f32_0_5
- %f32vec3_000 = OpConstantComposite %f32vec3 %f32_0 %f32_0 %f32_0
- %f32vec3_hhh = OpConstantComposite %f32vec3 %f32_0_5 %f32_0_5 %f32_0_5
- %f32vec4_0000 = OpConstantComposite %f32vec4 %f32_0 %f32_0 %f32_0 %f32_0
- %type_image_f32_2d_0001 = OpTypeImage %f32 2D 0 0 0 1 Unknown
- %ptr_image_f32_2d_0001 = OpTypePointer UniformConstant %type_image_f32_2d_0001
- %uniform_image_f32_2d_0001 = OpVariable %ptr_image_f32_2d_0001 UniformConstant
- %type_sampled_image_f32_2d_0001 = OpTypeSampledImage %type_image_f32_2d_0001
- %type_image_f32_2d_0011 = OpTypeImage %f32 2D 0 0 1 1 Unknown
- %ptr_image_f32_2d_0011 = OpTypePointer UniformConstant %type_image_f32_2d_0011
- %uniform_image_f32_2d_0011 = OpVariable %ptr_image_f32_2d_0011 UniformConstant
- %type_sampled_image_f32_2d_0011 = OpTypeSampledImage %type_image_f32_2d_0011
- %type_image_f32_3d_0011 = OpTypeImage %f32 3D 0 0 1 1 Unknown
- %ptr_image_f32_3d_0011 = OpTypePointer UniformConstant %type_image_f32_3d_0011
- %uniform_image_f32_3d_0011 = OpVariable %ptr_image_f32_3d_0011 UniformConstant
- %type_sampled_image_f32_3d_0011 = OpTypeSampledImage %type_image_f32_3d_0011
- %type_image_f32_rect_0001 = OpTypeImage %f32 Rect 0 0 0 1 Unknown
- %ptr_image_f32_rect_0001 = OpTypePointer UniformConstant %type_image_f32_rect_0001
- %uniform_image_f32_rect_0001 = OpVariable %ptr_image_f32_rect_0001 UniformConstant
- %type_sampled_image_f32_rect_0001 = OpTypeSampledImage %type_image_f32_rect_0001
- %type_sampler = OpTypeSampler
- %ptr_sampler = OpTypePointer UniformConstant %type_sampler
- %uniform_sampler = OpVariable %ptr_sampler UniformConstant
- %main = OpFunction %void None %func
- %main_entry = OpLabel
- )";
- ss << body;
- ss << R"(
- OpReturn
- OpFunctionEnd)";
- return ss.str();
- }
- std::string GetKernelHeader() {
- return R"(
- OpCapability Kernel
- OpCapability Addresses
- OpCapability Linkage
- OpMemoryModel Physical32 OpenCL
- %void = OpTypeVoid
- %func = OpTypeFunction %void
- %f32 = OpTypeFloat 32
- %u32 = OpTypeInt 32 0
- )";
- }
- std::string TrivialMain() {
- return R"(
- %main = OpFunction %void None %func
- %entry = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- }
- std::string GetShaderHeader(const std::string& capabilities_and_extensions = "",
- bool include_entry_point = true) {
- std::ostringstream ss;
- ss << R"(
- OpCapability Shader
- OpCapability Int64
- OpCapability Float64
- )";
- ss << capabilities_and_extensions;
- if (!include_entry_point) {
- ss << "OpCapability Linkage";
- }
- ss << R"(
- OpMemoryModel Logical GLSL450
- )";
- if (include_entry_point) {
- ss << "OpEntryPoint Fragment %main \"main\"\n";
- ss << "OpExecutionMode %main OriginUpperLeft";
- }
- ss << R"(
- %void = OpTypeVoid
- %func = OpTypeFunction %void
- %bool = OpTypeBool
- %f32 = OpTypeFloat 32
- %f64 = OpTypeFloat 64
- %u32 = OpTypeInt 32 0
- %u64 = OpTypeInt 64 0
- %s32 = OpTypeInt 32 1
- %s64 = OpTypeInt 64 1
- )";
- return ss.str();
- }
- TEST_F(ValidateImage, TypeImageWrongSampledType) {
- const std::string code = GetShaderHeader("", false) + R"(
- %img_type = OpTypeImage %bool 2D 0 0 0 1 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sampled Type to be either void or "
- "numerical scalar "
- "type"));
- }
- TEST_F(ValidateImage, TypeImageVoidSampledTypeVulkan) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %void 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04656"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sampled Type to be a 32-bit int, 64-bit int "
- "or 32-bit float scalar type for Vulkan environment"));
- }
- TEST_F(ValidateImage, TypeImageU32SampledTypeVulkan) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %u32 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImageI32SampledTypeVulkan) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %s32 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImageI64SampledTypeNoCapabilityVulkan) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %s64 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Capability Int64ImageEXT is required when using "
- "Sampled Type of 64-bit int"));
- }
- TEST_F(ValidateImage, TypeImageI64SampledTypeVulkan) {
- const std::string code = GetShaderHeader(
- "OpCapability Int64ImageEXT\nOpExtension "
- "\"SPV_EXT_shader_image_int64\"\n") +
- R"(
- %img_type = OpTypeImage %s64 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImageU64SampledTypeNoCapabilityVulkan) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %u64 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Capability Int64ImageEXT is required when using "
- "Sampled Type of 64-bit int"));
- }
- TEST_F(ValidateImage, TypeImageU64SampledTypeVulkan) {
- const std::string code = GetShaderHeader(
- "OpCapability Int64ImageEXT\nOpExtension "
- "\"SPV_EXT_shader_image_int64\"\n") +
- R"(
- %img_type = OpTypeImage %u64 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImageF32SampledTypeVulkan) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %f32 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImageF64SampledTypeVulkan) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %f64 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04656"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sampled Type to be a 32-bit int, 64-bit int "
- "or 32-bit float scalar type for Vulkan environment"));
- }
- TEST_F(ValidateImage, TypeImageF64SampledTypeWithInt64Vulkan) {
- const std::string code = GetShaderHeader(
- "OpCapability Int64ImageEXT\nOpExtension "
- "\"SPV_EXT_shader_image_int64\"\n") +
- R"(
- %img_type = OpTypeImage %f64 2D 0 0 0 1 Unknown
- %main = OpFunction %void None %func
- %main_lab = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(code, env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04656"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sampled Type to be a 32-bit int, 64-bit int "
- "or 32-bit float scalar type for Vulkan environment"));
- }
- TEST_F(ValidateImage, TypeImageWrongDepth) {
- const std::string code = GetShaderHeader("", false) + R"(
- %img_type = OpTypeImage %f32 2D 3 0 0 1 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Invalid Depth 3 (must be 0, 1 or 2)"));
- }
- TEST_F(ValidateImage, TypeImageWrongArrayed) {
- const std::string code = GetShaderHeader("", false) + R"(
- %img_type = OpTypeImage %f32 2D 0 2 0 1 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Invalid Arrayed 2 (must be 0 or 1)"));
- }
- TEST_F(ValidateImage, TypeImageWrongMS) {
- const std::string code = GetShaderHeader("", false) + R"(
- %img_type = OpTypeImage %f32 2D 0 0 2 1 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Invalid MS 2 (must be 0 or 1)"));
- }
- TEST_F(ValidateImage, TypeImageWrongSampled) {
- const std::string code = GetShaderHeader("", false) + R"(
- %img_type = OpTypeImage %f32 2D 0 0 0 3 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Invalid Sampled 3 (must be 0, 1 or 2)"));
- }
- TEST_F(ValidateImage, TypeImageWrongSampledForSubpassData) {
- const std::string code =
- GetShaderHeader("OpCapability InputAttachment\n", false) +
- R"(
- %img_type = OpTypeImage %f32 SubpassData 0 0 0 1 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Dim SubpassData requires Sampled to be 2"));
- }
- TEST_F(ValidateImage, TypeImage_OpenCL_Sampled0_OK) {
- const std::string code = GetKernelHeader() + R"(
- %img_type = OpTypeImage %void 2D 0 0 0 0 Unknown ReadOnly
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_OPENCL_2_1));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImage_OpenCL_Sampled1_Invalid) {
- const std::string code = GetKernelHeader() + R"(
- %img_type = OpTypeImage %void 2D 0 0 0 1 Unknown ReadOnly
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_2_1));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampled must be 0 in the OpenCL environment."));
- }
- TEST_F(ValidateImage, TypeImage_OpenCL_Sampled2_Invalid) {
- const std::string code = GetKernelHeader() + R"(
- %img_type = OpTypeImage %void 2D 0 0 0 2 Unknown ReadOnly
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_2_1));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampled must be 0 in the OpenCL environment."));
- }
- TEST_F(ValidateImage, TypeImage_OpenCL_AccessQualifierMissing) {
- const std::string code = GetKernelHeader() + R"(
- %img_type = OpTypeImage %void 2D 0 0 0 0 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_OPENCL_2_1));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("In the OpenCL environment, the optional Access "
- "Qualifier must be present"));
- }
- TEST_F(ValidateImage, TypeImage_Vulkan_Sampled1_OK) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %f32 2D 0 0 0 1 Unknown
- )" + TrivialMain();
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImage_Vulkan_Sampled2_OK) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
- )" + TrivialMain();
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImage_Vulkan_Sampled0_Invalid) {
- const std::string code = GetShaderHeader() + R"(
- %img_type = OpTypeImage %f32 2D 0 0 0 0 Unknown
- )" + TrivialMain();
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-OpTypeImage-04657"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampled must be 1 or 2 in the Vulkan environment."));
- }
- TEST_F(ValidateImage, TypeImageWrongFormatForSubpassData) {
- const std::string code =
- GetShaderHeader("OpCapability InputAttachment\n", false) +
- R"(
- %img_type = OpTypeImage %f32 SubpassData 0 0 0 2 Rgba32f
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Dim SubpassData requires format Unknown"));
- }
- TEST_F(ValidateImage, TypeImageMultisampleStorageImage_MissingCapability) {
- const std::string code = GetShaderHeader("", false) +
- R"(
- %img_type = OpTypeImage %f32 2D 0 0 1 2 Rgba32f
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions()) << code;
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Capability StorageImageMultisample is required when "
- "using multisampled storage image"));
- }
- TEST_F(ValidateImage, TypeImageMultisampleStorageImage_UsesCapability) {
- const std::string code =
- GetShaderHeader("OpCapability StorageImageMultisample\n", false) +
- R"(
- %img_type = OpTypeImage %f32 2D 0 0 1 2 Rgba32f
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()) << code;
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeImageMultisampleSubpassData_OK) {
- const std::string code =
- GetShaderHeader("OpCapability InputAttachment\n", false) +
- R"(
- %img_type = OpTypeImage %f32 SubpassData 0 0 1 2 Unknown
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions()) << code;
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, TypeSampledImage_NotImage_Error) {
- const std::string code = GetShaderHeader("", false) + R"(
- %simg_type = OpTypeSampledImage %f32
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, TypeSampledImage_Sampled0_Success) {
- // This is ok in the OpenCL and universal environments.
- // Vulkan will reject an OpTypeImage with Sampled=0, checked elsewhere.
- const std::string code = GetShaderHeader() + R"(
- %imty = OpTypeImage %f32 2D 0 0 0 0 Unknown
- %simg_type = OpTypeSampledImage %imty
- )" + TrivialMain();
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- EXPECT_EQ(getDiagnosticString(), "");
- }
- TEST_F(ValidateImage, TypeSampledImage_Sampled2_Error) {
- const std::string code = GetShaderHeader() + R"(
- %storage_image = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
- %simg_type = OpTypeSampledImage %storage_image
- )" + TrivialMain();
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampled image type requires an image type with "
- "\"Sampled\" operand set to 0 or 1"));
- }
- TEST_F(ValidateImage, TypeSampledImage_Sampled1_Success) {
- const std::string code = GetShaderHeader() + R"(
- %im = OpTypeImage %f32 2D 0 0 0 1 Unknown
- %simg_type = OpTypeSampledImage %im
- )" + TrivialMain();
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- EXPECT_EQ(getDiagnosticString(), "");
- }
- TEST_F(ValidateImage, SampledImageSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampledImageVulkanSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- )";
- const spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env), env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateImage, SampledImageWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_image_f32_2d_0001 %img %sampler
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampledImageNotImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg1 = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %simg2 = OpSampledImage %type_sampled_image_f32_2d_0001 %simg1 %sampler
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, SampledImageImageNotForSampling) {
- const std::string code = GetShaderHeader() + R"(
- %im_ty = OpTypeImage %f32 2D 0 0 0 2 Unknown
- %sampler_ty = OpTypeSampler
- %sampled_image_ty = OpTypeSampledImage %im_ty ; will fail here first!
- %ptr_im_ty = OpTypePointer UniformConstant %im_ty
- %var_im = OpVariable %ptr_im_ty UniformConstant
- %ptr_sampler_ty = OpTypePointer UniformConstant %sampler_ty
- %var_sampler = OpVariable %ptr_sampler_ty UniformConstant
- %main = OpFunction %void None %func
- %entry = OpLabel
- %im = OpLoad %im_ty %var_im
- %sampler = OpLoad %sampler_ty %var_sampler
- %sampled_image = OpSampledImage %sampled_image_ty %im %sampler
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(code.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampled image type requires an image type with "
- "\"Sampled\" operand set to 0 or 1"))
- << code;
- }
- TEST_F(ValidateImage, SampledImageNotSampler) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %img
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sampler to be of type OpTypeSampler"));
- }
- TEST_F(ValidateImage, ImageTexelPointerSuccess) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ImageTexelPointerResultTypeNotPointer) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %type_image_u32_buffer_0002_r32ui %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypePointer"));
- }
- TEST_F(ValidateImage, ImageTexelPointerResultTypeNotImageClass) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_image_f32_cube_0101 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypePointer whose "
- "Storage Class operand is Image"));
- }
- TEST_F(ValidateImage, ImageTexelPointerResultTypeNotNumericNorVoid) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32arr4 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypePointer whose Type operand "
- "must be a scalar numerical type or OpTypeVoid"));
- }
- TEST_F(ValidateImage, ImageTexelPointerImageNotResultTypePointer) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %type_image_f32_buffer_0002_r32ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(), HasSubstr("Operand 136[%136] cannot be a "
- "type"));
- }
- TEST_F(ValidateImage, ImageTexelPointerImageNotImage) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %uniform_sampler %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image to be OpTypePointer with Type OpTypeImage"));
- }
- TEST_F(ValidateImage, ImageTexelPointerImageSampledNotResultType) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %uniform_image_f32_cube_0101 %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as the "
- "Type pointed to by Result Type"));
- }
- TEST_F(ValidateImage, ImageTexelPointerImageDimSubpassDataBad) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_spd_0002 %u32_0 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Dim SubpassData cannot be used with OpImageTexelPointer"));
- }
- TEST_F(ValidateImage, ImageTexelPointerImageCoordTypeBad) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_f32 %private_image_f32_buffer_0002_r32ui %f32_0 %f32_0
- %sum = OpAtomicIAdd %f32 %texel_ptr %f32_1 %f32_0 %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be integer scalar or vector"));
- }
- TEST_F(ValidateImage, ImageTexelPointerImageCoordSizeBad) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %uniform_image_u32_2d_0002 %u32vec3_012 %u32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Coordinate to have 2 components, but given 3"));
- }
- TEST_F(ValidateImage, ImageTexelPointerSampleNotIntScalar) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %f32_0
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sample to be integer scalar"));
- }
- TEST_F(ValidateImage, ImageTexelPointerSampleNotZeroForImageWithMSZero) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_1
- %sum = OpAtomicIAdd %u32 %texel_ptr %u32_1 %u32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sample for Image with MS 0 to be a valid "
- "<id> for the value 0"));
- }
- TEST_F(ValidateImage, SampleImplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias %f32_0_25
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh ConstOffset %s32vec2_01
- %res5 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Offset %s32vec2_01
- %res6 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MinLod %f32_0_5
- %res7 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
- %res8 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleImplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float vector type"));
- }
- TEST_F(ValidateImage, SampleImplicitLodWrongNumComponentsResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec3 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 4 components"));
- }
- TEST_F(ValidateImage, SampleImplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageSampleImplicitLod %f32vec4 %img %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleImplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Sample %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampling operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, SampleImplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %u32vec4 %simg %f32vec2_00
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, SampleImplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %u32vec4 %simg %f32vec2_00
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleImplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %img
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleImplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, SampleExplicitLodSuccessShader) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Lod %f32_1
- %res2 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Grad %f32vec2_10 %f32vec2_01
- %res3 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh ConstOffset %s32vec2_01
- %res4 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec3_hhh Offset %s32vec2_01
- %res5 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Grad|Offset|MinLod %f32vec2_10 %f32vec2_01 %s32vec2_01 %f32_0_5
- %res6 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Lod|NonPrivateTexelKHR %f32_1
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleExplicitLodSuccessKernel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %u32vec4_0123 Lod %f32_1
- %res2 = OpImageSampleExplicitLod %f32vec4 %simg %u32vec2_01 Grad %f32vec2_10 %f32vec2_01
- %res3 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh ConstOffset %u32vec2_01
- %res4 = OpImageSampleExplicitLod %f32vec4 %simg %u32vec2_01 Offset %u32vec2_01
- %res5 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_hh Grad|Offset %f32vec2_10 %f32vec2_01 %u32vec2_01
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleExplicitLodSuccessCubeArrayed) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec3_hhh %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleExplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32 %simg %f32vec2_hh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float vector type"));
- }
- TEST_F(ValidateImage, SampleExplicitLodWrongNumComponentsResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec3 %simg %f32vec2_hh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 4 components"));
- }
- TEST_F(ValidateImage, SampleExplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageSampleExplicitLod %f32vec4 %img %f32vec2_hh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleExplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Lod|Sample %f32_0 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampling operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, SampleExplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %u32vec4 %simg %f32vec2_00 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, SampleExplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %u32vec4 %simg %f32vec2_00 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleExplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %img Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleExplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32_0_5 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, SampleExplicitLodBias) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Bias|Lod %f32_1 %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Operand Bias can only be used with ImplicitLod opcodes"));
- }
- TEST_F(ValidateImage, LodAndGrad) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod|Grad %f32_1 %f32vec2_hh %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Operand bits Lod and Grad cannot be set at the same time"));
- }
- TEST_F(ValidateImage, ImplicitLodWithLod) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Lod %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Image Operand Lod can only be used with ExplicitLod opcodes "
- "and OpImageFetch"));
- }
- TEST_F(ValidateImage, LodWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod %f32vec2_hh)";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand Lod to be float scalar when "
- "used with ExplicitLod"));
- }
- TEST_F(ValidateImage, LodWrongDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod %f32_0)";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand Lod requires 'Dim' parameter to be 1D, "
- "2D, 3D or Cube"));
- }
- TEST_F(ValidateImage, MinLodIncompatible) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Lod|MinLod %f32_0 %f32_0)";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Operand MinLod can only be used with ImplicitLod opcodes or "
- "together with Image Operand Grad"));
- }
- TEST_F(ValidateImage, ImplicitLodWithGrad) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Grad %f32vec2_hh %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Operand Grad can only be used with ExplicitLod opcodes"));
- }
- TEST_F(ValidateImage, SampleImplicitLodCubeArrayedSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Bias %f32_0_25
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 MinLod %f32_0_5
- %res5 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Bias|MinLod %f32_0_25 %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleImplicitLodBiasWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias %u32_0
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand Bias to be float scalar"));
- }
- TEST_F(ValidateImage, SampleImplicitLodBiasWrongDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh Bias %f32_0
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand Bias requires 'Dim' parameter to be 1D, "
- "2D, 3D or Cube"));
- }
- TEST_F(ValidateImage, SampleExplicitLodGradDxWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %s32vec3_012 %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected both Image Operand Grad ids to be float "
- "scalars or vectors"));
- }
- TEST_F(ValidateImage, SampleExplicitLodGradDyWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec3_hhh %s32vec3_012
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected both Image Operand Grad ids to be float "
- "scalars or vectors"));
- }
- TEST_F(ValidateImage, SampleExplicitLodGradDxWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec2_00 %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Expected Image Operand Grad dx to have 3 components, but given 2"));
- }
- TEST_F(ValidateImage, SampleExplicitLodGradDyWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec4_0000 Grad %f32vec3_hhh %f32vec2_00
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Expected Image Operand Grad dy to have 3 components, but given 2"));
- }
- TEST_F(ValidateImage, SampleImplicitLodConstOffsetCubeDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 ConstOffset %s32vec3_012
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Operand ConstOffset cannot be used with Cube Image 'Dim'"));
- }
- TEST_F(ValidateImage, SampleImplicitLodConstOffsetWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_00 ConstOffset %f32vec2_00
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Expected Image Operand ConstOffset to be int scalar or vector"));
- }
- TEST_F(ValidateImage, SampleImplicitLodConstOffsetWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_00 ConstOffset %s32vec3_012
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand ConstOffset to have 2 "
- "components, but given 3"));
- }
- TEST_F(ValidateImage, SampleImplicitLodConstOffsetNotConst) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %offset = OpSNegate %s32vec3 %s32vec3_012
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_00 ConstOffset %offset
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image Operand ConstOffset to be a const object"));
- }
- TEST_F(ValidateImage, SampleImplicitLodOffsetCubeDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec3_012
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Image Operand Offset cannot be used with Cube Image 'Dim'"));
- }
- TEST_F(ValidateImage, SampleImplicitLodOffsetWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %f32vec2_00
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image Operand Offset to be int scalar or vector"));
- }
- TEST_F(ValidateImage, SampleImplicitLodOffsetWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec3_012
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Expected Image Operand Offset to have 2 components, but given 3"));
- }
- TEST_F(ValidateImage, SampleImplicitLodVulkanOffsetWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 Offset %s32vec2_01
- )";
- CompileSuccessfully(
- GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-Offset-04663"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand Offset can only be used with "
- "OpImage*Gather operations"));
- }
- TEST_F(ValidateImage, SampleImplicitLodMoreThanOneOffset) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 ConstOffset|Offset %s32vec2_01 %s32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operands Offset, ConstOffset, ConstOffsets "
- "cannot be used together"));
- }
- TEST_F(ValidateImage, SampleImplicitLodVulkanMoreThanOneOffset) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res4 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 ConstOffset|Offset %s32vec2_01 %s32vec2_01
- )";
- CompileSuccessfully(
- GenerateShaderCode(body, "", "Fragment", "", SPV_ENV_VULKAN_1_0).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-Offset-04662"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operands Offset, ConstOffset, ConstOffsets "
- "cannot be used together"));
- }
- TEST_F(ValidateImage, SampleImplicitLodMinLodWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec4_0000 MinLod %s32_0
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand MinLod to be float scalar"));
- }
- TEST_F(ValidateImage, SampleImplicitLodMinLodWrongDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MinLod %f32_0_25
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand MinLod requires 'Dim' parameter to be "
- "1D, 2D, 3D or Cube"));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodSuccess2D) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Lod %f32_1
- %res3 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad %f32vec2_10 %f32vec2_01
- %res4 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh ConstOffset %s32vec2_01
- %res5 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Offset %s32vec2_01
- %res7 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad|Offset %f32vec2_10 %f32vec2_01 %s32vec2_01
- %res8 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Lod|NonPrivateTexelKHR %f32_1
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodSuccessRect) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad %f32vec2_10 %f32vec2_01
- %res2 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec3_hhh Grad|Offset %f32vec2_10 %f32vec2_01 %s32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleProjExplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %f32 %simg %f32vec3_hhh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float vector type"));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodWrongNumComponentsResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %f32vec3 %simg %f32vec3_hhh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 4 components"));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageSampleProjExplicitLod %f32vec4 %img %f32vec3_hhh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec2_hh Lod|Sample %f32_1 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'MS' parameter to be 0"));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %u32vec4 %simg %f32vec3_hhh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %u32vec4 %simg %f32vec3_hhh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleProjExplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %img Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleProjExplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjExplicitLod %f32vec4 %simg %f32vec2_hh Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 3 components, "
- "but given only 2"));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh
- %res2 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh Bias %f32_0_25
- %res4 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh ConstOffset %s32vec2_01
- %res5 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh Offset %s32vec2_01
- %res6 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh MinLod %f32_0_5
- %res7 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
- %res8 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec3_hhh NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %f32 %simg %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float vector type"));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodWrongNumComponentsResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %f32vec3 %simg %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 4 components"));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageSampleProjImplicitLod %f32vec4 %img %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec2_hh Sample %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'MS' parameter to be 0"));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %u32vec4 %simg %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %u32vec4 %simg %f32vec3_hhh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleProjImplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %img
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleProjImplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjImplicitLod %f32vec4 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 3 components, "
- "but given only 2"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1
- %res2 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 Bias %f32_0_25
- %res4 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 ConstOffset %s32vec2_01
- %res5 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 Offset %s32vec2_01
- %res6 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 MinLod %f32_0_5
- %res7 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
- %res8 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_hh %f32_1 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %void %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float scalar type"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
- %res1 = OpImageSampleDrefImplicitLod %u32 %img %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %f32 %simg %f32vec2_hh %f32_1 Sample %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Dref sampling operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %f32 %simg %f32vec2_00 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_00 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %u32 %simg %img %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %f32 %simg %f32_0_5 %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, SampleDrefImplicitLodWrongDrefType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefImplicitLod %u32 %simg %f32vec2_00 %f64_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Dref to be of 32-bit float type"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec4_0000 %f32_1 Lod %f32_1
- %res3 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %f32_1 Grad %f32vec3_hhh %f32vec3_hhh
- %res4 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %f32_1 ConstOffset %s32vec3_012
- %res5 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec4_0000 %f32_1 Offset %s32vec3_012
- %res7 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %f32_1 Grad|Offset %f32vec3_hhh %f32vec3_hhh %s32vec3_012
- %res8 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec4_0000 %f32_1 Lod|NonPrivateTexelKHR %f32_1
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %bool %simg %f32vec3_hhh %s32_1 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float scalar type"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
- %res1 = OpImageSampleDrefExplicitLod %s32 %img %f32vec3_hhh %s32_1 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec2_hh %f32_1 Lod|Sample %f32_1 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Dref sampling operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec3_hhh %s32_1 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %u32 %simg %f32vec2_00 %s32_1 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %s32 %simg %img %s32_1 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec2_hh %s32_1 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 3 components, "
- "but given only 2"));
- }
- TEST_F(ValidateImage, SampleDrefExplicitLodWrongDrefType) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_3d_0001 %uniform_image_s32_3d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_s32_3d_0001 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %s32 %simg %f32vec3_hhh %u32_1 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Dref to be of 32-bit float type"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5
- %res2 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Bias %f32_0_25
- %res4 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 ConstOffset %s32vec2_01
- %res5 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Offset %s32vec2_01
- %res6 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 MinLod %f32_0_5
- %res7 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
- %res8 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefImplicitLod %void %simg %f32vec3_hhh %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float scalar type"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageSampleProjDrefImplicitLod %f32 %img %f32vec3_hhh %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec2_hh %f32_1 Sample %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Dref sampling operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefImplicitLod %u32 %simg %f32vec3_hhh %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefImplicitLod %u32 %simg %f32vec3_hhh %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefImplicitLod %f32 %simg %img %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefImplicitLod %f32 %simg %f32vec2_hh %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 3 components, "
- "but given only 2"));
- }
- TEST_F(ValidateImage, SampleProjDrefImplicitLodWrongDrefType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefImplicitLod %u32 %simg %f32vec3_hhh %f32vec4_0000
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Dref to be of 32-bit float type"));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Lod %f32_1
- %res2 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec3_hhh %f32_0_5 Grad %f32_0_5 %f32_0_5
- %res3 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 ConstOffset %s32_1
- %res4 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Offset %s32_1
- %res5 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Grad|Offset %f32_0_5 %f32_0_5 %s32_1
- %res6 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32vec2_hh %f32_0_5 Lod|NonPrivateTexelKHR %f32_1
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefExplicitLod %bool %simg %f32vec2_hh %f32_0_5 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float scalar type"));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %res1 = OpImageSampleProjDrefExplicitLod %f32 %img %f32vec2_hh %f32_0_5 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleDrefExplicitLod %f32 %simg %f32vec2_hh %f32_1 Lod|Sample %f32_1 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Dref sampling operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefExplicitLod %u32 %simg %f32vec2_hh %f32_0_5 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefExplicitLod %u32 %simg %f32vec3_hhh %f32_0_5 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as Result Type"));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefExplicitLod %f32 %simg %img %f32_0_5 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, SampleProjDrefExplicitLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_1d_0001 %img %sampler
- %res1 = OpImageSampleProjDrefExplicitLod %f32 %simg %f32_0_5 %f32_0_5 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, FetchSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %res1 = OpImageFetch %f32vec4 %img %u32vec2_01
- %res2 = OpImageFetch %f32vec4 %img %u32vec2_01 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, FetchMultisampledSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %res1 = OpImageFetch %f32vec4 %img %u32vec2_01 Sample %u32_1
- %res2 = OpImageFetch %f32vec4 %img %u32vec2_01 Sample|NonPrivateTexelKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, FetchWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageFetch %f32 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float vector type"));
- }
- TEST_F(ValidateImage, FetchWrongNumComponentsResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageFetch %f32vec3 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 4 components"));
- }
- TEST_F(ValidateImage, FetchNotImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageFetch %f32vec4 %sampler %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, FetchSampledImageDirectly) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageFetch %f32vec4 %simg %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpSampledImage instruction must not appear as operand "
- "for OpImageFetch"));
- }
- TEST_F(ValidateImage, FetchNotSampled) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageFetch %u32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled' parameter to be 1"));
- }
- TEST_F(ValidateImage, FetchCube) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %res1 = OpImageFetch %f32vec4 %img %u32vec3_012
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'Dim' cannot be Cube"));
- }
- TEST_F(ValidateImage, FetchWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageFetch %u32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, FetchVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %res1 = OpImageFetch %f32vec4 %img %u32vec2_01
- %res2 = OpImageFetch %u32vec4 %img %u32vec2_01
- %res3 = OpImageFetch %s32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, FetchWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageFetch %f32vec4 %img %f32vec2_00
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be int scalar or vector"));
- }
- TEST_F(ValidateImage, FetchCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageFetch %f32vec4 %img %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, FetchLodNotInt) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageFetch %f32vec4 %img %u32vec2_01 Lod %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand Lod to be int scalar when used "
- "with OpImageFetch"));
- }
- TEST_F(ValidateImage, FetchMultisampledMissingSample) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %res1 = OpImageFetch %f32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions())
- << GenerateShaderCode(body);
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand Sample is required for operation on "
- "multi-sampled image"))
- << getDiagnosticString();
- }
- TEST_F(ValidateImage, GatherSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1
- %res2 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets
- %res3 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, GatherWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %f32 %simg %f32vec4_0000 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float vector type"));
- }
- TEST_F(ValidateImage, GatherWrongNumComponentsResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %f32vec3 %simg %f32vec4_0000 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 4 components"));
- }
- TEST_F(ValidateImage, GatherNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %res1 = OpImageGather %f32vec4 %img %f32vec4_0000 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sampled Image to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, GatherMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 Sample %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Gather operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, GatherWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %u32vec4 %simg %f32vec4_0000 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, GatherVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageGather %u32vec4 %simg %f32vec2_00 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, GatherWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %u32vec4_0123 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, GatherCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32_0_5 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 4 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, GatherWrongComponentType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Component to be 32-bit int scalar"));
- }
- TEST_F(ValidateImage, GatherComponentNot32Bit) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u64_0
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Component to be 32-bit int scalar"));
- }
- TEST_F(ValidateImage, GatherDimCube) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Operand ConstOffsets cannot be used with Cube Image 'Dim'"));
- }
- TEST_F(ValidateImage, GatherConstOffsetsNotArray) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %u32vec4_0123
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Expected Image Operand ConstOffsets to be an array of size 4"));
- }
- TEST_F(ValidateImage, GatherConstOffsetsArrayWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets3x2
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Expected Image Operand ConstOffsets to be an array of size 4"));
- }
- TEST_F(ValidateImage, GatherConstOffsetsArrayNotVector) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets4xu
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand ConstOffsets array componenets "
- "to be int vectors of size 2"));
- }
- TEST_F(ValidateImage, GatherConstOffsetsArrayVectorWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %const_offsets4x3
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand ConstOffsets array componenets "
- "to be int vectors of size 2"));
- }
- TEST_F(ValidateImage, GatherConstOffsetsArrayNotConst) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %offsets = OpUndef %u32vec2arr4
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 ConstOffsets %offsets
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image Operand ConstOffsets to be a const object"));
- }
- TEST_F(ValidateImage, NotGatherWithConstOffsets) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res2 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh ConstOffsets %const_offsets
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Image Operand ConstOffsets can only be used with OpImageGather "
- "and OpImageDrefGather"));
- }
- TEST_F(ValidateImage, DrefGatherSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_0_5
- %res2 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_0_5 ConstOffsets %const_offsets
- %res3 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_0_5 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, DrefGatherMultisampleError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %f32_1 Sample %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Gather operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, DrefGatherVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0001 %uniform_image_void_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_void_2d_0001 %img %sampler
- %res1 = OpImageDrefGather %u32vec4 %simg %f32vec2_00 %f32_0_5
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, DrefGatherWrongDrefType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0101 %uniform_image_f32_cube_0101
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_cube_0101 %img %sampler
- %res1 = OpImageDrefGather %f32vec4 %simg %f32vec4_0000 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Dref to be of 32-bit float type"));
- }
- TEST_F(ValidateImage, ReadSuccess1) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ReadSuccess2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability Image1D\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ReadSuccess3) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- %res1 = OpImageRead %f32vec4 %img %u32vec3_012
- )";
- const std::string extra = "\nOpCapability ImageCubeArray\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ReadSuccess4) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ReadNeedCapabilityStorageImageReadWithoutFormat) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ReadNeedCapabilityStorageImageReadWithoutFormatVulkan) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
- env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Capability StorageImageReadWithoutFormat is required "
- "to read storage image"));
- }
- TEST_F(ValidateImage, ReadNeedCapabilityImage1D) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Capability Image1D is required to access storage image"));
- }
- TEST_F(ValidateImage, ReadNeedCapabilityImageCubeArray) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- %res1 = OpImageRead %f32vec4 %img %u32vec3_012
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Capability ImageCubeArray is required to access storage image"));
- }
- // TODO([email protected]) Disabled until the spec is clarified.
- TEST_F(ValidateImage, DISABLED_ReadWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %f32 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int or float vector type"));
- }
- TEST_F(ValidateImage, ReadScalarResultType_Universal) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, ReadUnusualNumComponentsResultType_Universal) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec3 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_0));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, ReadWrongNumComponentsResultType_Vulkan) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec3 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_VULKAN_1_0)
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 4 components"));
- }
- TEST_F(ValidateImage, ReadNotImage) {
- const std::string body = R"(
- %sampler = OpLoad %type_sampler %uniform_sampler
- %res1 = OpImageRead %f32vec4 %sampler %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, ReadImageSampled) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled' parameter to be 0 or 2"));
- }
- TEST_F(ValidateImage, ReadWrongSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type components"));
- }
- TEST_F(ValidateImage, ReadVoidSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_void_2d_0002 %uniform_image_void_2d_0002
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01
- %res2 = OpImageRead %u32vec4 %img %u32vec2_01
- %res3 = OpImageRead %s32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ReadWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %f32vec2_00
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be int scalar or vector"));
- }
- TEST_F(ValidateImage, ReadCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32_1
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, WriteSuccess1) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, WriteSuccess2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
- OpImageWrite %img %u32_1 %f32vec4_0000
- )";
- const std::string extra = "\nOpCapability Image1D\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, WriteSuccess3) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- OpImageWrite %img %u32vec3_012 %f32vec4_0000
- )";
- const std::string extra = "\nOpCapability ImageCubeArray\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, WriteSuccess4) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0012 %uniform_image_f32_2d_0012
- OpImageWrite %img %u32vec2_01 %f32vec4_0000 Sample %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageWriteWithoutFormat
- OpCapability StorageImageMultisample
- )";
- const std::string declarations = R"(
- %type_image_f32_2d_0012 = OpTypeImage %f32 2D 0 0 1 2 Unknown
- %ptr_image_f32_2d_0012 = OpTypePointer UniformConstant %type_image_f32_2d_0012
- %uniform_image_f32_2d_0012 = OpVariable %ptr_image_f32_2d_0012 UniformConstant
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_0, "GLSL450",
- declarations)
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, WriteSubpassData) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
- OpImageWrite %img %u32vec2_01 %f32vec4_0000
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image 'Dim' cannot be SubpassData"));
- }
- TEST_F(ValidateImage, WriteNeedCapabilityStorageImageWriteWithoutFormat) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, WriteNeedCapabilityStorageImageWriteWithoutFormatVulkan) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
- env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Capability StorageImageWriteWithoutFormat is required to write to "
- "storage image"));
- }
- TEST_F(ValidateImage, WriteNeedCapabilityImage1D) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
- OpImageWrite %img %u32vec2_01 %f32vec4_0000
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Capability Image1D is required to access storage "
- "image"));
- }
- TEST_F(ValidateImage, WriteNeedCapabilityImageCubeArray) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- OpImageWrite %img %u32vec3_012 %f32vec4_0000
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Capability ImageCubeArray is required to access storage image"));
- }
- TEST_F(ValidateImage, WriteNotImage) {
- const std::string body = R"(
- %sampler = OpLoad %type_sampler %uniform_sampler
- OpImageWrite %sampler %u32vec2_01 %f32vec4_0000
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, WriteImageSampled) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- OpImageWrite %img %u32vec2_01 %f32vec4_0000
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled' parameter to be 0 or 2"));
- }
- TEST_F(ValidateImage, WriteWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %f32vec2_00 %u32vec4_0123
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be int scalar or vector"));
- }
- TEST_F(ValidateImage, WriteCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32_1 %u32vec4_0123
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, WriteTexelWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %img
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Texel to be int or float vector or scalar"));
- }
- TEST_F(ValidateImage, DISABLED_WriteTexelNotVector4) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec3_012
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Texel to have 4 components"));
- }
- TEST_F(ValidateImage, WriteTexelWrongComponentType) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %f32vec4_0000
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "Expected Image 'Sampled Type' to be the same as Texel components"));
- }
- TEST_F(ValidateImage, WriteSampleNotInteger) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0012 %uniform_image_f32_2d_0012
- OpImageWrite %img %u32vec2_01 %f32vec4_0000 Sample %f32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageWriteWithoutFormat
- OpCapability StorageImageMultisample
- )";
- const std::string declarations = R"(
- %type_image_f32_2d_0012 = OpTypeImage %f32 2D 0 0 1 2 Unknown
- %ptr_image_f32_2d_0012 = OpTypePointer UniformConstant %type_image_f32_2d_0012
- %uniform_image_f32_2d_0012 = OpVariable %ptr_image_f32_2d_0012 UniformConstant
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_0, "GLSL450",
- declarations)
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image Operand Sample to be int scalar"));
- }
- TEST_F(ValidateImage, WriteSampleNotMultisampled) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- OpImageWrite %img %u32vec2_01 %f32vec4_0000 Sample %u32_1
- )";
- const std::string extra = "\nOpCapability StorageImageWriteWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Image Operand Sample requires non-zero 'MS' parameter"));
- }
- TEST_F(ValidateImage, SampleWrongOpcode) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0011 %img %sampler
- %res1 = OpImageSampleExplicitLod %f32vec4 %simg %f32vec2_00 Sample %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampling operation is invalid for multisample image"));
- }
- TEST_F(ValidateImage, SampleImageToImageSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %img2 = OpImage %type_image_f32_2d_0001 %simg
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SampleImageToImageWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %img2 = OpImage %type_sampled_image_f32_2d_0001 %simg
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypeImage"));
- }
- TEST_F(ValidateImage, SampleImageToImageNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %img2 = OpImage %type_image_f32_2d_0001 %img
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Sample Image to be of type OpTypeSampleImage"));
- }
- TEST_F(ValidateImage, SampleImageToImageNotTheSameImageType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %img2 = OpImage %type_image_f32_2d_0002 %simg
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sample Image image type to be equal to "
- "Result Type"));
- }
- TEST_F(ValidateImage, QueryFormatSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQueryFormat %u32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QueryFormatWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQueryFormat %bool %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int scalar type"));
- }
- TEST_F(ValidateImage, QueryFormatNotImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryFormat %u32 %sampler
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected operand to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, QueryOrderSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQueryOrder %u32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QueryOrderWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQueryOrder %bool %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int scalar type"));
- }
- TEST_F(ValidateImage, QueryOrderNotImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryOrder %u32 %sampler
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected operand to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, QuerySizeLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QuerySizeLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQuerySizeLod %f32vec2 %img %u32_1
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Result Type to be int scalar or vector type"));
- }
- TEST_F(ValidateImage, QuerySizeLodResultTypeWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQuerySizeLod %u32 %img %u32_1
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Result Type has 1 components, but 2 expected"));
- }
- TEST_F(ValidateImage, QuerySizeLodNotImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQuerySizeLod %u32vec2 %sampler %u32_1
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, QuerySizeLodSampledImageDirectly) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQuerySizeLod %u32vec2 %simg %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpSampledImage instruction must not appear as operand "
- "for OpImageQuerySizeLod"));
- }
- TEST_F(ValidateImage, QuerySizeLodMultisampledError) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'MS' must be 0"));
- }
- TEST_F(ValidateImage, QuerySizeLodNonSampledUniversalSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- EXPECT_EQ(getDiagnosticString(), "");
- }
- TEST_F(ValidateImage, QuerySizeLodVulkanNonSampledError) {
- // Create a whole shader module. Avoid Vulkan incompatibility with
- // SampledRrect images inserted by helper function GenerateShaderCode.
- const std::string body = R"(
- OpCapability Shader
- OpCapability ImageQuery
- OpMemoryModel Logical Simple
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %f32 = OpTypeFloat 32
- %u32 = OpTypeInt 32 0
- %u32_0 = OpConstant %u32 0
- %u32vec2 = OpTypeVector %u32 2
- %void = OpTypeVoid
- %voidfn = OpTypeFunction %void
- ; Test with a storage image.
- %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
- %ptr_image_f32_2d_0002 = OpTypePointer UniformConstant %type_image_f32_2d_0002
- %uniform_image_f32_2d_0002 = OpVariable %ptr_image_f32_2d_0002 UniformConstant
- %main = OpFunction %void None %voidfn
- %entry = OpLabel
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_0
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(body.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "OpImageQuerySizeLod must only consume an \"Image\" operand whose "
- "type has its \"Sampled\" operand set to 1"));
- }
- TEST_F(ValidateImage, QuerySizeLodWrongImageDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageQuerySizeLod %u32vec2 %img %u32_1
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image 'Dim' must be 1D, 2D, 3D or Cube"));
- }
- TEST_F(ValidateImage, QuerySizeLodWrongLodType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQuerySizeLod %u32vec2 %img %f32_0
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Level of Detail to be int scalar"));
- }
- TEST_F(ValidateImage, QuerySizeSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %res1 = OpImageQuerySize %u32vec2 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QuerySizeWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %res1 = OpImageQuerySize %f32vec2 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Result Type to be int scalar or vector type"));
- }
- TEST_F(ValidateImage, QuerySizeNotImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQuerySize %u32vec2 %sampler
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, QuerySizeSampledImageDirectly) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQuerySize %u32vec2 %simg
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpSampledImage instruction must not appear as operand "
- "for OpImageQuerySize"));
- }
- TEST_F(ValidateImage, QuerySizeDimSubpassDataBad) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
- %res1 = OpImageQuerySize %u32vec2 %img
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Image 'Dim' must be 1D, Buffer, 2D, Cube, 3D or Rect"));
- }
- TEST_F(ValidateImage, QuerySizeWrongSampling) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQuerySize %u32vec2 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Image must have either 'MS'=1 or 'Sampled'=0 or 'Sampled'=2"));
- }
- TEST_F(ValidateImage, QuerySizeWrongNumberOfComponents) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_3d_0111 %uniform_image_f32_3d_0111
- %res1 = OpImageQuerySize %u32vec2 %img
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Result Type has 2 components, but 4 expected"));
- }
- TEST_F(ValidateImage, QueryLodSuccessKernel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
- %res2 = OpImageQueryLod %f32vec2 %simg %u32vec2_01
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QueryLodSuccessShader) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QueryLodWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %u32vec2 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be float vector type"));
- }
- TEST_F(ValidateImage, QueryLodResultTypeWrongSize) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec3 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to have 2 components"));
- }
- TEST_F(ValidateImage, QueryLodNotSampledImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQueryLod %f32vec2 %img %f32vec2_hh
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Image operand to be of type OpTypeSampledImage"));
- }
- TEST_F(ValidateImage, QueryLodWrongDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_rect_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image 'Dim' must be 1D, 2D, 3D or Cube"));
- }
- TEST_F(ValidateImage, QueryLodWrongCoordinateType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to be float scalar or vector"));
- }
- TEST_F(ValidateImage, QueryLodCoordinateSizeTooSmall) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32_0
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Coordinate to have at least 2 components, "
- "but given only 1"));
- }
- TEST_F(ValidateImage, QueryLevelsSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQueryLevels %u32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QueryLevelsWrongResultType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQueryLevels %f32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be int scalar type"));
- }
- TEST_F(ValidateImage, QueryLevelsNotImage) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLevels %u32 %sampler
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image to be of type OpTypeImage"));
- }
- TEST_F(ValidateImage, QueryLevelsSampledImageDirectly) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLevels %u32 %simg
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpSampledImage instruction must not appear as operand "
- "for OpImageQueryLevels"));
- }
- TEST_F(ValidateImage, QueryLevelsWrongDim) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageQueryLevels %u32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image 'Dim' must be 1D, 2D, 3D or Cube"));
- }
- TEST_F(ValidateImage, QuerySizeLevelsNonSampledUniversalSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageQueryLevels %u32 %img
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- EXPECT_EQ(getDiagnosticString(), "");
- }
- TEST_F(ValidateImage, QuerySizeLevelsVulkanNonSampledError) {
- // Create a whole shader module. Avoid Vulkan incompatibility with
- // SampledRrect images inserted by helper function GenerateShaderCode.
- const std::string body = R"(
- OpCapability Shader
- OpCapability ImageQuery
- OpMemoryModel Logical Simple
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- %f32 = OpTypeFloat 32
- %u32 = OpTypeInt 32 0
- %void = OpTypeVoid
- %voidfn = OpTypeFunction %void
- ; Test with a storage image.
- %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
- %ptr_image_f32_2d_0002 = OpTypePointer UniformConstant %type_image_f32_2d_0002
- %uniform_image_f32_2d_0002 = OpVariable %ptr_image_f32_2d_0002 UniformConstant
- %main = OpFunction %void None %voidfn
- %entry = OpLabel
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageQueryLevels %u32 %img
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(body.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("OpImageQueryLevels must only consume an \"Image\" operand "
- "whose type has its \"Sampled\" operand set to 1"));
- }
- TEST_F(ValidateImage, QuerySamplesSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0011 %uniform_image_f32_2d_0011
- %res1 = OpImageQuerySamples %u32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QuerySamplesNot2D) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_3d_0011 %uniform_image_f32_3d_0011
- %res1 = OpImageQuerySamples %u32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'Dim' must be 2D"));
- }
- TEST_F(ValidateImage, QuerySamplesNotMultisampled) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %res1 = OpImageQuerySamples %u32 %img
- )";
- CompileSuccessfully(GenerateKernelCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(), HasSubstr("Image 'MS' must be 1"));
- }
- TEST_F(ValidateImage, QueryLodWrongExecutionModel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body, "", "Vertex").c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "OpImageQueryLod requires Fragment or GLCompute execution model"));
- }
- TEST_F(ValidateImage, QueryLodWrongExecutionModelWithFunc) {
- const std::string body = R"(
- %call_ret = OpFunctionCall %void %my_func
- OpReturn
- OpFunctionEnd
- %my_func = OpFunction %void None %func
- %my_func_entry = OpLabel
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body, "", "Vertex").c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr(
- "OpImageQueryLod requires Fragment or GLCompute execution model"));
- }
- TEST_F(ValidateImage, QueryLodComputeShaderDerivatives) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
- )";
- const std::string extra = R"(
- OpCapability ComputeDerivativeGroupLinearNV
- OpExtension "SPV_NV_compute_shader_derivatives"
- )";
- const std::string mode = R"(
- OpExecutionMode %main LocalSize 8 8 1
- OpExecutionMode %main DerivativeGroupLinearNV
- )";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QueryLodUniversalSuccess) {
- // Create a whole shader module. Avoid Vulkan incompatibility with
- // SampledRrect images inserted by helper function GenerateShaderCode.
- const std::string body = R"(
- OpCapability Shader
- OpCapability ImageQuery
- OpMemoryModel Logical Simple
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpDecorate %uniform_image_f32_2d_0000 DescriptorSet 0
- OpDecorate %uniform_image_f32_2d_0000 Binding 0
- OpDecorate %sampler DescriptorSet 0
- OpDecorate %sampler Binding 1
- %f32 = OpTypeFloat 32
- %f32vec2 = OpTypeVector %f32 2
- %f32vec2_null = OpConstantNull %f32vec2
- %u32 = OpTypeInt 32 0
- %u32vec2 = OpTypeVector %u32 2
- %void = OpTypeVoid
- %voidfn = OpTypeFunction %void
- ; Test with an image with sampled = 0
- %type_image_f32_2d_0000 = OpTypeImage %f32 2D 0 0 0 0 Rgba32f
- %ptr_image_f32_2d_0000 = OpTypePointer UniformConstant %type_image_f32_2d_0000
- %uniform_image_f32_2d_0000 = OpVariable %ptr_image_f32_2d_0000 UniformConstant
- %sampled_image_ty = OpTypeSampledImage %type_image_f32_2d_0000
- %sampler_ty = OpTypeSampler
- %ptr_sampler_ty = OpTypePointer UniformConstant %sampler_ty
- %sampler = OpVariable %ptr_sampler_ty UniformConstant
- %main = OpFunction %void None %voidfn
- %entry = OpLabel
- %img = OpLoad %type_image_f32_2d_0000 %uniform_image_f32_2d_0000
- %s = OpLoad %sampler_ty %sampler
- %simg = OpSampledImage %sampled_image_ty %img %s
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_null
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(body.c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, QueryLodVulkanNonSampledError) {
- // Create a whole shader module. Avoid Vulkan incompatibility with
- // SampledRrect images inserted by helper function GenerateShaderCode.
- const std::string body = R"(
- OpCapability Shader
- OpCapability ImageQuery
- OpMemoryModel Logical Simple
- OpEntryPoint Fragment %main "main"
- OpExecutionMode %main OriginUpperLeft
- OpDecorate %sampled_image DescriptorSet 0
- OpDecorate %sampled_image Binding 0
- %f32 = OpTypeFloat 32
- %f32vec2 = OpTypeVector %f32 2
- %f32vec2_null = OpConstantNull %f32vec2
- %u32 = OpTypeInt 32 0
- %u32vec2 = OpTypeVector %u32 2
- %void = OpTypeVoid
- %voidfn = OpTypeFunction %void
- ; Test with an image with Sampled = 2
- ; In Vulkan it Sampled must be 1 or 2, checked in another part of the
- ; validation flow.
- %type_image_f32_2d_0002 = OpTypeImage %f32 2D 0 0 0 2 Rgba32f
- ; Expect to fail here.
- %sampled_image_ty = OpTypeSampledImage %type_image_f32_2d_0002
- %ptr_sampled_image_ty = OpTypePointer UniformConstant %sampled_image_ty
- %sampled_image = OpVariable %ptr_sampled_image_ty UniformConstant
- %main = OpFunction %void None %voidfn
- %entry = OpLabel
- %simg = OpLoad %sampled_image_ty %sampled_image
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_null
- OpReturn
- OpFunctionEnd
- )";
- CompileSuccessfully(body.c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(SPV_ENV_VULKAN_1_0));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Sampled image type requires an image type with "
- "\"Sampled\" operand set to 0 or 1"));
- }
- TEST_F(ValidateImage, QueryLodComputeShaderDerivativesMissingMode) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageQueryLod %f32vec2 %simg %f32vec2_hh
- )";
- const std::string extra = R"(
- OpCapability ComputeDerivativeGroupLinearNV
- OpExtension "SPV_NV_compute_shader_derivatives"
- )";
- const std::string mode = R"(
- OpExecutionMode %main LocalSize 8 8 1
- )";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpImageQueryLod requires DerivativeGroupQuadsNV or "
- "DerivativeGroupLinearNV execution mode for GLCompute "
- "execution model"));
- }
- TEST_F(ValidateImage, ImplicitLodWrongExecutionModel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body, "", "Vertex").c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("ImplicitLod instructions require Fragment or "
- "GLCompute execution model"));
- }
- TEST_F(ValidateImage, ImplicitLodComputeShaderDerivatives) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
- )";
- const std::string extra = R"(
- OpCapability ComputeDerivativeGroupLinearNV
- OpExtension "SPV_NV_compute_shader_derivatives"
- )";
- const std::string mode = R"(
- OpExecutionMode %main LocalSize 8 8 1
- OpExecutionMode %main DerivativeGroupLinearNV
- )";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ImplicitLodComputeShaderDerivativesMissingMode) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh
- )";
- const std::string extra = R"(
- OpCapability ComputeDerivativeGroupLinearNV
- OpExtension "SPV_NV_compute_shader_derivatives"
- )";
- const std::string mode = R"(
- OpExecutionMode %main LocalSize 8 8 1
- )";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "GLCompute", mode).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("ImplicitLod instructions require DerivativeGroupQuadsNV or "
- "DerivativeGroupLinearNV execution mode for GLCompute "
- "execution model"));
- }
- TEST_F(ValidateImage, ReadSubpassDataWrongExecutionModel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Vertex").c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Dim SubpassData requires Fragment execution model"));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh
- %res2 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh Bias %f32_0_25
- %res4 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh ConstOffset %s32vec2_01
- %res5 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh Offset %s32vec2_01
- %res6 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh MinLod %f32_0_5
- %res7 = OpImageSparseSampleImplicitLod %struct_u64_f32vec4 %simg %f32vec2_hh Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
- %res8 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4 %simg %f32vec2_hh NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeNotStruct) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %f32 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypeStruct"));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeNotTwoMembers1) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %struct_u32 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an int "
- "scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeNotTwoMembers2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %struct_u32_f32vec4_u32 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeFirstMemberNotInt) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %struct_f32_f32vec4 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodResultTypeTexelNotVector) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %struct_u32_u32 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type's second member to be int or "
- "float vector type"));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodWrongNumComponentsTexel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %struct_u32_f32vec3 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type's second member to have 4 "
- "components"));
- }
- TEST_F(ValidateImage, SparseSampleImplicitLodWrongComponentTypeTexel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleImplicitLod %struct_u32_u32vec4 %simg %f32vec2_hh
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type's second member components"));
- }
- TEST_F(ValidateImage, SparseSampleDrefImplicitLodSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0001 %uniform_image_u32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_u32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1
- %res2 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 Bias %f32_0_25
- %res4 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 ConstOffset %s32vec2_01
- %res5 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 Offset %s32vec2_01
- %res6 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 MinLod %f32_0_5
- %res7 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 Bias|Offset|MinLod %f32_0_25 %s32vec2_01 %f32_0_5
- %res8 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeNotStruct) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleDrefImplicitLod %f32 %simg %f32vec2_hh %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypeStruct"));
- }
- TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeNotTwoMembers1) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32 %simg %f32vec2_hh %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an int scalar "
- "and a texel"));
- }
- TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeNotTwoMembers2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32_f32_u32 %simg %f32vec2_hh %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an int scalar "
- "and a texel"));
- }
- TEST_F(ValidateImage, SparseSampleDrefImplicitLodResultTypeFirstMemberNotInt) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleDrefImplicitLod %struct_f32_f32 %simg %f32vec2_hh %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an int scalar "
- "and a texel"));
- }
- TEST_F(ValidateImage, SparseSampleDrefImplicitLodDifferentSampledType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseSampleDrefImplicitLod %struct_u32_u32 %simg %f32vec2_hh %f32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type's second member"));
- }
- TEST_F(ValidateImage, SparseFetchSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0001 %uniform_image_f32_1d_0001
- %res1 = OpImageSparseFetch %struct_u32_f32vec4 %img %u32vec2_01
- %res2 = OpImageSparseFetch %struct_u32_f32vec4 %img %u32vec2_01 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SparseFetchResultTypeNotStruct) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageSparseFetch %f32 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypeStruct"));
- }
- TEST_F(ValidateImage, SparseFetchResultTypeNotTwoMembers1) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageSparseFetch %struct_u32 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseFetchResultTypeNotTwoMembers2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageSparseFetch %struct_u32_f32vec4_u32 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseFetchResultTypeFirstMemberNotInt) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageSparseFetch %struct_f32_f32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseFetchResultTypeTexelNotVector) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageSparseFetch %struct_u32_u32 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type's second member to be int or "
- "float vector type"));
- }
- TEST_F(ValidateImage, SparseFetchWrongNumComponentsTexel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageSparseFetch %struct_u32_f32vec3 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type's second member to have 4 "
- "components"));
- }
- TEST_F(ValidateImage, SparseFetchWrongComponentTypeTexel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_rect_0001 %uniform_image_f32_rect_0001
- %res1 = OpImageSparseFetch %struct_u32_u32vec4 %img %u32vec2_01
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type's second member components"));
- }
- TEST_F(ValidateImage, SparseReadSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SparseReadResultTypeNotStruct) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %f32 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypeStruct"));
- }
- TEST_F(ValidateImage, SparseReadResultTypeNotTwoMembers1) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseReadResultTypeNotTwoMembers2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32_f32vec4_u32 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseReadResultTypeFirstMemberNotInt) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_f32_f32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseReadResultTypeTexelWrongType) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32_u32arr4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type's second member to be int or "
- "float scalar or vector type"));
- }
- TEST_F(ValidateImage, SparseReadWrongComponentTypeTexel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32_u32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type's second member components"));
- }
- TEST_F(ValidateImage, SparseReadSubpassDataNotAllowed) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_spd_0002 %uniform_image_f32_spd_0002
- %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment").c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Image Dim SubpassData cannot be used with ImageSparseRead"));
- }
- TEST_F(ValidateImage, SparseGatherSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1
- %res2 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1 NonPrivateTexelKHR
- )";
- const std::string extra = R"(
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, SparseGatherResultTypeNotStruct) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %f32 %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypeStruct"));
- }
- TEST_F(ValidateImage, SparseGatherResultTypeNotTwoMembers1) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32 %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an int "
- "scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseGatherResultTypeNotTwoMembers2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32_f32vec4_u32 %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an int "
- "scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseGatherResultTypeFirstMemberNotInt) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_f32_f32vec4 %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be a struct containing an "
- "int scalar and a texel"));
- }
- TEST_F(ValidateImage, SparseGatherResultTypeTexelNotVector) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32_u32 %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type's second member to be int or "
- "float vector type"));
- }
- TEST_F(ValidateImage, SparseGatherWrongNumComponentsTexel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32_f32vec3 %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type's second member to have 4 "
- "components"));
- }
- TEST_F(ValidateImage, SparseGatherWrongComponentTypeTexel) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32_u32vec4 %simg %f32vec2_hh %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Image 'Sampled Type' to be the same as "
- "Result Type's second member components"));
- }
- TEST_F(ValidateImage, SparseTexelsResidentSuccess) {
- const std::string body = R"(
- %res1 = OpImageSparseTexelsResident %bool %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SparseTexelsResidentResultTypeNotBool) {
- const std::string body = R"(
- %res1 = OpImageSparseTexelsResident %u32 %u32_1
- )";
- CompileSuccessfully(GenerateShaderCode(body).c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be bool scalar type"));
- }
- TEST_F(ValidateImage, MakeTexelVisibleKHRSuccessImageRead) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_2
- )";
- const std::string extra = R"(
- OpCapability StorageImageReadWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, MakeTexelVisibleKHRSuccessImageSparseRead) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_2
- )";
- const std::string extra = R"(
- OpCapability StorageImageReadWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, MakeTexelVisibleKHRFailureOpcode) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageReadWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Image Operand MakeTexelVisibleKHR can only be used with "
- "OpImageRead or OpImageSparseRead: OpImageSampleImplicitLod"));
- }
- TEST_F(ValidateImage, MakeTexelVisibleKHRFailureMissingNonPrivate) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageReadWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand MakeTexelVisibleKHR requires "
- "NonPrivateTexelKHR is also specified: OpImageRead"));
- }
- TEST_F(ValidateImage, MakeTexelAvailableKHRSuccessImageWrite) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_2
- )";
- const std::string extra = R"(
- OpCapability StorageImageWriteWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, MakeTexelAvailableKHRFailureOpcode) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSampleImplicitLod %f32vec4 %simg %f32vec2_hh MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageReadWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand MakeTexelAvailableKHR can only be used "
- "with OpImageWrite: OpImageSampleImplicitLod"));
- }
- TEST_F(ValidateImage, MakeTexelAvailableKHRFailureMissingNonPrivate) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageWriteWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand MakeTexelAvailableKHR requires "
- "NonPrivateTexelKHR is also specified: OpImageWrite"));
- }
- TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageWriteBad) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageWriteWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Use of device scope with VulkanKHR memory model requires the "
- "VulkanMemoryModelDeviceScopeKHR capability"));
- }
- TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageWriteGood) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123 MakeTexelAvailableKHR|NonPrivateTexelKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageWriteWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpCapability VulkanMemoryModelDeviceScopeKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageReadBad) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageReadWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- EXPECT_THAT(
- getDiagnosticString(),
- HasSubstr("Use of device scope with VulkanKHR memory model requires the "
- "VulkanMemoryModelDeviceScopeKHR capability"));
- }
- TEST_F(ValidateImage, VulkanMemoryModelDeviceScopeImageReadGood) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 MakeTexelVisibleKHR|NonPrivateTexelKHR %u32_1
- )";
- const std::string extra = R"(
- OpCapability StorageImageReadWithoutFormat
- OpCapability VulkanMemoryModelKHR
- OpCapability VulkanMemoryModelDeviceScopeKHR
- OpExtension "SPV_KHR_vulkan_memory_model"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "VulkanKHR")
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_3));
- }
- // This example used to cause a seg fault on OpReturnValue, verifying it doesn't
- // anymore.
- TEST_F(ValidateImage, Issue2463NoSegFault) {
- const std::string spirv = R"(
- OpCapability Linkage
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- %void = OpTypeVoid
- %6 = OpTypeFunction %void
- %float = OpTypeFloat 32
- %8 = OpTypeImage %float 3D 0 0 0 1 Unknown
- %_ptr_UniformConstant_8 = OpTypePointer UniformConstant %8
- %10 = OpTypeSampler
- %_ptr_UniformConstant_10 = OpTypePointer UniformConstant %10
- %12 = OpTypeSampledImage %8
- %13 = OpTypeFunction %12 %_ptr_UniformConstant_8 %_ptr_UniformConstant_10
- %23 = OpFunction %12 None %13
- %24 = OpFunctionParameter %_ptr_UniformConstant_8
- %25 = OpFunctionParameter %_ptr_UniformConstant_10
- %26 = OpLabel
- %27 = OpLoad %8 %24
- %28 = OpLoad %10 %25
- %29 = OpSampledImage %12 %27 %28
- OpReturnValue %29
- OpFunctionEnd
- )";
- CompileSuccessfully(spirv);
- ASSERT_EQ(SPV_ERROR_INVALID_ID, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("OpSampledImage instruction must not appear as operand "
- "for OpReturnValue"));
- }
- TEST_F(ValidateImage, SignExtendV13Bad) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 SignExtend
- )";
- EXPECT_THAT(CompileFailure(GenerateShaderCode(body, "", "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3)),
- HasSubstr("Invalid image operand 'SignExtend'"));
- }
- TEST_F(ValidateImage, ZeroExtendV13Bad) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 ZeroExtend
- )";
- EXPECT_THAT(CompileFailure(GenerateShaderCode(body, "", "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3)),
- HasSubstr("Invalid image operand 'ZeroExtend'"));
- }
- TEST_F(ValidateImage, SignExtendScalarUIntTexelV14Good) {
- // Unsigned int sampled type
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32 %img %u32vec2_01 SignExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, SignExtendScalarSIntTexelV14Good) {
- // Signed int sampled type
- const std::string body = R"(
- %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
- %res1 = OpImageRead %s32 %img %u32vec2_01 SignExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, SignExtendScalarVectorUIntTexelV14Good) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 SignExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, SignExtendVectorSIntTexelV14Good) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
- %res1 = OpImageRead %s32vec4 %img %u32vec2_01 SignExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- // No negative tests for SignExtend since we don't truly know the
- // texel format.
- TEST_F(ValidateImage, ZeroExtendScalarUIntTexelV14Good) {
- // Unsigned int sampled type
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32 %img %u32vec2_01 ZeroExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, ZeroExtendScalarSIntTexelV14Good) {
- // Zeroed int sampled type
- const std::string body = R"(
- %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
- %res1 = OpImageRead %s32 %img %u32vec2_01 ZeroExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, ZeroExtendScalarVectorUIntTexelV14Good) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 ZeroExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, ZeroExtendVectorSIntTexelV14Good) {
- const std::string body = R"(
- %img = OpLoad %type_image_s32_2d_0002 %uniform_image_s32_2d_0002
- %res1 = OpImageRead %s32vec4 %img %u32vec2_01 ZeroExtend
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_4),
- SPV_ENV_UNIVERSAL_1_4);
- EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_4));
- EXPECT_THAT(getDiagnosticString(), Eq(""));
- }
- TEST_F(ValidateImage, ReadLodAMDSuccess1) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- %res1 = OpImageRead %u32vec4 %img %u32vec2_01 Lod %u32_0
- )";
- const std::string extra =
- "\nOpCapability StorageImageReadWithoutFormat\n"
- "OpCapability ImageReadWriteLodAMD\n"
- "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- }
- TEST_F(ValidateImage, ReadLodAMDSuccess2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
- %res1 = OpImageRead %f32vec4 %img %u32vec2_01 Lod %u32_0
- )";
- const std::string extra =
- "\nOpCapability Image1D\n"
- "OpCapability ImageReadWriteLodAMD\n"
- "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- }
- TEST_F(ValidateImage, ReadLodAMDSuccess3) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- %res1 = OpImageRead %f32vec4 %img %u32vec3_012 Lod %u32_0
- )";
- const std::string extra =
- "\nOpCapability ImageCubeArray\n"
- "OpCapability ImageReadWriteLodAMD\n"
- "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- }
- TEST_F(ValidateImage, ReadLodAMDNeedCapability) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- %res1 = OpImageRead %f32vec4 %img %u32vec3_012 Lod %u32_0
- )";
- const std::string extra = "\nOpCapability ImageCubeArray\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand Lod can only be used with ExplicitLod "
- "opcodes and OpImageFetch"));
- }
- TEST_F(ValidateImage, WriteLodAMDSuccess1) {
- const std::string body = R"(
- %img = OpLoad %type_image_u32_2d_0002 %uniform_image_u32_2d_0002
- OpImageWrite %img %u32vec2_01 %u32vec4_0123 Lod %u32_0
- )";
- const std::string extra =
- "\nOpCapability StorageImageWriteWithoutFormat\n"
- "OpCapability ImageReadWriteLodAMD\n"
- "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- }
- TEST_F(ValidateImage, WriteLodAMDSuccess2) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_1d_0002_rgba32f %uniform_image_f32_1d_0002_rgba32f
- OpImageWrite %img %u32_1 %f32vec4_0000 Lod %u32_0
- )";
- const std::string extra =
- "\nOpCapability Image1D\n"
- "OpCapability ImageReadWriteLodAMD\n"
- "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- }
- TEST_F(ValidateImage, WriteLodAMDSuccess3) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- OpImageWrite %img %u32vec3_012 %f32vec4_0000 Lod %u32_0
- )";
- const std::string extra =
- "\nOpCapability ImageCubeArray\n"
- "OpCapability ImageReadWriteLodAMD\n"
- "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- }
- TEST_F(ValidateImage, WriteLodAMDNeedCapability) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_cube_0102_rgba32f %uniform_image_f32_cube_0102_rgba32f
- OpImageWrite %img %u32vec3_012 %f32vec4_0000 Lod %u32_0
- )";
- const std::string extra = "\nOpCapability ImageCubeArray\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand Lod can only be used with ExplicitLod "
- "opcodes and OpImageFetch"));
- }
- TEST_F(ValidateImage, SparseReadLodAMDSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01 Lod %u32_0
- )";
- const std::string extra =
- "\nOpCapability StorageImageReadWithoutFormat\n"
- "OpCapability ImageReadWriteLodAMD\n"
- "OpExtension \"SPV_AMD_shader_image_load_store_lod\"\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- }
- TEST_F(ValidateImage, SparseReadLodAMDNeedCapability) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0002 %uniform_image_f32_2d_0002
- %res1 = OpImageSparseRead %struct_u32_f32vec4 %img %u32vec2_01 Lod %u32_0
- )";
- const std::string extra = "\nOpCapability StorageImageReadWithoutFormat\n";
- CompileSuccessfully(
- GenerateShaderCode(body, extra, "Fragment", "", SPV_ENV_UNIVERSAL_1_1),
- SPV_ENV_UNIVERSAL_1_1);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA,
- ValidateInstructions(SPV_ENV_UNIVERSAL_1_1));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Image Operand Lod can only be used with ExplicitLod "
- "opcodes and OpImageFetch"));
- }
- TEST_F(ValidateImage, GatherBiasAMDSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 Bias %f32_1
- )";
- const std::string extra = R"(
- OpCapability ImageGatherBiasLodAMD
- OpExtension "SPV_AMD_texture_gather_bias_lod"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, GatherLodAMDSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageGather %f32vec4 %simg %f32vec4_0000 %u32_1 Lod %f32_1
- )";
- const std::string extra = R"(
- OpCapability ImageGatherBiasLodAMD
- OpExtension "SPV_AMD_texture_gather_bias_lod"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SparseGatherBiasAMDSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1 Bias %f32_1
- )";
- const std::string extra = R"(
- OpCapability ImageGatherBiasLodAMD
- OpExtension "SPV_AMD_texture_gather_bias_lod"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, SparseGatherLodAMDSuccess) {
- const std::string body = R"(
- %img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
- %sampler = OpLoad %type_sampler %uniform_sampler
- %simg = OpSampledImage %type_sampled_image_f32_2d_0001 %img %sampler
- %res1 = OpImageSparseGather %struct_u32_f32vec4 %simg %f32vec4_0000 %u32_1 Lod %f32_1
- )";
- const std::string extra = R"(
- OpCapability ImageGatherBiasLodAMD
- OpExtension "SPV_AMD_texture_gather_bias_lod"
- )";
- CompileSuccessfully(GenerateShaderCode(body, extra).c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- // No negative tests for ZeroExtend since we don't truly know the
- // texel format.
- // Tests for 64-bit images
- static const std::string capabilities_and_extensions_image64 = R"(
- OpCapability Int64ImageEXT
- OpExtension "SPV_EXT_shader_image_int64"
- )";
- static const std::string declarations_image64 = R"(
- %type_image_u64_buffer_0002_r64ui = OpTypeImage %u64 Buffer 0 0 0 2 R64ui
- %ptr_Image_u64 = OpTypePointer Image %u64
- %ptr_image_u64_buffer_0002_r64ui = OpTypePointer Private %type_image_u64_buffer_0002_r64ui
- %private_image_u64_buffer_0002_r64ui = OpVariable %ptr_image_u64_buffer_0002_r64ui Private
- )";
- static const std::string declarations_image64i = R"(
- %type_image_s64_buffer_0002_r64i = OpTypeImage %s64 Buffer 0 0 0 2 R64i
- %ptr_Image_s64 = OpTypePointer Image %s64
- %ptr_image_s64_buffer_0002_r64i = OpTypePointer Private %type_image_s64_buffer_0002_r64i
- %private_image_s64_buffer_0002_r64i = OpVariable %ptr_image_s64_buffer_0002_r64i Private
- )";
- TEST_F(ValidateImage, Image64MissingCapability) {
- CompileSuccessfully(GenerateShaderCode("", "", "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "GLSL450",
- declarations_image64)
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_CAPABILITY, ValidateInstructions());
- }
- TEST_F(ValidateImage, Image64MissingExtension) {
- const std::string extra = R"(
- OpCapability Int64ImageEXT
- )";
- CompileSuccessfully(GenerateShaderCode("", extra, "Fragment", "",
- SPV_ENV_UNIVERSAL_1_3, "GLSL450",
- declarations_image64)
- .c_str());
- ASSERT_EQ(SPV_ERROR_MISSING_EXTENSION, ValidateInstructions());
- }
- TEST_F(ValidateImage, ImageTexelPointer64Success) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u64 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
- )";
- CompileSuccessfully(GenerateShaderCode(body,
- capabilities_and_extensions_image64,
- "Fragment", "", SPV_ENV_UNIVERSAL_1_3,
- "GLSL450", declarations_image64)
- .c_str());
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions());
- }
- TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotPointer) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %type_image_u64_buffer_0002_r64ui %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
- )";
- CompileSuccessfully(GenerateShaderCode(body,
- capabilities_and_extensions_image64,
- "Fragment", "", SPV_ENV_UNIVERSAL_1_3,
- "GLSL450", declarations_image64)
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypePointer"));
- }
- TEST_F(ValidateImage, ImageTexelPointer64ResultTypeNotImageClass) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_image_f32_cube_0101 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
- %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
- )";
- CompileSuccessfully(GenerateShaderCode(body,
- capabilities_and_extensions_image64,
- "Fragment", "", SPV_ENV_UNIVERSAL_1_3,
- "GLSL450", declarations_image64)
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Result Type to be OpTypePointer whose "
- "Storage Class operand is Image"));
- }
- TEST_F(ValidateImage, ImageTexelPointer64SampleNotZeroForImageWithMSZero) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u64 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_1
- %sum = OpAtomicIAdd %u64 %texel_ptr %u32_1 %u32_0 %u64_1
- )";
- CompileSuccessfully(GenerateShaderCode(body,
- capabilities_and_extensions_image64,
- "Fragment", "", SPV_ENV_UNIVERSAL_1_3,
- "GLSL450", declarations_image64)
- .c_str());
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected Sample for Image with MS 0 to be a valid "
- "<id> for the value 0"));
- }
- TEST_F(ValidateImage, ImageTexelPointerR32uiSuccessVulkan) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u32 %private_image_u32_buffer_0002_r32ui %u32_0 %u32_0
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(GenerateShaderCode(body, "", "Fragment", "", env).c_str(),
- env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateImage, ImageTexelPointerR32iSuccessVulkan) {
- const std::string& declarations = R"(
- %type_image_s32_buffer_0002_r32i = OpTypeImage %s32 Buffer 0 0 0 2 R32i
- %ptr_Image_s32 = OpTypePointer Image %s32
- %ptr_image_s32_buffer_0002_r32i = OpTypePointer Private %type_image_s32_buffer_0002_r32i
- %private_image_s32_buffer_0002_r32i = OpVariable %ptr_image_s32_buffer_0002_r32i Private
- )";
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_r32i %u32_0 %u32_0
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(
- GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
- .c_str(),
- env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateImage, ImageTexelPointerR64uiSuccessVulkan) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_u64 %private_image_u64_buffer_0002_r64ui %u32_0 %u32_0
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(
- GenerateShaderCode(body, capabilities_and_extensions_image64, "Fragment",
- "", env, "GLSL450", declarations_image64)
- .c_str(),
- env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateImage, ImageTexelPointerR64iSuccessVulkan) {
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_s64 %private_image_s64_buffer_0002_r64i %u32_0 %u32_0
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(
- GenerateShaderCode(body, capabilities_and_extensions_image64, "Fragment",
- "", env, "GLSL450", declarations_image64i)
- .c_str(),
- env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateImage, ImageTexelPointerR32fSuccessVulkan) {
- const std::string& declarations = R"(
- %type_image_f32_buffer_0002_r32f = OpTypeImage %f32 Buffer 0 0 0 2 R32f
- %ptr_image_f32_buffer_0002_r32f = OpTypePointer Private %type_image_f32_buffer_0002_r32f
- %private_image_f32_buffer_0002_r32f = OpVariable %ptr_image_f32_buffer_0002_r32f Private
- )";
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_f32 %private_image_f32_buffer_0002_r32f %u32_0 %u32_0
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(
- GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
- .c_str(),
- env);
- ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(env));
- }
- TEST_F(ValidateImage, ImageTexelPointerRgba32iVulkan) {
- const std::string& declarations = R"(
- %type_image_s32_buffer_0002_rgba32i = OpTypeImage %s32 Buffer 0 0 0 2 Rgba32i
- %ptr_Image_s32 = OpTypePointer Image %s32
- %ptr_image_s32_buffer_0002_rgba32i = OpTypePointer Private %type_image_s32_buffer_0002_rgba32i
- %private_image_s32_buffer_0002_rgba32i = OpVariable %ptr_image_s32_buffer_0002_rgba32i Private
- )";
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_rgba32i %u32_0 %u32_0
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(
- GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
- .c_str(),
- env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-OpImageTexelPointer-04658"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected the Image Format in Image to be R64i, R64ui, "
- "R32f, R32i, or R32ui for Vulkan environment"));
- }
- TEST_F(ValidateImage, ImageTexelPointerRgba16fVulkan) {
- const std::string& declarations = R"(
- %type_image_s32_buffer_0002_rgba16f = OpTypeImage %s32 Buffer 0 0 0 2 Rgba16f
- %ptr_Image_s32 = OpTypePointer Image %s32
- %ptr_image_s32_buffer_0002_rgba16f = OpTypePointer Private %type_image_s32_buffer_0002_rgba16f
- %private_image_s32_buffer_0002_rgba16f = OpVariable %ptr_image_s32_buffer_0002_rgba16f Private
- )";
- const std::string body = R"(
- %texel_ptr = OpImageTexelPointer %ptr_Image_s32 %private_image_s32_buffer_0002_rgba16f %u32_0 %u32_0
- )";
- spv_target_env env = SPV_ENV_VULKAN_1_0;
- CompileSuccessfully(
- GenerateShaderCode(body, "", "Fragment", "", env, "GLSL450", declarations)
- .c_str(),
- env);
- ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
- EXPECT_THAT(getDiagnosticString(),
- AnyVUID("VUID-StandaloneSpirv-OpImageTexelPointer-04658"));
- EXPECT_THAT(getDiagnosticString(),
- HasSubstr("Expected the Image Format in Image to be R64i, R64ui, "
- "R32f, R32i, or R32ui for Vulkan environment"));
- }
- } // namespace
- } // namespace val
- } // namespace spvtools
|