ExecutionTest.cpp 230 KB

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