ExecutionTest.cpp 283 KB

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