ExecutionTest.cpp 256 KB

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