ExecutionTest.cpp 227 KB

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