ExecutionTest.cpp 230 KB

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