ExecutionTest.cpp 286 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // ExecutionTest.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // These tests run by executing compiled programs, and thus involve more //
  9. // moving parts, like the runtime and drivers. //
  10. // //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include <algorithm>
  13. #include <memory>
  14. #include <vector>
  15. #include <string>
  16. #include <map>
  17. #include <unordered_set>
  18. #include <strstream>
  19. #include <iomanip>
  20. #include "dxc/Test/CompilationResult.h"
  21. #include "dxc/Test/HLSLTestData.h"
  22. #include <Shlwapi.h>
  23. #include <atlcoll.h>
  24. #include <locale>
  25. #include <algorithm>
  26. #undef _read
  27. #include "WexTestClass.h"
  28. #include "dxc/Test/HlslTestUtils.h"
  29. #include "dxc/Test/DxcTestUtils.h"
  30. #include "dxc/Support/Global.h"
  31. #include "dxc/Support/WinIncludes.h"
  32. #include "dxc/Support/FileIOHelper.h"
  33. #include "dxc/Support/Unicode.h"
  34. //
  35. // d3d12.h and dxgi1_4.h are included in the Windows 10 SDK
  36. // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899120(v=vs.85).aspx
  37. // https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
  38. //
  39. #include <d3d12.h>
  40. #include <dxgi1_4.h>
  41. #include <DXGIDebug.h>
  42. #include "dxc/Support/d3dx12.h"
  43. #include <DirectXMath.h>
  44. #include <strsafe.h>
  45. #include <d3dcompiler.h>
  46. #include <wincodec.h>
  47. #include "ShaderOpTest.h"
  48. #pragma comment(lib, "d3dcompiler.lib")
  49. #pragma comment(lib, "windowscodecs.lib")
  50. #pragma comment(lib, "dxguid.lib")
  51. #pragma comment(lib, "version.lib")
  52. // A more recent Windows SDK than currently required is needed for these.
  53. typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)(
  54. UINT NumFeatures,
  55. __in_ecount(NumFeatures) const IID* pIIDs,
  56. __in_ecount_opt(NumFeatures) void* pConfigurationStructs,
  57. __in_ecount_opt(NumFeatures) UINT* pConfigurationStructSizes);
  58. static const GUID D3D12ExperimentalShaderModelsID = { /* 76f5573e-f13a-40f5-b297-81ce9e18933f */
  59. 0x76f5573e,
  60. 0xf13a,
  61. 0x40f5,
  62. { 0xb2, 0x97, 0x81, 0xce, 0x9e, 0x18, 0x93, 0x3f }
  63. };
  64. using namespace DirectX;
  65. using namespace hlsl_test;
  66. template <typename TSequence, typename T>
  67. static bool contains(TSequence s, const T &val) {
  68. return std::cend(s) != std::find(std::cbegin(s), std::cend(s), val);
  69. }
  70. template <typename InputIterator, typename T>
  71. static bool contains(InputIterator b, InputIterator e, const T &val) {
  72. return e != std::find(b, e, val);
  73. }
  74. static HRESULT EnableExperimentalShaderModels() {
  75. HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
  76. if (hRuntime == NULL) {
  77. return HRESULT_FROM_WIN32(GetLastError());
  78. }
  79. D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
  80. (D3D12EnableExperimentalFeaturesFn)GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures");
  81. if (pD3D12EnableExperimentalFeatures == nullptr) {
  82. FreeLibrary(hRuntime);
  83. return HRESULT_FROM_WIN32(GetLastError());
  84. }
  85. HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
  86. FreeLibrary(hRuntime);
  87. return hr;
  88. }
  89. static HRESULT ReportLiveObjects() {
  90. CComPtr<IDXGIDebug1> pDebug;
  91. IFR(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)));
  92. IFR(pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL));
  93. return S_OK;
  94. }
  95. static void WriteInfoQueueMessages(void *pStrCtx, st::OutputStringFn pOutputStrFn, ID3D12InfoQueue *pInfoQueue) {
  96. bool allMessagesOK = true;
  97. UINT64 count = pInfoQueue->GetNumStoredMessages();
  98. CAtlArray<BYTE> message;
  99. for (UINT64 i = 0; i < count; ++i) {
  100. // 'GetMessageA' rather than 'GetMessage' is an artifact of user32 headers.
  101. SIZE_T msgLen = 0;
  102. if (FAILED(pInfoQueue->GetMessageA(i, nullptr, &msgLen))) {
  103. allMessagesOK = false;
  104. continue;
  105. }
  106. if (message.GetCount() < msgLen) {
  107. if (!message.SetCount(msgLen)) {
  108. allMessagesOK = false;
  109. continue;
  110. }
  111. }
  112. D3D12_MESSAGE *pMessage = (D3D12_MESSAGE *)message.GetData();
  113. if (FAILED(pInfoQueue->GetMessageA(i, pMessage, &msgLen))) {
  114. allMessagesOK = false;
  115. continue;
  116. }
  117. CA2W msgW(pMessage->pDescription, CP_ACP);
  118. pOutputStrFn(pStrCtx, msgW.m_psz);
  119. pOutputStrFn(pStrCtx, L"\r\n");
  120. }
  121. if (!allMessagesOK) {
  122. pOutputStrFn(pStrCtx, L"Failed to retrieve some messages.\r\n");
  123. }
  124. }
  125. class CComContext {
  126. private:
  127. bool m_init;
  128. public:
  129. CComContext() : m_init(false) {}
  130. ~CComContext() { Dispose(); }
  131. void Dispose() { if (!m_init) return; m_init = false; CoUninitialize(); }
  132. HRESULT Init() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { m_init = true; } return hr; }
  133. };
  134. static void SavePixelsToFile(LPCVOID pPixels, DXGI_FORMAT format, UINT32 m_width, UINT32 m_height, LPCWSTR pFileName) {
  135. CComContext ctx;
  136. CComPtr<IWICImagingFactory> pFactory;
  137. CComPtr<IWICBitmap> pBitmap;
  138. CComPtr<IWICBitmapEncoder> pEncoder;
  139. CComPtr<IWICBitmapFrameEncode> pFrameEncode;
  140. CComPtr<hlsl::AbstractMemoryStream> pStream;
  141. CComPtr<IMalloc> pMalloc;
  142. struct PF {
  143. DXGI_FORMAT Format;
  144. GUID PixelFormat;
  145. UINT32 PixelSize;
  146. bool operator==(DXGI_FORMAT F) const {
  147. return F == Format;
  148. }
  149. } Vals[] = {
  150. // Add more pixel format mappings as needed.
  151. { DXGI_FORMAT_R8G8B8A8_UNORM, GUID_WICPixelFormat32bppRGBA, 4 }
  152. };
  153. PF *pFormat = std::find(Vals, Vals + _countof(Vals), format);
  154. VERIFY_SUCCEEDED(ctx.Init());
  155. VERIFY_SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory));
  156. VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
  157. VERIFY_SUCCEEDED(hlsl::CreateMemoryStream(pMalloc, &pStream));
  158. VERIFY_ARE_NOT_EQUAL(pFormat, Vals + _countof(Vals));
  159. VERIFY_SUCCEEDED(pFactory->CreateBitmapFromMemory(m_width, m_height, pFormat->PixelFormat, m_width * pFormat->PixelSize, m_width * m_height * pFormat->PixelSize, (BYTE *)pPixels, &pBitmap));
  160. VERIFY_SUCCEEDED(pFactory->CreateEncoder(GUID_ContainerFormatBmp, nullptr, &pEncoder));
  161. VERIFY_SUCCEEDED(pEncoder->Initialize(pStream, WICBitmapEncoderNoCache));
  162. VERIFY_SUCCEEDED(pEncoder->CreateNewFrame(&pFrameEncode, nullptr));
  163. VERIFY_SUCCEEDED(pFrameEncode->Initialize(nullptr));
  164. VERIFY_SUCCEEDED(pFrameEncode->WriteSource(pBitmap, nullptr));
  165. VERIFY_SUCCEEDED(pFrameEncode->Commit());
  166. VERIFY_SUCCEEDED(pEncoder->Commit());
  167. hlsl::WriteBinaryFile(pFileName, pStream->GetPtr(), pStream->GetPtrSize());
  168. }
  169. // Checks if the given warp version supports the given operation.
  170. bool IsValidWarpDllVersion(unsigned int minBuildNumber) {
  171. HMODULE pLibrary = LoadLibrary("D3D10Warp.dll");
  172. if (pLibrary) {
  173. char path[MAX_PATH];
  174. DWORD length = GetModuleFileName(pLibrary, path, MAX_PATH);
  175. if (length) {
  176. DWORD dwVerHnd = 0;
  177. DWORD dwVersionInfoSize = GetFileVersionInfoSize(path, &dwVerHnd);
  178. std::unique_ptr<int[]> VffInfo(new int[dwVersionInfoSize]);
  179. if (GetFileVersionInfo(path, NULL, dwVersionInfoSize, VffInfo.get())) {
  180. LPVOID versionInfo;
  181. UINT size;
  182. if (VerQueryValue(VffInfo.get(), "\\", &versionInfo, &size)) {
  183. if (size) {
  184. VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)versionInfo;
  185. unsigned int warpBuildNumber = verInfo->dwFileVersionLS >> 16 & 0xffff;
  186. if (verInfo->dwSignature == 0xFEEF04BD && warpBuildNumber >= minBuildNumber) {
  187. return true;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. FreeLibrary(pLibrary);
  194. }
  195. return false;
  196. }
  197. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS2
  198. #define D3D12_FEATURE_D3D12_OPTIONS3 ((D3D12_FEATURE)21)
  199. #define NTDDI_WIN10_RS3 0x0A000004 /* ABRACADABRA_WIN10_RS2 */
  200. typedef
  201. enum D3D12_COMMAND_LIST_SUPPORT_FLAGS
  202. {
  203. D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0,
  204. D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT = (1 << D3D12_COMMAND_LIST_TYPE_DIRECT),
  205. D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE = (1 << D3D12_COMMAND_LIST_TYPE_BUNDLE),
  206. D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE = (1 << D3D12_COMMAND_LIST_TYPE_COMPUTE),
  207. D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY = (1 << D3D12_COMMAND_LIST_TYPE_COPY),
  208. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE = (1 << 4),
  209. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS = (1 << 5)
  210. } D3D12_COMMAND_LIST_SUPPORT_FLAGS;
  211. typedef
  212. enum D3D12_VIEW_INSTANCING_TIER
  213. {
  214. D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0,
  215. D3D12_VIEW_INSTANCING_TIER_1 = 1,
  216. D3D12_VIEW_INSTANCING_TIER_2 = 2,
  217. D3D12_VIEW_INSTANCING_TIER_3 = 3
  218. } D3D12_VIEW_INSTANCING_TIER;
  219. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS3
  220. {
  221. _Out_ BOOL CopyQueueTimestampQueriesSupported;
  222. _Out_ BOOL CastingFullyTypedFormatSupported;
  223. _Out_ DWORD WriteBufferImmediateSupportFlags;
  224. _Out_ D3D12_VIEW_INSTANCING_TIER ViewInstancingTier;
  225. _Out_ BOOL BarycentricsSupported;
  226. } D3D12_FEATURE_DATA_D3D12_OPTIONS3;
  227. #endif
  228. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS3
  229. #define D3D12_FEATURE_D3D12_OPTIONS4 ((D3D12_FEATURE)23)
  230. typedef enum D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER
  231. {
  232. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_0,
  233. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1,
  234. } D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER;
  235. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS4
  236. {
  237. _Out_ BOOL ReservedBufferPlacementSupported;
  238. _Out_ D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER SharedResourceCompatibilityTier;
  239. _Out_ BOOL Native16BitShaderOpsSupported;
  240. } D3D12_FEATURE_DATA_D3D12_OPTIONS4;
  241. #endif
  242. // Virtual class to compute the expected result given a set of inputs
  243. struct TableParameter;
  244. class ExecutionTest {
  245. public:
  246. // By default, ignore these tests, which require a recent build to run properly.
  247. BEGIN_TEST_CLASS(ExecutionTest)
  248. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  249. TEST_CLASS_PROPERTY(L"Ignore", L"true")
  250. TEST_METHOD_PROPERTY(L"Priority", L"0")
  251. END_TEST_CLASS()
  252. TEST_CLASS_SETUP(ExecutionTestClassSetup)
  253. TEST_METHOD(BasicComputeTest);
  254. TEST_METHOD(BasicTriangleTest);
  255. TEST_METHOD(BasicTriangleOpTest);
  256. BEGIN_TEST_METHOD(BasicTriangleOpTestHalf)
  257. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  258. END_TEST_METHOD()
  259. TEST_METHOD(OutOfBoundsTest);
  260. TEST_METHOD(SaturateTest);
  261. TEST_METHOD(SignTest);
  262. TEST_METHOD(Int64Test);
  263. TEST_METHOD(WaveIntrinsicsTest);
  264. TEST_METHOD(WaveIntrinsicsDDITest);
  265. TEST_METHOD(WaveIntrinsicsInPSTest);
  266. TEST_METHOD(PartialDerivTest);
  267. BEGIN_TEST_METHOD(CBufferTestHalf)
  268. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  269. END_TEST_METHOD()
  270. TEST_METHOD(BasicShaderModel61);
  271. BEGIN_TEST_METHOD(BasicShaderModel63)
  272. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  273. END_TEST_METHOD()
  274. BEGIN_TEST_METHOD(WaveIntrinsicsActiveIntTest)
  275. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveIntTable")
  276. END_TEST_METHOD()
  277. BEGIN_TEST_METHOD(WaveIntrinsicsActiveUintTest)
  278. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveUintTable")
  279. END_TEST_METHOD()
  280. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixIntTest)
  281. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixIntTable")
  282. END_TEST_METHOD()
  283. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixUintTest)
  284. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixUintTable")
  285. END_TEST_METHOD()
  286. BEGIN_TEST_METHOD(WaveIntrinsicsSM65IntTest)
  287. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixIntTable")
  288. END_TEST_METHOD()
  289. BEGIN_TEST_METHOD(WaveIntrinsicsSM65UintTest)
  290. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixUintTable")
  291. END_TEST_METHOD()
  292. // TAEF data-driven tests.
  293. BEGIN_TEST_METHOD(UnaryFloatOpTest)
  294. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
  295. END_TEST_METHOD()
  296. BEGIN_TEST_METHOD(BinaryFloatOpTest)
  297. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
  298. END_TEST_METHOD()
  299. BEGIN_TEST_METHOD(TertiaryFloatOpTest)
  300. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
  301. END_TEST_METHOD()
  302. BEGIN_TEST_METHOD(UnaryHalfOpTest)
  303. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
  304. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  305. END_TEST_METHOD()
  306. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  307. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  308. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  309. END_TEST_METHOD()
  310. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  311. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  312. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  313. END_TEST_METHOD()
  314. BEGIN_TEST_METHOD(UnaryIntOpTest)
  315. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  316. END_TEST_METHOD()
  317. BEGIN_TEST_METHOD(BinaryIntOpTest)
  318. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  319. END_TEST_METHOD()
  320. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  321. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  322. END_TEST_METHOD()
  323. BEGIN_TEST_METHOD(UnaryUintOpTest)
  324. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  325. END_TEST_METHOD()
  326. BEGIN_TEST_METHOD(BinaryUintOpTest)
  327. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  328. END_TEST_METHOD()
  329. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  330. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  331. END_TEST_METHOD()
  332. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  333. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  334. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  335. END_TEST_METHOD()
  336. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  337. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  338. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  339. END_TEST_METHOD()
  340. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  341. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  342. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  343. END_TEST_METHOD()
  344. BEGIN_TEST_METHOD(UnaryUint16OpTest)
  345. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  346. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  347. END_TEST_METHOD()
  348. BEGIN_TEST_METHOD(BinaryUint16OpTest)
  349. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  350. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  351. END_TEST_METHOD()
  352. BEGIN_TEST_METHOD(TertiaryUint16OpTest)
  353. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  354. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  355. END_TEST_METHOD()
  356. BEGIN_TEST_METHOD(DotTest)
  357. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  358. END_TEST_METHOD()
  359. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  360. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  361. END_TEST_METHOD()
  362. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  363. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  364. END_TEST_METHOD()
  365. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  366. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  367. END_TEST_METHOD()
  368. BEGIN_TEST_METHOD(Msad4Test)
  369. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  370. END_TEST_METHOD()
  371. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  372. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  373. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  374. END_TEST_METHOD()
  375. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  376. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  377. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  378. END_TEST_METHOD()
  379. TEST_METHOD(BarycentricsTest);
  380. TEST_METHOD(ComputeRawBufferLdStI32);
  381. TEST_METHOD(ComputeRawBufferLdStFloat);
  382. BEGIN_TEST_METHOD(ComputeRawBufferLdStI64)
  383. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  384. END_TEST_METHOD()
  385. BEGIN_TEST_METHOD(ComputeRawBufferLdStDouble)
  386. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  387. END_TEST_METHOD()
  388. BEGIN_TEST_METHOD(ComputeRawBufferLdStI16)
  389. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  390. END_TEST_METHOD()
  391. BEGIN_TEST_METHOD(ComputeRawBufferLdStHalf)
  392. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  393. END_TEST_METHOD()
  394. TEST_METHOD(GraphicsRawBufferLdStI32);
  395. TEST_METHOD(GraphicsRawBufferLdStFloat);
  396. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI64)
  397. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  398. END_TEST_METHOD()
  399. BEGIN_TEST_METHOD(GraphicsRawBufferLdStDouble)
  400. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  401. END_TEST_METHOD()
  402. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI16)
  403. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  404. END_TEST_METHOD()
  405. BEGIN_TEST_METHOD(GraphicsRawBufferLdStHalf)
  406. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  407. END_TEST_METHOD()
  408. dxc::DxcDllSupport m_support;
  409. VersionSupportInfo m_ver;
  410. bool m_ExperimentalModeEnabled = false;
  411. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  412. // Do not remove the following line - it is used by TranslateExecutionTest.py
  413. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  414. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  415. // require the Windows 10 SDK.
  416. typedef enum D3D_SHADER_MODEL {
  417. D3D_SHADER_MODEL_5_1 = 0x51,
  418. D3D_SHADER_MODEL_6_0 = 0x60,
  419. D3D_SHADER_MODEL_6_1 = 0x61,
  420. D3D_SHADER_MODEL_6_2 = 0x62,
  421. D3D_SHADER_MODEL_6_3 = 0x63,
  422. D3D_SHADER_MODEL_6_4 = 0x64,
  423. D3D_SHADER_MODEL_6_5 = 0x65,
  424. D3D_SHADER_MODEL_6_6 = 0x66,
  425. } D3D_SHADER_MODEL;
  426. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  427. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  428. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  429. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  430. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  431. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  432. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  433. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  434. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  435. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  436. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  437. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  438. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  439. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  440. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  441. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  442. #else
  443. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  444. #endif
  445. bool UseDxbc() {
  446. #ifdef _HLK_CONF
  447. return false;
  448. #else
  449. return GetTestParamBool(L"DXBC");
  450. #endif
  451. }
  452. bool UseWarpByDefault() {
  453. #ifdef _HLK_CONF
  454. return false;
  455. #else
  456. return true;
  457. #endif
  458. }
  459. bool UseDebugIfaces() {
  460. return true;
  461. }
  462. bool SaveImages() {
  463. return GetTestParamBool(L"SaveImages");
  464. }
  465. template <class T1, class T2>
  466. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  467. size_t numParameter, bool isPrefix);
  468. template <typename T>
  469. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  470. size_t numParameters);
  471. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  472. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  473. enum class RawBufferLdStType {
  474. I32,
  475. Float,
  476. I64,
  477. Double,
  478. I16,
  479. Half
  480. };
  481. template <class Ty>
  482. struct RawBufferLdStTestData {
  483. Ty v1, v2[2], v3[3], v4[4];
  484. };
  485. template <class Ty>
  486. struct RawBufferLdStUavData {
  487. RawBufferLdStTestData<Ty> input, output, srvOut;
  488. };
  489. template <class Ty>
  490. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  491. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  492. template <class Ty>
  493. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  494. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  495. template <class Ty>
  496. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  497. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  498. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  499. template <class Ty>
  500. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  501. template <class Ty>
  502. const wchar_t* BasicShaderModelTest_GetFormatString();
  503. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  504. VERIFY_SUCCEEDED(m_support.Initialize());
  505. CComPtr<IDxcCompiler> pCompiler;
  506. CComPtr<IDxcLibrary> pLibrary;
  507. CComPtr<IDxcBlobEncoding> pTextBlob;
  508. CComPtr<IDxcOperationResult> pResult;
  509. HRESULT resultCode;
  510. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  511. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  512. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  513. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, nullptr, 0, nullptr, 0, nullptr, &pResult));
  514. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  515. if (FAILED(resultCode)) {
  516. CComPtr<IDxcBlobEncoding> errors;
  517. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  518. #ifndef _HLK_CONF
  519. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  520. #endif
  521. }
  522. VERIFY_SUCCEEDED(resultCode);
  523. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  524. }
  525. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  526. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  527. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  528. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE;
  529. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  530. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  531. }
  532. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, ID3D12PipelineState **ppComputeState) {
  533. CComPtr<ID3DBlob> pComputeShader;
  534. // Load and compile shaders.
  535. if (UseDxbc()) {
  536. #ifndef _HLK_CONF
  537. DXBCFromText(pShader, L"main", L"cs_6_0", &pComputeShader);
  538. #endif
  539. }
  540. else {
  541. CompileFromText(pShader, L"main", L"cs_6_0", &pComputeShader);
  542. }
  543. // Describe and create the compute pipeline state object (PSO).
  544. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  545. computePsoDesc.pRootSignature = pRootSignature;
  546. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  547. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  548. }
  549. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  550. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true) {
  551. if (testModel > HIGHEST_SHADER_MODEL) {
  552. UINT minor = (UINT)testModel & 0x0f;
  553. LogCommentFmt(L"Installed SDK does not support "
  554. L"shader model 6.%1u", minor);
  555. if (skipUnsupported) {
  556. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  557. }
  558. return false;
  559. }
  560. const D3D_FEATURE_LEVEL FeatureLevelRequired = D3D_FEATURE_LEVEL_11_0;
  561. CComPtr<IDXGIFactory4> factory;
  562. CComPtr<ID3D12Device> pDevice;
  563. *ppDevice = nullptr;
  564. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  565. if (GetTestParamUseWARP(UseWarpByDefault())) {
  566. CComPtr<IDXGIAdapter> warpAdapter;
  567. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  568. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  569. IID_PPV_ARGS(&pDevice));
  570. if (FAILED(createHR)) {
  571. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  572. if (skipUnsupported) {
  573. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  574. }
  575. return false;
  576. }
  577. } else {
  578. CComPtr<IDXGIAdapter1> hardwareAdapter;
  579. WEX::Common::String AdapterValue;
  580. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  581. AdapterValue);
  582. if (SUCCEEDED(hr)) {
  583. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  584. } else {
  585. WEX::Logging::Log::Comment(
  586. L"Using default hardware adapter with D3D12 support.");
  587. }
  588. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  589. IID_PPV_ARGS(&pDevice)));
  590. }
  591. // retrieve adapter information
  592. LUID adapterID = pDevice->GetAdapterLuid();
  593. CComPtr<IDXGIAdapter> adapter;
  594. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  595. DXGI_ADAPTER_DESC AdapterDesc;
  596. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  597. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  598. if (pDevice == nullptr)
  599. return false;
  600. if (!UseDxbc()) {
  601. // Check for DXIL support.
  602. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  603. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  604. } D3D12_FEATURE_DATA_SHADER_MODEL;
  605. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  606. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  607. SMData.HighestShaderModel = testModel;
  608. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
  609. (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
  610. if (SMData.HighestShaderModel < testModel) {
  611. UINT minor = (UINT)testModel & 0x0f;
  612. LogCommentFmt(L"The selected device does not support "
  613. L"shader model 6.%1u", minor);
  614. if (skipUnsupported) {
  615. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  616. }
  617. return false;
  618. }
  619. }
  620. if (UseDebugIfaces()) {
  621. CComPtr<ID3D12InfoQueue> pInfoQueue;
  622. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  623. pInfoQueue->SetMuteDebugOutput(FALSE);
  624. }
  625. }
  626. *ppDevice = pDevice.Detach();
  627. return true;
  628. }
  629. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  630. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  631. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  632. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  633. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  634. }
  635. void CreateGraphicsCommandQueueAndList(
  636. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  637. ID3D12CommandAllocator **ppAllocator,
  638. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  639. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  640. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  641. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  642. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  643. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  644. IID_PPV_ARGS(ppCommandList)));
  645. }
  646. void CreateGraphicsPSO(ID3D12Device *pDevice,
  647. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  648. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  649. ID3D12PipelineState **ppPSO) {
  650. CComPtr<ID3DBlob> vertexShader;
  651. CComPtr<ID3DBlob> pixelShader;
  652. if (UseDxbc()) {
  653. #ifndef _HLK_CONF
  654. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  655. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  656. #endif
  657. } else {
  658. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  659. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  660. }
  661. // Describe and create the graphics pipeline state object (PSO).
  662. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  663. psoDesc.InputLayout = *pInputLayout;
  664. psoDesc.pRootSignature = pRootSignature;
  665. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  666. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  667. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  668. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  669. psoDesc.DepthStencilState.DepthEnable = FALSE;
  670. psoDesc.DepthStencilState.StencilEnable = FALSE;
  671. psoDesc.SampleMask = UINT_MAX;
  672. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  673. psoDesc.NumRenderTargets = 1;
  674. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  675. psoDesc.SampleDesc.Count = 1;
  676. VERIFY_SUCCEEDED(
  677. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  678. }
  679. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  680. ID3D12DescriptorHeap *pHeap, UINT width,
  681. UINT height,
  682. ID3D12Resource **ppRenderTarget,
  683. ID3D12Resource **ppBuffer) {
  684. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  685. const size_t formatElementSize = 4;
  686. CComPtr<ID3D12Resource> pRenderTarget;
  687. CComPtr<ID3D12Resource> pBuffer;
  688. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  689. pHeap->GetCPUDescriptorHandleForHeapStart());
  690. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  691. CD3DX12_RESOURCE_DESC rtDesc(
  692. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  693. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  694. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  695. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  696. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  697. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  698. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  699. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  700. // resource.
  701. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  702. CD3DX12_RESOURCE_DESC readDesc(
  703. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  704. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  705. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  706. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  707. *ppRenderTarget = pRenderTarget.Detach();
  708. *ppBuffer = pBuffer.Detach();
  709. }
  710. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  711. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  712. ID3D12RootSignature **pRootSig) {
  713. CComPtr<ID3DBlob> signature;
  714. CComPtr<ID3DBlob> error;
  715. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  716. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  717. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  718. IID_PPV_ARGS(pRootSig)));
  719. }
  720. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  721. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  722. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  723. rtvHeapDesc.NumDescriptors = numDescriptors;
  724. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  725. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  726. VERIFY_SUCCEEDED(
  727. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  728. if (rtvDescriptorSize != nullptr) {
  729. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  730. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  731. }
  732. }
  733. void CreateTestUavs(ID3D12Device *pDevice,
  734. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  735. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  736. ID3D12Resource **ppReadBuffer,
  737. ID3D12Resource **ppUploadResource) {
  738. CComPtr<ID3D12Resource> pUavResource;
  739. CComPtr<ID3D12Resource> pReadBuffer;
  740. CComPtr<ID3D12Resource> pUploadResource;
  741. D3D12_SUBRESOURCE_DATA transferData;
  742. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  743. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  744. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  745. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  746. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  747. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  748. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  749. &defaultHeapProperties,
  750. D3D12_HEAP_FLAG_NONE,
  751. &bufferDesc,
  752. D3D12_RESOURCE_STATE_COPY_DEST,
  753. nullptr,
  754. IID_PPV_ARGS(&pUavResource)));
  755. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  756. &uploadHeapProperties,
  757. D3D12_HEAP_FLAG_NONE,
  758. &uploadBufferDesc,
  759. D3D12_RESOURCE_STATE_GENERIC_READ,
  760. nullptr,
  761. IID_PPV_ARGS(&pUploadResource)));
  762. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  763. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  764. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  765. transferData.pData = values;
  766. transferData.RowPitch = valueSizeInBytes;
  767. transferData.SlicePitch = transferData.RowPitch;
  768. UpdateSubresources<1>(pCommandList, pUavResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  769. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  770. *ppUavResource = pUavResource.Detach();
  771. *ppReadBuffer = pReadBuffer.Detach();
  772. *ppUploadResource = pUploadResource.Detach();
  773. }
  774. template <typename TVertex, int len>
  775. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  776. ID3D12Resource **ppVertexBuffer,
  777. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  778. size_t vertexBufferSize = sizeof(vertices);
  779. CComPtr<ID3D12Resource> pVertexBuffer;
  780. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  781. CD3DX12_RESOURCE_DESC bufferDesc(
  782. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  783. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  784. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  785. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  786. IID_PPV_ARGS(&pVertexBuffer)));
  787. UINT8 *pVertexDataBegin;
  788. CD3DX12_RANGE readRange(0, 0);
  789. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  790. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  791. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  792. pVertexBuffer->Unmap(0, nullptr);
  793. // Initialize the vertex buffer view.
  794. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  795. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  796. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  797. *ppVertexBuffer = pVertexBuffer.Detach();
  798. }
  799. // Requires Anniversary Edition headers, so simplifying things for current setup.
  800. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  801. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  802. BOOL WaveOps;
  803. UINT WaveLaneCountMin;
  804. UINT WaveLaneCountMax;
  805. UINT TotalLaneCount;
  806. BOOL ExpandedComputeResourceStates;
  807. BOOL Int64ShaderOps;
  808. };
  809. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  810. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  811. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  812. return false;
  813. return O.Int64ShaderOps != FALSE;
  814. }
  815. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  816. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  817. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  818. return false;
  819. return O.DoublePrecisionFloatShaderOps != FALSE;
  820. }
  821. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  822. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  823. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  824. return false;
  825. return O.WaveOps != FALSE;
  826. }
  827. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  828. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  829. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  830. return false;
  831. return O.BarycentricsSupported != FALSE;
  832. }
  833. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  834. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  835. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  836. return false;
  837. return O.Native16BitShaderOpsSupported != FALSE;
  838. }
  839. #ifndef _HLK_CONF
  840. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  841. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  842. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  843. CComPtr<ID3DBlob> pErrors;
  844. D3D_SHADER_MACRO d3dMacro[2];
  845. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  846. d3dMacro[0].Definition = "1";
  847. d3dMacro[0].Name = "USING_DXBC";
  848. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  849. if (pErrors != nullptr) {
  850. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  851. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  852. }
  853. VERIFY_SUCCEEDED(hr);
  854. }
  855. #endif
  856. HRESULT EnableDebugLayer() {
  857. // The debug layer does net yet validate DXIL programs that require rewriting,
  858. // but basic logging should work properly.
  859. HRESULT hr = S_FALSE;
  860. if (UseDebugIfaces()) {
  861. CComPtr<ID3D12Debug> debugController;
  862. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  863. if (SUCCEEDED(hr)) {
  864. debugController->EnableDebugLayer();
  865. hr = S_OK;
  866. }
  867. }
  868. return hr;
  869. }
  870. #ifndef _HLK_CONF
  871. HRESULT EnableExperimentalMode() {
  872. if (m_ExperimentalModeEnabled) {
  873. return S_OK;
  874. }
  875. if (!GetTestParamBool(L"ExperimentalShaders")) {
  876. return S_FALSE;
  877. }
  878. HRESULT hr = EnableExperimentalShaderModels();
  879. if (SUCCEEDED(hr)) {
  880. m_ExperimentalModeEnabled = true;
  881. }
  882. return hr;
  883. }
  884. #endif
  885. struct FenceObj {
  886. HANDLE m_fenceEvent = NULL;
  887. CComPtr<ID3D12Fence> m_fence;
  888. UINT64 m_fenceValue;
  889. ~FenceObj() {
  890. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  891. }
  892. };
  893. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  894. pObj->m_fenceValue = 1;
  895. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  896. IID_PPV_ARGS(&pObj->m_fence)));
  897. // Create an event handle to use for frame synchronization.
  898. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  899. if (pObj->m_fenceEvent == nullptr) {
  900. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  901. }
  902. }
  903. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  904. VERIFY_SUCCEEDED(m_support.Initialize());
  905. CComPtr<IDxcLibrary> pLibrary;
  906. CComPtr<IDxcBlobEncoding> pBlob;
  907. CComPtr<IStream> pStream;
  908. std::wstring path = GetPathToHlslDataFile(relativePath);
  909. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  910. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  911. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  912. *ppStream = pStream.Detach();
  913. }
  914. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  915. ID3D12DescriptorHeap *pRtvHeap,
  916. UINT rtvDescriptorSize,
  917. UINT instanceCount,
  918. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  919. ID3D12RootSignature *pRootSig,
  920. ID3D12Resource *pRenderTarget,
  921. ID3D12Resource *pReadBuffer) {
  922. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  923. D3D12_VIEWPORT viewport;
  924. D3D12_RECT scissorRect;
  925. memset(&viewport, 0, sizeof(viewport));
  926. viewport.Height = (float)rtDesc.Height;
  927. viewport.Width = (float)rtDesc.Width;
  928. viewport.MaxDepth = 1.0f;
  929. memset(&scissorRect, 0, sizeof(scissorRect));
  930. scissorRect.right = (long)rtDesc.Width;
  931. scissorRect.bottom = rtDesc.Height;
  932. if (pRootSig != nullptr) {
  933. pList->SetGraphicsRootSignature(pRootSig);
  934. }
  935. pList->RSSetViewports(1, &viewport);
  936. pList->RSSetScissorRects(1, &scissorRect);
  937. // Indicate that the buffer will be used as a render target.
  938. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  939. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  940. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  941. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  942. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  943. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  944. pList->DrawInstanced(3, instanceCount, 0, 0);
  945. // Transition to copy source and copy into read-back buffer.
  946. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  947. // Copy into read-back buffer.
  948. UINT64 rowPitch = rtDesc.Width * 4;
  949. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  950. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  951. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  952. Footprint.Offset = 0;
  953. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  954. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  955. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  956. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  957. }
  958. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  959. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  960. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  961. pCommandList->SetDescriptorHeaps(1, pHeaps);
  962. }
  963. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  964. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  965. }
  966. };
  967. #define WAVE_INTRINSIC_DXBC_GUARD \
  968. "#ifdef USING_DXBC\r\n" \
  969. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  970. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  971. "bool WaveIsFirstLane() { return true; }\r\n" \
  972. "uint WaveGetLaneCount() { return 1; }\r\n" \
  973. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  974. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  975. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  976. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  977. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  978. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  979. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  980. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  981. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  982. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  983. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  984. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  985. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  986. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  987. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  988. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  989. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  990. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  991. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  992. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  993. "#endif\r\n"
  994. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  995. size_t count) {
  996. values.resize(count); // one element per dispatch group, in bytes
  997. for (size_t i = 0; i < count; ++i) {
  998. values[i] = (uint32_t)i;
  999. }
  1000. }
  1001. bool ExecutionTest::ExecutionTestClassSetup() {
  1002. #ifdef _HLK_CONF
  1003. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1004. VERIFY_SUCCEEDED(m_support.Initialize());
  1005. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1006. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1007. if (m_EnableDebugLayer) {
  1008. EnableDebugLayer();
  1009. }
  1010. return true;
  1011. #else
  1012. HRESULT hr = EnableExperimentalMode();
  1013. if (FAILED(hr)) {
  1014. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1015. }
  1016. else if (hr == S_FALSE) {
  1017. LogCommentFmt(L"Experimental mode not enabled.");
  1018. }
  1019. else {
  1020. LogCommentFmt(L"Experimental mode enabled.");
  1021. }
  1022. hr = EnableDebugLayer();
  1023. if (FAILED(hr)) {
  1024. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1025. }
  1026. else {
  1027. LogCommentFmt(L"Debug layer enabled.");
  1028. }
  1029. return true;
  1030. #endif
  1031. }
  1032. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1033. static const int DispatchGroupX = 1;
  1034. static const int DispatchGroupY = 1;
  1035. static const int DispatchGroupZ = 1;
  1036. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1037. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1038. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1039. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1040. UINT uavDescriptorSize;
  1041. FenceObj FO;
  1042. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1043. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1044. InitFenceObj(pDevice, &FO);
  1045. // Describe and create a UAV descriptor heap.
  1046. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1047. heapDesc.NumDescriptors = 1;
  1048. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1049. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1050. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1051. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1052. // Create root signature.
  1053. CComPtr<ID3D12RootSignature> pRootSignature;
  1054. {
  1055. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1056. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1057. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1058. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1059. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1060. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1061. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1062. }
  1063. // Create pipeline state object.
  1064. CComPtr<ID3D12PipelineState> pComputeState;
  1065. CreateComputePSO(pDevice, pRootSignature, pShader, &pComputeState);
  1066. // Create a command allocator and list for compute.
  1067. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1068. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1069. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1070. // Set up UAV resource.
  1071. CComPtr<ID3D12Resource> pUavResource;
  1072. CComPtr<ID3D12Resource> pReadBuffer;
  1073. CComPtr<ID3D12Resource> pUploadResource;
  1074. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pReadBuffer, &pUploadResource);
  1075. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1076. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1077. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1078. // Close the command list and execute it to perform the GPU setup.
  1079. pCommandList->Close();
  1080. ExecuteCommandList(pCommandQueue, pCommandList);
  1081. WaitForSignal(pCommandQueue, FO);
  1082. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1083. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1084. // Run the compute shader and copy the results back to readable memory.
  1085. {
  1086. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1087. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1088. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1089. uavDesc.Buffer.FirstElement = 0;
  1090. uavDesc.Buffer.NumElements = (UINT)values.size();
  1091. uavDesc.Buffer.StructureByteStride = 0;
  1092. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1093. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1094. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1095. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1096. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1097. SetDescriptorHeap(pCommandList, pUavHeap);
  1098. pCommandList->SetComputeRootSignature(pRootSignature);
  1099. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1100. }
  1101. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1102. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1103. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1104. pCommandList->Close();
  1105. ExecuteCommandList(pCommandQueue, pCommandList);
  1106. WaitForSignal(pCommandQueue, FO);
  1107. {
  1108. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1109. uint32_t *pData = (uint32_t *)mappedData.data();
  1110. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1111. }
  1112. WaitForSignal(pCommandQueue, FO);
  1113. }
  1114. TEST_F(ExecutionTest, BasicComputeTest) {
  1115. #ifndef _HLK_CONF
  1116. //
  1117. // BasicComputeTest is a simple compute shader that can be used as the basis
  1118. // for more interesting compute execution tests.
  1119. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1120. // rendering code paths for comparison.
  1121. //
  1122. static const char pShader[] =
  1123. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1124. "[numthreads(8,8,1)]\r\n"
  1125. "void main(uint GI : SV_GroupIndex) {"
  1126. " uint addr = GI * 4;\r\n"
  1127. " uint val = g_bab.Load(addr);\r\n"
  1128. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1129. " g_bab.Store(addr, val + 1);\r\n"
  1130. "}";
  1131. static const int NumThreadsX = 8;
  1132. static const int NumThreadsY = 8;
  1133. static const int NumThreadsZ = 1;
  1134. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1135. static const int DispatchGroupCount = 1;
  1136. CComPtr<ID3D12Device> pDevice;
  1137. if (!CreateDevice(&pDevice))
  1138. return;
  1139. std::vector<uint32_t> values;
  1140. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1141. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1142. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1143. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1144. #endif
  1145. }
  1146. TEST_F(ExecutionTest, BasicTriangleTest) {
  1147. #ifndef _HLK_CONF
  1148. static const UINT FrameCount = 2;
  1149. static const UINT m_width = 320;
  1150. static const UINT m_height = 200;
  1151. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1152. struct Vertex {
  1153. XMFLOAT3 position;
  1154. XMFLOAT4 color;
  1155. };
  1156. // Pipeline objects.
  1157. CComPtr<ID3D12Device> pDevice;
  1158. CComPtr<ID3D12Resource> pRenderTarget;
  1159. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1160. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1161. CComPtr<ID3D12RootSignature> pRootSig;
  1162. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1163. CComPtr<ID3D12PipelineState> pPipelineState;
  1164. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1165. CComPtr<ID3D12Resource> pReadBuffer;
  1166. UINT rtvDescriptorSize;
  1167. CComPtr<ID3D12Resource> pVertexBuffer;
  1168. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1169. // Synchronization objects.
  1170. FenceObj FO;
  1171. // Shaders.
  1172. static const char pShaders[] =
  1173. "struct PSInput {\r\n"
  1174. " float4 position : SV_POSITION;\r\n"
  1175. " float4 color : COLOR;\r\n"
  1176. "};\r\n\r\n"
  1177. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1178. " PSInput result;\r\n"
  1179. "\r\n"
  1180. " result.position = position;\r\n"
  1181. " result.color = color;\r\n"
  1182. " return result;\r\n"
  1183. "}\r\n\r\n"
  1184. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1185. " return 1; //input.color;\r\n"
  1186. "};\r\n";
  1187. if (!CreateDevice(&pDevice))
  1188. return;
  1189. struct BasicTestChecker {
  1190. CComPtr<ID3D12Device> m_pDevice;
  1191. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1192. bool m_OK = false;
  1193. void SetOK(bool value) { m_OK = value; }
  1194. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1195. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1196. return;
  1197. m_pInfoQueue->PushEmptyStorageFilter();
  1198. m_pInfoQueue->PushEmptyRetrievalFilter();
  1199. }
  1200. ~BasicTestChecker() {
  1201. if (!m_OK && m_pInfoQueue != nullptr) {
  1202. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1203. bool invalidBytecodeFound = false;
  1204. CAtlArray<BYTE> m_pBytes;
  1205. for (UINT64 i = 0; i < count; ++i) {
  1206. SIZE_T len = 0;
  1207. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1208. continue;
  1209. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1210. continue;
  1211. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1212. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1213. continue;
  1214. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1215. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1216. invalidBytecodeFound = true;
  1217. break;
  1218. }
  1219. }
  1220. if (invalidBytecodeFound) {
  1221. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1222. L"typically indicates that experimental mode "
  1223. L"is not set up properly.");
  1224. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1225. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1226. }
  1227. }
  1228. else {
  1229. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1230. L"queue - dumping complete queue.");
  1231. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1232. }
  1233. }
  1234. }
  1235. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1236. LogCommentFmt(L"%s", pMsg);
  1237. }
  1238. };
  1239. BasicTestChecker BTC(pDevice);
  1240. {
  1241. InitFenceObj(pDevice, &FO);
  1242. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1243. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1244. // Create an empty root signature.
  1245. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1246. rootSignatureDesc.Init(
  1247. 0, nullptr, 0, nullptr,
  1248. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1249. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1250. // Create the pipeline state, which includes compiling and loading shaders.
  1251. // Define the vertex input layout.
  1252. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1253. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1254. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1255. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1256. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1257. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1258. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1259. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1260. &pCommandAllocator, &pCommandList,
  1261. pPipelineState);
  1262. // Define the geometry for a triangle.
  1263. Vertex triangleVertices[] = {
  1264. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1265. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1266. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1267. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1268. WaitForSignal(pCommandQueue, FO);
  1269. }
  1270. // Render and execute the command list.
  1271. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1272. &vertexBufferView, pRootSig, pRenderTarget,
  1273. pReadBuffer);
  1274. VERIFY_SUCCEEDED(pCommandList->Close());
  1275. ExecuteCommandList(pCommandQueue, pCommandList);
  1276. // Wait for previous frame.
  1277. WaitForSignal(pCommandQueue, FO);
  1278. // At this point, we've verified that execution succeeded with DXIL.
  1279. BTC.SetOK(true);
  1280. // Read back to CPU and examine contents.
  1281. {
  1282. MappedData data(pReadBuffer, m_width * m_height * 4);
  1283. const uint32_t *pPixels = (uint32_t *)data.data();
  1284. if (SaveImages()) {
  1285. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1286. }
  1287. uint32_t top = pPixels[m_width / 2]; // Top center.
  1288. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1289. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1290. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1291. }
  1292. #endif
  1293. }
  1294. TEST_F(ExecutionTest, Int64Test) {
  1295. static const char pShader[] =
  1296. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1297. "[numthreads(8,8,1)]\r\n"
  1298. "void main(uint GI : SV_GroupIndex) {"
  1299. " uint addr = GI * 4;\r\n"
  1300. " uint val = g_bab.Load(addr);\r\n"
  1301. " uint64_t u64 = val;\r\n"
  1302. " u64 *= val;\r\n"
  1303. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1304. "}";
  1305. static const int NumThreadsX = 8;
  1306. static const int NumThreadsY = 8;
  1307. static const int NumThreadsZ = 1;
  1308. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1309. static const int DispatchGroupCount = 1;
  1310. CComPtr<ID3D12Device> pDevice;
  1311. if (!CreateDevice(&pDevice))
  1312. return;
  1313. if (!DoesDeviceSupportInt64(pDevice)) {
  1314. // Optional feature, so it's correct to not support it if declared as such.
  1315. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1316. return;
  1317. }
  1318. std::vector<uint32_t> values;
  1319. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1320. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1321. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1322. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1323. }
  1324. TEST_F(ExecutionTest, SignTest) {
  1325. static const char pShader[] =
  1326. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1327. "[numthreads(8,1,1)]\r\n"
  1328. "void main(uint GI : SV_GroupIndex) {"
  1329. " uint addr = GI * 4;\r\n"
  1330. " int val = g_bab.Load(addr);\r\n"
  1331. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1332. "}";
  1333. static const int NumThreadsX = 8;
  1334. static const int NumThreadsY = 1;
  1335. static const int NumThreadsZ = 1;
  1336. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1337. static const int DispatchGroupCount = 1;
  1338. CComPtr<ID3D12Device> pDevice;
  1339. if (!CreateDevice(&pDevice))
  1340. return;
  1341. const uint32_t neg1 = (uint32_t)-1;
  1342. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1343. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1344. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1345. VERIFY_ARE_EQUAL(values[0], neg1);
  1346. VERIFY_ARE_EQUAL(values[1], neg1);
  1347. VERIFY_ARE_EQUAL(values[2], neg1);
  1348. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1349. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1350. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1351. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1352. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1353. }
  1354. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1355. #ifndef _HLK_CONF
  1356. CComPtr<ID3D12Device> pDevice;
  1357. if (!CreateDevice(&pDevice))
  1358. return;
  1359. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1360. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1361. return;
  1362. bool waveSupported = O.WaveOps;
  1363. UINT laneCountMin = O.WaveLaneCountMin;
  1364. UINT laneCountMax = O.WaveLaneCountMax;
  1365. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1366. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1367. if (waveSupported) {
  1368. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1369. }
  1370. else {
  1371. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1372. }
  1373. #endif
  1374. }
  1375. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1376. #ifndef _HLK_CONF
  1377. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1378. struct PerThreadData {
  1379. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1380. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1381. uint32_t pfBC, pfSum, pfProd;
  1382. uint32_t ballot[4];
  1383. uint32_t diver; // divergent value, used in calculation
  1384. int32_t i_diver; // divergent value, used in calculation
  1385. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1386. int32_t i_pfSum, i_pfProd;
  1387. };
  1388. static const char pShader[] =
  1389. WAVE_INTRINSIC_DXBC_GUARD
  1390. "struct PerThreadData {\r\n"
  1391. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1392. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1393. " uint pfBC, pfSum, pfProd;\r\n"
  1394. " uint4 ballot;\r\n"
  1395. " uint diver;\r\n"
  1396. " int i_diver;\r\n"
  1397. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1398. " int i_pfSum, i_pfProd;\r\n"
  1399. "};\r\n"
  1400. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1401. "[numthreads(8,8,1)]\r\n"
  1402. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1403. " PerThreadData pts = g_sb[GI];\r\n"
  1404. " uint diver = GTID.x + 2;\r\n"
  1405. " pts.diver = diver;\r\n"
  1406. " pts.flags = 0;\r\n"
  1407. " pts.preds = 0;\r\n"
  1408. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1409. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1410. " pts.laneCount = WaveGetLaneCount();\r\n"
  1411. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1412. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1413. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1414. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1415. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1416. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1417. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1418. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1419. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1420. "\r\n"
  1421. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1422. " pts.allSum = WaveActiveSum(diver);\r\n"
  1423. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1424. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1425. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1426. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1427. " pts.allMin = WaveActiveMin(diver);\r\n"
  1428. " pts.allMax = WaveActiveMax(diver);\r\n"
  1429. "\r\n"
  1430. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1431. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1432. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1433. "\r\n"
  1434. " int i_diver = pts.i_diver;\r\n"
  1435. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1436. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1437. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1438. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1439. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1440. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1441. "\r\n"
  1442. " g_sb[GI] = pts;\r\n"
  1443. "}";
  1444. static const int NumtheadsX = 8;
  1445. static const int NumtheadsY = 8;
  1446. static const int NumtheadsZ = 1;
  1447. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1448. static const int DispatchGroupCount = 1;
  1449. CComPtr<ID3D12Device> pDevice;
  1450. if (!CreateDevice(&pDevice))
  1451. return;
  1452. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1453. // Optional feature, so it's correct to not support it if declared as such.
  1454. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1455. return;
  1456. }
  1457. std::vector<PerThreadData> values;
  1458. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1459. for (size_t i = 0; i < values.size(); ++i) {
  1460. memset(&values[i], 0, sizeof(PerThreadData));
  1461. values[i].id = i;
  1462. values[i].i_diver = (int)i;
  1463. values[i].i_diver *= (i % 2) ? 1 : -1;
  1464. }
  1465. static const int DispatchGroupX = 1;
  1466. static const int DispatchGroupY = 1;
  1467. static const int DispatchGroupZ = 1;
  1468. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1469. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1470. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1471. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1472. UINT uavDescriptorSize;
  1473. FenceObj FO;
  1474. bool dxbc = UseDxbc();
  1475. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1476. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1477. InitFenceObj(pDevice, &FO);
  1478. // Describe and create a UAV descriptor heap.
  1479. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1480. heapDesc.NumDescriptors = 1;
  1481. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1482. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1483. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1484. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1485. // Create root signature.
  1486. CComPtr<ID3D12RootSignature> pRootSignature;
  1487. {
  1488. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1489. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1490. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1491. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1492. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1493. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1494. CComPtr<ID3DBlob> signature;
  1495. CComPtr<ID3DBlob> error;
  1496. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  1497. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  1498. }
  1499. // Create pipeline state object.
  1500. CComPtr<ID3D12PipelineState> pComputeState;
  1501. CreateComputePSO(pDevice, pRootSignature, pShader, &pComputeState);
  1502. // Create a command allocator and list for compute.
  1503. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1504. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1505. // Set up UAV resource.
  1506. CComPtr<ID3D12Resource> pUavResource;
  1507. CComPtr<ID3D12Resource> pReadBuffer;
  1508. CComPtr<ID3D12Resource> pUploadResource;
  1509. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pReadBuffer, &pUploadResource);
  1510. // Close the command list and execute it to perform the GPU setup.
  1511. pCommandList->Close();
  1512. ExecuteCommandList(pCommandQueue, pCommandList);
  1513. WaitForSignal(pCommandQueue, FO);
  1514. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1515. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1516. // Run the compute shader and copy the results back to readable memory.
  1517. {
  1518. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1519. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  1520. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1521. uavDesc.Buffer.FirstElement = 0;
  1522. uavDesc.Buffer.NumElements = values.size();
  1523. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  1524. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1525. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  1526. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1527. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1528. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1529. SetDescriptorHeap(pCommandList, pUavHeap);
  1530. pCommandList->SetComputeRootSignature(pRootSignature);
  1531. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1532. }
  1533. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1534. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1535. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1536. pCommandList->Close();
  1537. ExecuteCommandList(pCommandQueue, pCommandList);
  1538. WaitForSignal(pCommandQueue, FO);
  1539. {
  1540. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1541. PerThreadData *pData = (PerThreadData *)mappedData.data();
  1542. memcpy(values.data(), pData, valueSizeInBytes);
  1543. // Gather some general data.
  1544. // The 'firstLaneId' captures a unique number per first-lane per wave.
  1545. // Counting the number distinct firstLaneIds gives us the number of waves.
  1546. std::vector<uint32_t> firstLaneIds;
  1547. for (size_t i = 0; i < values.size(); ++i) {
  1548. PerThreadData &pts = values[i];
  1549. uint32_t firstLaneId = pts.firstLaneId;
  1550. if (!contains(firstLaneIds, firstLaneId)) {
  1551. firstLaneIds.push_back(firstLaneId);
  1552. }
  1553. }
  1554. // Waves should cover 4 threads or more.
  1555. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  1556. if (!dxbc) {
  1557. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  1558. }
  1559. // Now, group threads into waves.
  1560. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  1561. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  1562. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  1563. }
  1564. for (size_t i = 0; i < values.size(); ++i) {
  1565. PerThreadData &pts = values[i];
  1566. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  1567. wave->push_back(&pts);
  1568. }
  1569. // Verify that all the wave values are coherent across the wave.
  1570. for (size_t i = 0; i < values.size(); ++i) {
  1571. PerThreadData &pts = values[i];
  1572. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  1573. // Sort the lanes by increasing lane ID.
  1574. struct LaneIdOrderPred {
  1575. bool operator()(PerThreadData *a, PerThreadData *b) {
  1576. return a->laneIndex < b->laneIndex;
  1577. }
  1578. };
  1579. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  1580. // Verify some interesting properties of the first lane.
  1581. uint32_t pfBC, pfSum, pfProd;
  1582. int32_t i_pfSum, i_pfProd;
  1583. int32_t i_allMax, i_allMin;
  1584. {
  1585. PerThreadData *ptdFirst = wave->front();
  1586. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  1587. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  1588. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  1589. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  1590. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  1591. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  1592. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  1593. pfSum = ptdFirst->diver;
  1594. pfProd = ptdFirst->diver;
  1595. i_pfSum = ptdFirst->i_diver;
  1596. i_pfProd = ptdFirst->i_diver;
  1597. i_allMax = i_allMin = ptdFirst->i_diver;
  1598. }
  1599. // Calculate values which take into consideration all lanes.
  1600. uint32_t preds = 0;
  1601. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  1602. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  1603. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  1604. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  1605. uint32_t ballot[4] = { 0, 0, 0, 0 };
  1606. int32_t i_allSum = 0, i_allProd = 1;
  1607. for (size_t n = 0; n < wave->size(); ++n) {
  1608. std::vector<PerThreadData *> &lanes = *wave.get();
  1609. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  1610. if (lanes[n]->diver == 1) preds |= (1 << 0);
  1611. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  1612. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  1613. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  1614. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  1615. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1616. if (lanes[n]->diver > 3) {
  1617. // This is the uint4 result layout:
  1618. // .x -> bits 0 .. 31
  1619. // .y -> bits 32 .. 63
  1620. // .z -> bits 64 .. 95
  1621. // .w -> bits 96 ..127
  1622. uint32_t component = lanes[n]->laneIndex / 32;
  1623. uint32_t bit = lanes[n]->laneIndex % 32;
  1624. ballot[component] |= 1 << bit;
  1625. }
  1626. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  1627. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  1628. i_allProd *= lanes[n]->i_diver;
  1629. i_allSum += lanes[n]->i_diver;
  1630. }
  1631. for (size_t n = 1; n < wave->size(); ++n) {
  1632. // 'All' operations are uniform across the wave.
  1633. std::vector<PerThreadData *> &lanes = *wave.get();
  1634. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  1635. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  1636. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  1637. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  1638. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  1639. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  1640. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  1641. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  1642. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  1643. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  1644. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  1645. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  1646. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  1647. // first-lane reads and uniform reads are uniform across the wave.
  1648. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  1649. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  1650. // the lane count is uniform across the wave.
  1651. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  1652. // The predicates are uniform across the wave.
  1653. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  1654. // the lane index is distinct per thread.
  1655. for (size_t prior = 0; prior < n; ++prior) {
  1656. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  1657. }
  1658. // Ballot results are uniform across the wave.
  1659. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  1660. // Keep running total of prefix calculation. Prefix values are exclusive to
  1661. // the executing lane.
  1662. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  1663. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  1664. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  1665. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  1666. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  1667. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  1668. pfSum += lanes[n]->diver;
  1669. pfProd *= lanes[n]->diver;
  1670. i_pfSum += lanes[n]->i_diver;
  1671. i_pfProd *= lanes[n]->i_diver;
  1672. }
  1673. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  1674. }
  1675. // Compare each value of each per-thread element.
  1676. for (size_t i = 0; i < values.size(); ++i) {
  1677. PerThreadData &pts = values[i];
  1678. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  1679. }
  1680. }
  1681. #endif
  1682. }
  1683. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  1684. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  1685. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1686. struct Vertex {
  1687. XMFLOAT3 position;
  1688. };
  1689. struct PerPixelData {
  1690. XMFLOAT4 position;
  1691. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  1692. uint32_t id0, id1, id2, id3;
  1693. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  1694. };
  1695. const UINT RTWidth = 128;
  1696. const UINT RTHeight = 128;
  1697. // Shaders.
  1698. static const char pShaders[] =
  1699. WAVE_INTRINSIC_DXBC_GUARD
  1700. "struct PSInput {\r\n"
  1701. " float4 position : SV_POSITION;\r\n"
  1702. "};\r\n\r\n"
  1703. "PSInput VSMain(float4 position : POSITION) {\r\n"
  1704. " PSInput result;\r\n"
  1705. "\r\n"
  1706. " result.position = position;\r\n"
  1707. " return result;\r\n"
  1708. "}\r\n\r\n"
  1709. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  1710. "struct PerPixelData {\r\n"
  1711. " float4 position;\r\n"
  1712. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  1713. " uint id0, id1, id2, id3;\r\n"
  1714. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  1715. "};\r\n"
  1716. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  1717. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1718. " uint one = 1;\r\n"
  1719. " PerPixelData d;\r\n"
  1720. " d.position = input.position;\r\n"
  1721. " d.id = pos_to_id(input.position);\r\n"
  1722. " d.flags = 0;\r\n"
  1723. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  1724. " d.laneIndex = WaveGetLaneIndex();\r\n"
  1725. " d.laneCount = WaveGetLaneCount();\r\n"
  1726. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  1727. " d.sum1 = WaveActiveSum(one);\r\n"
  1728. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  1729. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  1730. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  1731. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  1732. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  1733. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  1734. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  1735. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  1736. " g_sb.Append(d);\r\n"
  1737. " return 1;\r\n"
  1738. "};\r\n";
  1739. CComPtr<ID3D12Device> pDevice;
  1740. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1741. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  1742. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1743. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1744. CComPtr<ID3D12PipelineState> pPSO;
  1745. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  1746. UINT uavDescriptorSize, rtvDescriptorSize;
  1747. CComPtr<ID3D12Resource> pVertexBuffer;
  1748. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1749. if (!CreateDevice(&pDevice))
  1750. return;
  1751. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1752. // Optional feature, so it's correct to not support it if declared as such.
  1753. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1754. return;
  1755. }
  1756. FenceObj FO;
  1757. InitFenceObj(pDevice, &FO);
  1758. // Describe and create a UAV descriptor heap.
  1759. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1760. heapDesc.NumDescriptors = 1;
  1761. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1762. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1763. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1764. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1765. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  1766. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  1767. // Create root signature: one UAV.
  1768. CComPtr<ID3D12RootSignature> pRootSignature;
  1769. {
  1770. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1771. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  1772. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1773. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1774. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1775. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1776. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1777. }
  1778. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  1779. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1780. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1781. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  1782. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  1783. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  1784. &pCommandList, pPSO);
  1785. // Single triangle covering half the target.
  1786. Vertex vertices[] = {
  1787. { { -1.0f, 1.0f, 0.0f } },
  1788. { { 1.0f, 1.0f, 0.0f } },
  1789. { { -1.0f, -1.0f, 0.0f } } };
  1790. const UINT TriangleCount = _countof(vertices) / 3;
  1791. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  1792. bool dxbc = UseDxbc();
  1793. // Set up UAV resource.
  1794. std::vector<PerPixelData> values;
  1795. values.resize(RTWidth * RTHeight * 2);
  1796. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  1797. memset(values.data(), 0, valueSizeInBytes);
  1798. CComPtr<ID3D12Resource> pUavResource;
  1799. CComPtr<ID3D12Resource> pUavReadBuffer;
  1800. CComPtr<ID3D12Resource> pUploadResource;
  1801. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUavReadBuffer, &pUploadResource);
  1802. // Set up the append counter resource.
  1803. CComPtr<ID3D12Resource> pUavCounterResource;
  1804. CComPtr<ID3D12Resource> pReadCounterBuffer;
  1805. CComPtr<ID3D12Resource> pUploadCounterResource;
  1806. BYTE zero[sizeof(UINT)] = { 0 };
  1807. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pReadCounterBuffer, &pUploadCounterResource);
  1808. // Close the command list and execute it to perform the GPU setup.
  1809. pCommandList->Close();
  1810. ExecuteCommandList(pCommandQueue, pCommandList);
  1811. WaitForSignal(pCommandQueue, FO);
  1812. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1813. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  1814. pCommandList->SetGraphicsRootSignature(pRootSignature);
  1815. SetDescriptorHeap(pCommandList, pUavHeap);
  1816. {
  1817. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1818. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  1819. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1820. uavDesc.Buffer.FirstElement = 0;
  1821. uavDesc.Buffer.NumElements = (UINT)values.size();
  1822. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  1823. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1824. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  1825. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1826. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1827. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  1828. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  1829. }
  1830. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  1831. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1832. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1833. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  1834. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  1835. VERIFY_SUCCEEDED(pCommandList->Close());
  1836. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  1837. ExecuteCommandList(pCommandQueue, pCommandList);
  1838. WaitForSignal(pCommandQueue, FO);
  1839. {
  1840. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  1841. const uint32_t *pPixels = (uint32_t *)data.data();
  1842. if (SaveImages()) {
  1843. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  1844. }
  1845. }
  1846. uint32_t appendCount;
  1847. {
  1848. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  1849. appendCount = *((uint32_t *)mappedData.data());
  1850. LogCommentFmt(L"%u elements in append buffer", appendCount);
  1851. }
  1852. {
  1853. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  1854. PerPixelData *pData = (PerPixelData *)mappedData.data();
  1855. memcpy(values.data(), pData, valueSizeInBytes);
  1856. // DXBC is handy to test pipeline setup, but interesting functions are
  1857. // stubbed out, so there is no point in further validation.
  1858. if (dxbc)
  1859. return;
  1860. uint32_t maxActiveLaneCount = 0;
  1861. uint32_t maxLaneCount = 0;
  1862. for (uint32_t i = 0; i < appendCount; ++i) {
  1863. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  1864. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  1865. }
  1866. uint32_t peerOfHelperLanes = 0;
  1867. for (uint32_t i = 0; i < appendCount; ++i) {
  1868. if (values[i].sum1 != maxActiveLaneCount) {
  1869. ++peerOfHelperLanes;
  1870. }
  1871. }
  1872. LogCommentFmt(
  1873. L"Found: %u threads. Waves reported up to %u total lanes, up "
  1874. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  1875. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  1876. // Group threads into quad invocations.
  1877. uint32_t singlePixelCount = 0;
  1878. uint32_t multiPixelCount = 0;
  1879. std::unordered_set<uint32_t> ids;
  1880. std::multimap<uint32_t, PerPixelData *> idGroups;
  1881. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  1882. for (uint32_t i = 0; i < appendCount; ++i) {
  1883. ids.insert(values[i].id);
  1884. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  1885. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  1886. }
  1887. for (uint32_t id : ids) {
  1888. if (idGroups.count(id) == 1)
  1889. ++singlePixelCount;
  1890. else
  1891. ++multiPixelCount;
  1892. }
  1893. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  1894. singlePixelCount, multiPixelCount);
  1895. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  1896. // Where every pixel is distinct, it's very straightforward to validate.
  1897. {
  1898. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  1899. while (cur != end) {
  1900. bool simpleWave = true;
  1901. uint32_t firstId = (*cur).first;
  1902. auto groupEnd = cur;
  1903. while (groupEnd != end && (*groupEnd).first == firstId) {
  1904. if (idGroups.count((*groupEnd).second->id) > 1)
  1905. simpleWave = false;
  1906. ++groupEnd;
  1907. }
  1908. if (simpleWave) {
  1909. // Break the wave into quads.
  1910. struct QuadData {
  1911. unsigned count;
  1912. PerPixelData *data[4];
  1913. };
  1914. std::map<uint32_t, QuadData> quads;
  1915. for (auto i = cur; i != groupEnd; ++i) {
  1916. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  1917. uint32_t laneId = (*i).second->id;
  1918. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  1919. (*i).second->id2, (*i).second->id3};
  1920. // Since this is a simple wave, each lane has an unique id and
  1921. // therefore should not have any ids in there.
  1922. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  1923. // check if QuadReadLaneAt is returning same values in a single quad.
  1924. bool newQuad = true;
  1925. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  1926. auto match = quads.find(laneIds[quadIndex]);
  1927. if (match != quads.end()) {
  1928. (*match).second.data[(*match).second.count++] = (*i).second;
  1929. newQuad = false;
  1930. break;
  1931. }
  1932. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  1933. if (quadMemberData != idGroups.end()) {
  1934. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  1935. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  1936. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  1937. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  1938. }
  1939. }
  1940. if (newQuad) {
  1941. QuadData qdata;
  1942. qdata.count = 1;
  1943. qdata.data[0] = (*i).second;
  1944. quads.insert(std::make_pair(laneId, qdata));
  1945. }
  1946. }
  1947. for (auto quadPair : quads) {
  1948. unsigned count = quadPair.second.count;
  1949. // There could be only one pixel data on the edge of the triangle
  1950. if (count < 2) continue;
  1951. PerPixelData **data = quadPair.second.data;
  1952. bool isTop[4];
  1953. bool isLeft[4];
  1954. PerPixelData helperData;
  1955. memset(&helperData, sizeof(helperData), 0);
  1956. PerPixelData *layout[4]; // tl,tr,bl,br
  1957. memset(layout, sizeof(layout), 0);
  1958. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  1959. int idx = top ? 0 : 2;
  1960. idx += left ? 0 : 1;
  1961. return &layout[idx];
  1962. };
  1963. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  1964. PerPixelData **pResult = fnToLayout(top, left);
  1965. if (*pResult == nullptr) return &helperData;
  1966. return *pResult;
  1967. };
  1968. VERIFY_IS_TRUE(count <= 4);
  1969. if (count == 2) {
  1970. isTop[0] = data[0]->position.y < data[1]->position.y;
  1971. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  1972. isLeft[0] = data[0]->position.x < data[1]->position.x;
  1973. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  1974. }
  1975. else {
  1976. // with at least three samples, we have distinct x and y coordinates.
  1977. float left = std::min(data[0]->position.x, data[1]->position.x);
  1978. left = std::min(data[2]->position.x, left);
  1979. float top = std::min(data[0]->position.y, data[1]->position.y);
  1980. top = std::min(data[2]->position.y, top);
  1981. for (unsigned i = 0; i < count; ++i) {
  1982. isTop[i] = data[i]->position.y == top;
  1983. isLeft[i] = data[i]->position.x == left;
  1984. }
  1985. }
  1986. for (unsigned i = 0; i < count; ++i) {
  1987. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  1988. }
  1989. // Finally, we have a proper quad reconstructed. Validate.
  1990. for (unsigned i = 0; i < count; ++i) {
  1991. PerPixelData *d = data[i];
  1992. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  1993. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  1994. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  1995. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  1996. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  1997. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  1998. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  1999. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2000. }
  2001. }
  2002. }
  2003. cur = groupEnd;
  2004. }
  2005. }
  2006. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2007. //
  2008. // Consider: for pixels that were shaded multiple times, check whether
  2009. // some grouping of threads into quads satisfies all value requirements.
  2010. }
  2011. }
  2012. struct ShaderOpTestResult {
  2013. st::ShaderOp *ShaderOp;
  2014. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2015. std::shared_ptr<st::ShaderOpTest> Test;
  2016. };
  2017. struct SPrimitives {
  2018. float f_float;
  2019. float f_float2;
  2020. float f_float_o;
  2021. float f_float2_o;
  2022. };
  2023. std::shared_ptr<ShaderOpTestResult>
  2024. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2025. LPCSTR pName,
  2026. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2027. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2028. st::ShaderOp *pShaderOp;
  2029. if (pName == nullptr) {
  2030. if (ShaderOpSet->ShaderOps.size() != 1) {
  2031. VERIFY_FAIL(L"Expected a single shader operation.");
  2032. }
  2033. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2034. }
  2035. else {
  2036. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2037. }
  2038. if (pShaderOp == nullptr) {
  2039. std::string msg = "Unable to find shader op ";
  2040. msg += pName;
  2041. msg += "; available ops";
  2042. const char sep = ':';
  2043. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2044. msg += sep;
  2045. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2046. }
  2047. CA2W msgWide(msg.c_str());
  2048. VERIFY_FAIL(msgWide.m_psz);
  2049. }
  2050. // This won't actually be used since we're supplying the device,
  2051. // but let's make it consistent.
  2052. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2053. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2054. test->SetDxcSupport(&support);
  2055. test->SetInitCallback(pInitCallback);
  2056. test->SetDevice(pDevice);
  2057. test->RunShaderOp(pShaderOp);
  2058. std::shared_ptr<ShaderOpTestResult> result =
  2059. std::make_shared<ShaderOpTestResult>();
  2060. result->ShaderOpSet = ShaderOpSet;
  2061. result->Test = test;
  2062. result->ShaderOp = pShaderOp;
  2063. return result;
  2064. }
  2065. std::shared_ptr<ShaderOpTestResult>
  2066. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2067. IStream *pStream, LPCSTR pName,
  2068. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2069. DXASSERT_NOMSG(pStream != nullptr);
  2070. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2071. std::make_shared<st::ShaderOpSet>();
  2072. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2073. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2074. }
  2075. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2076. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2077. CComPtr<IStream> pStream;
  2078. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2079. // Single operation test at the moment.
  2080. CComPtr<ID3D12Device> pDevice;
  2081. if (!CreateDevice(&pDevice))
  2082. return;
  2083. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2084. MappedData data;
  2085. // Read back to CPU and examine contents - should get pure red.
  2086. {
  2087. MappedData data;
  2088. test->Test->GetReadBackData("RTarget", &data);
  2089. const uint32_t *pPixels = (uint32_t *)data.data();
  2090. uint32_t first = *pPixels;
  2091. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2092. }
  2093. }
  2094. TEST_F(ExecutionTest, SaturateTest) {
  2095. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2096. CComPtr<IStream> pStream;
  2097. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2098. // Single operation test at the moment.
  2099. CComPtr<ID3D12Device> pDevice;
  2100. if (!CreateDevice(&pDevice))
  2101. return;
  2102. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2103. MappedData data;
  2104. test->Test->GetReadBackData("U0", &data);
  2105. const float *pValues = (float *)data.data();
  2106. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2107. const float ExpectedCases[9] = {
  2108. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2109. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2110. 0.0f // nan
  2111. };
  2112. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2113. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2114. ++pValues;
  2115. }
  2116. }
  2117. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2118. #ifdef _HLK_CONF
  2119. UNREFERENCED_PARAMETER(ShaderOpName);
  2120. UNREFERENCED_PARAMETER(FileName);
  2121. UNREFERENCED_PARAMETER(testModel);
  2122. #else
  2123. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2124. CComPtr<IStream> pStream;
  2125. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2126. // Single operation test at the moment.
  2127. CComPtr<ID3D12Device> pDevice;
  2128. if (!CreateDevice(&pDevice, testModel))
  2129. return;
  2130. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2131. MappedData data;
  2132. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2133. UINT width = (UINT64)D.Width;
  2134. UINT height = (UINT64)D.Height;
  2135. test->Test->GetReadBackData("RTarget", &data);
  2136. const uint32_t *pPixels = (uint32_t *)data.data();
  2137. if (SaveImages()) {
  2138. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2139. }
  2140. uint32_t top = pPixels[width / 2]; // Top center.
  2141. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2142. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2143. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2144. // This is the basic validation test for shader operations, so it's good to
  2145. // check this here at least for this one test case.
  2146. data.reset();
  2147. test.reset();
  2148. ReportLiveObjects();
  2149. #endif
  2150. }
  2151. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2152. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2153. }
  2154. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2155. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2156. }
  2157. // Rendering two right triangles forming a square and assigning a texture value
  2158. // for each pixel to calculate derivates.
  2159. TEST_F(ExecutionTest, PartialDerivTest) {
  2160. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2161. CComPtr<IStream> pStream;
  2162. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2163. CComPtr<ID3D12Device> pDevice;
  2164. if (!CreateDevice(&pDevice))
  2165. return;
  2166. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2167. MappedData data;
  2168. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2169. UINT width = (UINT)D.Width;
  2170. UINT height = D.Height;
  2171. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2172. test->Test->GetReadBackData("RTarget", &data);
  2173. const float *pPixels = (float *)data.data();
  2174. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2175. // pixel at the center
  2176. UINT offsetCenter = centerIndex * pixelSize;
  2177. float CenterDDXFine = pPixels[offsetCenter];
  2178. float CenterDDYFine = pPixels[offsetCenter + 1];
  2179. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2180. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2181. LogCommentFmt(
  2182. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2183. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2184. // The texture for the 9 pixels in the center should look like the following
  2185. // 256 32 64
  2186. // 2048 256 512
  2187. // 1 .125 .25
  2188. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2189. // So for fine derivatives there can be up to two possible results for the center pixel,
  2190. // while for coarse derivatives there can be up to six possible results.
  2191. int ulpTolerance = 1;
  2192. // 512 - 256 or 2048 - 256
  2193. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2194. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2195. // 256 - 32 or 256 - .125
  2196. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2197. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2198. if (top && left) {
  2199. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2200. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2201. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2202. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2203. }
  2204. else if (top) { // top right quad
  2205. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2206. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2207. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2208. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2209. }
  2210. else if (left) { // bottom left quad
  2211. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2212. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2213. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2214. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2215. }
  2216. else { // bottom right
  2217. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2218. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2219. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2220. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2221. }
  2222. }
  2223. // Executing a simple binop to verify shadel model 6.1 support; runs with
  2224. // ShaderModel61.CoreRequirement
  2225. TEST_F(ExecutionTest, BasicShaderModel61) {
  2226. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  2227. }
  2228. // Executing a simple binop to verify shadel model 6.3 support; runs with
  2229. // ShaderModel63.CoreRequirement
  2230. TEST_F(ExecutionTest, BasicShaderModel63) {
  2231. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  2232. }
  2233. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  2234. WEX::TestExecution::SetVerifyOutput verifySettings(
  2235. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2236. CComPtr<ID3D12Device> pDevice;
  2237. if (!CreateDevice(&pDevice, shaderModel)) {
  2238. return;
  2239. }
  2240. char *pShaderModelStr;
  2241. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  2242. pShaderModelStr = "cs_6_1";
  2243. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  2244. pShaderModelStr = "cs_6_3";
  2245. } else {
  2246. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  2247. pShaderModelStr = nullptr;
  2248. }
  2249. const char shaderTemplate[] =
  2250. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  2251. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  2252. "[numthreads(8,8,1)]"
  2253. "void main(uint GI : SV_GroupIndex) {"
  2254. " SBinaryOp l = g_buf[GI];"
  2255. " l.output = l.input1 + l.input2;"
  2256. " g_buf[GI] = l;"
  2257. "}";
  2258. char shader[sizeof(shaderTemplate) + 50];
  2259. // Run simple shader with float data types
  2260. char* sTy = "float";
  2261. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  2262. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  2263. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  2264. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  2265. // Run simple shader with double data types
  2266. if (DoesDeviceSupportDouble(pDevice)) {
  2267. sTy = "double";
  2268. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  2269. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  2270. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  2271. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  2272. }
  2273. else {
  2274. // Optional feature, so it's correct to not support it if declared as such.
  2275. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  2276. }
  2277. // Run simple shader with int64 types
  2278. if (DoesDeviceSupportInt64(pDevice)) {
  2279. sTy = "int64_t";
  2280. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  2281. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  2282. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  2283. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  2284. }
  2285. else {
  2286. // Optional feature, so it's correct to not support it if declared as such.
  2287. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  2288. }
  2289. }
  2290. template <class Ty>
  2291. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  2292. DXASSERT_NOMSG("Unsupported type");
  2293. return "";
  2294. }
  2295. template <>
  2296. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  2297. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  2298. }
  2299. template <>
  2300. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  2301. return BasicShaderModelTest_GetFormatString<float>();
  2302. }
  2303. template <>
  2304. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  2305. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  2306. }
  2307. template <class Ty>
  2308. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  2309. Ty *pInputDataPairs, unsigned inputDataCount) {
  2310. struct SBinaryOp {
  2311. Ty input1;
  2312. Ty input2;
  2313. Ty output;
  2314. };
  2315. CComPtr<IStream> pStream;
  2316. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2317. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  2318. pDevice, m_support, pStream, "BinaryFPOp",
  2319. // this callbacked is called when the test is creating the resource to run the test
  2320. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2321. UNREFERENCED_PARAMETER(Name);
  2322. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  2323. pShaderOp->Shaders.at(0).Text = pShader;
  2324. size_t size = sizeof(SBinaryOp) * inputDataCount;
  2325. Data.resize(size);
  2326. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  2327. Ty *pIn = pInputDataPairs;
  2328. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  2329. SBinaryOp *p = &pPrimitives[i];
  2330. p->input1 = pIn[0];
  2331. p->input2 = pIn[1];
  2332. }
  2333. });
  2334. VERIFY_SUCCEEDED(S_OK);
  2335. MappedData data;
  2336. test->Test->GetReadBackData("SBinaryFPOp", &data);
  2337. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  2338. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  2339. Ty *pIn = pInputDataPairs;
  2340. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  2341. Ty expValue = pIn[0] + pIn[1];
  2342. SBinaryOp *p = &pPrimitives[i];
  2343. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  2344. VERIFY_ARE_EQUAL(p->output, expValue);
  2345. }
  2346. }
  2347. // Resource structure for data-driven tests.
  2348. struct SUnaryFPOp {
  2349. float input;
  2350. float output;
  2351. };
  2352. struct SBinaryFPOp {
  2353. float input1;
  2354. float input2;
  2355. float output1;
  2356. float output2;
  2357. };
  2358. struct STertiaryFPOp {
  2359. float input1;
  2360. float input2;
  2361. float input3;
  2362. float output;
  2363. };
  2364. struct SUnaryHalfOp {
  2365. uint16_t input;
  2366. uint16_t output;
  2367. };
  2368. struct SBinaryHalfOp {
  2369. uint16_t input1;
  2370. uint16_t input2;
  2371. uint16_t output1;
  2372. uint16_t output2;
  2373. };
  2374. struct STertiaryHalfOp {
  2375. uint16_t input1;
  2376. uint16_t input2;
  2377. uint16_t input3;
  2378. uint16_t output;
  2379. };
  2380. struct SUnaryIntOp {
  2381. int input;
  2382. int output;
  2383. };
  2384. struct SUnaryUintOp {
  2385. unsigned int input;
  2386. unsigned int output;
  2387. };
  2388. struct SBinaryIntOp {
  2389. int input1;
  2390. int input2;
  2391. int output1;
  2392. int output2;
  2393. };
  2394. struct STertiaryIntOp {
  2395. int input1;
  2396. int input2;
  2397. int input3;
  2398. int output;
  2399. };
  2400. struct SBinaryUintOp {
  2401. unsigned int input1;
  2402. unsigned int input2;
  2403. unsigned int output1;
  2404. unsigned int output2;
  2405. };
  2406. struct STertiaryUintOp {
  2407. unsigned int input1;
  2408. unsigned int input2;
  2409. unsigned int input3;
  2410. unsigned int output;
  2411. };
  2412. struct SUnaryInt16Op {
  2413. short input;
  2414. short output;
  2415. };
  2416. struct SUnaryUint16Op {
  2417. unsigned short input;
  2418. unsigned short output;
  2419. };
  2420. struct SBinaryInt16Op {
  2421. short input1;
  2422. short input2;
  2423. short output1;
  2424. short output2;
  2425. };
  2426. struct STertiaryInt16Op {
  2427. short input1;
  2428. short input2;
  2429. short input3;
  2430. short output;
  2431. };
  2432. struct SBinaryUint16Op {
  2433. unsigned short input1;
  2434. unsigned short input2;
  2435. unsigned short output1;
  2436. unsigned short output2;
  2437. };
  2438. struct STertiaryUint16Op {
  2439. unsigned short input1;
  2440. unsigned short input2;
  2441. unsigned short input3;
  2442. unsigned short output;
  2443. };
  2444. // representation for HLSL float vectors
  2445. struct SDotOp {
  2446. XMFLOAT4 input1;
  2447. XMFLOAT4 input2;
  2448. float o_dot2;
  2449. float o_dot3;
  2450. float o_dot4;
  2451. };
  2452. struct Half2
  2453. {
  2454. uint16_t x;
  2455. uint16_t y;
  2456. Half2() = default;
  2457. Half2(const Half2&) = default;
  2458. Half2& operator=(const Half2&) = default;
  2459. Half2(Half2&&) = default;
  2460. Half2& operator=(Half2&&) = default;
  2461. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  2462. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  2463. };
  2464. struct SDot2AddHalfOp {
  2465. Half2 input1;
  2466. Half2 input2;
  2467. float acc;
  2468. float result;
  2469. };
  2470. struct SDot4AddI8PackedOp {
  2471. uint32_t input1;
  2472. uint32_t input2;
  2473. int32_t acc;
  2474. int32_t result;
  2475. };
  2476. struct SDot4AddU8PackedOp {
  2477. uint32_t input1;
  2478. uint32_t input2;
  2479. uint32_t acc;
  2480. uint32_t result;
  2481. };
  2482. struct SMsad4 {
  2483. unsigned int ref;
  2484. XMUINT2 src;
  2485. XMUINT4 accum;
  2486. XMUINT4 result;
  2487. };
  2488. // Parameter representation for taef data-driven tests
  2489. struct TableParameter {
  2490. LPCWSTR m_name;
  2491. enum TableParameterType {
  2492. INT8,
  2493. INT16,
  2494. INT32,
  2495. UINT,
  2496. FLOAT,
  2497. HALF,
  2498. DOUBLE,
  2499. STRING,
  2500. BOOL,
  2501. INT8_TABLE,
  2502. INT16_TABLE,
  2503. INT32_TABLE,
  2504. FLOAT_TABLE,
  2505. HALF_TABLE,
  2506. DOUBLE_TABLE,
  2507. STRING_TABLE,
  2508. UINT8_TABLE,
  2509. UINT16_TABLE,
  2510. UINT32_TABLE,
  2511. BOOL_TABLE
  2512. };
  2513. TableParameterType m_type;
  2514. bool m_required; // required parameter
  2515. int8_t m_int8;
  2516. int16_t m_int16;
  2517. int m_int32;
  2518. unsigned int m_uint;
  2519. float m_float;
  2520. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  2521. double m_double;
  2522. bool m_bool;
  2523. WEX::Common::String m_str;
  2524. std::vector<int8_t> m_int8Table;
  2525. std::vector<int16_t> m_int16Table;
  2526. std::vector<int> m_int32Table;
  2527. std::vector<uint8_t> m_uint8Table;
  2528. std::vector<uint16_t> m_uint16Table;
  2529. std::vector<unsigned int> m_uint32Table;
  2530. std::vector<float> m_floatTable;
  2531. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  2532. std::vector<double> m_doubleTable;
  2533. std::vector<bool> m_boolTable;
  2534. std::vector<WEX::Common::String> m_StringTable;
  2535. };
  2536. class TableParameterHandler {
  2537. private:
  2538. HRESULT ParseTableRow();
  2539. public:
  2540. TableParameter* m_table;
  2541. size_t m_tableSize;
  2542. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  2543. clearTableParameter();
  2544. VERIFY_SUCCEEDED(ParseTableRow());
  2545. }
  2546. TableParameter* GetTableParamByName(LPCWSTR name) {
  2547. for (size_t i = 0; i < m_tableSize; ++i) {
  2548. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2549. return &m_table[i];
  2550. }
  2551. }
  2552. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2553. return nullptr;
  2554. }
  2555. void clearTableParameter() {
  2556. for (size_t i = 0; i < m_tableSize; ++i) {
  2557. m_table[i].m_int32 = 0;
  2558. m_table[i].m_uint = 0;
  2559. m_table[i].m_double = 0;
  2560. m_table[i].m_bool = false;
  2561. m_table[i].m_str = WEX::Common::String();
  2562. }
  2563. }
  2564. template <class T1>
  2565. std::vector<T1> *GetDataArray(LPCWSTR name) {
  2566. return nullptr;
  2567. }
  2568. template <>
  2569. std::vector<int> *GetDataArray(LPCWSTR name) {
  2570. for (size_t i = 0; i < m_tableSize; ++i) {
  2571. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2572. return &(m_table[i].m_int32Table);
  2573. }
  2574. }
  2575. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2576. return nullptr;
  2577. }
  2578. template <>
  2579. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  2580. for (size_t i = 0; i < m_tableSize; ++i) {
  2581. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2582. return &(m_table[i].m_int8Table);
  2583. }
  2584. }
  2585. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2586. return nullptr;
  2587. }
  2588. template <>
  2589. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  2590. for (size_t i = 0; i < m_tableSize; ++i) {
  2591. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2592. return &(m_table[i].m_int16Table);
  2593. }
  2594. }
  2595. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2596. return nullptr;
  2597. }
  2598. template <>
  2599. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  2600. for (size_t i = 0; i < m_tableSize; ++i) {
  2601. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2602. return &(m_table[i].m_uint32Table);
  2603. }
  2604. }
  2605. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2606. return nullptr;
  2607. }
  2608. template <>
  2609. std::vector<float> *GetDataArray(LPCWSTR name) {
  2610. for (size_t i = 0; i < m_tableSize; ++i) {
  2611. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2612. return &(m_table[i].m_floatTable);
  2613. }
  2614. }
  2615. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2616. return nullptr;
  2617. }
  2618. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  2619. template <>
  2620. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  2621. for (size_t i = 0; i < m_tableSize; ++i) {
  2622. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2623. return &(m_table[i].m_halfTable);
  2624. }
  2625. }
  2626. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2627. return nullptr;
  2628. }
  2629. template <>
  2630. std::vector<double> *GetDataArray(LPCWSTR name) {
  2631. for (size_t i = 0; i < m_tableSize; ++i) {
  2632. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2633. return &(m_table[i].m_doubleTable);
  2634. }
  2635. }
  2636. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2637. return nullptr;
  2638. }
  2639. template <>
  2640. std::vector<bool> *GetDataArray(LPCWSTR name) {
  2641. for (size_t i = 0; i < m_tableSize; ++i) {
  2642. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  2643. return &(m_table[i].m_boolTable);
  2644. }
  2645. }
  2646. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  2647. return nullptr;
  2648. }
  2649. };
  2650. static TableParameter UnaryFPOpParameters[] = {
  2651. { L"ShaderOp.Target", TableParameter::STRING, true },
  2652. { L"ShaderOp.Text", TableParameter::STRING, true },
  2653. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  2654. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  2655. { L"Validation.Type", TableParameter::STRING, true },
  2656. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2657. { L"Warp.Version", TableParameter::UINT, false }
  2658. };
  2659. static TableParameter BinaryFPOpParameters[] = {
  2660. { L"ShaderOp.Target", TableParameter::STRING, true },
  2661. { L"ShaderOp.Text", TableParameter::STRING, true },
  2662. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  2663. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  2664. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  2665. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  2666. { L"Validation.Type", TableParameter::STRING, true },
  2667. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2668. };
  2669. static TableParameter TertiaryFPOpParameters[] = {
  2670. { L"ShaderOp.Target", TableParameter::STRING, true },
  2671. { L"ShaderOp.Text", TableParameter::STRING, true },
  2672. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  2673. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  2674. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  2675. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  2676. { L"Validation.Type", TableParameter::STRING, true },
  2677. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2678. };
  2679. static TableParameter UnaryHalfOpParameters[] = {
  2680. { L"ShaderOp.Target", TableParameter::STRING, true },
  2681. { L"ShaderOp.Text", TableParameter::STRING, true },
  2682. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2683. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  2684. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  2685. { L"Validation.Type", TableParameter::STRING, true },
  2686. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2687. { L"Warp.Version", TableParameter::UINT, false }
  2688. };
  2689. static TableParameter BinaryHalfOpParameters[] = {
  2690. { L"ShaderOp.Target", TableParameter::STRING, true },
  2691. { L"ShaderOp.Text", TableParameter::STRING, true },
  2692. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2693. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  2694. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  2695. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  2696. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  2697. { L"Validation.Type", TableParameter::STRING, true },
  2698. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2699. };
  2700. static TableParameter TertiaryHalfOpParameters[] = {
  2701. { L"ShaderOp.Target", TableParameter::STRING, true },
  2702. { L"ShaderOp.Text", TableParameter::STRING, true },
  2703. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2704. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  2705. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  2706. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  2707. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  2708. { L"Validation.Type", TableParameter::STRING, true },
  2709. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2710. };
  2711. static TableParameter UnaryIntOpParameters[] = {
  2712. { L"ShaderOp.Target", TableParameter::STRING, true },
  2713. { L"ShaderOp.Text", TableParameter::STRING, true },
  2714. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  2715. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  2716. { L"Validation.Tolerance", TableParameter::INT32, true },
  2717. };
  2718. static TableParameter UnaryUintOpParameters[] = {
  2719. { L"ShaderOp.Target", TableParameter::STRING, true },
  2720. { L"ShaderOp.Text", TableParameter::STRING, true },
  2721. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  2722. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  2723. { L"Validation.Tolerance", TableParameter::INT32, true },
  2724. };
  2725. static TableParameter BinaryIntOpParameters[] = {
  2726. { L"ShaderOp.Target", TableParameter::STRING, true },
  2727. { L"ShaderOp.Text", TableParameter::STRING, true },
  2728. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  2729. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  2730. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  2731. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  2732. { L"Validation.Tolerance", TableParameter::INT32, true },
  2733. };
  2734. static TableParameter TertiaryIntOpParameters[] = {
  2735. { L"ShaderOp.Target", TableParameter::STRING, true },
  2736. { L"ShaderOp.Text", TableParameter::STRING, true },
  2737. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  2738. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  2739. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  2740. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  2741. { L"Validation.Tolerance", TableParameter::INT32, true },
  2742. };
  2743. static TableParameter BinaryUintOpParameters[] = {
  2744. { L"ShaderOp.Target", TableParameter::STRING, true },
  2745. { L"ShaderOp.Text", TableParameter::STRING, true },
  2746. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  2747. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  2748. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  2749. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  2750. { L"Validation.Tolerance", TableParameter::INT32, true },
  2751. };
  2752. static TableParameter TertiaryUintOpParameters[] = {
  2753. { L"ShaderOp.Target", TableParameter::STRING, true },
  2754. { L"ShaderOp.Text", TableParameter::STRING, true },
  2755. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  2756. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  2757. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  2758. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  2759. { L"Validation.Tolerance", TableParameter::INT32, true },
  2760. };
  2761. static TableParameter UnaryInt16OpParameters[] = {
  2762. { L"ShaderOp.Target", TableParameter::STRING, true },
  2763. { L"ShaderOp.Text", TableParameter::STRING, true },
  2764. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2765. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  2766. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  2767. { L"Validation.Tolerance", TableParameter::INT32, true },
  2768. };
  2769. static TableParameter UnaryUint16OpParameters[] = {
  2770. { L"ShaderOp.Target", TableParameter::STRING, true },
  2771. { L"ShaderOp.Text", TableParameter::STRING, true },
  2772. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2773. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  2774. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  2775. { L"Validation.Tolerance", TableParameter::INT32, true },
  2776. };
  2777. static TableParameter BinaryInt16OpParameters[] = {
  2778. { L"ShaderOp.Target", TableParameter::STRING, true },
  2779. { L"ShaderOp.Text", TableParameter::STRING, true },
  2780. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2781. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  2782. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  2783. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  2784. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  2785. { L"Validation.Tolerance", TableParameter::INT32, true },
  2786. };
  2787. static TableParameter TertiaryInt16OpParameters[] = {
  2788. { L"ShaderOp.Target", TableParameter::STRING, true },
  2789. { L"ShaderOp.Text", TableParameter::STRING, true },
  2790. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2791. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  2792. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  2793. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  2794. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  2795. { L"Validation.Tolerance", TableParameter::INT32, true },
  2796. };
  2797. static TableParameter BinaryUint16OpParameters[] = {
  2798. { L"ShaderOp.Target", TableParameter::STRING, true },
  2799. { L"ShaderOp.Text", TableParameter::STRING, true },
  2800. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2801. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  2802. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  2803. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  2804. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  2805. { L"Validation.Tolerance", TableParameter::INT32, true },
  2806. };
  2807. static TableParameter TertiaryUint16OpParameters[] = {
  2808. { L"ShaderOp.Target", TableParameter::STRING, true },
  2809. { L"ShaderOp.Text", TableParameter::STRING, true },
  2810. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2811. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  2812. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  2813. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  2814. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  2815. { L"Validation.Tolerance", TableParameter::INT32, true },
  2816. };
  2817. static TableParameter DotOpParameters[] = {
  2818. { L"ShaderOp.Target", TableParameter::STRING, true },
  2819. { L"ShaderOp.Text", TableParameter::STRING, true },
  2820. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  2821. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  2822. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  2823. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  2824. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  2825. { L"Validation.Type", TableParameter::STRING, true },
  2826. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2827. };
  2828. static TableParameter Dot2AddHalfOpParameters[] = {
  2829. { L"ShaderOp.Target", TableParameter::STRING, true },
  2830. { L"ShaderOp.Text", TableParameter::STRING, true },
  2831. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2832. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  2833. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  2834. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  2835. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  2836. { L"Validation.Type", TableParameter::STRING, true },
  2837. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2838. };
  2839. static TableParameter Dot4AddI8PackedOpParameters[] = {
  2840. { L"ShaderOp.Target", TableParameter::STRING, true },
  2841. { L"ShaderOp.Text", TableParameter::STRING, true },
  2842. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  2843. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  2844. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  2845. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  2846. };
  2847. static TableParameter Dot4AddU8PackedOpParameters[] = {
  2848. { L"ShaderOp.Target", TableParameter::STRING, true },
  2849. { L"ShaderOp.Text", TableParameter::STRING, true },
  2850. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  2851. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  2852. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  2853. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  2854. };
  2855. static TableParameter Msad4OpParameters[] = {
  2856. { L"ShaderOp.Text", TableParameter::STRING, true },
  2857. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2858. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  2859. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  2860. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  2861. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  2862. };
  2863. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  2864. { L"ShaderOp.Name", TableParameter::STRING, true },
  2865. { L"ShaderOp.Text", TableParameter::STRING, true },
  2866. { L"Validation.NumInputSet", TableParameter::UINT, true },
  2867. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  2868. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  2869. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  2870. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  2871. };
  2872. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  2873. { L"ShaderOp.Name", TableParameter::STRING, true },
  2874. { L"ShaderOp.Text", TableParameter::STRING, true },
  2875. { L"Validation.NumInputSet", TableParameter::UINT, true },
  2876. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  2877. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  2878. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  2879. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  2880. };
  2881. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  2882. { L"ShaderOp.Name", TableParameter::STRING, true },
  2883. { L"ShaderOp.Text", TableParameter::STRING, true },
  2884. { L"Validation.NumInputSet", TableParameter::UINT, true },
  2885. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  2886. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  2887. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  2888. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  2889. };
  2890. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  2891. { L"ShaderOp.Name", TableParameter::STRING, true },
  2892. { L"ShaderOp.Text", TableParameter::STRING, true },
  2893. { L"Validation.NumInputSet", TableParameter::UINT, true },
  2894. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  2895. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  2896. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  2897. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  2898. };
  2899. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  2900. { L"ShaderOp.Name", TableParameter::STRING, true },
  2901. { L"ShaderOp.Target", TableParameter::STRING, true },
  2902. { L"ShaderOp.Text", TableParameter::STRING, true },
  2903. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  2904. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  2905. };
  2906. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  2907. { L"ShaderOp.Name", TableParameter::STRING, true },
  2908. { L"ShaderOp.Target", TableParameter::STRING, true },
  2909. { L"ShaderOp.Text", TableParameter::STRING, true },
  2910. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  2911. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  2912. };
  2913. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  2914. { L"ShaderOp.Name", TableParameter::STRING, true },
  2915. { L"ShaderOp.Text", TableParameter::STRING, true },
  2916. { L"Validation.NumInputSet", TableParameter::UINT, true },
  2917. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  2918. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  2919. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  2920. };
  2921. static TableParameter CBufferTestHalfParameters[] = {
  2922. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  2923. };
  2924. static TableParameter DenormBinaryFPOpParameters[] = {
  2925. { L"ShaderOp.Target", TableParameter::STRING, true },
  2926. { L"ShaderOp.Text", TableParameter::STRING, true },
  2927. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2928. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  2929. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  2930. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  2931. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  2932. { L"Validation.Type", TableParameter::STRING, true },
  2933. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2934. };
  2935. static TableParameter DenormTertiaryFPOpParameters[] = {
  2936. { L"ShaderOp.Target", TableParameter::STRING, true },
  2937. { L"ShaderOp.Text", TableParameter::STRING, true },
  2938. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  2939. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  2940. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  2941. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  2942. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  2943. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  2944. { L"Validation.Type", TableParameter::STRING, true },
  2945. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  2946. };
  2947. static bool IsHexString(PCWSTR str, uint16_t *value) {
  2948. std::wstring wString(str);
  2949. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  2950. LPCWSTR wstr = wString.c_str();
  2951. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  2952. *value = (uint16_t)wcstol(wstr, NULL, 0);
  2953. return true;
  2954. }
  2955. return false;
  2956. }
  2957. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  2958. std::wstring wString(str);
  2959. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  2960. PCWSTR wstr = wString.data();
  2961. if (_wcsicmp(wstr, L"NaN") == 0) {
  2962. value = NAN;
  2963. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  2964. value = -(INFINITY);
  2965. } else if (_wcsicmp(wstr, L"inf") == 0) {
  2966. value = INFINITY;
  2967. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  2968. value = -(FLT_MIN / 2);
  2969. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  2970. value = FLT_MIN / 2;
  2971. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  2972. _wcsicmp(wstr, L"-0") == 0) {
  2973. value = -0.0f;
  2974. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  2975. _wcsicmp(wstr, L"0") == 0) {
  2976. value = 0.0f;
  2977. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  2978. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  2979. value = (float&)temp_i;
  2980. }
  2981. else {
  2982. // evaluate the expression of wstring
  2983. double val = _wtof(wstr);
  2984. if (val == 0) {
  2985. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  2986. return E_FAIL;
  2987. }
  2988. value = (float)val;
  2989. }
  2990. return S_OK;
  2991. }
  2992. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  2993. std::wstring wString(str);
  2994. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  2995. PCWSTR wstr = wString.data();
  2996. // evaluate the expression of string
  2997. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  2998. value = 0;
  2999. return S_OK;
  3000. }
  3001. int val = _wtoi(wstr);
  3002. if (val == 0) {
  3003. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3004. return E_FAIL;
  3005. }
  3006. value = val;
  3007. return S_OK;
  3008. }
  3009. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3010. std::wstring wString(str);
  3011. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3012. PCWSTR wstr = wString.data();
  3013. // evaluate the expression of string
  3014. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3015. value = 0;
  3016. return S_OK;
  3017. }
  3018. wchar_t *end;
  3019. unsigned int val = std::wcstoul(wstr, &end, 0);
  3020. if (val == 0) {
  3021. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3022. return E_FAIL;
  3023. }
  3024. value = val;
  3025. return S_OK;
  3026. }
  3027. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3028. std::wstring wstr(str);
  3029. size_t curPosition = 0;
  3030. // parse a string of dot product separated by commas
  3031. for (size_t i = 0; i < count; ++i) {
  3032. size_t nextPosition = wstr.find(L",", curPosition);
  3033. if (FAILED(ParseDataToFloat(
  3034. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3035. *(ptr + i)))) {
  3036. return E_FAIL;
  3037. }
  3038. curPosition = nextPosition + 1;
  3039. }
  3040. return S_OK;
  3041. }
  3042. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3043. std::wstring wstr(str);
  3044. size_t curPosition = 0;
  3045. // parse a string of dot product separated by commas
  3046. for (size_t i = 0; i < count; ++i) {
  3047. size_t nextPosition = wstr.find(L",", curPosition);
  3048. float floatValue;
  3049. if (FAILED(ParseDataToFloat(
  3050. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3051. return E_FAIL;
  3052. }
  3053. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3054. curPosition = nextPosition + 1;
  3055. }
  3056. return S_OK;
  3057. }
  3058. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3059. std::wstring wstr(str);
  3060. size_t curPosition = 0;
  3061. // parse a string of dot product separated by commas
  3062. for (size_t i = 0; i < count; ++i) {
  3063. size_t nextPosition = wstr.find(L",", curPosition);
  3064. if (FAILED(ParseDataToUint(
  3065. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3066. *(ptr + i)))) {
  3067. return E_FAIL;
  3068. }
  3069. curPosition = nextPosition + 1;
  3070. }
  3071. return S_OK;
  3072. }
  3073. HRESULT TableParameterHandler::ParseTableRow() {
  3074. TableParameter *table = m_table;
  3075. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3076. switch (table[i].m_type) {
  3077. case TableParameter::INT8:
  3078. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3079. table[i].m_int32)) && table[i].m_required) {
  3080. // TryGetValue does not suppport reading from int16
  3081. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3082. return E_FAIL;
  3083. }
  3084. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3085. break;
  3086. case TableParameter::INT16:
  3087. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3088. table[i].m_int32)) && table[i].m_required) {
  3089. // TryGetValue does not suppport reading from int16
  3090. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3091. return E_FAIL;
  3092. }
  3093. table[i].m_int16 = (short)(table[i].m_int32);
  3094. break;
  3095. case TableParameter::INT32:
  3096. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3097. table[i].m_int32)) && table[i].m_required) {
  3098. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3099. return E_FAIL;
  3100. }
  3101. break;
  3102. case TableParameter::UINT:
  3103. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3104. table[i].m_uint)) && table[i].m_required) {
  3105. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3106. return E_FAIL;
  3107. }
  3108. break;
  3109. case TableParameter::DOUBLE:
  3110. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3111. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3112. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3113. return E_FAIL;
  3114. }
  3115. break;
  3116. case TableParameter::STRING:
  3117. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3118. table[i].m_str)) && table[i].m_required) {
  3119. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3120. return E_FAIL;
  3121. }
  3122. break;
  3123. case TableParameter::BOOL:
  3124. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3125. table[i].m_str)) && table[i].m_bool) {
  3126. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3127. return E_FAIL;
  3128. }
  3129. break;
  3130. case TableParameter::INT8_TABLE: {
  3131. WEX::TestExecution::TestDataArray<int> tempTable;
  3132. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3133. table[i].m_name, tempTable)) && table[i].m_required) {
  3134. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3135. return E_FAIL;
  3136. }
  3137. // TryGetValue does not suppport reading from int8
  3138. table[i].m_int8Table.resize(tempTable.GetSize());
  3139. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3140. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  3141. }
  3142. break;
  3143. }
  3144. case TableParameter::INT16_TABLE: {
  3145. WEX::TestExecution::TestDataArray<int> tempTable;
  3146. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3147. table[i].m_name, tempTable)) && table[i].m_required) {
  3148. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3149. return E_FAIL;
  3150. }
  3151. // TryGetValue does not suppport reading from int8
  3152. table[i].m_int16Table.resize(tempTable.GetSize());
  3153. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3154. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  3155. }
  3156. break;
  3157. }case TableParameter::INT32_TABLE: {
  3158. WEX::TestExecution::TestDataArray<int> tempTable;
  3159. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3160. table[i].m_name, tempTable)) && table[i].m_required) {
  3161. // TryGetValue does not suppport reading from int8
  3162. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3163. return E_FAIL;
  3164. }
  3165. table[i].m_int32Table.resize(tempTable.GetSize());
  3166. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3167. table[i].m_int32Table[j] = tempTable[j];
  3168. }
  3169. break;
  3170. }
  3171. case TableParameter::UINT8_TABLE: {
  3172. WEX::TestExecution::TestDataArray<int> tempTable;
  3173. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3174. table[i].m_name, tempTable)) && table[i].m_required) {
  3175. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3176. return E_FAIL;
  3177. }
  3178. // TryGetValue does not suppport reading from int8
  3179. table[i].m_int8Table.resize(tempTable.GetSize());
  3180. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3181. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  3182. }
  3183. break;
  3184. }
  3185. case TableParameter::UINT16_TABLE: {
  3186. WEX::TestExecution::TestDataArray<int> tempTable;
  3187. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3188. table[i].m_name, tempTable)) && table[i].m_required) {
  3189. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3190. return E_FAIL;
  3191. }
  3192. // TryGetValue does not suppport reading from int8
  3193. table[i].m_uint16Table.resize(tempTable.GetSize());
  3194. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3195. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  3196. }
  3197. break;
  3198. }
  3199. case TableParameter::UINT32_TABLE: {
  3200. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  3201. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3202. table[i].m_name, tempTable)) && table[i].m_required) {
  3203. // TryGetValue does not suppport reading from int8
  3204. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3205. return E_FAIL;
  3206. }
  3207. table[i].m_uint32Table.resize(tempTable.GetSize());
  3208. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3209. table[i].m_uint32Table[j] = tempTable[j];
  3210. }
  3211. break;
  3212. }
  3213. case TableParameter::FLOAT_TABLE: {
  3214. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3215. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3216. table[i].m_name, tempTable)) && table[i].m_required) {
  3217. // TryGetValue does not suppport reading from int8
  3218. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3219. return E_FAIL;
  3220. }
  3221. table[i].m_floatTable.resize(tempTable.GetSize());
  3222. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3223. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  3224. }
  3225. break;
  3226. }
  3227. case TableParameter::HALF_TABLE: {
  3228. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3229. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3230. table[i].m_name, tempTable)) && table[i].m_required) {
  3231. // TryGetValue does not suppport reading from int8
  3232. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3233. return E_FAIL;
  3234. }
  3235. table[i].m_halfTable.resize(tempTable.GetSize());
  3236. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3237. uint16_t value = 0;
  3238. if (IsHexString(tempTable[j], &value)) {
  3239. table[i].m_halfTable[j] = value;
  3240. }
  3241. else {
  3242. float val;
  3243. ParseDataToFloat(tempTable[j], val);
  3244. if (isdenorm(val))
  3245. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  3246. else
  3247. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  3248. }
  3249. }
  3250. break;
  3251. }
  3252. case TableParameter::DOUBLE_TABLE: {
  3253. WEX::TestExecution::TestDataArray<double> tempTable;
  3254. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3255. table[i].m_name, tempTable)) && table[i].m_required) {
  3256. // TryGetValue does not suppport reading from int8
  3257. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3258. return E_FAIL;
  3259. }
  3260. table[i].m_doubleTable.resize(tempTable.GetSize());
  3261. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3262. table[i].m_doubleTable[j] = tempTable[j];
  3263. }
  3264. break;
  3265. }
  3266. case TableParameter::BOOL_TABLE: {
  3267. WEX::TestExecution::TestDataArray<bool> tempTable;
  3268. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3269. table[i].m_name, tempTable)) && table[i].m_required) {
  3270. // TryGetValue does not suppport reading from int8
  3271. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3272. return E_FAIL;
  3273. }
  3274. table[i].m_boolTable.resize(tempTable.GetSize());
  3275. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3276. table[i].m_boolTable[j] = tempTable[j];
  3277. }
  3278. break;
  3279. }
  3280. case TableParameter::STRING_TABLE: {
  3281. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3282. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3283. table[i].m_name, tempTable)) && table[i].m_required) {
  3284. // TryGetValue does not suppport reading from int8
  3285. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3286. return E_FAIL;
  3287. }
  3288. table[i].m_StringTable.resize(tempTable.GetSize());
  3289. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3290. table[i].m_StringTable[j] = tempTable[j];
  3291. }
  3292. break;
  3293. }
  3294. default:
  3295. DXASSERT_NOMSG("Invalid Parameter Type");
  3296. }
  3297. if (errno == ERANGE) {
  3298. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  3299. return E_FAIL;
  3300. }
  3301. }
  3302. return S_OK;
  3303. }
  3304. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  3305. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  3306. }
  3307. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  3308. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  3309. }
  3310. static void VerifyOutputWithExpectedValueFloat(
  3311. float output, float ref, LPCWSTR type, double tolerance,
  3312. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  3313. if (_wcsicmp(type, L"Relative") == 0) {
  3314. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  3315. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  3316. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  3317. } else if (_wcsicmp(type, L"ULP") == 0) {
  3318. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  3319. } else {
  3320. LogErrorFmt(L"Failed to read comparison type %S", type);
  3321. }
  3322. }
  3323. static bool CompareOutputWithExpectedValueFloat(
  3324. float output, float ref, LPCWSTR type, double tolerance,
  3325. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  3326. if (_wcsicmp(type, L"Relative") == 0) {
  3327. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  3328. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  3329. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  3330. } else if (_wcsicmp(type, L"ULP") == 0) {
  3331. return CompareFloatULP(output, ref, (int)tolerance, mode);
  3332. } else {
  3333. LogErrorFmt(L"Failed to read comparison type %S", type);
  3334. return false;
  3335. }
  3336. }
  3337. static void VerifyOutputWithExpectedValueHalf(
  3338. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  3339. if (_wcsicmp(type, L"Relative") == 0) {
  3340. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  3341. }
  3342. else if (_wcsicmp(type, L"Epsilon") == 0) {
  3343. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  3344. }
  3345. else if (_wcsicmp(type, L"ULP") == 0) {
  3346. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  3347. }
  3348. else {
  3349. LogErrorFmt(L"Failed to read comparison type %S", type);
  3350. }
  3351. }
  3352. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  3353. WEX::TestExecution::SetVerifyOutput verifySettings(
  3354. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3355. CComPtr<IStream> pStream;
  3356. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3357. CComPtr<ID3D12Device> pDevice;
  3358. if (!CreateDevice(&pDevice)) {
  3359. return;
  3360. }
  3361. // Read data from the table
  3362. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  3363. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  3364. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3365. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3366. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  3367. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  3368. return;
  3369. }
  3370. std::vector<float> *Validation_Input =
  3371. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  3372. std::vector<float> *Validation_Expected =
  3373. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  3374. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  3375. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  3376. size_t count = Validation_Input->size();
  3377. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3378. pDevice, m_support, pStream, "UnaryFPOp",
  3379. // this callbacked is called when the test
  3380. // is creating the resource to run the test
  3381. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3382. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  3383. size_t size = sizeof(SUnaryFPOp) * count;
  3384. Data.resize(size);
  3385. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  3386. for (size_t i = 0; i < count; ++i) {
  3387. SUnaryFPOp *p = &pPrimitives[i];
  3388. p->input = (*Validation_Input)[i % Validation_Input->size()];
  3389. }
  3390. // use shader from data table
  3391. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3392. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3393. });
  3394. MappedData data;
  3395. test->Test->GetReadBackData("SUnaryFPOp", &data);
  3396. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  3397. WEX::TestExecution::DisableVerifyExceptions dve;
  3398. for (unsigned i = 0; i < count; ++i) {
  3399. SUnaryFPOp *p = &pPrimitives[i];
  3400. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  3401. LogCommentFmt(
  3402. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  3403. p->input, p->output, val);
  3404. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  3405. }
  3406. }
  3407. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  3408. WEX::TestExecution::SetVerifyOutput verifySettings(
  3409. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3410. CComPtr<IStream> pStream;
  3411. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3412. CComPtr<ID3D12Device> pDevice;
  3413. if (!CreateDevice(&pDevice)) {
  3414. return;
  3415. }
  3416. // Read data from the table
  3417. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  3418. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  3419. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3420. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3421. std::vector<float> *Validation_Input1 =
  3422. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  3423. std::vector<float> *Validation_Input2 =
  3424. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  3425. std::vector<float> *Validation_Expected1 =
  3426. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  3427. std::vector<float> *Validation_Expected2 =
  3428. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  3429. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  3430. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  3431. size_t count = Validation_Input1->size();
  3432. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3433. pDevice, m_support, pStream, "BinaryFPOp",
  3434. // this callbacked is called when the test
  3435. // is creating the resource to run the test
  3436. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3437. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  3438. size_t size = sizeof(SBinaryFPOp) * count;
  3439. Data.resize(size);
  3440. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  3441. for (size_t i = 0; i < count; ++i) {
  3442. SBinaryFPOp *p = &pPrimitives[i];
  3443. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  3444. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  3445. }
  3446. // use shader from data table
  3447. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3448. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3449. });
  3450. MappedData data;
  3451. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3452. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  3453. WEX::TestExecution::DisableVerifyExceptions dve;
  3454. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  3455. if (numExpected == 2) {
  3456. for (unsigned i = 0; i < count; ++i) {
  3457. SBinaryFPOp *p = &pPrimitives[i];
  3458. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  3459. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  3460. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  3461. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  3462. i, p->input1, p->input2, p->output1, val1, p->output2,
  3463. val2);
  3464. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  3465. Validation_Tolerance);
  3466. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  3467. Validation_Tolerance);
  3468. }
  3469. }
  3470. else if (numExpected == 1) {
  3471. for (unsigned i = 0; i < count; ++i) {
  3472. SBinaryFPOp *p = &pPrimitives[i];
  3473. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  3474. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  3475. L"%6.8f, expected1 = %6.8f",
  3476. i, p->input1, p->input2, p->output1, val1);
  3477. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  3478. Validation_Tolerance);
  3479. }
  3480. }
  3481. else {
  3482. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  3483. }
  3484. }
  3485. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  3486. WEX::TestExecution::SetVerifyOutput verifySettings(
  3487. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3488. CComPtr<IStream> pStream;
  3489. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3490. CComPtr<ID3D12Device> pDevice;
  3491. if (!CreateDevice(&pDevice)) {
  3492. return;
  3493. }
  3494. // Read data from the table
  3495. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  3496. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  3497. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3498. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3499. std::vector<float> *Validation_Input1 =
  3500. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  3501. std::vector<float> *Validation_Input2 =
  3502. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  3503. std::vector<float> *Validation_Input3 =
  3504. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  3505. std::vector<float> *Validation_Expected =
  3506. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  3507. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  3508. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  3509. size_t count = Validation_Input1->size();
  3510. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3511. pDevice, m_support, pStream, "TertiaryFPOp",
  3512. // this callbacked is called when the test
  3513. // is creating the resource to run the test
  3514. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3515. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  3516. size_t size = sizeof(STertiaryFPOp) * count;
  3517. Data.resize(size);
  3518. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  3519. for (size_t i = 0; i < count; ++i) {
  3520. STertiaryFPOp *p = &pPrimitives[i];
  3521. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  3522. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  3523. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  3524. }
  3525. // use shader from data table
  3526. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3527. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3528. });
  3529. MappedData data;
  3530. test->Test->GetReadBackData("STertiaryFPOp", &data);
  3531. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  3532. WEX::TestExecution::DisableVerifyExceptions dve;
  3533. for (unsigned i = 0; i < count; ++i) {
  3534. STertiaryFPOp *p = &pPrimitives[i];
  3535. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  3536. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  3537. L"%6.8f, expected = %6.8f",
  3538. i, p->input1, p->input2, p->input3, p->output, val);
  3539. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  3540. Validation_Tolerance);
  3541. }
  3542. }
  3543. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  3544. WEX::TestExecution::SetVerifyOutput verifySettings(
  3545. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3546. CComPtr<IStream> pStream;
  3547. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3548. CComPtr<ID3D12Device> pDevice;
  3549. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  3550. return;
  3551. }
  3552. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  3553. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  3554. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  3555. return;
  3556. }
  3557. // Read data from the table
  3558. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  3559. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  3560. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3561. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3562. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  3563. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  3564. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  3565. return;
  3566. }
  3567. std::vector<uint16_t> *Validation_Input =
  3568. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  3569. std::vector<uint16_t> *Validation_Expected =
  3570. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  3571. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  3572. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  3573. size_t count = Validation_Input->size();
  3574. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3575. pDevice, m_support, pStream, "UnaryFPOp",
  3576. // this callbacked is called when the test
  3577. // is creating the resource to run the test
  3578. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3579. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  3580. size_t size = sizeof(SUnaryHalfOp) * count;
  3581. Data.resize(size);
  3582. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  3583. for (size_t i = 0; i < count; ++i) {
  3584. SUnaryHalfOp *p = &pPrimitives[i];
  3585. p->input = (*Validation_Input)[i % Validation_Input->size()];
  3586. }
  3587. // use shader from data table
  3588. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3589. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3590. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  3591. });
  3592. MappedData data;
  3593. test->Test->GetReadBackData("SUnaryFPOp", &data);
  3594. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  3595. WEX::TestExecution::DisableVerifyExceptions dve;
  3596. for (unsigned i = 0; i < count; ++i) {
  3597. SUnaryHalfOp *p = &pPrimitives[i];
  3598. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  3599. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  3600. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  3601. i, ConvertFloat16ToFloat32(p->input), p->input,
  3602. ConvertFloat16ToFloat32(p->output), p->output,
  3603. ConvertFloat16ToFloat32(expected), expected);
  3604. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  3605. }
  3606. }
  3607. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  3608. WEX::TestExecution::SetVerifyOutput verifySettings(
  3609. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3610. CComPtr<IStream> pStream;
  3611. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3612. CComPtr<ID3D12Device> pDevice;
  3613. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  3614. return;
  3615. }
  3616. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  3617. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  3618. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  3619. return;
  3620. }
  3621. // Read data from the table
  3622. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  3623. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  3624. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3625. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3626. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  3627. std::vector<uint16_t> *Validation_Input1 =
  3628. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  3629. std::vector<uint16_t> *Validation_Input2 =
  3630. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  3631. std::vector<uint16_t> *Validation_Expected1 =
  3632. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  3633. std::vector<uint16_t> *Validation_Expected2 =
  3634. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  3635. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  3636. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  3637. size_t count = Validation_Input1->size();
  3638. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3639. pDevice, m_support, pStream, "BinaryFPOp",
  3640. // this callbacked is called when the test
  3641. // is creating the resource to run the test
  3642. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3643. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  3644. size_t size = sizeof(SBinaryHalfOp) * count;
  3645. Data.resize(size);
  3646. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  3647. for (size_t i = 0; i < count; ++i) {
  3648. SBinaryHalfOp *p = &pPrimitives[i];
  3649. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  3650. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  3651. }
  3652. // use shader from data table
  3653. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3654. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3655. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  3656. });
  3657. MappedData data;
  3658. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3659. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  3660. WEX::TestExecution::DisableVerifyExceptions dve;
  3661. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  3662. if (numExpected == 2) {
  3663. for (unsigned i = 0; i < count; ++i) {
  3664. SBinaryHalfOp *p = &pPrimitives[i];
  3665. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  3666. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  3667. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  3668. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  3669. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  3670. ConvertFloat16ToFloat32(p->input2), p->input2,
  3671. ConvertFloat16ToFloat32(p->output1), p->output1,
  3672. ConvertFloat16ToFloat32(p->output2), p->output2,
  3673. ConvertFloat16ToFloat32(expected1), expected1,
  3674. ConvertFloat16ToFloat32(expected2), expected2);
  3675. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  3676. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  3677. }
  3678. }
  3679. else if (numExpected == 1) {
  3680. for (unsigned i = 0; i < count; ++i) {
  3681. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  3682. SBinaryHalfOp *p = &pPrimitives[i];
  3683. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  3684. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  3685. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  3686. ConvertFloat16ToFloat32(p->output1), p->output1,
  3687. ConvertFloat16ToFloat32(expected), expected);
  3688. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  3689. }
  3690. }
  3691. else {
  3692. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  3693. }
  3694. }
  3695. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  3696. WEX::TestExecution::SetVerifyOutput verifySettings(
  3697. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3698. CComPtr<IStream> pStream;
  3699. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3700. CComPtr<ID3D12Device> pDevice;
  3701. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  3702. return;
  3703. }
  3704. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  3705. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  3706. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  3707. return;
  3708. }
  3709. // Read data from the table
  3710. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  3711. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  3712. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3713. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3714. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  3715. std::vector<uint16_t> *Validation_Input1 =
  3716. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  3717. std::vector<uint16_t> *Validation_Input2 =
  3718. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  3719. std::vector<uint16_t> *Validation_Input3 =
  3720. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  3721. std::vector<uint16_t> *Validation_Expected =
  3722. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  3723. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  3724. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  3725. size_t count = Validation_Input1->size();
  3726. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3727. pDevice, m_support, pStream, "TertiaryFPOp",
  3728. // this callbacked is called when the test
  3729. // is creating the resource to run the test
  3730. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3731. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  3732. size_t size = sizeof(STertiaryHalfOp) * count;
  3733. Data.resize(size);
  3734. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  3735. for (size_t i = 0; i < count; ++i) {
  3736. STertiaryHalfOp *p = &pPrimitives[i];
  3737. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  3738. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  3739. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  3740. }
  3741. // use shader from data table
  3742. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3743. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3744. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  3745. });
  3746. MappedData data;
  3747. test->Test->GetReadBackData("STertiaryFPOp", &data);
  3748. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  3749. WEX::TestExecution::DisableVerifyExceptions dve;
  3750. for (unsigned i = 0; i < count; ++i) {
  3751. STertiaryHalfOp *p = &pPrimitives[i];
  3752. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  3753. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  3754. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  3755. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  3756. ConvertFloat16ToFloat32(p->input2), p->input2,
  3757. ConvertFloat16ToFloat32(p->input3), p->input3,
  3758. ConvertFloat16ToFloat32(p->output), p->output,
  3759. ConvertFloat16ToFloat32(expected), expected);
  3760. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  3761. }
  3762. }
  3763. TEST_F(ExecutionTest, UnaryIntOpTest) {
  3764. WEX::TestExecution::SetVerifyOutput verifySettings(
  3765. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3766. CComPtr<IStream> pStream;
  3767. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3768. CComPtr<ID3D12Device> pDevice;
  3769. if (!CreateDevice(&pDevice)) {
  3770. return;
  3771. }
  3772. // Read data from the table
  3773. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  3774. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  3775. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3776. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3777. std::vector<int> *Validation_Input =
  3778. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  3779. std::vector<int> *Validation_Expected =
  3780. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  3781. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  3782. size_t count = Validation_Input->size();
  3783. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3784. pDevice, m_support, pStream, "UnaryIntOp",
  3785. // this callbacked is called when the test
  3786. // is creating the resource to run the test
  3787. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3788. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  3789. size_t size = sizeof(SUnaryIntOp) * count;
  3790. Data.resize(size);
  3791. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  3792. for (size_t i = 0; i < count; ++i) {
  3793. SUnaryIntOp *p = &pPrimitives[i];
  3794. int val = (*Validation_Input)[i % Validation_Input->size()];
  3795. p->input = val;
  3796. }
  3797. // use shader data table
  3798. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3799. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3800. });
  3801. MappedData data;
  3802. test->Test->GetReadBackData("SUnaryIntOp", &data);
  3803. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  3804. WEX::TestExecution::DisableVerifyExceptions dve;
  3805. for (unsigned i = 0; i < count; ++i) {
  3806. SUnaryIntOp *p = &pPrimitives[i];
  3807. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  3808. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  3809. L"expected = %11i(0x%08x)",
  3810. i, p->input, p->input, p->output, p->output, val, val);
  3811. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  3812. }
  3813. }
  3814. TEST_F(ExecutionTest, UnaryUintOpTest) {
  3815. WEX::TestExecution::SetVerifyOutput verifySettings(
  3816. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3817. CComPtr<IStream> pStream;
  3818. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3819. CComPtr<ID3D12Device> pDevice;
  3820. if (!CreateDevice(&pDevice)) {
  3821. return;
  3822. }
  3823. // Read data from the table
  3824. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  3825. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  3826. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3827. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3828. std::vector<unsigned int> *Validation_Input =
  3829. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  3830. std::vector<unsigned int> *Validation_Expected =
  3831. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  3832. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  3833. size_t count = Validation_Input->size();
  3834. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3835. pDevice, m_support, pStream, "UnaryUintOp",
  3836. // this callbacked is called when the test
  3837. // is creating the resource to run the test
  3838. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3839. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  3840. size_t size = sizeof(SUnaryUintOp) * count;
  3841. Data.resize(size);
  3842. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  3843. for (size_t i = 0; i < count; ++i) {
  3844. SUnaryUintOp *p = &pPrimitives[i];
  3845. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  3846. p->input = val;
  3847. }
  3848. // use shader data table
  3849. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3850. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3851. });
  3852. MappedData data;
  3853. test->Test->GetReadBackData("SUnaryUintOp", &data);
  3854. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  3855. WEX::TestExecution::DisableVerifyExceptions dve;
  3856. for (unsigned i = 0; i < count; ++i) {
  3857. SUnaryUintOp *p = &pPrimitives[i];
  3858. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  3859. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  3860. L"expected = %11u(0x%08x)",
  3861. i, p->input, p->input, p->output, p->output, val, val);
  3862. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  3863. }
  3864. }
  3865. TEST_F(ExecutionTest, BinaryIntOpTest) {
  3866. WEX::TestExecution::SetVerifyOutput verifySettings(
  3867. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3868. CComPtr<IStream> pStream;
  3869. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3870. CComPtr<ID3D12Device> pDevice;
  3871. if (!CreateDevice(&pDevice)) {
  3872. return;
  3873. }
  3874. // Read data from the table
  3875. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  3876. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  3877. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3878. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3879. std::vector<int> *Validation_Input1 =
  3880. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  3881. std::vector<int> *Validation_Input2 =
  3882. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  3883. std::vector<int> *Validation_Expected1 =
  3884. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  3885. std::vector<int> *Validation_Expected2 =
  3886. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  3887. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  3888. size_t count = Validation_Input1->size();
  3889. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  3890. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3891. pDevice, m_support, pStream, "BinaryIntOp",
  3892. // this callbacked is called when the test
  3893. // is creating the resource to run the test
  3894. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3895. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  3896. size_t size = sizeof(SBinaryIntOp) * count;
  3897. Data.resize(size);
  3898. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  3899. for (size_t i = 0; i < count; ++i) {
  3900. SBinaryIntOp *p = &pPrimitives[i];
  3901. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  3902. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  3903. p->input1 = val1;
  3904. p->input2 = val2;
  3905. }
  3906. // use shader from data table
  3907. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3908. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3909. });
  3910. MappedData data;
  3911. test->Test->GetReadBackData("SBinaryIntOp", &data);
  3912. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  3913. WEX::TestExecution::DisableVerifyExceptions dve;
  3914. if (numExpected == 2) {
  3915. for (unsigned i = 0; i < count; ++i) {
  3916. SBinaryIntOp *p = &pPrimitives[i];
  3917. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  3918. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  3919. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  3920. L"%11i(0x%08x), output1 = "
  3921. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  3922. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  3923. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  3924. p->output1, val1, val1, p->output2, p->output2, val2,
  3925. val2);
  3926. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  3927. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  3928. }
  3929. }
  3930. else if (numExpected == 1) {
  3931. for (unsigned i = 0; i < count; ++i) {
  3932. SBinaryIntOp *p = &pPrimitives[i];
  3933. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  3934. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  3935. L"%11i(0x%08x), output = "
  3936. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  3937. p->input1, p->input1, p->input2, p->input2,
  3938. p->output1, p->output1, val1, val1);
  3939. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  3940. }
  3941. }
  3942. else {
  3943. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  3944. }
  3945. }
  3946. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  3947. WEX::TestExecution::SetVerifyOutput verifySettings(
  3948. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3949. CComPtr<IStream> pStream;
  3950. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3951. CComPtr<ID3D12Device> pDevice;
  3952. if (!CreateDevice(&pDevice)) {
  3953. return;
  3954. }
  3955. // Read data from the table
  3956. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  3957. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  3958. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  3959. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  3960. std::vector<int> *Validation_Input1 =
  3961. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  3962. std::vector<int> *Validation_Input2 =
  3963. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  3964. std::vector<int> *Validation_Input3 =
  3965. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  3966. std::vector<int> *Validation_Expected =
  3967. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  3968. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  3969. size_t count = Validation_Input1->size();
  3970. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3971. pDevice, m_support, pStream, "TertiaryIntOp",
  3972. // this callbacked is called when the test
  3973. // is creating the resource to run the test
  3974. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3975. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  3976. size_t size = sizeof(STertiaryIntOp) * count;
  3977. Data.resize(size);
  3978. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  3979. for (size_t i = 0; i < count; ++i) {
  3980. STertiaryIntOp *p = &pPrimitives[i];
  3981. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  3982. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  3983. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  3984. p->input1 = val1;
  3985. p->input2 = val2;
  3986. p->input3 = val3;
  3987. }
  3988. // use shader from data table
  3989. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  3990. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  3991. });
  3992. MappedData data;
  3993. test->Test->GetReadBackData("STertiaryIntOp", &data);
  3994. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  3995. WEX::TestExecution::DisableVerifyExceptions dve;
  3996. for (unsigned i = 0; i < count; ++i) {
  3997. STertiaryIntOp *p = &pPrimitives[i];
  3998. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  3999. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4000. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4001. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4002. i, p->input1, p->input1, p->input2, p->input2,
  4003. p->input3, p->input3, p->output, p->output, val1,
  4004. val1);
  4005. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4006. }
  4007. }
  4008. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4009. WEX::TestExecution::SetVerifyOutput verifySettings(
  4010. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4011. CComPtr<IStream> pStream;
  4012. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4013. CComPtr<ID3D12Device> pDevice;
  4014. if (!CreateDevice(&pDevice)) {
  4015. return;
  4016. }
  4017. // Read data from the table
  4018. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4019. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4020. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4021. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4022. std::vector<unsigned int> *Validation_Input1 =
  4023. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4024. std::vector<unsigned int> *Validation_Input2 =
  4025. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4026. std::vector<unsigned int> *Validation_Expected1 =
  4027. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4028. std::vector<unsigned int> *Validation_Expected2 =
  4029. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4030. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4031. size_t count = Validation_Input1->size();
  4032. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4033. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4034. pDevice, m_support, pStream, "BinaryUintOp",
  4035. // this callbacked is called when the test
  4036. // is creating the resource to run the test
  4037. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4038. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4039. size_t size = sizeof(SBinaryUintOp) * count;
  4040. Data.resize(size);
  4041. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4042. for (size_t i = 0; i < count; ++i) {
  4043. SBinaryUintOp *p = &pPrimitives[i];
  4044. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4045. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4046. p->input1 = val1;
  4047. p->input2 = val2;
  4048. }
  4049. // use shader from data table
  4050. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4051. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4052. });
  4053. MappedData data;
  4054. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4055. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4056. WEX::TestExecution::DisableVerifyExceptions dve;
  4057. if (numExpected == 2) {
  4058. for (unsigned i = 0; i < count; ++i) {
  4059. SBinaryUintOp *p = &pPrimitives[i];
  4060. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4061. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4062. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4063. L"%11u(0x%08x), output1 = "
  4064. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4065. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4066. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4067. p->output1, val1, val1, p->output2, p->output2, val2,
  4068. val2);
  4069. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4070. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4071. }
  4072. }
  4073. else if (numExpected == 1) {
  4074. for (unsigned i = 0; i < count; ++i) {
  4075. SBinaryUintOp *p = &pPrimitives[i];
  4076. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4077. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4078. L"%11u(0x%08x), output = "
  4079. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4080. p->input1, p->input1, p->input2, p->input2,
  4081. p->output1, p->output1, val1, val1);
  4082. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4083. }
  4084. }
  4085. else {
  4086. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4087. }
  4088. }
  4089. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4090. WEX::TestExecution::SetVerifyOutput verifySettings(
  4091. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4092. CComPtr<IStream> pStream;
  4093. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4094. CComPtr<ID3D12Device> pDevice;
  4095. if (!CreateDevice(&pDevice)) {
  4096. return;
  4097. }
  4098. // Read data from the table
  4099. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4100. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4101. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4102. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4103. std::vector<unsigned int> *Validation_Input1 =
  4104. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4105. std::vector<unsigned int> *Validation_Input2 =
  4106. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4107. std::vector<unsigned int> *Validation_Input3 =
  4108. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4109. std::vector<unsigned int> *Validation_Expected =
  4110. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4111. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4112. size_t count = Validation_Input1->size();
  4113. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4114. pDevice, m_support, pStream, "TertiaryUintOp",
  4115. // this callbacked is called when the test
  4116. // is creating the resource to run the test
  4117. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4118. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4119. size_t size = sizeof(STertiaryUintOp) * count;
  4120. Data.resize(size);
  4121. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4122. for (size_t i = 0; i < count; ++i) {
  4123. STertiaryUintOp *p = &pPrimitives[i];
  4124. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4125. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4126. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4127. p->input1 = val1;
  4128. p->input2 = val2;
  4129. p->input3 = val3;
  4130. }
  4131. // use shader from data table
  4132. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4133. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4134. });
  4135. MappedData data;
  4136. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4137. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  4138. WEX::TestExecution::DisableVerifyExceptions dve;
  4139. for (unsigned i = 0; i < count; ++i) {
  4140. STertiaryUintOp *p = &pPrimitives[i];
  4141. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4142. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4143. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  4144. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4145. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4146. p->output, p->output, val1, val1);
  4147. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4148. }
  4149. }
  4150. // 16 bit integer type tests
  4151. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  4152. WEX::TestExecution::SetVerifyOutput verifySettings(
  4153. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4154. CComPtr<IStream> pStream;
  4155. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4156. CComPtr<ID3D12Device> pDevice;
  4157. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4158. return;
  4159. }
  4160. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4161. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4162. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4163. return;
  4164. }
  4165. // Read data from the table
  4166. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  4167. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  4168. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4169. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4170. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4171. std::vector<short> *Validation_Input =
  4172. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4173. std::vector<short> *Validation_Expected =
  4174. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4175. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4176. size_t count = Validation_Input->size();
  4177. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4178. pDevice, m_support, pStream, "UnaryIntOp",
  4179. // this callbacked is called when the test
  4180. // is creating the resource to run the test
  4181. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4182. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4183. size_t size = sizeof(SUnaryInt16Op) * count;
  4184. Data.resize(size);
  4185. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  4186. for (size_t i = 0; i < count; ++i) {
  4187. SUnaryInt16Op *p = &pPrimitives[i];
  4188. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4189. }
  4190. // use shader data table
  4191. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4192. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4193. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4194. });
  4195. MappedData data;
  4196. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4197. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  4198. WEX::TestExecution::DisableVerifyExceptions dve;
  4199. for (unsigned i = 0; i < count; ++i) {
  4200. SUnaryInt16Op *p = &pPrimitives[i];
  4201. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  4202. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  4203. L"expected = %5hi(0x%08x)",
  4204. i, p->input, p->input, p->output, p->output, val, val);
  4205. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4206. }
  4207. }
  4208. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  4209. WEX::TestExecution::SetVerifyOutput verifySettings(
  4210. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4211. CComPtr<IStream> pStream;
  4212. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4213. CComPtr<ID3D12Device> pDevice;
  4214. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4215. return;
  4216. }
  4217. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4218. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4219. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4220. return;
  4221. }
  4222. // Read data from the table
  4223. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  4224. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  4225. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4226. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4227. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4228. std::vector<unsigned short> *Validation_Input =
  4229. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  4230. std::vector<unsigned short> *Validation_Expected =
  4231. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  4232. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4233. size_t count = Validation_Input->size();
  4234. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4235. pDevice, m_support, pStream, "UnaryUintOp",
  4236. // this callbacked is called when the test
  4237. // is creating the resource to run the test
  4238. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4239. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4240. size_t size = sizeof(SUnaryUint16Op) * count;
  4241. Data.resize(size);
  4242. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  4243. for (size_t i = 0; i < count; ++i) {
  4244. SUnaryUint16Op *p = &pPrimitives[i];
  4245. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4246. }
  4247. // use shader data table
  4248. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4249. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4250. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4251. });
  4252. MappedData data;
  4253. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4254. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  4255. WEX::TestExecution::DisableVerifyExceptions dve;
  4256. for (unsigned i = 0; i < count; ++i) {
  4257. SUnaryUint16Op *p = &pPrimitives[i];
  4258. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  4259. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  4260. L"expected = %5hu(0x%08x)",
  4261. i, p->input, p->input, p->output, p->output, val, val);
  4262. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4263. }
  4264. }
  4265. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  4266. WEX::TestExecution::SetVerifyOutput verifySettings(
  4267. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4268. CComPtr<IStream> pStream;
  4269. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4270. CComPtr<ID3D12Device> pDevice;
  4271. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4272. return;
  4273. }
  4274. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4275. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4276. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4277. return;
  4278. }
  4279. // Read data from the table
  4280. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  4281. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  4282. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4283. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4284. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4285. std::vector<short> *Validation_Input1 =
  4286. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4287. std::vector<short> *Validation_Input2 =
  4288. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  4289. std::vector<short> *Validation_Expected1 =
  4290. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4291. std::vector<short> *Validation_Expected2 =
  4292. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  4293. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4294. size_t count = Validation_Input1->size();
  4295. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4296. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4297. pDevice, m_support, pStream, "BinaryIntOp",
  4298. // this callbacked is called when the test
  4299. // is creating the resource to run the test
  4300. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4301. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4302. size_t size = sizeof(SBinaryInt16Op) * count;
  4303. Data.resize(size);
  4304. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  4305. for (size_t i = 0; i < count; ++i) {
  4306. SBinaryInt16Op *p = &pPrimitives[i];
  4307. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4308. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4309. }
  4310. // use shader from data table
  4311. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4312. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4313. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4314. });
  4315. MappedData data;
  4316. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4317. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  4318. WEX::TestExecution::DisableVerifyExceptions dve;
  4319. if (numExpected == 2) {
  4320. for (unsigned i = 0; i < count; ++i) {
  4321. SBinaryInt16Op *p = &pPrimitives[i];
  4322. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4323. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4324. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  4325. L"%5hi(0x%08x), output1 = "
  4326. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  4327. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  4328. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4329. p->output1, val1, val1, p->output2, p->output2, val2,
  4330. val2);
  4331. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4332. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4333. }
  4334. }
  4335. else if (numExpected == 1) {
  4336. for (unsigned i = 0; i < count; ++i) {
  4337. SBinaryInt16Op *p = &pPrimitives[i];
  4338. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4339. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  4340. L"%5hi(0x%08x), output = "
  4341. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  4342. p->input1, p->input1, p->input2, p->input2,
  4343. p->output1, p->output1, val1, val1);
  4344. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4345. }
  4346. }
  4347. else {
  4348. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4349. }
  4350. }
  4351. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  4352. WEX::TestExecution::SetVerifyOutput verifySettings(
  4353. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4354. CComPtr<IStream> pStream;
  4355. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4356. CComPtr<ID3D12Device> pDevice;
  4357. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4358. return;
  4359. }
  4360. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4361. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4362. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4363. return;
  4364. }
  4365. // Read data from the table
  4366. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  4367. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  4368. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4369. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4370. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4371. std::vector<short> *Validation_Input1 =
  4372. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4373. std::vector<short> *Validation_Input2 =
  4374. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  4375. std::vector<short> *Validation_Input3 =
  4376. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  4377. std::vector<short> *Validation_Expected =
  4378. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4379. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4380. size_t count = Validation_Input1->size();
  4381. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4382. pDevice, m_support, pStream, "TertiaryIntOp",
  4383. // this callbacked is called when the test
  4384. // is creating the resource to run the test
  4385. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4386. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4387. size_t size = sizeof(STertiaryInt16Op) * count;
  4388. Data.resize(size);
  4389. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  4390. for (size_t i = 0; i < count; ++i) {
  4391. STertiaryInt16Op *p = &pPrimitives[i];
  4392. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4393. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4394. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4395. }
  4396. // use shader from data table
  4397. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4398. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4399. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4400. });
  4401. MappedData data;
  4402. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4403. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  4404. WEX::TestExecution::DisableVerifyExceptions dve;
  4405. for (unsigned i = 0; i < count; ++i) {
  4406. STertiaryInt16Op *p = &pPrimitives[i];
  4407. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4408. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4409. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4410. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4411. i, p->input1, p->input1, p->input2, p->input2,
  4412. p->input3, p->input3, p->output, p->output, val1,
  4413. val1);
  4414. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4415. }
  4416. }
  4417. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  4418. WEX::TestExecution::SetVerifyOutput verifySettings(
  4419. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4420. CComPtr<IStream> pStream;
  4421. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4422. CComPtr<ID3D12Device> pDevice;
  4423. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4424. return;
  4425. }
  4426. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4427. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4428. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4429. return;
  4430. }
  4431. // Read data from the table
  4432. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  4433. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  4434. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4435. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4436. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4437. std::vector<unsigned short> *Validation_Input1 =
  4438. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  4439. std::vector<unsigned short> *Validation_Input2 =
  4440. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  4441. std::vector<unsigned short> *Validation_Expected1 =
  4442. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  4443. std::vector<unsigned short> *Validation_Expected2 =
  4444. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  4445. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4446. size_t count = Validation_Input1->size();
  4447. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4448. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4449. pDevice, m_support, pStream, "BinaryUintOp",
  4450. // this callbacked is called when the test
  4451. // is creating the resource to run the test
  4452. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4453. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4454. size_t size = sizeof(SBinaryUint16Op) * count;
  4455. Data.resize(size);
  4456. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  4457. for (size_t i = 0; i < count; ++i) {
  4458. SBinaryUint16Op *p = &pPrimitives[i];
  4459. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4460. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4461. }
  4462. // use shader from data table
  4463. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4464. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4465. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4466. });
  4467. MappedData data;
  4468. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4469. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  4470. WEX::TestExecution::DisableVerifyExceptions dve;
  4471. if (numExpected == 2) {
  4472. for (unsigned i = 0; i < count; ++i) {
  4473. SBinaryUint16Op *p = &pPrimitives[i];
  4474. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4475. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4476. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  4477. L"%5hu(0x%08x), output1 = "
  4478. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  4479. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  4480. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4481. p->output1, val1, val1, p->output2, p->output2, val2,
  4482. val2);
  4483. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4484. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4485. }
  4486. }
  4487. else if (numExpected == 1) {
  4488. for (unsigned i = 0; i < count; ++i) {
  4489. SBinaryUint16Op *p = &pPrimitives[i];
  4490. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4491. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  4492. L"%5hu(0x%08x), output = "
  4493. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  4494. p->input1, p->input1, p->input2, p->input2,
  4495. p->output1, p->output1, val1, val1);
  4496. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4497. }
  4498. }
  4499. else {
  4500. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4501. }
  4502. }
  4503. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  4504. WEX::TestExecution::SetVerifyOutput verifySettings(
  4505. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4506. CComPtr<IStream> pStream;
  4507. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4508. CComPtr<ID3D12Device> pDevice;
  4509. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4510. return;
  4511. }
  4512. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4513. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4514. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4515. return;
  4516. }
  4517. // Read data from the table
  4518. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  4519. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  4520. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4521. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4522. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4523. std::vector<unsigned short> *Validation_Input1 =
  4524. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  4525. std::vector<unsigned short> *Validation_Input2 =
  4526. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  4527. std::vector<unsigned short> *Validation_Input3 =
  4528. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  4529. std::vector<unsigned short> *Validation_Expected =
  4530. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  4531. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4532. size_t count = Validation_Input1->size();
  4533. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4534. pDevice, m_support, pStream, "TertiaryUintOp",
  4535. // this callbacked is called when the test
  4536. // is creating the resource to run the test
  4537. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4538. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4539. size_t size = sizeof(STertiaryUint16Op) * count;
  4540. Data.resize(size);
  4541. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  4542. for (size_t i = 0; i < count; ++i) {
  4543. STertiaryUint16Op *p = &pPrimitives[i];
  4544. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4545. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4546. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4547. }
  4548. // use shader from data table
  4549. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4550. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4551. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4552. });
  4553. MappedData data;
  4554. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4555. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  4556. WEX::TestExecution::DisableVerifyExceptions dve;
  4557. for (unsigned i = 0; i < count; ++i) {
  4558. STertiaryUint16Op *p = &pPrimitives[i];
  4559. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4560. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  4561. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  4562. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  4563. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4564. p->output, p->output, val1, val1);
  4565. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4566. }
  4567. }
  4568. TEST_F(ExecutionTest, DotTest) {
  4569. WEX::TestExecution::SetVerifyOutput verifySettings(
  4570. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4571. CComPtr<IStream> pStream;
  4572. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4573. CComPtr<ID3D12Device> pDevice;
  4574. if (!CreateDevice(&pDevice)) {
  4575. return;
  4576. }
  4577. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  4578. TableParameterHandler handler(DotOpParameters, tableSize);
  4579. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4580. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4581. std::vector<WEX::Common::String> *Validation_Input1 =
  4582. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  4583. std::vector<WEX::Common::String> *Validation_Input2 =
  4584. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  4585. std::vector<WEX::Common::String> *Validation_dot2 =
  4586. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  4587. std::vector<WEX::Common::String> *Validation_dot3 =
  4588. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  4589. std::vector<WEX::Common::String> *Validation_dot4 =
  4590. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  4591. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4592. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4593. size_t count = Validation_Input1->size();
  4594. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4595. pDevice, m_support, pStream, "DotOp",
  4596. // this callbacked is called when the test
  4597. // is creating the resource to run the test
  4598. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4599. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  4600. size_t size = sizeof(SDotOp) * count;
  4601. Data.resize(size);
  4602. SDotOp *pPrimitives = (SDotOp*)Data.data();
  4603. for (size_t i = 0; i < count; ++i) {
  4604. SDotOp *p = &pPrimitives[i];
  4605. XMFLOAT4 val1,val2;
  4606. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  4607. (float *)&val1, 4));
  4608. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  4609. (float *)&val2, 4));
  4610. p->input1 = val1;
  4611. p->input2 = val2;
  4612. }
  4613. // use shader from data table
  4614. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4615. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4616. });
  4617. MappedData data;
  4618. test->Test->GetReadBackData("SDotOp", &data);
  4619. SDotOp *pPrimitives = (SDotOp*)data.data();
  4620. WEX::TestExecution::DisableVerifyExceptions dve;
  4621. for (size_t i = 0; i < count; ++i) {
  4622. SDotOp *p = &pPrimitives[i];
  4623. float dot2, dot3, dot4;
  4624. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  4625. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  4626. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  4627. LogCommentFmt(
  4628. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  4629. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  4630. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  4631. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  4632. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  4633. p->o_dot4, dot4);
  4634. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  4635. tolerance);
  4636. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  4637. tolerance);
  4638. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  4639. tolerance);
  4640. }
  4641. }
  4642. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  4643. WEX::TestExecution::SetVerifyOutput verifySettings(
  4644. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4645. CComPtr<IStream> pStream;
  4646. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4647. CComPtr<ID3D12Device> pDevice;
  4648. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  4649. return;
  4650. }
  4651. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4652. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4653. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4654. return;
  4655. }
  4656. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  4657. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  4658. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4659. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4660. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4661. std::vector<WEX::Common::String> *validation_input1 =
  4662. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  4663. std::vector<WEX::Common::String> *validation_input2 =
  4664. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  4665. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  4666. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  4667. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4668. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4669. size_t count = validation_input1->size();
  4670. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4671. pDevice, m_support, pStream, "Dot2AddHalfOp",
  4672. // this callback is called when the test
  4673. // is creating the resource to run the test
  4674. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4675. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  4676. size_t size = sizeof(SDot2AddHalfOp) * count;
  4677. Data.resize(size);
  4678. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  4679. for (size_t i = 0; i < count; ++i) {
  4680. SDot2AddHalfOp *p = &pPrimitives[i];
  4681. Half2 val1,val2;
  4682. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  4683. (uint16_t *)&val1, 2));
  4684. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  4685. (uint16_t *)&val2, 2));
  4686. p->input1 = val1;
  4687. p->input2 = val2;
  4688. p->acc = (*validation_acc)[i];
  4689. }
  4690. // use shader from data table
  4691. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4692. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4693. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4694. });
  4695. MappedData data;
  4696. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  4697. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  4698. WEX::TestExecution::DisableVerifyExceptions dve;
  4699. for (size_t i = 0; i < count; ++i) {
  4700. SDot2AddHalfOp *p = &pPrimitives[i];
  4701. float expectedResult = (*validation_result)[i];
  4702. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  4703. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  4704. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  4705. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  4706. LogCommentFmt(
  4707. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  4708. L"result = %f, result_expected = %f",
  4709. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  4710. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  4711. }
  4712. }
  4713. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  4714. WEX::TestExecution::SetVerifyOutput verifySettings(
  4715. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4716. CComPtr<IStream> pStream;
  4717. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4718. CComPtr<ID3D12Device> pDevice;
  4719. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  4720. return;
  4721. }
  4722. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  4723. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  4724. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4725. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4726. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4727. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4728. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4729. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4730. size_t count = validation_input1->size();
  4731. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4732. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  4733. // this callback is called when the test
  4734. // is creating the resource to run the test
  4735. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4736. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  4737. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  4738. Data.resize(size);
  4739. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  4740. for (size_t i = 0; i < count; ++i) {
  4741. SDot4AddI8PackedOp *p = &pPrimitives[i];
  4742. p->input1 = (*validation_input1)[i];
  4743. p->input2 = (*validation_input2)[i];
  4744. p->acc = (*validation_acc)[i];
  4745. }
  4746. // use shader from data table
  4747. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4748. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4749. });
  4750. MappedData data;
  4751. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  4752. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  4753. WEX::TestExecution::DisableVerifyExceptions dve;
  4754. for (size_t i = 0; i < count; ++i) {
  4755. SDot4AddI8PackedOp *p = &pPrimitives[i];
  4756. int32_t expectedResult = (*validation_result)[i];
  4757. LogCommentFmt(
  4758. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  4759. L"result = %d, result_expected = %d",
  4760. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  4761. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  4762. }
  4763. }
  4764. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  4765. WEX::TestExecution::SetVerifyOutput verifySettings(
  4766. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4767. CComPtr<IStream> pStream;
  4768. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4769. CComPtr<ID3D12Device> pDevice;
  4770. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  4771. return;
  4772. }
  4773. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  4774. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  4775. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4776. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4777. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4778. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4779. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4780. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4781. size_t count = validation_input1->size();
  4782. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4783. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  4784. // this callback is called when the test
  4785. // is creating the resource to run the test
  4786. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4787. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  4788. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  4789. Data.resize(size);
  4790. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  4791. for (size_t i = 0; i < count; ++i) {
  4792. SDot4AddU8PackedOp *p = &pPrimitives[i];
  4793. p->input1 = (*validation_input1)[i];
  4794. p->input2 = (*validation_input2)[i];
  4795. p->acc = (*validation_acc)[i];
  4796. }
  4797. // use shader from data table
  4798. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4799. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4800. });
  4801. MappedData data;
  4802. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  4803. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  4804. WEX::TestExecution::DisableVerifyExceptions dve;
  4805. for (size_t i = 0; i < count; ++i) {
  4806. SDot4AddU8PackedOp *p = &pPrimitives[i];
  4807. uint32_t expectedResult = (*validation_result)[i];
  4808. LogCommentFmt(
  4809. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  4810. L"result = %u, result_expected = %u, ",
  4811. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  4812. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  4813. }
  4814. }
  4815. TEST_F(ExecutionTest, Msad4Test) {
  4816. WEX::TestExecution::SetVerifyOutput verifySettings(
  4817. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4818. CComPtr<IStream> pStream;
  4819. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4820. CComPtr<ID3D12Device> pDevice;
  4821. if (!CreateDevice(&pDevice)) {
  4822. return;
  4823. }
  4824. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  4825. TableParameterHandler handler(Msad4OpParameters, tableSize);
  4826. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4827. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4828. std::vector<unsigned int> *Validation_Reference =
  4829. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4830. std::vector<WEX::Common::String> *Validation_Source =
  4831. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  4832. std::vector<WEX::Common::String> *Validation_Accum =
  4833. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  4834. std::vector<WEX::Common::String> *Validation_Expected =
  4835. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  4836. size_t count = Validation_Expected->size();
  4837. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4838. pDevice, m_support, pStream, "Msad4",
  4839. // this callbacked is called when the test
  4840. // is creating the resource to run the test
  4841. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4842. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  4843. size_t size = sizeof(SMsad4) * count;
  4844. Data.resize(size);
  4845. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  4846. for (size_t i = 0; i < count; ++i) {
  4847. SMsad4 *p = &pPrimitives[i];
  4848. XMUINT2 src;
  4849. XMUINT4 accum;
  4850. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  4851. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  4852. p->ref = (*Validation_Reference)[i];
  4853. p->src = src;
  4854. p->accum = accum;
  4855. }
  4856. // use shader from data table
  4857. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4858. });
  4859. MappedData data;
  4860. test->Test->GetReadBackData("SMsad4", &data);
  4861. SMsad4 *pPrimitives = (SMsad4*)data.data();
  4862. WEX::TestExecution::DisableVerifyExceptions dve;
  4863. for (size_t i = 0; i < count; ++i) {
  4864. SMsad4 *p = &pPrimitives[i];
  4865. XMUINT4 result;
  4866. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  4867. (unsigned int *)&result, 4));
  4868. LogCommentFmt(
  4869. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  4870. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  4871. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  4872. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  4873. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  4874. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  4875. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  4876. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  4877. result.x, result.x, result.y, result.y, result.z, result.z,
  4878. result.w, result.w);
  4879. int toleranceInt = (int)tolerance;
  4880. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  4881. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  4882. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  4883. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  4884. }
  4885. }
  4886. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  4887. WEX::TestExecution::SetVerifyOutput verifySettings(
  4888. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4889. CComPtr<IStream> pStream;
  4890. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4891. CComPtr<ID3D12Device> pDevice;
  4892. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4893. return;
  4894. }
  4895. // Read data from the table
  4896. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  4897. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  4898. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4899. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4900. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4901. std::vector<WEX::Common::String> *Validation_Input1 =
  4902. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  4903. std::vector<WEX::Common::String> *Validation_Input2 =
  4904. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  4905. std::vector<WEX::Common::String> *Validation_Expected1 =
  4906. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  4907. // two expected outputs for any mode
  4908. std::vector<WEX::Common::String> *Validation_Expected2 =
  4909. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  4910. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4911. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4912. size_t count = Validation_Input1->size();
  4913. using namespace hlsl::DXIL;
  4914. Float32DenormMode mode = Float32DenormMode::Any;
  4915. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  4916. mode = Float32DenormMode::Preserve;
  4917. }
  4918. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  4919. mode = Float32DenormMode::FTZ;
  4920. }
  4921. if (mode == Float32DenormMode::Any) {
  4922. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  4923. "must have same number of expected values");
  4924. }
  4925. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4926. pDevice, m_support, pStream, "BinaryFPOp",
  4927. // this callbacked is called when the test
  4928. // is creating the resource to run the test
  4929. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4930. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4931. size_t size = sizeof(SBinaryFPOp) * count;
  4932. Data.resize(size);
  4933. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4934. for (size_t i = 0; i < count; ++i) {
  4935. SBinaryFPOp *p = &pPrimitives[i];
  4936. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4937. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4938. float val1, val2;
  4939. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  4940. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  4941. p->input1 = val1;
  4942. p->input2 = val2;
  4943. }
  4944. // use shader from data table
  4945. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4946. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4947. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4948. });
  4949. MappedData data;
  4950. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4951. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4952. WEX::TestExecution::DisableVerifyExceptions dve;
  4953. for (unsigned i = 0; i < count; ++i) {
  4954. SBinaryFPOp *p = &pPrimitives[i];
  4955. if (mode == Float32DenormMode::Any) {
  4956. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4957. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4958. float val1;
  4959. float val2;
  4960. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  4961. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  4962. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  4963. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  4964. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  4965. VERIFY_IS_TRUE(
  4966. CompareOutputWithExpectedValueFloat(
  4967. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  4968. CompareOutputWithExpectedValueFloat(
  4969. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  4970. }
  4971. else {
  4972. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4973. float val1;
  4974. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  4975. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  4976. L"%6.8f, expected = %6.8f(%a)",
  4977. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  4978. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4979. Validation_Tolerance, mode);
  4980. }
  4981. }
  4982. }
  4983. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  4984. WEX::TestExecution::SetVerifyOutput verifySettings(
  4985. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4986. CComPtr<IStream> pStream;
  4987. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4988. CComPtr<ID3D12Device> pDevice;
  4989. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4990. return;
  4991. }
  4992. // Read data from the table
  4993. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  4994. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  4995. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4996. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4997. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4998. std::vector<WEX::Common::String> *Validation_Input1 =
  4999. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5000. std::vector<WEX::Common::String> *Validation_Input2 =
  5001. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5002. std::vector<WEX::Common::String> *Validation_Input3 =
  5003. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5004. std::vector<WEX::Common::String> *Validation_Expected1 =
  5005. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5006. // two expected outputs for any mode
  5007. std::vector<WEX::Common::String> *Validation_Expected2 =
  5008. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5009. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5010. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5011. size_t count = Validation_Input1->size();
  5012. using namespace hlsl::DXIL;
  5013. Float32DenormMode mode = Float32DenormMode::Any;
  5014. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5015. mode = Float32DenormMode::Preserve;
  5016. }
  5017. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5018. mode = Float32DenormMode::FTZ;
  5019. }
  5020. if (mode == Float32DenormMode::Any) {
  5021. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5022. "must have same number of expected values");
  5023. }
  5024. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5025. pDevice, m_support, pStream, "TertiaryFPOp",
  5026. // this callbacked is called when the test
  5027. // is creating the resource to run the test
  5028. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5029. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5030. size_t size = sizeof(STertiaryFPOp) * count;
  5031. Data.resize(size);
  5032. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5033. for (size_t i = 0; i < count; ++i) {
  5034. STertiaryFPOp *p = &pPrimitives[i];
  5035. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5036. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5037. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5038. float val1, val2, val3;
  5039. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5040. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5041. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5042. p->input1 = val1;
  5043. p->input2 = val2;
  5044. p->input3 = val3;
  5045. }
  5046. // use shader from data table
  5047. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5048. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5049. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5050. });
  5051. MappedData data;
  5052. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5053. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5054. WEX::TestExecution::DisableVerifyExceptions dve;
  5055. for (unsigned i = 0; i < count; ++i) {
  5056. STertiaryFPOp *p = &pPrimitives[i];
  5057. if (mode == Float32DenormMode::Any) {
  5058. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5059. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5060. float val1;
  5061. float val2;
  5062. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5063. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5064. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5065. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5066. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5067. VERIFY_IS_TRUE(
  5068. CompareOutputWithExpectedValueFloat(
  5069. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5070. CompareOutputWithExpectedValueFloat(
  5071. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5072. }
  5073. else {
  5074. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5075. float val1;
  5076. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5077. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5078. L"%6.8f, expected = %6.8f(%a)",
  5079. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5080. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5081. Validation_Tolerance, mode);
  5082. }
  5083. }
  5084. }
  5085. // Setup for wave intrinsics tests
  5086. enum class ShaderOpKind {
  5087. WaveSum,
  5088. WaveProduct,
  5089. WaveActiveMax,
  5090. WaveActiveMin,
  5091. WaveCountBits,
  5092. WaveActiveAllEqual,
  5093. WaveActiveAnyTrue,
  5094. WaveActiveAllTrue,
  5095. WaveActiveBitOr,
  5096. WaveActiveBitAnd,
  5097. WaveActiveBitXor,
  5098. ShaderOpInvalid
  5099. };
  5100. struct ShaderOpKindPair {
  5101. LPCWSTR name;
  5102. ShaderOpKind kind;
  5103. };
  5104. static ShaderOpKindPair ShaderOpKindTable[] = {
  5105. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5106. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5107. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5108. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5109. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5110. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5111. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5112. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5113. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5114. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5115. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5116. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5117. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5118. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5119. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5120. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5121. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5122. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  5123. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  5124. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  5125. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  5126. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  5127. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  5128. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  5129. };
  5130. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  5131. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  5132. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  5133. return ShaderOpKindTable[i].kind;
  5134. }
  5135. }
  5136. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  5137. return ShaderOpKind::ShaderOpInvalid;
  5138. }
  5139. template <typename InType, typename OutType, ShaderOpKind kind>
  5140. struct computeExpected {
  5141. OutType operator()(const std::vector<InType> &inputs,
  5142. const std::vector<int> &masks, int maskValue,
  5143. unsigned int index) {
  5144. return 0;
  5145. }
  5146. };
  5147. template <typename InType, typename OutType>
  5148. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  5149. OutType operator()(const std::vector<InType> &inputs,
  5150. const std::vector<int> &masks, int maskValue,
  5151. unsigned int index) {
  5152. OutType sum = 0;
  5153. for (size_t i = 0; i < index; ++i) {
  5154. if (masks.at(i) == maskValue) {
  5155. sum += inputs.at(i);
  5156. }
  5157. }
  5158. return sum;
  5159. }
  5160. };
  5161. template <typename InType, typename OutType>
  5162. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  5163. OutType operator()(const std::vector<InType> &inputs,
  5164. const std::vector<int> &masks, int maskValue,
  5165. unsigned int index) {
  5166. OutType prod = 1;
  5167. for (size_t i = 0; i < index; ++i) {
  5168. if (masks.at(i) == maskValue) {
  5169. prod *= inputs.at(i);
  5170. }
  5171. }
  5172. return prod;
  5173. }
  5174. };
  5175. template <typename InType, typename OutType>
  5176. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  5177. OutType operator()(const std::vector<InType> &inputs,
  5178. const std::vector<int> &masks, int maskValue,
  5179. unsigned int index) {
  5180. OutType maximum = std::numeric_limits<OutType>::min();
  5181. for (size_t i = 0; i < index; ++i) {
  5182. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  5183. maximum = inputs.at(i);
  5184. }
  5185. return maximum;
  5186. }
  5187. };
  5188. template <typename InType, typename OutType>
  5189. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  5190. OutType operator()(const std::vector<InType> &inputs,
  5191. const std::vector<int> &masks, int maskValue,
  5192. unsigned int index) {
  5193. OutType minimum = std::numeric_limits<OutType>::max();
  5194. for (size_t i = 0; i < index; ++i) {
  5195. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  5196. minimum = inputs.at(i);
  5197. }
  5198. return minimum;
  5199. }
  5200. };
  5201. template <typename InType, typename OutType>
  5202. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  5203. OutType operator()(const std::vector<InType> &inputs,
  5204. const std::vector<int> &masks, int maskValue,
  5205. unsigned int index) {
  5206. OutType count = 0;
  5207. for (size_t i = 0; i < index; ++i) {
  5208. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  5209. count++;
  5210. }
  5211. }
  5212. return count;
  5213. }
  5214. };
  5215. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  5216. // So we cannot use c++ bool type to represent bool in HLSL
  5217. // HLSL returns 0 for false and 1 for true
  5218. template <typename InType, typename OutType>
  5219. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  5220. OutType operator()(const std::vector<InType> &inputs,
  5221. const std::vector<int> &masks, int maskValue,
  5222. unsigned int index) {
  5223. for (size_t i = 0; i < index; ++i) {
  5224. if (masks.at(i) == maskValue && inputs.at(i) != 0) {
  5225. return 1;
  5226. }
  5227. }
  5228. return 0;
  5229. }
  5230. };
  5231. template <typename InType, typename OutType>
  5232. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  5233. OutType operator()(const std::vector<InType> &inputs,
  5234. const std::vector<int> &masks, int maskValue,
  5235. unsigned int index) {
  5236. for (size_t i = 0; i < index; ++i) {
  5237. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  5238. return 0;
  5239. }
  5240. }
  5241. return 1;
  5242. }
  5243. };
  5244. template <typename InType, typename OutType>
  5245. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  5246. OutType operator()(const std::vector<InType> &inputs,
  5247. const std::vector<int> &masks, int maskValue,
  5248. unsigned int index) {
  5249. const InType *val = nullptr;
  5250. for (size_t i = 0; i < index; ++i) {
  5251. if (masks.at(i) == maskValue) {
  5252. if (val && *val != inputs.at(i)) {
  5253. return 0;
  5254. }
  5255. val = &inputs.at(i);
  5256. }
  5257. }
  5258. return 1;
  5259. }
  5260. };
  5261. template <typename InType, typename OutType>
  5262. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  5263. OutType operator()(const std::vector<InType> &inputs,
  5264. const std::vector<int> &masks, int maskValue,
  5265. unsigned int index) {
  5266. OutType bits = 0x00000000;
  5267. for (size_t i = 0; i < index; ++i) {
  5268. if (masks.at(i) == maskValue) {
  5269. bits |= inputs.at(i);
  5270. }
  5271. }
  5272. return bits;
  5273. }
  5274. };
  5275. template <typename InType, typename OutType>
  5276. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  5277. OutType operator()(const std::vector<InType> &inputs,
  5278. const std::vector<int> &masks, int maskValue,
  5279. unsigned int index) {
  5280. OutType bits = 0xffffffff;
  5281. for (size_t i = 0; i < index; ++i) {
  5282. if (masks.at(i) == maskValue) {
  5283. bits &= inputs.at(i);
  5284. }
  5285. }
  5286. return bits;
  5287. }
  5288. };
  5289. template <typename InType, typename OutType>
  5290. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  5291. OutType operator()(const std::vector<InType> &inputs,
  5292. const std::vector<int> &masks, int maskValue,
  5293. unsigned int index) {
  5294. OutType bits = 0x00000000;
  5295. for (size_t i = 0; i < index; ++i) {
  5296. if (masks.at(i) == maskValue) {
  5297. bits ^= inputs.at(i);
  5298. }
  5299. }
  5300. return bits;
  5301. }
  5302. };
  5303. // Mask functions used to control active lanes
  5304. static int MaskAll(int i) {
  5305. UNREFERENCED_PARAMETER(i);
  5306. return 1;
  5307. }
  5308. static int MaskEveryOther(int i) {
  5309. return i % 2 == 0 ? 1 : 0;
  5310. }
  5311. static int MaskEveryThird(int i) {
  5312. return i % 3 == 0 ? 1 : 0;
  5313. }
  5314. typedef int(*MaskFunction)(int);
  5315. static MaskFunction MaskFunctionTable[] = {
  5316. MaskAll, MaskEveryOther, MaskEveryThird
  5317. };
  5318. template <typename InType, typename OutType>
  5319. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  5320. const std::vector<int> &masks,
  5321. int maskValue, unsigned int index,
  5322. LPCWSTR str) {
  5323. ShaderOpKind kind = GetShaderOpKind(str);
  5324. switch (kind) {
  5325. case ShaderOpKind::WaveSum:
  5326. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  5327. case ShaderOpKind::WaveProduct:
  5328. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  5329. case ShaderOpKind::WaveActiveMax:
  5330. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  5331. case ShaderOpKind::WaveActiveMin:
  5332. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  5333. case ShaderOpKind::WaveCountBits:
  5334. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  5335. case ShaderOpKind::WaveActiveBitOr:
  5336. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  5337. case ShaderOpKind::WaveActiveBitAnd:
  5338. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  5339. case ShaderOpKind::WaveActiveBitXor:
  5340. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  5341. case ShaderOpKind::WaveActiveAnyTrue:
  5342. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  5343. case ShaderOpKind::WaveActiveAllTrue:
  5344. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  5345. case ShaderOpKind::WaveActiveAllEqual:
  5346. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  5347. default:
  5348. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  5349. return (OutType) 0;
  5350. }
  5351. };
  5352. // A framework for testing individual wave intrinsics tests.
  5353. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  5354. template <class T1, class T2>
  5355. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  5356. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  5357. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5358. // Resource representation for compute shader
  5359. // firstLaneId is used to group different waves
  5360. // laneIndex is used to identify lane within the wave.
  5361. // Lane ids are not necessarily in same order as thread ids.
  5362. struct PerThreadData {
  5363. unsigned firstLaneId;
  5364. unsigned laneIndex;
  5365. int mask;
  5366. T1 input;
  5367. T2 output;
  5368. };
  5369. unsigned int NumThreadsX = 8;
  5370. unsigned int NumThreadsY = 12;
  5371. unsigned int NumThreadsZ = 1;
  5372. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  5373. static const unsigned int DispatchGroupCount = 1;
  5374. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  5375. CComPtr<IStream> pStream;
  5376. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5377. CComPtr<ID3D12Device> pDevice;
  5378. if (!CreateDevice(&pDevice)) {
  5379. return;
  5380. }
  5381. if (!DoesDeviceSupportWaveOps(pDevice)) {
  5382. // Optional feature, so it's correct to not support it if declared as such.
  5383. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  5384. return;
  5385. }
  5386. TableParameterHandler handler(pParameterList, numParameter);
  5387. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  5388. // Obtain the list of input lists
  5389. std::vector<std::vector<T1>*> InputDataList;
  5390. for (unsigned int i = 0;
  5391. i < numInputSet; ++i) {
  5392. std::wstring inputName = L"Validation.InputSet";
  5393. inputName.append(std::to_wstring(i + 1));
  5394. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  5395. }
  5396. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  5397. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  5398. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  5399. // Running compute shader for each input set with different masks
  5400. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  5401. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  5402. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  5403. pDevice, m_support, "WaveIntrinsicsOp",
  5404. // this callbacked is called when the test
  5405. // is creating the resource to run the test
  5406. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5407. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  5408. size_t size = sizeof(PerThreadData) * ThreadCount;
  5409. Data.resize(size);
  5410. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  5411. // 4 different inputs for each operation test
  5412. size_t index = 0;
  5413. std::vector<T1> *IntList = InputDataList[setIndex];
  5414. while (index < ThreadCount) {
  5415. PerThreadData *p = &pPrimitives[index];
  5416. p->firstLaneId = 0xFFFFBFFF;
  5417. p->laneIndex = 0xFFFFBFFF;
  5418. p->mask = MaskFunctionTable[maskIndex]((int)index);
  5419. p->input = (*IntList)[index % IntList->size()];
  5420. p->output = 0xFFFFBFFF;
  5421. index++;
  5422. }
  5423. // use shader from data table
  5424. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5425. }, ShaderOpSet);
  5426. // Check the value
  5427. MappedData data;
  5428. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  5429. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  5430. WEX::TestExecution::DisableVerifyExceptions dve;
  5431. // Grouping data by waves
  5432. std::vector<int> firstLaneIds;
  5433. for (size_t i = 0; i < ThreadCount; ++i) {
  5434. PerThreadData *p = &pPrimitives[i];
  5435. int firstLaneId = p->firstLaneId;
  5436. if (!contains(firstLaneIds, firstLaneId)) {
  5437. firstLaneIds.push_back(firstLaneId);
  5438. }
  5439. }
  5440. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  5441. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  5442. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  5443. }
  5444. for (size_t i = 0; i < ThreadCount; ++i) {
  5445. PerThreadData *p = &pPrimitives[i];
  5446. waves[p->firstLaneId].get()->push_back(p);
  5447. }
  5448. // validate for each wave
  5449. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  5450. // collect inputs and masks for a given wave
  5451. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  5452. std::vector<T1> inputList(waveData->size());
  5453. std::vector<int> maskList(waveData->size(), -1);
  5454. std::vector<T2> outputList(waveData->size());
  5455. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  5456. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  5457. unsigned laneID = waveData->at(j)->laneIndex;
  5458. // ensure that each lane ID is unique and within the range
  5459. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  5460. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  5461. maskList.at(laneID) = waveData->at(j)->mask;
  5462. inputList.at(laneID) = waveData->at(j)->input;
  5463. outputList.at(laneID) = waveData->at(j)->output;
  5464. }
  5465. std::wstring inputStr = L"Wave Inputs: ";
  5466. std::wstring maskStr = L"Wave Masks: ";
  5467. std::wstring outputStr = L"Wave Outputs: ";
  5468. // append input string and mask string in lane id order
  5469. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  5470. maskStr.append(std::to_wstring(maskList.at(j)));
  5471. maskStr.append(L" ");
  5472. inputStr.append(std::to_wstring(inputList.at(j)));
  5473. inputStr.append(L" ");
  5474. outputStr.append(std::to_wstring(outputList.at(j)));
  5475. outputStr.append(L" ");
  5476. }
  5477. LogCommentFmt(inputStr.data());
  5478. LogCommentFmt(maskStr.data());
  5479. LogCommentFmt(outputStr.data());
  5480. LogCommentFmt(L"\n");
  5481. // Compute expected output for a given inputs, masks, and index
  5482. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  5483. T2 expected;
  5484. // WaveActive is equivalent to WavePrefix lane # lane count
  5485. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  5486. if (maskList.at(laneIndex) == 1) {
  5487. expected = computeExpectedWithShaderOp<T1, T2>(
  5488. inputList, maskList, 1, index,
  5489. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  5490. }
  5491. else {
  5492. expected = computeExpectedWithShaderOp<T1, T2>(
  5493. inputList, maskList, 0, index,
  5494. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  5495. }
  5496. // TODO: use different comparison for floating point inputs
  5497. bool equal = outputList.at(laneIndex) == expected;
  5498. if (!equal) {
  5499. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  5500. }
  5501. VERIFY_IS_TRUE(equal);
  5502. }
  5503. }
  5504. }
  5505. }
  5506. }
  5507. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  5508. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  5509. if (GetTestParamUseWARP(true) &&
  5510. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  5511. return;
  5512. }
  5513. WaveIntrinsicsActivePrefixTest<int, int>(
  5514. WaveIntrinsicsActiveIntParameters,
  5515. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  5516. /*isPrefix*/ false);
  5517. }
  5518. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  5519. if (GetTestParamUseWARP(true) &&
  5520. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  5521. return;
  5522. }
  5523. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  5524. WaveIntrinsicsActiveUintParameters,
  5525. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  5526. /*isPrefix*/ false);
  5527. }
  5528. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  5529. if (GetTestParamUseWARP(true) &&
  5530. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  5531. return;
  5532. }
  5533. WaveIntrinsicsActivePrefixTest<int, int>(
  5534. WaveIntrinsicsPrefixIntParameters,
  5535. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  5536. /*isPrefix*/ true);
  5537. }
  5538. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  5539. if (GetTestParamUseWARP(true) &&
  5540. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  5541. return;
  5542. }
  5543. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  5544. WaveIntrinsicsPrefixUintParameters,
  5545. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  5546. /*isPrefix*/ true);
  5547. }
  5548. template <typename T>
  5549. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  5550. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  5551. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  5552. return static_cast<T>(1);
  5553. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  5554. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  5555. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  5556. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  5557. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  5558. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  5559. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  5560. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  5561. return static_cast<T>(0);
  5562. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  5563. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  5564. return static_cast<T>(-1);
  5565. } else {
  5566. return static_cast<T>(0);
  5567. }
  5568. }
  5569. template <typename T>
  5570. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  5571. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  5572. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  5573. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  5574. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  5575. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  5576. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  5577. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  5578. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  5579. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  5580. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  5581. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  5582. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  5583. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  5584. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  5585. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  5586. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  5587. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  5588. // For CountBits, each lane contributes a boolean value. The test input is
  5589. // a zero or non-zero integer. If the input is a non-zero value then the
  5590. // condition is true, thus we contribute one to the bit count.
  5591. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  5592. } else {
  5593. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  5594. }
  5595. }
  5596. template <class T>
  5597. void
  5598. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  5599. size_t numParameters) {
  5600. WEX::TestExecution::SetVerifyOutput
  5601. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5602. struct PerThreadData {
  5603. uint32_t key;
  5604. uint32_t firstLaneId;
  5605. uint32_t laneId;
  5606. uint32_t mask;
  5607. T value;
  5608. T result;
  5609. };
  5610. constexpr size_t NumThreadsX = 8;
  5611. constexpr size_t NumThreadsY = 12;
  5612. constexpr size_t NumThreadsZ = 1;
  5613. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  5614. constexpr size_t DispatchGroupSize = 1;
  5615. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  5616. CComPtr<IStream> pStream;
  5617. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5618. CComPtr<ID3D12Device> pDevice;
  5619. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  5620. return;
  5621. }
  5622. if (!DoesDeviceSupportWaveOps(pDevice)) {
  5623. // Optional feature, so it's correct to not support it if declared as such.
  5624. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  5625. return;
  5626. }
  5627. std::shared_ptr<st::ShaderOpSet>
  5628. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  5629. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  5630. TableParameterHandler handler(pParameterList, numParameters);
  5631. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5632. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5633. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  5634. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  5635. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  5636. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  5637. std::shared_ptr<ShaderOpTestResult> test =
  5638. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  5639. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  5640. UNREFERENCED_PARAMETER(name);
  5641. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  5642. data.resize(dataSize);
  5643. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  5644. for (size_t i = 0; i != ThreadCount; ++i) {
  5645. pThreadData[i].key = keys->at(i % keys->size());
  5646. pThreadData[i].value = values->at(i % values->size());
  5647. pThreadData[i].firstLaneId = 0xdeadbeef;
  5648. pThreadData[i].laneId = 0xdeadbeef;
  5649. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  5650. pThreadData[i].result = 0xdeadbeef;
  5651. }
  5652. pShaderOp->Shaders.at(0).Text = shaderSource;
  5653. pShaderOp->Shaders.at(0).Target = shaderProfile;
  5654. }, ShaderOpSet);
  5655. MappedData mappedData;
  5656. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  5657. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  5658. // Partition our data into waves
  5659. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  5660. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  5661. PerThreadData *elt = &resultData[i];
  5662. // Basic sanity checks
  5663. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  5664. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  5665. waves[elt->firstLaneId].push_back(elt);
  5666. }
  5667. // Verify each wave
  5668. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  5669. for (auto &w : waves) {
  5670. std::vector<PerThreadData *> &waveData = w.second;
  5671. struct {
  5672. bool operator()(PerThreadData *a, PerThreadData *b) const {
  5673. return (a->laneId < b->laneId);
  5674. }
  5675. } compare;
  5676. // Need to sort based on the lane id
  5677. std::sort(waveData.begin(), waveData.end(), compare);
  5678. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  5679. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  5680. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  5681. PerThreadData *data = waveData[i];
  5682. // Compute prefix operation over each previous lane element that has the
  5683. // same key value, and is part of the same active thread group
  5684. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  5685. for (unsigned j = 0; j < i; ++j) {
  5686. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  5687. accum = refFn(accum, waveData[j]->value);
  5688. }
  5689. }
  5690. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  5691. VERIFY_IS_TRUE(accum == data->result);
  5692. }
  5693. LogCommentFmt(L"\n");
  5694. }
  5695. }
  5696. }
  5697. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  5698. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  5699. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  5700. }
  5701. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  5702. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  5703. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  5704. }
  5705. TEST_F(ExecutionTest, CBufferTestHalf) {
  5706. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5707. CComPtr<IStream> pStream;
  5708. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5709. // Single operation test at the moment.
  5710. CComPtr<ID3D12Device> pDevice;
  5711. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  5712. return;
  5713. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5714. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5715. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5716. return;
  5717. }
  5718. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  5719. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  5720. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5721. UNREFERENCED_PARAMETER(pShaderOp);
  5722. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  5723. // use shader from data table.
  5724. Data.resize(sizeof(InputData));
  5725. uint16_t *pData = (uint16_t *)Data.data();
  5726. for (size_t i = 0; i < 4; ++i, ++pData) {
  5727. *pData = InputData[i];
  5728. }
  5729. });
  5730. {
  5731. MappedData data;
  5732. test->Test->GetReadBackData("RTarget", &data);
  5733. const uint16_t *pPixels = (uint16_t *)data.data();
  5734. for (int i = 0; i < 4; ++i) {
  5735. uint16_t output = *(pPixels + i);
  5736. float outputFloat = ConvertFloat16ToFloat32(output);
  5737. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  5738. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  5739. i, inputFloat, InputData[i], outputFloat, output);
  5740. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  5741. }
  5742. }
  5743. }
  5744. TEST_F(ExecutionTest, BarycentricsTest) {
  5745. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5746. CComPtr<IStream> pStream;
  5747. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5748. CComPtr<ID3D12Device> pDevice;
  5749. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  5750. return;
  5751. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  5752. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  5753. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5754. return;
  5755. }
  5756. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  5757. MappedData data;
  5758. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  5759. UINT width = (UINT)D.Width;
  5760. UINT height = D.Height;
  5761. UINT pixelSize = GetByteSizeForFormat(D.Format);
  5762. test->Test->GetReadBackData("RTarget", &data);
  5763. //const uint8_t *pPixels = (uint8_t *)data.data();
  5764. const float *pPixels = (float *)data.data();
  5765. // Get the vertex of barycentric coordinate using VBuffer
  5766. MappedData triangleData;
  5767. test->Test->GetReadBackData("VBuffer", &triangleData);
  5768. const float *pTriangleData = (float*)triangleData.data();
  5769. // get the size of the input data
  5770. unsigned triangleVertexSizeInFloat = 0;
  5771. for (auto element : test->ShaderOp->InputElements)
  5772. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  5773. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  5774. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  5775. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  5776. XMFLOAT3 barycentricWeights[4] = {
  5777. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  5778. XMFLOAT3(0.5f, 0.25f, 0.25f),
  5779. XMFLOAT3(0.25f, 0.5f, 0.25f),
  5780. XMFLOAT3(0.25f, 0.25f, 0.50f)
  5781. };
  5782. float tolerance = 0.001f;
  5783. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  5784. float w0 = barycentricWeights[i].x;
  5785. float w1 = barycentricWeights[i].y;
  5786. float w2 = barycentricWeights[i].z;
  5787. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  5788. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  5789. // map from x1 y1 to rtv pixels
  5790. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  5791. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  5792. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  5793. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  5794. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  5795. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  5796. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  5797. }
  5798. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  5799. }
  5800. static const char RawBufferTestShaderDeclarations[] =
  5801. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  5802. "typedef COMPONENT_TYPE scalar; \r\n"
  5803. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  5804. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  5805. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  5806. "\r\n"
  5807. "struct TestData { \r\n"
  5808. " scalar v1; \r\n"
  5809. " vector2 v2; \r\n"
  5810. " vector3 v3; \r\n"
  5811. " vector4 v4; \r\n"
  5812. "}; \r\n"
  5813. "\r\n"
  5814. "struct UavData {\r\n"
  5815. " TestData input; \r\n"
  5816. " TestData output; \r\n"
  5817. " TestData srvOut; \r\n"
  5818. "}; \r\n"
  5819. "\r\n"
  5820. "ByteAddressBuffer srv0 : register(t0); \r\n"
  5821. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  5822. "ByteAddressBuffer srv2 : register(t2); \r\n"
  5823. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  5824. "\r\n"
  5825. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  5826. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  5827. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  5828. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  5829. static const char RawBufferTestShaderBody[] =
  5830. " // offset of 'out' in 'UavData'\r\n"
  5831. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  5832. "\r\n"
  5833. " // offset of 'srv_out' in 'UavData'\r\n"
  5834. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  5835. "\r\n"
  5836. " // offsets within the 'Data' struct\r\n"
  5837. " const int v1_offset = 0; \r\n"
  5838. " const int v2_offset = COMPONENT_SIZE; \r\n"
  5839. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  5840. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  5841. "\r\n"
  5842. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  5843. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  5844. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  5845. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  5846. "\r\n"
  5847. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  5848. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  5849. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  5850. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  5851. "\r\n"
  5852. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  5853. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  5854. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  5855. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  5856. "\r\n"
  5857. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  5858. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  5859. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  5860. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  5861. "\r\n"
  5862. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  5863. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  5864. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  5865. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  5866. "\r\n"
  5867. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  5868. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  5869. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  5870. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  5871. "\r\n"
  5872. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  5873. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  5874. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  5875. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  5876. "\r\n"
  5877. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  5878. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  5879. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  5880. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  5881. static const char RawBufferTestComputeShaderTemplate[] =
  5882. "%s\r\n" // <- RawBufferTestShaderDeclarations
  5883. "[numthreads(1, 1, 1)]\r\n"
  5884. "void main(uint GI : SV_GroupIndex) {\r\n"
  5885. "%s\r\n" // <- RawBufferTestShaderBody
  5886. "};";
  5887. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  5888. "%s\r\n" // <- RawBufferTestShaderDeclarations
  5889. "struct PSInput { \r\n"
  5890. " float4 pos : SV_POSITION; \r\n"
  5891. "}; \r\n"
  5892. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  5893. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  5894. "%s\r\n" // <- RawBufferTestShaderBody
  5895. " } \r\n"
  5896. " return uint4(1, 2, 3, 4); \r\n"
  5897. "};";
  5898. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  5899. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  5900. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  5901. }
  5902. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  5903. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  5904. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  5905. }
  5906. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  5907. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  5908. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  5909. }
  5910. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  5911. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  5912. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  5913. }
  5914. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  5915. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  5916. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  5917. }
  5918. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  5919. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  5920. RawBufferLdStTestData<uint16_t> halfData;
  5921. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  5922. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  5923. }
  5924. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  5925. }
  5926. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  5927. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  5928. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  5929. }
  5930. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  5931. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  5932. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  5933. }
  5934. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  5935. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  5936. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  5937. }
  5938. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  5939. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  5940. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  5941. }
  5942. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  5943. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  5944. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  5945. }
  5946. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  5947. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  5948. RawBufferLdStTestData<uint16_t> halfData;
  5949. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  5950. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  5951. }
  5952. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  5953. }
  5954. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  5955. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  5956. char *&sTy, char *&additionalOptions) {
  5957. if (!CreateDevice(&pDevice, shaderModel)) {
  5958. return false;
  5959. }
  5960. additionalOptions = "";
  5961. switch (dataType) {
  5962. case RawBufferLdStType::I64:
  5963. if (!DoesDeviceSupportInt64(pDevice)) {
  5964. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  5965. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5966. return false;
  5967. }
  5968. sTy = "int64_t";
  5969. break;
  5970. case RawBufferLdStType::Double:
  5971. if (!DoesDeviceSupportDouble(pDevice)) {
  5972. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  5973. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5974. return false;
  5975. }
  5976. sTy = "double";
  5977. break;
  5978. case RawBufferLdStType::I16:
  5979. case RawBufferLdStType::Half:
  5980. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5981. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5982. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5983. return false;
  5984. }
  5985. additionalOptions = "-enable-16bit-types";
  5986. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  5987. break;
  5988. case RawBufferLdStType::I32:
  5989. sTy = "int32_t";
  5990. break;
  5991. case RawBufferLdStType::Float:
  5992. sTy = "float";
  5993. break;
  5994. default:
  5995. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  5996. }
  5997. // read shader config
  5998. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5999. return true;
  6000. }
  6001. template <class Ty>
  6002. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6003. // read buffers back & verify expected values
  6004. static const int UavBufferCount = 4;
  6005. char bufferName[11] = "UAVBufferX";
  6006. for (unsigned i = 0; i < UavBufferCount; i++) {
  6007. MappedData dataUav;
  6008. RawBufferLdStUavData<Ty> *pOutData;
  6009. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6010. test->GetReadBackData(bufferName, &dataUav);
  6011. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6012. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6013. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6014. // scalar
  6015. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6016. // vector 2
  6017. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6018. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6019. // vector 3
  6020. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6021. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6022. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6023. // vector 4
  6024. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6025. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6026. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6027. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6028. // verify SRV Store
  6029. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6030. // scalar
  6031. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6032. // vector 2
  6033. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6034. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6035. // vector 3
  6036. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6037. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6038. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6039. // vector 4
  6040. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6041. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6042. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6043. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6044. }
  6045. }
  6046. template <class Ty>
  6047. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6048. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6049. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6050. CComPtr<ID3D12Device> pDevice;
  6051. CComPtr<IStream> pStream;
  6052. char *sTy, *additionalOptions;
  6053. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6054. return;
  6055. }
  6056. // format shader source
  6057. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6058. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6059. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6060. // format compiler args
  6061. char compilerOptions[256];
  6062. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6063. // run the shader
  6064. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6065. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6066. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6067. (Name[9] >= '0' && Name[9] <= '3'));
  6068. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6069. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6070. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6071. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6072. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6073. });
  6074. // verify expected values
  6075. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6076. }
  6077. template <class Ty>
  6078. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6079. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6080. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6081. CComPtr<ID3D12Device> pDevice;
  6082. CComPtr<IStream> pStream;
  6083. char *sTy, *additionalOptions;
  6084. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6085. return;
  6086. }
  6087. // format shader source
  6088. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6089. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6090. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6091. // format compiler args
  6092. char compilerOptions[256];
  6093. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6094. // run the shader
  6095. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6096. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6097. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6098. (Name[9] >= '0' && Name[9] <= '3'));
  6099. // pixel shader is at index 1, vertex shader at index 0
  6100. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6101. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6102. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6103. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6104. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6105. });
  6106. // verify expected values
  6107. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6108. }
  6109. #ifndef _HLK_CONF
  6110. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  6111. char **pReadBackDump) {
  6112. std::stringstream str;
  6113. unsigned count = 0;
  6114. for (auto &R : pShaderOp->Resources) {
  6115. if (!R.ReadBack)
  6116. continue;
  6117. ++count;
  6118. str << "Resource: " << R.Name << "\r\n";
  6119. // Find a descriptor that can tell us how to dump this resource.
  6120. bool found = false;
  6121. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  6122. for (auto &D : Heaps.Descriptors) {
  6123. if (_stricmp(D.ResName, R.Name) != 0) {
  6124. continue;
  6125. }
  6126. found = true;
  6127. if (_stricmp(D.Kind, "UAV") != 0) {
  6128. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  6129. break;
  6130. }
  6131. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  6132. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  6133. break;
  6134. }
  6135. // We can map back to the structure if a structured buffer via the shader, but
  6136. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  6137. MappedData data;
  6138. pTest->GetReadBackData(R.Name, &data);
  6139. uint32_t *pData = (uint32_t *)data.data();
  6140. size_t u32_count = R.Desc.Width / sizeof(uint32_t);
  6141. for (size_t i = 0; i < u32_count; ++i) {
  6142. float f = *(float *)pData;
  6143. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  6144. << std::dec << " " << f << "\r\n";
  6145. ++pData;
  6146. }
  6147. break;
  6148. }
  6149. if (found) break;
  6150. }
  6151. if (!found) {
  6152. str << "Unable to find a view for the resource.\r\n";
  6153. }
  6154. }
  6155. str << "Resources read back: " << count << "\r\n";
  6156. std::string s(str.str());
  6157. CComHeapPtr<char> pDump;
  6158. if (!pDump.Allocate(s.size() + 1))
  6159. throw std::bad_alloc();
  6160. memcpy(pDump.m_pData, s.data(), s.size());
  6161. pDump.m_pData[s.size()] = '\0';
  6162. *pReadBackDump = pDump.Detach();
  6163. }
  6164. // This is the exported interface by use from HLSLHost.exe.
  6165. // It's exclusive with the use of the DLL as a TAEF target.
  6166. extern "C" {
  6167. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  6168. HRESULT hr = EnableExperimentalShaderModels();
  6169. if (FAILED(hr)) {
  6170. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  6171. }
  6172. return S_OK;
  6173. }
  6174. __declspec(dllexport) HRESULT WINAPI
  6175. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  6176. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  6177. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  6178. HRESULT hr;
  6179. if (pReadBackDump) *pReadBackDump = nullptr;
  6180. st::SetOutputFn(pStrCtx, pOutputStrFn);
  6181. CComPtr<ID3D12InfoQueue> pInfoQueue;
  6182. CComHeapPtr<char> pDump;
  6183. bool FilterCreation = false;
  6184. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  6185. // Creation is largely driven by inputs, so don't log create/destroy messages.
  6186. pInfoQueue->PushEmptyStorageFilter();
  6187. pInfoQueue->PushEmptyRetrievalFilter();
  6188. if (FilterCreation) {
  6189. D3D12_INFO_QUEUE_FILTER filter;
  6190. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  6191. ZeroMemory(&filter, sizeof(filter));
  6192. filter.DenyList.NumCategories = _countof(denyCategories);
  6193. filter.DenyList.pCategoryList = denyCategories;
  6194. pInfoQueue->PushStorageFilter(&filter);
  6195. }
  6196. }
  6197. else {
  6198. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  6199. }
  6200. try {
  6201. dxc::DxcDllSupport m_support;
  6202. m_support.Initialize();
  6203. const char *pName = nullptr;
  6204. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, strlen(pText));
  6205. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  6206. std::make_shared<st::ShaderOpSet>();
  6207. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6208. st::ShaderOp *pShaderOp;
  6209. if (pName == nullptr) {
  6210. if (ShaderOpSet->ShaderOps.size() != 1) {
  6211. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  6212. return E_FAIL;
  6213. }
  6214. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  6215. }
  6216. else {
  6217. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  6218. }
  6219. if (pShaderOp == nullptr) {
  6220. std::string msg = "Unable to find shader op ";
  6221. msg += pName;
  6222. msg += "; available ops";
  6223. const char sep = ':';
  6224. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  6225. msg += sep;
  6226. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  6227. }
  6228. CA2W msgWide(msg.c_str());
  6229. pOutputStrFn(pStrCtx, msgWide);
  6230. return E_FAIL;
  6231. }
  6232. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  6233. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  6234. test->SetDxcSupport(&m_support);
  6235. test->RunShaderOp(pShaderOp);
  6236. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  6237. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  6238. if (!pShaderOp->IsCompute()) {
  6239. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  6240. test->GetPipelineStats(&stats);
  6241. wchar_t statsText[400];
  6242. StringCchPrintfW(statsText, _countof(statsText),
  6243. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  6244. L"Vertex shader invocations: %I64u\r\n"
  6245. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  6246. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  6247. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  6248. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  6249. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  6250. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  6251. stats.DSInvocations, stats.CSInvocations);
  6252. pOutputStrFn(pStrCtx, statsText);
  6253. }
  6254. if (pReadBackDump) {
  6255. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  6256. }
  6257. hr = S_OK;
  6258. }
  6259. catch (const CAtlException &E)
  6260. {
  6261. hr = E.m_hr;
  6262. }
  6263. catch (const std::bad_alloc &)
  6264. {
  6265. hr = E_OUTOFMEMORY;
  6266. }
  6267. catch (const std::exception &)
  6268. {
  6269. hr = E_FAIL;
  6270. }
  6271. // Drain the device message queue if available.
  6272. if (pInfoQueue != nullptr) {
  6273. wchar_t buf[200];
  6274. StringCchPrintfW(buf, _countof(buf),
  6275. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  6276. L"allowed/denied by storage filter=%u/%u "
  6277. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  6278. (unsigned)pInfoQueue->GetNumStoredMessages(),
  6279. (unsigned)pInfoQueue->GetMessageCountLimit(),
  6280. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  6281. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  6282. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  6283. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  6284. pOutputStrFn(pStrCtx, buf);
  6285. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  6286. pInfoQueue->ClearStoredMessages();
  6287. pInfoQueue->PopRetrievalFilter();
  6288. pInfoQueue->PopStorageFilter();
  6289. if (FilterCreation) {
  6290. pInfoQueue->PopStorageFilter();
  6291. }
  6292. }
  6293. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  6294. return hr;
  6295. }
  6296. }
  6297. #endif
  6298. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  6299. // Do not remove the line above - it is used by TranslateExecutionTest.py