ExecutionTest.cpp 388 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490
  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 <array>
  15. #include <vector>
  16. #include <string>
  17. #include <map>
  18. #include <unordered_set>
  19. #include <strstream>
  20. #include <iomanip>
  21. #include "dxc/Test/CompilationResult.h"
  22. #include "dxc/Test/HLSLTestData.h"
  23. #include <Shlwapi.h>
  24. #include <atlcoll.h>
  25. #include <locale>
  26. #include <algorithm>
  27. #undef _read
  28. #include "WexTestClass.h"
  29. #include "dxc/Test/HlslTestUtils.h"
  30. #include "dxc/Test/DxcTestUtils.h"
  31. #include "dxc/Support/Global.h"
  32. #include "dxc/Support/WinIncludes.h"
  33. #include "dxc/Support/FileIOHelper.h"
  34. #include "dxc/Support/Unicode.h"
  35. //
  36. // d3d12.h and dxgi1_4.h are included in the Windows 10 SDK
  37. // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899120(v=vs.85).aspx
  38. // https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
  39. //
  40. #include <d3d12.h>
  41. #include <dxgi1_4.h>
  42. #include <DXGIDebug.h>
  43. #include "dxc/Support/d3dx12.h"
  44. #include <DirectXMath.h>
  45. #include <strsafe.h>
  46. #include <d3dcompiler.h>
  47. #include <wincodec.h>
  48. #include "ShaderOpTest.h"
  49. #pragma comment(lib, "d3dcompiler.lib")
  50. #pragma comment(lib, "windowscodecs.lib")
  51. #pragma comment(lib, "dxguid.lib")
  52. #pragma comment(lib, "version.lib")
  53. // A more recent Windows SDK than currently required is needed for these.
  54. typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)(
  55. UINT NumFeatures,
  56. __in_ecount(NumFeatures) const IID* pIIDs,
  57. __in_ecount_opt(NumFeatures) void* pConfigurationStructs,
  58. __in_ecount_opt(NumFeatures) UINT* pConfigurationStructSizes);
  59. static const GUID D3D12ExperimentalShaderModelsID = { /* 76f5573e-f13a-40f5-b297-81ce9e18933f */
  60. 0x76f5573e,
  61. 0xf13a,
  62. 0x40f5,
  63. { 0xb2, 0x97, 0x81, 0xce, 0x9e, 0x18, 0x93, 0x3f }
  64. };
  65. using namespace DirectX;
  66. using namespace hlsl_test;
  67. template <typename TSequence, typename T>
  68. static bool contains(TSequence s, const T &val) {
  69. return std::cend(s) != std::find(std::cbegin(s), std::cend(s), val);
  70. }
  71. template <typename InputIterator, typename T>
  72. static bool contains(InputIterator b, InputIterator e, const T &val) {
  73. return e != std::find(b, e, val);
  74. }
  75. static HRESULT EnableExperimentalShaderModels() {
  76. HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
  77. if (hRuntime == NULL) {
  78. return HRESULT_FROM_WIN32(GetLastError());
  79. }
  80. D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
  81. (D3D12EnableExperimentalFeaturesFn)GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures");
  82. if (pD3D12EnableExperimentalFeatures == nullptr) {
  83. FreeLibrary(hRuntime);
  84. return HRESULT_FROM_WIN32(GetLastError());
  85. }
  86. HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
  87. FreeLibrary(hRuntime);
  88. return hr;
  89. }
  90. static HRESULT ReportLiveObjects() {
  91. CComPtr<IDXGIDebug1> pDebug;
  92. IFR(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)));
  93. IFR(pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL));
  94. return S_OK;
  95. }
  96. static void WriteInfoQueueMessages(void *pStrCtx, st::OutputStringFn pOutputStrFn, ID3D12InfoQueue *pInfoQueue) {
  97. bool allMessagesOK = true;
  98. UINT64 count = pInfoQueue->GetNumStoredMessages();
  99. CAtlArray<BYTE> message;
  100. for (UINT64 i = 0; i < count; ++i) {
  101. // 'GetMessageA' rather than 'GetMessage' is an artifact of user32 headers.
  102. SIZE_T msgLen = 0;
  103. if (FAILED(pInfoQueue->GetMessageA(i, nullptr, &msgLen))) {
  104. allMessagesOK = false;
  105. continue;
  106. }
  107. if (message.GetCount() < msgLen) {
  108. if (!message.SetCount(msgLen)) {
  109. allMessagesOK = false;
  110. continue;
  111. }
  112. }
  113. D3D12_MESSAGE *pMessage = (D3D12_MESSAGE *)message.GetData();
  114. if (FAILED(pInfoQueue->GetMessageA(i, pMessage, &msgLen))) {
  115. allMessagesOK = false;
  116. continue;
  117. }
  118. CA2W msgW(pMessage->pDescription, CP_ACP);
  119. pOutputStrFn(pStrCtx, msgW.m_psz);
  120. pOutputStrFn(pStrCtx, L"\r\n");
  121. }
  122. if (!allMessagesOK) {
  123. pOutputStrFn(pStrCtx, L"Failed to retrieve some messages.\r\n");
  124. }
  125. }
  126. class CComContext {
  127. private:
  128. bool m_init;
  129. public:
  130. CComContext() : m_init(false) {}
  131. ~CComContext() { Dispose(); }
  132. void Dispose() { if (!m_init) return; m_init = false; CoUninitialize(); }
  133. HRESULT Init() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { m_init = true; } return hr; }
  134. };
  135. static void SavePixelsToFile(LPCVOID pPixels, DXGI_FORMAT format, UINT32 m_width, UINT32 m_height, LPCWSTR pFileName) {
  136. CComContext ctx;
  137. CComPtr<IWICImagingFactory> pFactory;
  138. CComPtr<IWICBitmap> pBitmap;
  139. CComPtr<IWICBitmapEncoder> pEncoder;
  140. CComPtr<IWICBitmapFrameEncode> pFrameEncode;
  141. CComPtr<hlsl::AbstractMemoryStream> pStream;
  142. CComPtr<IMalloc> pMalloc;
  143. struct PF {
  144. DXGI_FORMAT Format;
  145. GUID PixelFormat;
  146. UINT32 PixelSize;
  147. bool operator==(DXGI_FORMAT F) const {
  148. return F == Format;
  149. }
  150. } Vals[] = {
  151. // Add more pixel format mappings as needed.
  152. { DXGI_FORMAT_R8G8B8A8_UNORM, GUID_WICPixelFormat32bppRGBA, 4 }
  153. };
  154. PF *pFormat = std::find(Vals, Vals + _countof(Vals), format);
  155. VERIFY_SUCCEEDED(ctx.Init());
  156. VERIFY_SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory));
  157. VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
  158. VERIFY_SUCCEEDED(hlsl::CreateMemoryStream(pMalloc, &pStream));
  159. VERIFY_ARE_NOT_EQUAL(pFormat, Vals + _countof(Vals));
  160. VERIFY_SUCCEEDED(pFactory->CreateBitmapFromMemory(m_width, m_height, pFormat->PixelFormat, m_width * pFormat->PixelSize, m_width * m_height * pFormat->PixelSize, (BYTE *)pPixels, &pBitmap));
  161. VERIFY_SUCCEEDED(pFactory->CreateEncoder(GUID_ContainerFormatBmp, nullptr, &pEncoder));
  162. VERIFY_SUCCEEDED(pEncoder->Initialize(pStream, WICBitmapEncoderNoCache));
  163. VERIFY_SUCCEEDED(pEncoder->CreateNewFrame(&pFrameEncode, nullptr));
  164. VERIFY_SUCCEEDED(pFrameEncode->Initialize(nullptr));
  165. VERIFY_SUCCEEDED(pFrameEncode->WriteSource(pBitmap, nullptr));
  166. VERIFY_SUCCEEDED(pFrameEncode->Commit());
  167. VERIFY_SUCCEEDED(pEncoder->Commit());
  168. hlsl::WriteBinaryFile(pFileName, pStream->GetPtr(), pStream->GetPtrSize());
  169. }
  170. // Checks if the given warp version supports the given operation.
  171. bool IsValidWarpDllVersion(unsigned int minBuildNumber) {
  172. HMODULE pLibrary = LoadLibrary("D3D10Warp.dll");
  173. if (pLibrary) {
  174. char path[MAX_PATH];
  175. DWORD length = GetModuleFileName(pLibrary, path, MAX_PATH);
  176. if (length) {
  177. DWORD dwVerHnd = 0;
  178. DWORD dwVersionInfoSize = GetFileVersionInfoSize(path, &dwVerHnd);
  179. std::unique_ptr<int[]> VffInfo(new int[dwVersionInfoSize]);
  180. if (GetFileVersionInfo(path, NULL, dwVersionInfoSize, VffInfo.get())) {
  181. LPVOID versionInfo;
  182. UINT size;
  183. if (VerQueryValue(VffInfo.get(), "\\", &versionInfo, &size)) {
  184. if (size) {
  185. VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)versionInfo;
  186. unsigned int warpBuildNumber = verInfo->dwFileVersionLS >> 16 & 0xffff;
  187. if (verInfo->dwSignature == 0xFEEF04BD && warpBuildNumber >= minBuildNumber) {
  188. return true;
  189. }
  190. }
  191. }
  192. }
  193. }
  194. FreeLibrary(pLibrary);
  195. }
  196. return false;
  197. }
  198. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS2
  199. #define D3D12_FEATURE_D3D12_OPTIONS3 ((D3D12_FEATURE)21)
  200. #define NTDDI_WIN10_RS3 0x0A000004 /* ABRACADABRA_WIN10_RS2 */
  201. typedef
  202. enum D3D12_COMMAND_LIST_SUPPORT_FLAGS
  203. {
  204. D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0,
  205. D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT = (1 << D3D12_COMMAND_LIST_TYPE_DIRECT),
  206. D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE = (1 << D3D12_COMMAND_LIST_TYPE_BUNDLE),
  207. D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE = (1 << D3D12_COMMAND_LIST_TYPE_COMPUTE),
  208. D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY = (1 << D3D12_COMMAND_LIST_TYPE_COPY),
  209. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE = (1 << 4),
  210. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS = (1 << 5)
  211. } D3D12_COMMAND_LIST_SUPPORT_FLAGS;
  212. typedef
  213. enum D3D12_VIEW_INSTANCING_TIER
  214. {
  215. D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0,
  216. D3D12_VIEW_INSTANCING_TIER_1 = 1,
  217. D3D12_VIEW_INSTANCING_TIER_2 = 2,
  218. D3D12_VIEW_INSTANCING_TIER_3 = 3
  219. } D3D12_VIEW_INSTANCING_TIER;
  220. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS3
  221. {
  222. _Out_ BOOL CopyQueueTimestampQueriesSupported;
  223. _Out_ BOOL CastingFullyTypedFormatSupported;
  224. _Out_ DWORD WriteBufferImmediateSupportFlags;
  225. _Out_ D3D12_VIEW_INSTANCING_TIER ViewInstancingTier;
  226. _Out_ BOOL BarycentricsSupported;
  227. } D3D12_FEATURE_DATA_D3D12_OPTIONS3;
  228. #endif
  229. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS3
  230. #define D3D12_FEATURE_D3D12_OPTIONS4 ((D3D12_FEATURE)23)
  231. typedef enum D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER
  232. {
  233. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_0,
  234. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1,
  235. } D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER;
  236. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS4
  237. {
  238. _Out_ BOOL ReservedBufferPlacementSupported;
  239. _Out_ D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER SharedResourceCompatibilityTier;
  240. _Out_ BOOL Native16BitShaderOpsSupported;
  241. } D3D12_FEATURE_DATA_D3D12_OPTIONS4;
  242. #endif
  243. // Virtual class to compute the expected result given a set of inputs
  244. struct TableParameter;
  245. class ExecutionTest {
  246. public:
  247. // By default, ignore these tests, which require a recent build to run properly.
  248. BEGIN_TEST_CLASS(ExecutionTest)
  249. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  250. TEST_CLASS_PROPERTY(L"Ignore", L"true")
  251. TEST_METHOD_PROPERTY(L"Priority", L"0")
  252. END_TEST_CLASS()
  253. TEST_CLASS_SETUP(ExecutionTestClassSetup)
  254. TEST_METHOD(BasicComputeTest);
  255. TEST_METHOD(BasicTriangleTest);
  256. TEST_METHOD(BasicTriangleOpTest);
  257. BEGIN_TEST_METHOD(BasicTriangleOpTestHalf)
  258. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  259. END_TEST_METHOD()
  260. TEST_METHOD(OutOfBoundsTest);
  261. TEST_METHOD(SaturateTest);
  262. TEST_METHOD(SignTest);
  263. TEST_METHOD(Int64Test);
  264. TEST_METHOD(LifetimeIntrinsicTest)
  265. TEST_METHOD(WaveIntrinsicsTest);
  266. TEST_METHOD(WaveIntrinsicsDDITest);
  267. TEST_METHOD(WaveIntrinsicsInPSTest);
  268. TEST_METHOD(WaveSizeTest);
  269. TEST_METHOD(PartialDerivTest);
  270. TEST_METHOD(DerivativesTest);
  271. TEST_METHOD(ComputeSampleTest);
  272. TEST_METHOD(AtomicsTest);
  273. TEST_METHOD(Atomics64Test);
  274. TEST_METHOD(AtomicsTyped64Test);
  275. TEST_METHOD(AtomicsShared64Test);
  276. TEST_METHOD(AtomicsFloatTest);
  277. TEST_METHOD(HelperLaneTest);
  278. TEST_METHOD(HelperLaneTestWave);
  279. TEST_METHOD(SignatureResourcesTest)
  280. TEST_METHOD(DynamicResourcesTest)
  281. TEST_METHOD(QuadReadTest)
  282. BEGIN_TEST_METHOD(CBufferTestHalf)
  283. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  284. END_TEST_METHOD()
  285. TEST_METHOD(BasicShaderModel61);
  286. BEGIN_TEST_METHOD(BasicShaderModel63)
  287. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  288. END_TEST_METHOD()
  289. BEGIN_TEST_METHOD(WaveIntrinsicsActiveIntTest)
  290. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveIntTable")
  291. END_TEST_METHOD()
  292. BEGIN_TEST_METHOD(WaveIntrinsicsActiveUintTest)
  293. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveUintTable")
  294. END_TEST_METHOD()
  295. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixIntTest)
  296. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixIntTable")
  297. END_TEST_METHOD()
  298. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixUintTest)
  299. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixUintTable")
  300. END_TEST_METHOD()
  301. BEGIN_TEST_METHOD(WaveIntrinsicsSM65IntTest)
  302. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixIntTable")
  303. END_TEST_METHOD()
  304. BEGIN_TEST_METHOD(WaveIntrinsicsSM65UintTest)
  305. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixUintTable")
  306. END_TEST_METHOD()
  307. // TAEF data-driven tests.
  308. BEGIN_TEST_METHOD(UnaryFloatOpTest)
  309. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
  310. END_TEST_METHOD()
  311. BEGIN_TEST_METHOD(BinaryFloatOpTest)
  312. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
  313. END_TEST_METHOD()
  314. BEGIN_TEST_METHOD(TertiaryFloatOpTest)
  315. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
  316. END_TEST_METHOD()
  317. BEGIN_TEST_METHOD(UnaryHalfOpTest)
  318. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
  319. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  320. END_TEST_METHOD()
  321. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  322. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  323. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  324. END_TEST_METHOD()
  325. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  326. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  327. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  328. END_TEST_METHOD()
  329. BEGIN_TEST_METHOD(UnaryIntOpTest)
  330. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  331. END_TEST_METHOD()
  332. BEGIN_TEST_METHOD(BinaryIntOpTest)
  333. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  334. END_TEST_METHOD()
  335. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  336. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  337. END_TEST_METHOD()
  338. BEGIN_TEST_METHOD(UnaryUintOpTest)
  339. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  340. END_TEST_METHOD()
  341. BEGIN_TEST_METHOD(BinaryUintOpTest)
  342. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  343. END_TEST_METHOD()
  344. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  345. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  346. END_TEST_METHOD()
  347. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  348. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  349. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  350. END_TEST_METHOD()
  351. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  352. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  353. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  354. END_TEST_METHOD()
  355. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  356. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  357. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  358. END_TEST_METHOD()
  359. BEGIN_TEST_METHOD(UnaryUint16OpTest)
  360. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  361. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  362. END_TEST_METHOD()
  363. BEGIN_TEST_METHOD(BinaryUint16OpTest)
  364. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  365. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  366. END_TEST_METHOD()
  367. BEGIN_TEST_METHOD(TertiaryUint16OpTest)
  368. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  369. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  370. END_TEST_METHOD()
  371. BEGIN_TEST_METHOD(DotTest)
  372. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  373. END_TEST_METHOD()
  374. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  375. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  376. END_TEST_METHOD()
  377. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  378. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  379. END_TEST_METHOD()
  380. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  381. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  382. END_TEST_METHOD()
  383. BEGIN_TEST_METHOD(Msad4Test)
  384. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  385. END_TEST_METHOD()
  386. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  387. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  388. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  389. END_TEST_METHOD()
  390. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  391. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  392. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  393. END_TEST_METHOD()
  394. TEST_METHOD(BarycentricsTest);
  395. TEST_METHOD(ComputeRawBufferLdStI32);
  396. TEST_METHOD(ComputeRawBufferLdStFloat);
  397. BEGIN_TEST_METHOD(ComputeRawBufferLdStI64)
  398. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  399. END_TEST_METHOD()
  400. BEGIN_TEST_METHOD(ComputeRawBufferLdStDouble)
  401. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  402. END_TEST_METHOD()
  403. BEGIN_TEST_METHOD(ComputeRawBufferLdStI16)
  404. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  405. END_TEST_METHOD()
  406. BEGIN_TEST_METHOD(ComputeRawBufferLdStHalf)
  407. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  408. END_TEST_METHOD()
  409. TEST_METHOD(GraphicsRawBufferLdStI32);
  410. TEST_METHOD(GraphicsRawBufferLdStFloat);
  411. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI64)
  412. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  413. END_TEST_METHOD()
  414. BEGIN_TEST_METHOD(GraphicsRawBufferLdStDouble)
  415. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  416. END_TEST_METHOD()
  417. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI16)
  418. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  419. END_TEST_METHOD()
  420. BEGIN_TEST_METHOD(GraphicsRawBufferLdStHalf)
  421. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  422. END_TEST_METHOD()
  423. BEGIN_TEST_METHOD(PackUnpackTest)
  424. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#PackUnpackOpTable")
  425. END_TEST_METHOD()
  426. dxc::DxcDllSupport m_support;
  427. VersionSupportInfo m_ver;
  428. bool m_ExperimentalModeEnabled = false;
  429. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  430. // Do not remove the following line - it is used by TranslateExecutionTest.py
  431. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  432. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  433. // require the Windows 10 SDK.
  434. typedef enum D3D_SHADER_MODEL {
  435. D3D_SHADER_MODEL_5_1 = 0x51,
  436. D3D_SHADER_MODEL_6_0 = 0x60,
  437. D3D_SHADER_MODEL_6_1 = 0x61,
  438. D3D_SHADER_MODEL_6_2 = 0x62,
  439. D3D_SHADER_MODEL_6_3 = 0x63,
  440. D3D_SHADER_MODEL_6_4 = 0x64,
  441. D3D_SHADER_MODEL_6_5 = 0x65,
  442. D3D_SHADER_MODEL_6_6 = 0x66,
  443. } D3D_SHADER_MODEL;
  444. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  445. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  446. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  447. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  448. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  449. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  450. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  451. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  452. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  453. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  454. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  455. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  456. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  457. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  458. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  459. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  460. #else
  461. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  462. #endif
  463. bool UseDxbc() {
  464. #ifdef _HLK_CONF
  465. return false;
  466. #else
  467. return GetTestParamBool(L"DXBC");
  468. #endif
  469. }
  470. bool UseWarpByDefault() {
  471. #ifdef _HLK_CONF
  472. return false;
  473. #else
  474. return true;
  475. #endif
  476. }
  477. bool UseDebugIfaces() {
  478. return true;
  479. }
  480. bool SaveImages() {
  481. return GetTestParamBool(L"SaveImages");
  482. }
  483. void RunResourceTest(ID3D12Device *pDevice, const char *pShader, const wchar_t *sm, bool isDynamic);
  484. template <class T1, class T2>
  485. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  486. size_t numParameter, bool isPrefix);
  487. template <typename T>
  488. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  489. size_t numParameters);
  490. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  491. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  492. enum class RawBufferLdStType {
  493. I32,
  494. Float,
  495. I64,
  496. Double,
  497. I16,
  498. Half
  499. };
  500. template <class Ty>
  501. struct RawBufferLdStTestData {
  502. Ty v1, v2[2], v3[3], v4[4];
  503. };
  504. template <class Ty>
  505. struct RawBufferLdStUavData {
  506. RawBufferLdStTestData<Ty> input, output, srvOut;
  507. };
  508. template <class Ty>
  509. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  510. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  511. template <class Ty>
  512. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  513. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  514. template <class Ty>
  515. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  516. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  517. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  518. template <class Ty>
  519. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  520. template <class Ty>
  521. const wchar_t* BasicShaderModelTest_GetFormatString();
  522. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  523. VERIFY_SUCCEEDED(m_support.Initialize());
  524. CComPtr<IDxcCompiler> pCompiler;
  525. CComPtr<IDxcLibrary> pLibrary;
  526. CComPtr<IDxcBlobEncoding> pTextBlob;
  527. CComPtr<IDxcOperationResult> pResult;
  528. HRESULT resultCode;
  529. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  530. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  531. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  532. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, pOptions, numOptions, nullptr, 0, nullptr, &pResult));
  533. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  534. if (FAILED(resultCode)) {
  535. CComPtr<IDxcBlobEncoding> errors;
  536. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  537. #ifndef _HLK_CONF
  538. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  539. #endif
  540. }
  541. VERIFY_SUCCEEDED(resultCode);
  542. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  543. }
  544. void CreateCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue, D3D12_COMMAND_LIST_TYPE type) {
  545. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  546. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  547. queueDesc.Type = type;
  548. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  549. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  550. }
  551. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  552. CreateCommandQueue(pDevice, pName, ppCommandQueue, D3D12_COMMAND_LIST_TYPE_COMPUTE);
  553. }
  554. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, LPCWSTR pTargetProfile, ID3D12PipelineState **ppComputeState, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  555. CComPtr<ID3DBlob> pComputeShader;
  556. // Load and compile shaders.
  557. if (UseDxbc()) {
  558. #ifndef _HLK_CONF
  559. DXBCFromText(pShader, L"main", pTargetProfile, &pComputeShader);
  560. #endif
  561. }
  562. else {
  563. CompileFromText(pShader, L"main", pTargetProfile, &pComputeShader, pOptions, numOptions);
  564. }
  565. // Describe and create the compute pipeline state object (PSO).
  566. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  567. computePsoDesc.pRootSignature = pRootSignature;
  568. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  569. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  570. }
  571. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  572. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true,
  573. bool enableRayTracing = false) {
  574. if (testModel > HIGHEST_SHADER_MODEL) {
  575. UINT minor = (UINT)testModel & 0x0f;
  576. LogCommentFmt(L"Installed SDK does not support "
  577. L"shader model 6.%1u", minor);
  578. if (skipUnsupported) {
  579. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  580. }
  581. return false;
  582. }
  583. const D3D_FEATURE_LEVEL FeatureLevelRequired = enableRayTracing ? D3D_FEATURE_LEVEL_12_0 : D3D_FEATURE_LEVEL_11_0;
  584. CComPtr<IDXGIFactory4> factory;
  585. CComPtr<ID3D12Device> pDevice;
  586. *ppDevice = nullptr;
  587. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  588. if (GetTestParamUseWARP(UseWarpByDefault())) {
  589. CComPtr<IDXGIAdapter> warpAdapter;
  590. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  591. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  592. IID_PPV_ARGS(&pDevice));
  593. if (FAILED(createHR)) {
  594. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  595. if (skipUnsupported) {
  596. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  597. }
  598. return false;
  599. }
  600. } else {
  601. CComPtr<IDXGIAdapter1> hardwareAdapter;
  602. WEX::Common::String AdapterValue;
  603. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  604. AdapterValue);
  605. if (SUCCEEDED(hr)) {
  606. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  607. } else {
  608. WEX::Logging::Log::Comment(
  609. L"Using default hardware adapter with D3D12 support.");
  610. }
  611. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  612. IID_PPV_ARGS(&pDevice)));
  613. }
  614. // retrieve adapter information
  615. LUID adapterID = pDevice->GetAdapterLuid();
  616. CComPtr<IDXGIAdapter> adapter;
  617. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  618. DXGI_ADAPTER_DESC AdapterDesc;
  619. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  620. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  621. if (pDevice == nullptr)
  622. return false;
  623. if (!UseDxbc()) {
  624. // Check for DXIL support.
  625. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  626. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  627. } D3D12_FEATURE_DATA_SHADER_MODEL;
  628. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  629. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  630. SMData.HighestShaderModel = testModel;
  631. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
  632. (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
  633. if (SMData.HighestShaderModel < testModel) {
  634. UINT minor = (UINT)testModel & 0x0f;
  635. LogCommentFmt(L"The selected device does not support "
  636. L"shader model 6.%1u", minor);
  637. if (skipUnsupported) {
  638. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  639. }
  640. return false;
  641. }
  642. }
  643. if (UseDebugIfaces()) {
  644. CComPtr<ID3D12InfoQueue> pInfoQueue;
  645. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  646. pInfoQueue->SetMuteDebugOutput(FALSE);
  647. }
  648. }
  649. *ppDevice = pDevice.Detach();
  650. return true;
  651. }
  652. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  653. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  654. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  655. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  656. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  657. }
  658. void CreateGraphicsCommandQueueAndList(
  659. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  660. ID3D12CommandAllocator **ppAllocator,
  661. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  662. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  663. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  664. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  665. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  666. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  667. IID_PPV_ARGS(ppCommandList)));
  668. }
  669. void CreateGraphicsPSO(ID3D12Device *pDevice,
  670. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  671. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  672. ID3D12PipelineState **ppPSO) {
  673. CComPtr<ID3DBlob> vertexShader;
  674. CComPtr<ID3DBlob> pixelShader;
  675. if (UseDxbc()) {
  676. #ifndef _HLK_CONF
  677. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  678. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  679. #endif
  680. } else {
  681. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  682. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  683. }
  684. // Describe and create the graphics pipeline state object (PSO).
  685. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  686. psoDesc.InputLayout = *pInputLayout;
  687. psoDesc.pRootSignature = pRootSignature;
  688. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  689. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  690. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  691. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  692. psoDesc.DepthStencilState.DepthEnable = FALSE;
  693. psoDesc.DepthStencilState.StencilEnable = FALSE;
  694. psoDesc.SampleMask = UINT_MAX;
  695. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  696. psoDesc.NumRenderTargets = 1;
  697. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  698. psoDesc.SampleDesc.Count = 1;
  699. VERIFY_SUCCEEDED(
  700. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  701. }
  702. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  703. ID3D12DescriptorHeap *pHeap, UINT width,
  704. UINT height,
  705. ID3D12Resource **ppRenderTarget,
  706. ID3D12Resource **ppBuffer) {
  707. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  708. const size_t formatElementSize = 4;
  709. CComPtr<ID3D12Resource> pRenderTarget;
  710. CComPtr<ID3D12Resource> pBuffer;
  711. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  712. pHeap->GetCPUDescriptorHandleForHeapStart());
  713. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  714. CD3DX12_RESOURCE_DESC rtDesc(
  715. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  716. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  717. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  718. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  719. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  720. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  721. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  722. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  723. // resource.
  724. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  725. CD3DX12_RESOURCE_DESC readDesc(
  726. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  727. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  728. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  729. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  730. *ppRenderTarget = pRenderTarget.Detach();
  731. *ppBuffer = pBuffer.Detach();
  732. }
  733. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  734. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  735. ID3D12RootSignature **pRootSig) {
  736. CComPtr<ID3DBlob> signature;
  737. CComPtr<ID3DBlob> error;
  738. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  739. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  740. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  741. IID_PPV_ARGS(pRootSig)));
  742. }
  743. void CreateRootSignatureFromRanges(ID3D12Device *pDevice, ID3D12RootSignature **pRootSig,
  744. CD3DX12_DESCRIPTOR_RANGE *resRanges, UINT resCt,
  745. CD3DX12_DESCRIPTOR_RANGE *sampRanges = nullptr, UINT sampCt = 0,
  746. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
  747. CD3DX12_ROOT_PARAMETER rootParameters[2];
  748. rootParameters[0].InitAsDescriptorTable(resCt, resRanges, D3D12_SHADER_VISIBILITY_ALL);
  749. rootParameters[1].InitAsDescriptorTable(sampCt, sampRanges, D3D12_SHADER_VISIBILITY_ALL);
  750. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  751. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, flags);
  752. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, pRootSig);
  753. }
  754. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  755. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  756. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  757. rtvHeapDesc.NumDescriptors = numDescriptors;
  758. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  759. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  760. VERIFY_SUCCEEDED(
  761. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  762. if (rtvDescriptorSize != nullptr) {
  763. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  764. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  765. }
  766. }
  767. void CreateTestResources(ID3D12Device *pDevice,
  768. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  769. UINT32 valueSizeInBytes, D3D12_RESOURCE_DESC resDesc,
  770. ID3D12Resource **ppResource,
  771. ID3D12Resource **ppUploadResource,
  772. ID3D12Resource **ppReadBuffer = nullptr) {
  773. CComPtr<ID3D12Resource> pResource;
  774. CComPtr<ID3D12Resource> pReadBuffer;
  775. CComPtr<ID3D12Resource> pUploadResource;
  776. D3D12_SUBRESOURCE_DATA transferData;
  777. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  778. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  779. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  780. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  781. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  782. pDevice->GetCopyableFootprints(&resDesc, 0, 1/*mipleveles*/, 0, nullptr, nullptr, nullptr, &uploadBufferDesc.Width);
  783. uploadBufferDesc.Height = 1;
  784. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  785. &defaultHeapProperties,
  786. D3D12_HEAP_FLAG_NONE,
  787. &resDesc,
  788. D3D12_RESOURCE_STATE_COPY_DEST,
  789. nullptr,
  790. IID_PPV_ARGS(&pResource)));
  791. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  792. &uploadHeapProperties,
  793. D3D12_HEAP_FLAG_NONE,
  794. &uploadBufferDesc,
  795. D3D12_RESOURCE_STATE_GENERIC_READ,
  796. nullptr,
  797. IID_PPV_ARGS(&pUploadResource)));
  798. if (ppReadBuffer)
  799. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  800. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  801. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  802. transferData.pData = values;
  803. transferData.RowPitch = valueSizeInBytes/resDesc.Height;
  804. transferData.SlicePitch = valueSizeInBytes;
  805. UpdateSubresources<1>(pCommandList, pResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  806. if (resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
  807. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  808. else
  809. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
  810. *ppResource = pResource.Detach();
  811. *ppUploadResource = pUploadResource.Detach();
  812. if (ppReadBuffer)
  813. *ppReadBuffer = pReadBuffer.Detach();
  814. }
  815. void CreateTestUavs(ID3D12Device *pDevice,
  816. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  817. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  818. ID3D12Resource **ppUploadResource = nullptr,
  819. ID3D12Resource **ppReadBuffer = nullptr) {
  820. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  821. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufferDesc,
  822. ppUavResource, ppUploadResource, ppReadBuffer);
  823. }
  824. // Create and return descriptor heaps for the given device
  825. // with the given number of resources and samples.
  826. // using some reasonable defaults
  827. void CreateDefaultDescHeaps(ID3D12Device *pDevice,
  828. int NumResources, int NumSamplers,
  829. ID3D12DescriptorHeap **ppResHeap, ID3D12DescriptorHeap **ppSampHeap) {
  830. // Describe and create descriptor heaps.
  831. ID3D12DescriptorHeap *pResHeap, *pSampHeap;
  832. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  833. heapDesc.NumDescriptors = NumResources;
  834. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  835. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  836. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pResHeap)));
  837. heapDesc.NumDescriptors = NumSamplers;
  838. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
  839. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pSampHeap)));
  840. *ppResHeap = pResHeap;
  841. *ppSampHeap = pSampHeap;
  842. }
  843. void CreateSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  844. DXGI_FORMAT format, D3D12_SRV_DIMENSION viewDimension, UINT numElements, UINT stride,
  845. const CComPtr<ID3D12Resource> pResource) {
  846. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  847. // Create SRV
  848. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  849. srvDesc.Format = format;
  850. srvDesc.ViewDimension = viewDimension;
  851. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  852. switch (viewDimension) {
  853. case D3D12_SRV_DIMENSION_BUFFER:
  854. srvDesc.Buffer.FirstElement = 0;
  855. srvDesc.Buffer.NumElements = numElements;
  856. srvDesc.Buffer.StructureByteStride = stride;
  857. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  858. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
  859. else
  860. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
  861. break;
  862. case D3D12_SRV_DIMENSION_TEXTURE1D:
  863. srvDesc.Texture1D.MostDetailedMip = 0;
  864. srvDesc.Texture1D.MipLevels = 1;
  865. srvDesc.Texture1D.ResourceMinLODClamp = 0;
  866. break;
  867. case D3D12_SRV_DIMENSION_TEXTURE2D:
  868. srvDesc.Texture2D.MostDetailedMip = 0;
  869. srvDesc.Texture2D.MipLevels = 1;
  870. srvDesc.Texture2D.PlaneSlice = 0;
  871. srvDesc.Texture2D.ResourceMinLODClamp = 0;
  872. break;
  873. }
  874. pDevice->CreateShaderResourceView(pResource, &srvDesc, baseHandle);
  875. baseHandle.Offset(descriptorSize);
  876. }
  877. void CreateRawSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  878. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  879. CreateSRV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  880. }
  881. void CreateStructSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  882. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  883. CreateSRV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_SRV_DIMENSION_BUFFER, numElements, stride, pResource);
  884. }
  885. void CreateTypedSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  886. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  887. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  888. }
  889. void CreateTex1DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  890. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  891. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  892. }
  893. void CreateTex2DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  894. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  895. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  896. }
  897. void CreateUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  898. DXGI_FORMAT format, D3D12_UAV_DIMENSION viewDimension, UINT numElements, UINT stride,
  899. const CComPtr<ID3D12Resource> pResource) {
  900. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  901. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  902. uavDesc.Format = format;
  903. uavDesc.ViewDimension = viewDimension;
  904. switch (viewDimension) {
  905. case D3D12_UAV_DIMENSION_BUFFER:
  906. uavDesc.Buffer.FirstElement = 0;
  907. uavDesc.Buffer.NumElements = numElements;
  908. uavDesc.Buffer.StructureByteStride = stride;
  909. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  910. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  911. else
  912. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  913. break;
  914. case D3D12_UAV_DIMENSION_TEXTURE1D:
  915. uavDesc.Texture1D.MipSlice = 0;
  916. break;
  917. case D3D12_UAV_DIMENSION_TEXTURE2D:
  918. uavDesc.Texture2D.MipSlice = 0;
  919. uavDesc.Texture2D.PlaneSlice = 0;
  920. break;
  921. }
  922. pDevice->CreateUnorderedAccessView(pResource, nullptr, &uavDesc, baseHandle);
  923. baseHandle.Offset(descriptorSize);
  924. }
  925. void CreateRawUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  926. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  927. CreateUAV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  928. }
  929. void CreateStructUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  930. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  931. CreateUAV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_UAV_DIMENSION_BUFFER, numElements, stride, pResource);
  932. }
  933. void CreateTypedUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  934. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  935. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  936. }
  937. void CreateTex1DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  938. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  939. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  940. }
  941. void CreateTex2DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  942. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  943. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  944. }
  945. // Create Samplers for <pDevice> given the filter and border color information provided
  946. // using some reasonable defaults
  947. void CreateDefaultSamplers(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  948. D3D12_FILTER filters[], float BorderColors[], int NumSamplers) {
  949. CD3DX12_CPU_DESCRIPTOR_HANDLE sampHandle(heapStart);
  950. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
  951. D3D12_SAMPLER_DESC sampDesc = {};
  952. sampDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  953. sampDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  954. sampDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  955. sampDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  956. sampDesc.MipLODBias = 0;
  957. sampDesc.MaxAnisotropy = 1;
  958. sampDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_EQUAL;
  959. sampDesc.MinLOD = 0;
  960. sampDesc.MaxLOD = 0;
  961. for (int i = 0; i < NumSamplers; i++) {
  962. sampDesc.Filter = filters[i];
  963. for (int j = 0; j < 4; j++)
  964. sampDesc.BorderColor[j] = BorderColors[i];
  965. pDevice->CreateSampler(&sampDesc, sampHandle);
  966. sampHandle = sampHandle.Offset(descriptorSize);
  967. }
  968. }
  969. template <typename TVertex, int len>
  970. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  971. ID3D12Resource **ppVertexBuffer,
  972. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  973. size_t vertexBufferSize = sizeof(vertices);
  974. CComPtr<ID3D12Resource> pVertexBuffer;
  975. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  976. CD3DX12_RESOURCE_DESC bufferDesc(
  977. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  978. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  979. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  980. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  981. IID_PPV_ARGS(&pVertexBuffer)));
  982. UINT8 *pVertexDataBegin;
  983. CD3DX12_RANGE readRange(0, 0);
  984. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  985. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  986. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  987. pVertexBuffer->Unmap(0, nullptr);
  988. // Initialize the vertex buffer view.
  989. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  990. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  991. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  992. *ppVertexBuffer = pVertexBuffer.Detach();
  993. }
  994. // Requires Anniversary Edition headers, so simplifying things for current setup.
  995. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  996. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  997. BOOL WaveOps;
  998. UINT WaveLaneCountMin;
  999. UINT WaveLaneCountMax;
  1000. UINT TotalLaneCount;
  1001. BOOL ExpandedComputeResourceStates;
  1002. BOOL Int64ShaderOps;
  1003. };
  1004. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  1005. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1006. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1007. return false;
  1008. return O.Int64ShaderOps != FALSE;
  1009. }
  1010. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  1011. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  1012. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  1013. return false;
  1014. return O.DoublePrecisionFloatShaderOps != FALSE;
  1015. }
  1016. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  1017. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1018. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1019. return false;
  1020. return O.WaveOps != FALSE;
  1021. }
  1022. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  1023. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  1024. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  1025. return false;
  1026. return O.BarycentricsSupported != FALSE;
  1027. }
  1028. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  1029. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  1030. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  1031. return false;
  1032. return O.Native16BitShaderOpsSupported != FALSE;
  1033. }
  1034. bool DoesDeviceSupportMeshShaders(ID3D12Device *pDevice) {
  1035. #if defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB
  1036. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1037. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))))
  1038. return false;
  1039. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
  1040. #else
  1041. return false;
  1042. #endif
  1043. }
  1044. bool DoesDeviceSupportRayTracing(ID3D12Device *pDevice) {
  1045. #if WDK_NTDDI_VERSION > NTDDI_WIN10_RS4
  1046. D3D12_FEATURE_DATA_D3D12_OPTIONS5 O5;
  1047. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS5, &O5, sizeof(O5))))
  1048. return false;
  1049. return O5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
  1050. #else
  1051. return false;
  1052. #endif
  1053. }
  1054. // Replace with appropriate WDK check when available
  1055. #define SM66_RUNTIME_SUPPORT 0
  1056. bool DoesDeviceSupportMeshAmpDerivatives(ID3D12Device *pDevice) {
  1057. #if SM66_RUNTIME_SUPPORT
  1058. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1059. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1060. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))) ||
  1061. FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1062. return false;
  1063. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED &&
  1064. O9.DerivativesInMeshAndAmplificationShadersSupported != FALSE;
  1065. #else
  1066. return false;
  1067. #endif
  1068. }
  1069. bool DoesDeviceSupportTyped64Atomics(ID3D12Device *pDevice) {
  1070. #if SM66_RUNTIME_SUPPORT
  1071. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1072. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1073. return false;
  1074. return O9.AtomicInt64OnTypedResourceSupported != FALSE;
  1075. #else
  1076. return false;
  1077. #endif
  1078. }
  1079. bool DoesDeviceSupportShared64Atomics(ID3D12Device *pDevice) {
  1080. #if SM66_RUNTIME_SUPPORT
  1081. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1082. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1083. return false;
  1084. return O9.AtomicInt64OnGroupSharedSupported != FALSE;
  1085. #else
  1086. return false;
  1087. #endif
  1088. }
  1089. #ifndef _HLK_CONF
  1090. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  1091. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  1092. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  1093. CComPtr<ID3DBlob> pErrors;
  1094. D3D_SHADER_MACRO d3dMacro[2];
  1095. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  1096. d3dMacro[0].Definition = "1";
  1097. d3dMacro[0].Name = "USING_DXBC";
  1098. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  1099. if (pErrors != nullptr) {
  1100. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  1101. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  1102. }
  1103. VERIFY_SUCCEEDED(hr);
  1104. }
  1105. #endif
  1106. HRESULT EnableDebugLayer() {
  1107. // The debug layer does net yet validate DXIL programs that require rewriting,
  1108. // but basic logging should work properly.
  1109. HRESULT hr = S_FALSE;
  1110. if (UseDebugIfaces()) {
  1111. CComPtr<ID3D12Debug> debugController;
  1112. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  1113. if (SUCCEEDED(hr)) {
  1114. debugController->EnableDebugLayer();
  1115. hr = S_OK;
  1116. }
  1117. }
  1118. return hr;
  1119. }
  1120. #ifndef _HLK_CONF
  1121. HRESULT EnableExperimentalMode() {
  1122. if (m_ExperimentalModeEnabled) {
  1123. return S_OK;
  1124. }
  1125. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1126. return S_FALSE;
  1127. }
  1128. HRESULT hr = EnableExperimentalShaderModels();
  1129. if (SUCCEEDED(hr)) {
  1130. m_ExperimentalModeEnabled = true;
  1131. }
  1132. return hr;
  1133. }
  1134. #endif
  1135. struct FenceObj {
  1136. HANDLE m_fenceEvent = NULL;
  1137. CComPtr<ID3D12Fence> m_fence;
  1138. UINT64 m_fenceValue;
  1139. ~FenceObj() {
  1140. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  1141. }
  1142. };
  1143. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  1144. pObj->m_fenceValue = 1;
  1145. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  1146. IID_PPV_ARGS(&pObj->m_fence)));
  1147. // Create an event handle to use for frame synchronization.
  1148. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  1149. if (pObj->m_fenceEvent == nullptr) {
  1150. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  1151. }
  1152. }
  1153. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  1154. VERIFY_SUCCEEDED(m_support.Initialize());
  1155. CComPtr<IDxcLibrary> pLibrary;
  1156. CComPtr<IDxcBlobEncoding> pBlob;
  1157. CComPtr<IStream> pStream;
  1158. std::wstring path = GetPathToHlslDataFile(relativePath);
  1159. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  1160. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  1161. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  1162. *ppStream = pStream.Detach();
  1163. }
  1164. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  1165. ID3D12DescriptorHeap *pRtvHeap,
  1166. UINT rtvDescriptorSize,
  1167. UINT instanceCount,
  1168. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  1169. ID3D12RootSignature *pRootSig,
  1170. ID3D12Resource *pRenderTarget,
  1171. ID3D12Resource *pReadBuffer) {
  1172. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  1173. D3D12_VIEWPORT viewport;
  1174. D3D12_RECT scissorRect;
  1175. memset(&viewport, 0, sizeof(viewport));
  1176. viewport.Height = (float)rtDesc.Height;
  1177. viewport.Width = (float)rtDesc.Width;
  1178. viewport.MaxDepth = 1.0f;
  1179. memset(&scissorRect, 0, sizeof(scissorRect));
  1180. scissorRect.right = (long)rtDesc.Width;
  1181. scissorRect.bottom = rtDesc.Height;
  1182. if (pRootSig != nullptr) {
  1183. pList->SetGraphicsRootSignature(pRootSig);
  1184. }
  1185. pList->RSSetViewports(1, &viewport);
  1186. pList->RSSetScissorRects(1, &scissorRect);
  1187. // Indicate that the buffer will be used as a render target.
  1188. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  1189. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  1190. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  1191. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  1192. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  1193. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  1194. pList->DrawInstanced(3, instanceCount, 0, 0);
  1195. // Transition to copy source and copy into read-back buffer.
  1196. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1197. // Copy into read-back buffer.
  1198. UINT64 rowPitch = rtDesc.Width * 4;
  1199. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  1200. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  1201. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  1202. Footprint.Offset = 0;
  1203. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  1204. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  1205. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  1206. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  1207. }
  1208. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  1209. void RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR shader, D3D_SHADER_MODEL shaderModel, bool useLibTarget, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1210. void RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1211. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1212. void RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1213. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions);
  1214. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  1215. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  1216. pCommandList->SetDescriptorHeaps(1, pHeaps);
  1217. }
  1218. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  1219. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  1220. }
  1221. };
  1222. #define WAVE_INTRINSIC_DXBC_GUARD \
  1223. "#ifdef USING_DXBC\r\n" \
  1224. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  1225. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  1226. "bool WaveIsFirstLane() { return true; }\r\n" \
  1227. "uint WaveGetLaneCount() { return 1; }\r\n" \
  1228. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  1229. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  1230. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  1231. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  1232. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  1233. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  1234. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  1235. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  1236. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  1237. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  1238. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  1239. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  1240. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  1241. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  1242. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  1243. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  1244. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  1245. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  1246. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  1247. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  1248. "#endif\r\n"
  1249. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  1250. size_t count) {
  1251. values.resize(count); // one element per dispatch group, in bytes
  1252. for (size_t i = 0; i < count; ++i) {
  1253. values[i] = (uint32_t)i;
  1254. }
  1255. }
  1256. bool ExecutionTest::ExecutionTestClassSetup() {
  1257. #ifdef _HLK_CONF
  1258. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1259. VERIFY_SUCCEEDED(m_support.Initialize());
  1260. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1261. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1262. if (m_EnableDebugLayer) {
  1263. EnableDebugLayer();
  1264. }
  1265. return true;
  1266. #else
  1267. HRESULT hr = EnableExperimentalMode();
  1268. if (FAILED(hr)) {
  1269. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1270. }
  1271. else if (hr == S_FALSE) {
  1272. LogCommentFmt(L"Experimental mode not enabled.");
  1273. }
  1274. else {
  1275. LogCommentFmt(L"Experimental mode enabled.");
  1276. }
  1277. hr = EnableDebugLayer();
  1278. if (FAILED(hr)) {
  1279. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1280. }
  1281. else {
  1282. LogCommentFmt(L"Debug layer enabled.");
  1283. }
  1284. return true;
  1285. #endif
  1286. }
  1287. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1288. static const int DispatchGroupX = 1;
  1289. static const int DispatchGroupY = 1;
  1290. static const int DispatchGroupZ = 1;
  1291. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1292. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1293. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1294. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1295. UINT uavDescriptorSize;
  1296. FenceObj FO;
  1297. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1298. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1299. InitFenceObj(pDevice, &FO);
  1300. // Describe and create a UAV descriptor heap.
  1301. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1302. heapDesc.NumDescriptors = 1;
  1303. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1304. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1305. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1306. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1307. // Create root signature.
  1308. CComPtr<ID3D12RootSignature> pRootSignature;
  1309. {
  1310. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1311. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1312. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1313. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1314. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1315. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1316. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1317. }
  1318. // Create pipeline state object.
  1319. CComPtr<ID3D12PipelineState> pComputeState;
  1320. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1321. // Create a command allocator and list for compute.
  1322. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1323. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1324. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1325. // Set up UAV resource.
  1326. CComPtr<ID3D12Resource> pUavResource;
  1327. CComPtr<ID3D12Resource> pReadBuffer;
  1328. CComPtr<ID3D12Resource> pUploadResource;
  1329. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1330. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1331. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1332. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1333. // Close the command list and execute it to perform the GPU setup.
  1334. pCommandList->Close();
  1335. ExecuteCommandList(pCommandQueue, pCommandList);
  1336. WaitForSignal(pCommandQueue, FO);
  1337. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1338. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1339. // Run the compute shader and copy the results back to readable memory.
  1340. {
  1341. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1342. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1343. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1344. uavDesc.Buffer.FirstElement = 0;
  1345. uavDesc.Buffer.NumElements = (UINT)values.size();
  1346. uavDesc.Buffer.StructureByteStride = 0;
  1347. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1348. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1349. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1350. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1351. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1352. SetDescriptorHeap(pCommandList, pUavHeap);
  1353. pCommandList->SetComputeRootSignature(pRootSignature);
  1354. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1355. }
  1356. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1357. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1358. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1359. pCommandList->Close();
  1360. ExecuteCommandList(pCommandQueue, pCommandList);
  1361. WaitForSignal(pCommandQueue, FO);
  1362. {
  1363. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1364. uint32_t *pData = (uint32_t *)mappedData.data();
  1365. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1366. }
  1367. WaitForSignal(pCommandQueue, FO);
  1368. }
  1369. void ExecutionTest::RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1370. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1371. // Create command queue.
  1372. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1373. CreateComputeCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue);
  1374. FenceObj FO;
  1375. InitFenceObj(pDevice, &FO);
  1376. // Compile shader "main" and create pipeline state object.
  1377. CComPtr<ID3D12PipelineState> pComputeState;
  1378. CreateComputePSO(pDevice, pRootSignature, pShader, pTargetProfile, &pComputeState, pOptions, numOptions);
  1379. // Create a command allocator and list for compute.
  1380. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1381. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1382. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1383. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1384. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1385. // Set up UAV resource.
  1386. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1387. CComPtr<ID3D12Resource> pUavResource;
  1388. CComPtr<ID3D12Resource> pReadBuffer;
  1389. CComPtr<ID3D12Resource> pUploadResource;
  1390. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1391. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunLifetimeIntrinsicTest UAV"));
  1392. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunLifetimeIntrinsicTest UAV Read Buffer"));
  1393. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunLifetimeIntrinsicTest UAV Upload Buffer"));
  1394. // Close the command list and execute it to perform the GPU setup.
  1395. pCommandList->Close();
  1396. ExecuteCommandList(pCommandQueue, pCommandList);
  1397. WaitForSignal(pCommandQueue, FO);
  1398. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1399. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1400. // Run the compute shader and copy the results back to readable memory.
  1401. {
  1402. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1403. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1404. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1405. uavDesc.Buffer.FirstElement = 0;
  1406. uavDesc.Buffer.NumElements = (UINT)values.size();
  1407. uavDesc.Buffer.StructureByteStride = 0;
  1408. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1409. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1410. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1411. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1412. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1413. SetDescriptorHeap(pCommandList, pUavHeap);
  1414. pCommandList->SetComputeRootSignature(pRootSignature);
  1415. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1416. }
  1417. static const int DispatchGroupX = 1;
  1418. static const int DispatchGroupY = 1;
  1419. static const int DispatchGroupZ = 1;
  1420. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1421. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1422. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1423. pCommandList->Close();
  1424. ExecuteCommandList(pCommandQueue, pCommandList);
  1425. WaitForSignal(pCommandQueue, FO);
  1426. {
  1427. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1428. uint32_t *pData = (uint32_t *)mappedData.data();
  1429. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1430. }
  1431. WaitForSignal(pCommandQueue, FO);
  1432. }
  1433. void ExecutionTest::RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1434. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions) {
  1435. // Create command queue.
  1436. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1437. CreateCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue, D3D12_COMMAND_LIST_TYPE_DIRECT);
  1438. FenceObj FO;
  1439. InitFenceObj(pDevice, &FO);
  1440. // Compile raygen shader.
  1441. CComPtr<ID3DBlob> pShaderLib;
  1442. CompileFromText(pShader, L"RayGen", pTargetProfile, &pShaderLib, pOptions, numOptions);
  1443. // Describe and create the RT pipeline state object (RTPSO).
  1444. CD3DX12_STATE_OBJECT_DESC stateObjectDesc(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
  1445. auto lib = stateObjectDesc.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
  1446. CD3DX12_SHADER_BYTECODE byteCode(pShaderLib);
  1447. lib->SetDXILLibrary(&byteCode);
  1448. lib->DefineExport(L"RayGen");
  1449. const int payloadCount = 4;
  1450. const int attributeCount = 2;
  1451. const int maxRecursion = 2;
  1452. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT>()->Config(payloadCount * sizeof(float), attributeCount * sizeof(float));
  1453. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT>()->Config(maxRecursion);
  1454. // Create (local!) root sig subobject and associate with shader.
  1455. auto localRootSigSubObj = stateObjectDesc.CreateSubobject<CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT>();
  1456. localRootSigSubObj->SetRootSignature(pRootSignature);
  1457. auto x = stateObjectDesc.CreateSubobject<CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT>();
  1458. x->SetSubobjectToAssociate(*localRootSigSubObj);
  1459. x->AddExport(L"RayGen");
  1460. CComPtr<ID3D12StateObject> pStateObject;
  1461. VERIFY_SUCCEEDED(pDevice->CreateStateObject(stateObjectDesc, IID_PPV_ARGS(&pStateObject)));
  1462. // Create a command allocator and list.
  1463. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1464. CComPtr<ID3D12GraphicsCommandList4> pCommandList;
  1465. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator)));
  1466. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, nullptr, IID_PPV_ARGS(&pCommandList)));
  1467. pCommandList->SetPipelineState1(pStateObject);
  1468. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1469. // Close the command list and execute it to kick-off compilation in the driver.
  1470. // NOTE: We don't care about anything else, so we're not setting up any resources and don't actually execute the shader.
  1471. pCommandList->Close();
  1472. ExecuteCommandList(pCommandQueue, pCommandList);
  1473. WaitForSignal(pCommandQueue, FO);
  1474. }
  1475. void ExecutionTest::RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR pShader, D3D_SHADER_MODEL shaderModel, bool useLibTarget,
  1476. LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1477. LPCWSTR pTargetProfile;
  1478. switch (shaderModel) {
  1479. default: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_0"; break; // Default to 6.3 for lib, 6.0 otherwise.
  1480. case D3D_SHADER_MODEL_6_0: pTargetProfile = useLibTarget ? L"lib_6_0" : L"cs_6_0"; break;
  1481. case D3D_SHADER_MODEL_6_3: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_3"; break;
  1482. case D3D_SHADER_MODEL_6_5: pTargetProfile = useLibTarget ? L"lib_6_5" : L"cs_6_5"; break;
  1483. case D3D_SHADER_MODEL_6_6: pTargetProfile = useLibTarget ? L"lib_6_6" : L"cs_6_6"; break;
  1484. }
  1485. // Describe a UAV descriptor heap.
  1486. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1487. heapDesc.NumDescriptors = 1;
  1488. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1489. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1490. // Create the UAV descriptor heap.
  1491. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1492. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1493. // Create root signature.
  1494. CComPtr<ID3D12RootSignature> pRootSignature;
  1495. {
  1496. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1497. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1498. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1499. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1500. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1501. D3D12_ROOT_SIGNATURE_FLAGS rootSigFlag = useLibTarget ? D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE : D3D12_ROOT_SIGNATURE_FLAG_NONE;
  1502. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSigFlag);
  1503. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1504. }
  1505. if (useLibTarget)
  1506. RunLifetimeIntrinsicLibTest(reinterpret_cast<ID3D12Device5*>(pDevice), pShader, pRootSignature, pTargetProfile, pOptions, numOptions);
  1507. else
  1508. RunLifetimeIntrinsicComputeTest(pDevice, pShader, pUavHeap, pRootSignature, pTargetProfile, pOptions, numOptions, values);
  1509. }
  1510. TEST_F(ExecutionTest, LifetimeIntrinsicTest) {
  1511. // The only thing we test here is that existence of lifetime intrinsics or
  1512. // their fallback replacement (store undef or store zeroinitializer) do not
  1513. // cause any issues in the runtime and driver stack.
  1514. // The easiest way to force placement of intrinsics is to create an array in
  1515. // a local scope that is dynamically indexed. It must not be optimized away,
  1516. // so we do some bogus initialization that prevents this. Since all the code
  1517. // is guarded by a conditional that is dynamically always false, the actual
  1518. // effect of the shader is that the same value that was read is written back.
  1519. static const char* pShader = R"(
  1520. RWByteAddressBuffer g_bab : register(u0);
  1521. void fn(uint GI) {
  1522. const uint addr = GI * 4;
  1523. const int val = g_bab.Load(addr);
  1524. int res = val;
  1525. if (val < 0) { // Never true.
  1526. int arr[200];
  1527. for (int i = 0; i < 200; ++i) {
  1528. arr[i] = arr[val - i];
  1529. }
  1530. res += arr[val];
  1531. }
  1532. g_bab.Store(addr, (uint)res);
  1533. }
  1534. [numthreads(8,8,1)]
  1535. void main(uint GI : SV_GroupIndex) {
  1536. fn(GI);
  1537. }
  1538. [shader("raygeneration")]
  1539. void RayGen() {
  1540. const uint d = DispatchRaysIndex().x;
  1541. const uint g = g > 64 ? 63 : g;
  1542. fn(g);
  1543. }
  1544. )";
  1545. static const int NumThreadsX = 8;
  1546. static const int NumThreadsY = 8;
  1547. static const int NumThreadsZ = 1;
  1548. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1549. static const int DispatchGroupCount = 1;
  1550. // TODO: There's probably a lot of things in the rest of this test that could be stripped away.
  1551. CComPtr<ID3D12Device5> pDevice;
  1552. if (!CreateDevice(reinterpret_cast<ID3D12Device**>(&pDevice), D3D_SHADER_MODEL_6_6, true, true)) {
  1553. WEX::Logging::Log::Comment(L"Lifetime test not run pre 6.6");
  1554. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  1555. return;
  1556. }
  1557. std::vector<uint32_t> values;
  1558. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1559. // Run a number of tests for different configurations that will cause
  1560. // lifetime intrinsics to be placed directly, be replaced by a zeroinitializer
  1561. // store, or be replaced by an undef store.
  1562. LPCWSTR pOptions15[] = {L"/validator-version 1.5"};
  1563. LPCWSTR pOptions16[] = {L"/validator-version 1.6", L"/Vd"};
  1564. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1565. // Test regular shader with zeroinitializer store.
  1566. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions15, _countof(pOptions15), values);
  1567. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1568. if (DoesDeviceSupportRayTracing(pDevice)) {
  1569. // Test library with zeroinitializer store.
  1570. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions15, _countof(pOptions15), values);
  1571. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1572. }
  1573. // Testing SM 6.6 and validator version 1.6 requires experimental shaders
  1574. // being turned on.
  1575. if (!m_ExperimentalModeEnabled)
  1576. return;
  1577. // Test regular shader with undef store.
  1578. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions16, _countof(pOptions16), values);
  1579. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1580. if (DoesDeviceSupportRayTracing(pDevice)) {
  1581. // Test library with undef store.
  1582. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions16, _countof(pOptions16), values);
  1583. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1584. }
  1585. // Test regular shader with lifetime intrinsics.
  1586. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, false, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1587. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1588. if (DoesDeviceSupportRayTracing(pDevice)) {
  1589. // Test library with lifetime intrinsics.
  1590. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, true, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1591. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1592. }
  1593. }
  1594. TEST_F(ExecutionTest, BasicComputeTest) {
  1595. #ifndef _HLK_CONF
  1596. //
  1597. // BasicComputeTest is a simple compute shader that can be used as the basis
  1598. // for more interesting compute execution tests.
  1599. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1600. // rendering code paths for comparison.
  1601. //
  1602. static const char pShader[] =
  1603. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1604. "[numthreads(8,8,1)]\r\n"
  1605. "void main(uint GI : SV_GroupIndex) {"
  1606. " uint addr = GI * 4;\r\n"
  1607. " uint val = g_bab.Load(addr);\r\n"
  1608. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1609. " g_bab.Store(addr, val + 1);\r\n"
  1610. "}";
  1611. static const int NumThreadsX = 8;
  1612. static const int NumThreadsY = 8;
  1613. static const int NumThreadsZ = 1;
  1614. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1615. static const int DispatchGroupCount = 1;
  1616. CComPtr<ID3D12Device> pDevice;
  1617. if (!CreateDevice(&pDevice))
  1618. return;
  1619. std::vector<uint32_t> values;
  1620. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1621. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1622. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1623. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1624. #endif
  1625. }
  1626. TEST_F(ExecutionTest, BasicTriangleTest) {
  1627. #ifndef _HLK_CONF
  1628. static const UINT FrameCount = 2;
  1629. static const UINT m_width = 320;
  1630. static const UINT m_height = 200;
  1631. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1632. struct Vertex {
  1633. XMFLOAT3 position;
  1634. XMFLOAT4 color;
  1635. };
  1636. // Pipeline objects.
  1637. CComPtr<ID3D12Device> pDevice;
  1638. CComPtr<ID3D12Resource> pRenderTarget;
  1639. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1640. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1641. CComPtr<ID3D12RootSignature> pRootSig;
  1642. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1643. CComPtr<ID3D12PipelineState> pPipelineState;
  1644. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1645. CComPtr<ID3D12Resource> pReadBuffer;
  1646. UINT rtvDescriptorSize;
  1647. CComPtr<ID3D12Resource> pVertexBuffer;
  1648. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1649. // Synchronization objects.
  1650. FenceObj FO;
  1651. // Shaders.
  1652. static const char pShaders[] =
  1653. "struct PSInput {\r\n"
  1654. " float4 position : SV_POSITION;\r\n"
  1655. " float4 color : COLOR;\r\n"
  1656. "};\r\n\r\n"
  1657. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1658. " PSInput result;\r\n"
  1659. "\r\n"
  1660. " result.position = position;\r\n"
  1661. " result.color = color;\r\n"
  1662. " return result;\r\n"
  1663. "}\r\n\r\n"
  1664. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1665. " return 1; //input.color;\r\n"
  1666. "};\r\n";
  1667. if (!CreateDevice(&pDevice))
  1668. return;
  1669. struct BasicTestChecker {
  1670. CComPtr<ID3D12Device> m_pDevice;
  1671. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1672. bool m_OK = false;
  1673. void SetOK(bool value) { m_OK = value; }
  1674. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1675. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1676. return;
  1677. m_pInfoQueue->PushEmptyStorageFilter();
  1678. m_pInfoQueue->PushEmptyRetrievalFilter();
  1679. }
  1680. ~BasicTestChecker() {
  1681. if (!m_OK && m_pInfoQueue != nullptr) {
  1682. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1683. bool invalidBytecodeFound = false;
  1684. CAtlArray<BYTE> m_pBytes;
  1685. for (UINT64 i = 0; i < count; ++i) {
  1686. SIZE_T len = 0;
  1687. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1688. continue;
  1689. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1690. continue;
  1691. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1692. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1693. continue;
  1694. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1695. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1696. invalidBytecodeFound = true;
  1697. break;
  1698. }
  1699. }
  1700. if (invalidBytecodeFound) {
  1701. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1702. L"typically indicates that experimental mode "
  1703. L"is not set up properly.");
  1704. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1705. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1706. }
  1707. }
  1708. else {
  1709. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1710. L"queue - dumping complete queue.");
  1711. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1712. }
  1713. }
  1714. }
  1715. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1716. LogCommentFmt(L"%s", pMsg);
  1717. }
  1718. };
  1719. BasicTestChecker BTC(pDevice);
  1720. {
  1721. InitFenceObj(pDevice, &FO);
  1722. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1723. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1724. // Create an empty root signature.
  1725. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1726. rootSignatureDesc.Init(
  1727. 0, nullptr, 0, nullptr,
  1728. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1729. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1730. // Create the pipeline state, which includes compiling and loading shaders.
  1731. // Define the vertex input layout.
  1732. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1733. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1734. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1735. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1736. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1737. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1738. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1739. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1740. &pCommandAllocator, &pCommandList,
  1741. pPipelineState);
  1742. // Define the geometry for a triangle.
  1743. Vertex triangleVertices[] = {
  1744. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1745. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1746. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1747. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1748. WaitForSignal(pCommandQueue, FO);
  1749. }
  1750. // Render and execute the command list.
  1751. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1752. &vertexBufferView, pRootSig, pRenderTarget,
  1753. pReadBuffer);
  1754. VERIFY_SUCCEEDED(pCommandList->Close());
  1755. ExecuteCommandList(pCommandQueue, pCommandList);
  1756. // Wait for previous frame.
  1757. WaitForSignal(pCommandQueue, FO);
  1758. // At this point, we've verified that execution succeeded with DXIL.
  1759. BTC.SetOK(true);
  1760. // Read back to CPU and examine contents.
  1761. {
  1762. MappedData data(pReadBuffer, m_width * m_height * 4);
  1763. const uint32_t *pPixels = (uint32_t *)data.data();
  1764. if (SaveImages()) {
  1765. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1766. }
  1767. uint32_t top = pPixels[m_width / 2]; // Top center.
  1768. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1769. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1770. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1771. }
  1772. #endif
  1773. }
  1774. TEST_F(ExecutionTest, Int64Test) {
  1775. static const char pShader[] =
  1776. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1777. "[numthreads(8,8,1)]\r\n"
  1778. "void main(uint GI : SV_GroupIndex) {"
  1779. " uint addr = GI * 4;\r\n"
  1780. " uint val = g_bab.Load(addr);\r\n"
  1781. " uint64_t u64 = val;\r\n"
  1782. " u64 *= val;\r\n"
  1783. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1784. "}";
  1785. static const int NumThreadsX = 8;
  1786. static const int NumThreadsY = 8;
  1787. static const int NumThreadsZ = 1;
  1788. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1789. static const int DispatchGroupCount = 1;
  1790. CComPtr<ID3D12Device> pDevice;
  1791. if (!CreateDevice(&pDevice))
  1792. return;
  1793. if (!DoesDeviceSupportInt64(pDevice)) {
  1794. // Optional feature, so it's correct to not support it if declared as such.
  1795. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1796. return;
  1797. }
  1798. std::vector<uint32_t> values;
  1799. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1800. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1801. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1802. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1803. }
  1804. TEST_F(ExecutionTest, SignTest) {
  1805. static const char pShader[] =
  1806. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1807. "[numthreads(8,1,1)]\r\n"
  1808. "void main(uint GI : SV_GroupIndex) {"
  1809. " uint addr = GI * 4;\r\n"
  1810. " int val = g_bab.Load(addr);\r\n"
  1811. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1812. "}";
  1813. static const int NumThreadsX = 8;
  1814. static const int NumThreadsY = 1;
  1815. static const int NumThreadsZ = 1;
  1816. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1817. static const int DispatchGroupCount = 1;
  1818. CComPtr<ID3D12Device> pDevice;
  1819. if (!CreateDevice(&pDevice))
  1820. return;
  1821. const uint32_t neg1 = (uint32_t)-1;
  1822. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1823. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1824. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1825. VERIFY_ARE_EQUAL(values[0], neg1);
  1826. VERIFY_ARE_EQUAL(values[1], neg1);
  1827. VERIFY_ARE_EQUAL(values[2], neg1);
  1828. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1829. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1830. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1831. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1832. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1833. }
  1834. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1835. #ifndef _HLK_CONF
  1836. CComPtr<ID3D12Device> pDevice;
  1837. if (!CreateDevice(&pDevice))
  1838. return;
  1839. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1840. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1841. return;
  1842. bool waveSupported = O.WaveOps;
  1843. UINT laneCountMin = O.WaveLaneCountMin;
  1844. UINT laneCountMax = O.WaveLaneCountMax;
  1845. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1846. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1847. if (waveSupported) {
  1848. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1849. }
  1850. else {
  1851. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1852. }
  1853. #endif
  1854. }
  1855. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1856. #ifndef _HLK_CONF
  1857. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1858. struct PerThreadData {
  1859. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1860. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1861. uint32_t pfBC, pfSum, pfProd;
  1862. uint32_t ballot[4];
  1863. uint32_t diver; // divergent value, used in calculation
  1864. int32_t i_diver; // divergent value, used in calculation
  1865. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1866. int32_t i_pfSum, i_pfProd;
  1867. };
  1868. static const char pShader[] =
  1869. WAVE_INTRINSIC_DXBC_GUARD
  1870. "struct PerThreadData {\r\n"
  1871. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1872. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1873. " uint pfBC, pfSum, pfProd;\r\n"
  1874. " uint4 ballot;\r\n"
  1875. " uint diver;\r\n"
  1876. " int i_diver;\r\n"
  1877. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1878. " int i_pfSum, i_pfProd;\r\n"
  1879. "};\r\n"
  1880. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1881. "[numthreads(8,8,1)]\r\n"
  1882. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1883. " PerThreadData pts = g_sb[GI];\r\n"
  1884. " uint diver = GTID.x + 2;\r\n"
  1885. " pts.diver = diver;\r\n"
  1886. " pts.flags = 0;\r\n"
  1887. " pts.preds = 0;\r\n"
  1888. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1889. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1890. " pts.laneCount = WaveGetLaneCount();\r\n"
  1891. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1892. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1893. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1894. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1895. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1896. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1897. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1898. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1899. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1900. "\r\n"
  1901. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1902. " pts.allSum = WaveActiveSum(diver);\r\n"
  1903. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1904. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1905. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1906. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1907. " pts.allMin = WaveActiveMin(diver);\r\n"
  1908. " pts.allMax = WaveActiveMax(diver);\r\n"
  1909. "\r\n"
  1910. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1911. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1912. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1913. "\r\n"
  1914. " int i_diver = pts.i_diver;\r\n"
  1915. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1916. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1917. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1918. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1919. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1920. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1921. "\r\n"
  1922. " g_sb[GI] = pts;\r\n"
  1923. "}";
  1924. static const int NumtheadsX = 8;
  1925. static const int NumtheadsY = 8;
  1926. static const int NumtheadsZ = 1;
  1927. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1928. static const int DispatchGroupCount = 1;
  1929. CComPtr<ID3D12Device> pDevice;
  1930. if (!CreateDevice(&pDevice))
  1931. return;
  1932. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1933. // Optional feature, so it's correct to not support it if declared as such.
  1934. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1935. return;
  1936. }
  1937. std::vector<PerThreadData> values;
  1938. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1939. for (size_t i = 0; i < values.size(); ++i) {
  1940. memset(&values[i], 0, sizeof(PerThreadData));
  1941. values[i].id = i;
  1942. values[i].i_diver = (int)i;
  1943. values[i].i_diver *= (i % 2) ? 1 : -1;
  1944. }
  1945. static const int DispatchGroupX = 1;
  1946. static const int DispatchGroupY = 1;
  1947. static const int DispatchGroupZ = 1;
  1948. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1949. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1950. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1951. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1952. UINT uavDescriptorSize;
  1953. FenceObj FO;
  1954. bool dxbc = UseDxbc();
  1955. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1956. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1957. InitFenceObj(pDevice, &FO);
  1958. // Describe and create a UAV descriptor heap.
  1959. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1960. heapDesc.NumDescriptors = 1;
  1961. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1962. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1963. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1964. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1965. // Create root signature.
  1966. CComPtr<ID3D12RootSignature> pRootSignature;
  1967. {
  1968. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1969. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1970. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1971. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1972. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1973. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1974. CComPtr<ID3DBlob> signature;
  1975. CComPtr<ID3DBlob> error;
  1976. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  1977. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  1978. }
  1979. // Create pipeline state object.
  1980. CComPtr<ID3D12PipelineState> pComputeState;
  1981. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1982. // Create a command allocator and list for compute.
  1983. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1984. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1985. // Set up UAV resource.
  1986. CComPtr<ID3D12Resource> pUavResource;
  1987. CComPtr<ID3D12Resource> pReadBuffer;
  1988. CComPtr<ID3D12Resource> pUploadResource;
  1989. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1990. // Close the command list and execute it to perform the GPU setup.
  1991. pCommandList->Close();
  1992. ExecuteCommandList(pCommandQueue, pCommandList);
  1993. WaitForSignal(pCommandQueue, FO);
  1994. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1995. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1996. // Run the compute shader and copy the results back to readable memory.
  1997. {
  1998. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1999. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2000. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2001. uavDesc.Buffer.FirstElement = 0;
  2002. uavDesc.Buffer.NumElements = values.size();
  2003. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  2004. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2005. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2006. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2007. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2008. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  2009. SetDescriptorHeap(pCommandList, pUavHeap);
  2010. pCommandList->SetComputeRootSignature(pRootSignature);
  2011. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  2012. }
  2013. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  2014. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2015. pCommandList->CopyResource(pReadBuffer, pUavResource);
  2016. pCommandList->Close();
  2017. ExecuteCommandList(pCommandQueue, pCommandList);
  2018. WaitForSignal(pCommandQueue, FO);
  2019. {
  2020. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  2021. PerThreadData *pData = (PerThreadData *)mappedData.data();
  2022. memcpy(values.data(), pData, valueSizeInBytes);
  2023. // Gather some general data.
  2024. // The 'firstLaneId' captures a unique number per first-lane per wave.
  2025. // Counting the number distinct firstLaneIds gives us the number of waves.
  2026. std::vector<uint32_t> firstLaneIds;
  2027. for (size_t i = 0; i < values.size(); ++i) {
  2028. PerThreadData &pts = values[i];
  2029. uint32_t firstLaneId = pts.firstLaneId;
  2030. if (!contains(firstLaneIds, firstLaneId)) {
  2031. firstLaneIds.push_back(firstLaneId);
  2032. }
  2033. }
  2034. // Waves should cover 4 threads or more.
  2035. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  2036. if (!dxbc) {
  2037. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  2038. }
  2039. // Now, group threads into waves.
  2040. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  2041. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  2042. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  2043. }
  2044. for (size_t i = 0; i < values.size(); ++i) {
  2045. PerThreadData &pts = values[i];
  2046. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2047. wave->push_back(&pts);
  2048. }
  2049. // Verify that all the wave values are coherent across the wave.
  2050. for (size_t i = 0; i < values.size(); ++i) {
  2051. PerThreadData &pts = values[i];
  2052. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2053. // Sort the lanes by increasing lane ID.
  2054. struct LaneIdOrderPred {
  2055. bool operator()(PerThreadData *a, PerThreadData *b) {
  2056. return a->laneIndex < b->laneIndex;
  2057. }
  2058. };
  2059. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  2060. // Verify some interesting properties of the first lane.
  2061. uint32_t pfBC, pfSum, pfProd;
  2062. int32_t i_pfSum, i_pfProd;
  2063. int32_t i_allMax, i_allMin;
  2064. {
  2065. PerThreadData *ptdFirst = wave->front();
  2066. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  2067. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  2068. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  2069. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  2070. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  2071. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  2072. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  2073. pfSum = ptdFirst->diver;
  2074. pfProd = ptdFirst->diver;
  2075. i_pfSum = ptdFirst->i_diver;
  2076. i_pfProd = ptdFirst->i_diver;
  2077. i_allMax = i_allMin = ptdFirst->i_diver;
  2078. }
  2079. // Calculate values which take into consideration all lanes.
  2080. uint32_t preds = 0;
  2081. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  2082. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  2083. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  2084. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  2085. uint32_t ballot[4] = { 0, 0, 0, 0 };
  2086. int32_t i_allSum = 0, i_allProd = 1;
  2087. for (size_t n = 0; n < wave->size(); ++n) {
  2088. std::vector<PerThreadData *> &lanes = *wave.get();
  2089. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  2090. if (lanes[n]->diver == 1) preds |= (1 << 0);
  2091. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  2092. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  2093. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  2094. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  2095. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  2096. if (lanes[n]->diver > 3) {
  2097. // This is the uint4 result layout:
  2098. // .x -> bits 0 .. 31
  2099. // .y -> bits 32 .. 63
  2100. // .z -> bits 64 .. 95
  2101. // .w -> bits 96 ..127
  2102. uint32_t component = lanes[n]->laneIndex / 32;
  2103. uint32_t bit = lanes[n]->laneIndex % 32;
  2104. ballot[component] |= 1 << bit;
  2105. }
  2106. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  2107. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  2108. i_allProd *= lanes[n]->i_diver;
  2109. i_allSum += lanes[n]->i_diver;
  2110. }
  2111. for (size_t n = 1; n < wave->size(); ++n) {
  2112. // 'All' operations are uniform across the wave.
  2113. std::vector<PerThreadData *> &lanes = *wave.get();
  2114. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  2115. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  2116. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  2117. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  2118. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  2119. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  2120. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  2121. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  2122. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  2123. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  2124. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  2125. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  2126. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  2127. // first-lane reads and uniform reads are uniform across the wave.
  2128. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  2129. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  2130. // the lane count is uniform across the wave.
  2131. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  2132. // The predicates are uniform across the wave.
  2133. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  2134. // the lane index is distinct per thread.
  2135. for (size_t prior = 0; prior < n; ++prior) {
  2136. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  2137. }
  2138. // Ballot results are uniform across the wave.
  2139. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  2140. // Keep running total of prefix calculation. Prefix values are exclusive to
  2141. // the executing lane.
  2142. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  2143. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  2144. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  2145. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  2146. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  2147. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  2148. pfSum += lanes[n]->diver;
  2149. pfProd *= lanes[n]->diver;
  2150. i_pfSum += lanes[n]->i_diver;
  2151. i_pfProd *= lanes[n]->i_diver;
  2152. }
  2153. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  2154. }
  2155. // Compare each value of each per-thread element.
  2156. for (size_t i = 0; i < values.size(); ++i) {
  2157. PerThreadData &pts = values[i];
  2158. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  2159. }
  2160. }
  2161. #endif
  2162. }
  2163. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  2164. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  2165. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2166. struct Vertex {
  2167. XMFLOAT3 position;
  2168. };
  2169. struct PerPixelData {
  2170. XMFLOAT4 position;
  2171. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  2172. uint32_t id0, id1, id2, id3;
  2173. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  2174. };
  2175. const UINT RTWidth = 128;
  2176. const UINT RTHeight = 128;
  2177. // Shaders.
  2178. static const char pShaders[] =
  2179. WAVE_INTRINSIC_DXBC_GUARD
  2180. "struct PSInput {\r\n"
  2181. " float4 position : SV_POSITION;\r\n"
  2182. "};\r\n\r\n"
  2183. "PSInput VSMain(float4 position : POSITION) {\r\n"
  2184. " PSInput result;\r\n"
  2185. "\r\n"
  2186. " result.position = position;\r\n"
  2187. " return result;\r\n"
  2188. "}\r\n\r\n"
  2189. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  2190. "struct PerPixelData {\r\n"
  2191. " float4 position;\r\n"
  2192. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  2193. " uint id0, id1, id2, id3;\r\n"
  2194. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  2195. "};\r\n"
  2196. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  2197. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  2198. " uint one = 1;\r\n"
  2199. " PerPixelData d;\r\n"
  2200. " d.position = input.position;\r\n"
  2201. " d.id = pos_to_id(input.position);\r\n"
  2202. " d.flags = 0;\r\n"
  2203. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  2204. " d.laneIndex = WaveGetLaneIndex();\r\n"
  2205. " d.laneCount = WaveGetLaneCount();\r\n"
  2206. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  2207. " d.sum1 = WaveActiveSum(one);\r\n"
  2208. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  2209. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  2210. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  2211. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  2212. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  2213. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  2214. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  2215. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  2216. " g_sb.Append(d);\r\n"
  2217. " return 1;\r\n"
  2218. "};\r\n";
  2219. CComPtr<ID3D12Device> pDevice;
  2220. CComPtr<ID3D12CommandQueue> pCommandQueue;
  2221. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  2222. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  2223. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  2224. CComPtr<ID3D12PipelineState> pPSO;
  2225. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  2226. UINT uavDescriptorSize, rtvDescriptorSize;
  2227. CComPtr<ID3D12Resource> pVertexBuffer;
  2228. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  2229. if (!CreateDevice(&pDevice))
  2230. return;
  2231. if (!DoesDeviceSupportWaveOps(pDevice)) {
  2232. // Optional feature, so it's correct to not support it if declared as such.
  2233. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  2234. return;
  2235. }
  2236. FenceObj FO;
  2237. InitFenceObj(pDevice, &FO);
  2238. // Describe and create a UAV descriptor heap.
  2239. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  2240. heapDesc.NumDescriptors = 1;
  2241. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  2242. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  2243. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  2244. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2245. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  2246. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  2247. // Create root signature: one UAV.
  2248. CComPtr<ID3D12RootSignature> pRootSignature;
  2249. {
  2250. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2251. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  2252. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2253. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2254. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2255. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  2256. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  2257. }
  2258. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  2259. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  2260. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  2261. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  2262. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  2263. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  2264. &pCommandList, pPSO);
  2265. // Single triangle covering half the target.
  2266. Vertex vertices[] = {
  2267. { { -1.0f, 1.0f, 0.0f } },
  2268. { { 1.0f, 1.0f, 0.0f } },
  2269. { { -1.0f, -1.0f, 0.0f } } };
  2270. const UINT TriangleCount = _countof(vertices) / 3;
  2271. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  2272. bool dxbc = UseDxbc();
  2273. // Set up UAV resource.
  2274. std::vector<PerPixelData> values;
  2275. values.resize(RTWidth * RTHeight * 2);
  2276. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  2277. memset(values.data(), 0, valueSizeInBytes);
  2278. CComPtr<ID3D12Resource> pUavResource;
  2279. CComPtr<ID3D12Resource> pUavReadBuffer;
  2280. CComPtr<ID3D12Resource> pUploadResource;
  2281. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pUavReadBuffer);
  2282. // Set up the append counter resource.
  2283. CComPtr<ID3D12Resource> pUavCounterResource;
  2284. CComPtr<ID3D12Resource> pReadCounterBuffer;
  2285. CComPtr<ID3D12Resource> pUploadCounterResource;
  2286. BYTE zero[sizeof(UINT)] = { 0 };
  2287. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pUploadCounterResource, &pReadCounterBuffer);
  2288. // Close the command list and execute it to perform the GPU setup.
  2289. pCommandList->Close();
  2290. ExecuteCommandList(pCommandQueue, pCommandList);
  2291. WaitForSignal(pCommandQueue, FO);
  2292. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2293. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  2294. pCommandList->SetGraphicsRootSignature(pRootSignature);
  2295. SetDescriptorHeap(pCommandList, pUavHeap);
  2296. {
  2297. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2298. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2299. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2300. uavDesc.Buffer.FirstElement = 0;
  2301. uavDesc.Buffer.NumElements = (UINT)values.size();
  2302. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  2303. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2304. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2305. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2306. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2307. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  2308. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  2309. }
  2310. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  2311. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2312. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2313. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  2314. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  2315. VERIFY_SUCCEEDED(pCommandList->Close());
  2316. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  2317. ExecuteCommandList(pCommandQueue, pCommandList);
  2318. WaitForSignal(pCommandQueue, FO);
  2319. {
  2320. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  2321. const uint32_t *pPixels = (uint32_t *)data.data();
  2322. if (SaveImages()) {
  2323. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  2324. }
  2325. }
  2326. uint32_t appendCount;
  2327. {
  2328. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  2329. appendCount = *((uint32_t *)mappedData.data());
  2330. LogCommentFmt(L"%u elements in append buffer", appendCount);
  2331. }
  2332. {
  2333. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  2334. PerPixelData *pData = (PerPixelData *)mappedData.data();
  2335. memcpy(values.data(), pData, valueSizeInBytes);
  2336. // DXBC is handy to test pipeline setup, but interesting functions are
  2337. // stubbed out, so there is no point in further validation.
  2338. if (dxbc)
  2339. return;
  2340. uint32_t maxActiveLaneCount = 0;
  2341. uint32_t maxLaneCount = 0;
  2342. for (uint32_t i = 0; i < appendCount; ++i) {
  2343. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  2344. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  2345. }
  2346. uint32_t peerOfHelperLanes = 0;
  2347. for (uint32_t i = 0; i < appendCount; ++i) {
  2348. if (values[i].sum1 != maxActiveLaneCount) {
  2349. ++peerOfHelperLanes;
  2350. }
  2351. }
  2352. LogCommentFmt(
  2353. L"Found: %u threads. Waves reported up to %u total lanes, up "
  2354. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  2355. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  2356. // Group threads into quad invocations.
  2357. uint32_t singlePixelCount = 0;
  2358. uint32_t multiPixelCount = 0;
  2359. std::unordered_set<uint32_t> ids;
  2360. std::multimap<uint32_t, PerPixelData *> idGroups;
  2361. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  2362. for (uint32_t i = 0; i < appendCount; ++i) {
  2363. ids.insert(values[i].id);
  2364. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  2365. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  2366. }
  2367. for (uint32_t id : ids) {
  2368. if (idGroups.count(id) == 1)
  2369. ++singlePixelCount;
  2370. else
  2371. ++multiPixelCount;
  2372. }
  2373. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  2374. singlePixelCount, multiPixelCount);
  2375. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  2376. // Where every pixel is distinct, it's very straightforward to validate.
  2377. {
  2378. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  2379. while (cur != end) {
  2380. bool simpleWave = true;
  2381. uint32_t firstId = (*cur).first;
  2382. auto groupEnd = cur;
  2383. while (groupEnd != end && (*groupEnd).first == firstId) {
  2384. if (idGroups.count((*groupEnd).second->id) > 1)
  2385. simpleWave = false;
  2386. ++groupEnd;
  2387. }
  2388. if (simpleWave) {
  2389. // Break the wave into quads.
  2390. struct QuadData {
  2391. unsigned count;
  2392. PerPixelData *data[4];
  2393. };
  2394. std::map<uint32_t, QuadData> quads;
  2395. for (auto i = cur; i != groupEnd; ++i) {
  2396. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  2397. uint32_t laneId = (*i).second->id;
  2398. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  2399. (*i).second->id2, (*i).second->id3};
  2400. // Since this is a simple wave, each lane has an unique id and
  2401. // therefore should not have any ids in there.
  2402. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  2403. // check if QuadReadLaneAt is returning same values in a single quad.
  2404. bool newQuad = true;
  2405. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  2406. auto match = quads.find(laneIds[quadIndex]);
  2407. if (match != quads.end()) {
  2408. (*match).second.data[(*match).second.count++] = (*i).second;
  2409. newQuad = false;
  2410. break;
  2411. }
  2412. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  2413. if (quadMemberData != idGroups.end()) {
  2414. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  2415. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  2416. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  2417. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  2418. }
  2419. }
  2420. if (newQuad) {
  2421. QuadData qdata;
  2422. qdata.count = 1;
  2423. qdata.data[0] = (*i).second;
  2424. quads.insert(std::make_pair(laneId, qdata));
  2425. }
  2426. }
  2427. for (auto quadPair : quads) {
  2428. unsigned count = quadPair.second.count;
  2429. // There could be only one pixel data on the edge of the triangle
  2430. if (count < 2) continue;
  2431. PerPixelData **data = quadPair.second.data;
  2432. bool isTop[4];
  2433. bool isLeft[4];
  2434. PerPixelData helperData;
  2435. memset(&helperData, sizeof(helperData), 0);
  2436. PerPixelData *layout[4]; // tl,tr,bl,br
  2437. memset(layout, sizeof(layout), 0);
  2438. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  2439. int idx = top ? 0 : 2;
  2440. idx += left ? 0 : 1;
  2441. return &layout[idx];
  2442. };
  2443. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  2444. PerPixelData **pResult = fnToLayout(top, left);
  2445. if (*pResult == nullptr) return &helperData;
  2446. return *pResult;
  2447. };
  2448. VERIFY_IS_TRUE(count <= 4);
  2449. if (count == 2) {
  2450. isTop[0] = data[0]->position.y < data[1]->position.y;
  2451. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  2452. isLeft[0] = data[0]->position.x < data[1]->position.x;
  2453. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  2454. }
  2455. else {
  2456. // with at least three samples, we have distinct x and y coordinates.
  2457. float left = std::min(data[0]->position.x, data[1]->position.x);
  2458. left = std::min(data[2]->position.x, left);
  2459. float top = std::min(data[0]->position.y, data[1]->position.y);
  2460. top = std::min(data[2]->position.y, top);
  2461. for (unsigned i = 0; i < count; ++i) {
  2462. isTop[i] = data[i]->position.y == top;
  2463. isLeft[i] = data[i]->position.x == left;
  2464. }
  2465. }
  2466. for (unsigned i = 0; i < count; ++i) {
  2467. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  2468. }
  2469. // Finally, we have a proper quad reconstructed. Validate.
  2470. for (unsigned i = 0; i < count; ++i) {
  2471. PerPixelData *d = data[i];
  2472. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  2473. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  2474. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  2475. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  2476. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  2477. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  2478. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  2479. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2480. }
  2481. }
  2482. }
  2483. cur = groupEnd;
  2484. }
  2485. }
  2486. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2487. //
  2488. // Consider: for pixels that were shaded multiple times, check whether
  2489. // some grouping of threads into quads satisfies all value requirements.
  2490. }
  2491. }
  2492. struct ShaderOpTestResult {
  2493. st::ShaderOp *ShaderOp;
  2494. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2495. std::shared_ptr<st::ShaderOpTest> Test;
  2496. };
  2497. struct SPrimitives {
  2498. float f_float;
  2499. float f_float2;
  2500. float f_float_o;
  2501. float f_float2_o;
  2502. };
  2503. std::shared_ptr<ShaderOpTestResult>
  2504. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2505. LPCSTR pName,
  2506. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2507. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2508. st::ShaderOp *pShaderOp;
  2509. if (pName == nullptr) {
  2510. if (ShaderOpSet->ShaderOps.size() != 1) {
  2511. VERIFY_FAIL(L"Expected a single shader operation.");
  2512. }
  2513. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2514. }
  2515. else {
  2516. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2517. }
  2518. if (pShaderOp == nullptr) {
  2519. std::string msg = "Unable to find shader op ";
  2520. msg += pName;
  2521. msg += "; available ops";
  2522. const char sep = ':';
  2523. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2524. msg += sep;
  2525. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2526. }
  2527. CA2W msgWide(msg.c_str());
  2528. VERIFY_FAIL(msgWide.m_psz);
  2529. }
  2530. // This won't actually be used since we're supplying the device,
  2531. // but let's make it consistent.
  2532. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2533. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2534. test->SetDxcSupport(&support);
  2535. test->SetInitCallback(pInitCallback);
  2536. test->SetDevice(pDevice);
  2537. test->RunShaderOp(pShaderOp);
  2538. std::shared_ptr<ShaderOpTestResult> result =
  2539. std::make_shared<ShaderOpTestResult>();
  2540. result->ShaderOpSet = ShaderOpSet;
  2541. result->Test = test;
  2542. result->ShaderOp = pShaderOp;
  2543. return result;
  2544. }
  2545. std::shared_ptr<ShaderOpTestResult>
  2546. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2547. IStream *pStream, LPCSTR pName,
  2548. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2549. DXASSERT_NOMSG(pStream != nullptr);
  2550. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2551. std::make_shared<st::ShaderOpSet>();
  2552. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2553. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2554. }
  2555. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2556. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2557. CComPtr<IStream> pStream;
  2558. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2559. // Single operation test at the moment.
  2560. CComPtr<ID3D12Device> pDevice;
  2561. if (!CreateDevice(&pDevice))
  2562. return;
  2563. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2564. MappedData data;
  2565. // Read back to CPU and examine contents - should get pure red.
  2566. {
  2567. MappedData data;
  2568. test->Test->GetReadBackData("RTarget", &data);
  2569. const uint32_t *pPixels = (uint32_t *)data.data();
  2570. uint32_t first = *pPixels;
  2571. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2572. }
  2573. }
  2574. TEST_F(ExecutionTest, SaturateTest) {
  2575. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2576. CComPtr<IStream> pStream;
  2577. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2578. // Single operation test at the moment.
  2579. CComPtr<ID3D12Device> pDevice;
  2580. if (!CreateDevice(&pDevice))
  2581. return;
  2582. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2583. MappedData data;
  2584. test->Test->GetReadBackData("U0", &data);
  2585. const float *pValues = (float *)data.data();
  2586. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2587. const float ExpectedCases[9] = {
  2588. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2589. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2590. 0.0f // nan
  2591. };
  2592. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2593. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2594. ++pValues;
  2595. }
  2596. }
  2597. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2598. #ifdef _HLK_CONF
  2599. UNREFERENCED_PARAMETER(ShaderOpName);
  2600. UNREFERENCED_PARAMETER(FileName);
  2601. UNREFERENCED_PARAMETER(testModel);
  2602. #else
  2603. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2604. CComPtr<IStream> pStream;
  2605. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2606. // Single operation test at the moment.
  2607. CComPtr<ID3D12Device> pDevice;
  2608. if (!CreateDevice(&pDevice, testModel))
  2609. return;
  2610. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2611. MappedData data;
  2612. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2613. UINT width = (UINT64)D.Width;
  2614. UINT height = (UINT64)D.Height;
  2615. test->Test->GetReadBackData("RTarget", &data);
  2616. const uint32_t *pPixels = (uint32_t *)data.data();
  2617. if (SaveImages()) {
  2618. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2619. }
  2620. uint32_t top = pPixels[width / 2]; // Top center.
  2621. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2622. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2623. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2624. // This is the basic validation test for shader operations, so it's good to
  2625. // check this here at least for this one test case.
  2626. data.reset();
  2627. test.reset();
  2628. ReportLiveObjects();
  2629. #endif
  2630. }
  2631. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2632. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2633. }
  2634. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2635. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2636. }
  2637. void VerifyDerivResults(const float *pPixels, UINT offsetCenter) {
  2638. // pixel at the center
  2639. float CenterDDXFine = pPixels[offsetCenter];
  2640. float CenterDDYFine = pPixels[offsetCenter + 1];
  2641. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2642. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2643. LogCommentFmt(
  2644. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2645. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2646. // The texture for the 9 pixels in the center should look like the following
  2647. // 256 32 64
  2648. // 2048 256 512
  2649. // 1 .125 .25
  2650. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2651. // So for fine derivatives there can be up to two possible results for the center pixel,
  2652. // while for coarse derivatives there can be up to six possible results.
  2653. int ulpTolerance = 1;
  2654. // 512 - 256 or 2048 - 256
  2655. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2656. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2657. // 256 - 32 or 256 - .125
  2658. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2659. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2660. if (top && left) {
  2661. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2662. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2663. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2664. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2665. }
  2666. else if (top) { // top right quad
  2667. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2668. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2669. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2670. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2671. }
  2672. else if (left) { // bottom left quad
  2673. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2674. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2675. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2676. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2677. }
  2678. else { // bottom right
  2679. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2680. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2681. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2682. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2683. }
  2684. }
  2685. // Rendering two right triangles forming a square and assigning a texture value
  2686. // for each pixel to calculate derivates.
  2687. TEST_F(ExecutionTest, PartialDerivTest) {
  2688. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2689. CComPtr<IStream> pStream;
  2690. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2691. CComPtr<ID3D12Device> pDevice;
  2692. if (!CreateDevice(&pDevice))
  2693. return;
  2694. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2695. MappedData data;
  2696. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2697. UINT width = (UINT)D.Width;
  2698. UINT height = D.Height;
  2699. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2700. test->Test->GetReadBackData("RTarget", &data);
  2701. const float *pPixels = (float *)data.data();
  2702. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2703. UINT offsetCenter = centerIndex * pixelSize;
  2704. VerifyDerivResults(pPixels, offsetCenter);
  2705. }
  2706. TEST_F(ExecutionTest, DerivativesTest) {
  2707. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2708. CComPtr<IStream> pStream;
  2709. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2710. CComPtr<ID3D12Device> pDevice;
  2711. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2712. return;
  2713. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2714. std::make_shared<st::ShaderOpSet>();
  2715. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2716. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Derivatives");
  2717. LPCSTR CS = pShaderOp->CS;
  2718. struct Dispatch {
  2719. int x, y, z;
  2720. int mx, my, mz;
  2721. };
  2722. std::vector<Dispatch> dispatches =
  2723. {
  2724. {32, 32, 1, 8, 8, 1},
  2725. {64, 4, 1, 64, 2, 1},
  2726. {1, 4, 64, 1, 4, 32},
  2727. {64, 1, 1, 64, 1, 1},
  2728. {1, 64, 1, 1, 64, 1},
  2729. {1, 1, 64, 1, 1, 64},
  2730. {16, 16, 3, 4, 4, 3},
  2731. {32, 3, 8, 8, 3, 2},
  2732. {3, 1, 64, 3, 1, 32}
  2733. };
  2734. char compilerOptions[256];
  2735. for (Dispatch &D : dispatches) {
  2736. UINT width = D.x;
  2737. UINT height = D.y;
  2738. UINT depth = D.z;
  2739. UINT mwidth = D.mx;
  2740. UINT mheight = D.my;
  2741. UINT mdepth = D.mz;
  2742. UINT pixelSize = 4; // always float4
  2743. // format compiler args
  2744. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2745. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2746. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2747. width, height, depth, mwidth, mheight, mdepth));
  2748. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2749. S.Arguments = compilerOptions;
  2750. pShaderOp->DispatchX = width;
  2751. pShaderOp->DispatchY = height;
  2752. pShaderOp->DispatchZ = depth;
  2753. // Test Compute Shader
  2754. pShaderOp->CS = CS;
  2755. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2756. MappedData data;
  2757. test->Test->GetReadBackData("U0", &data);
  2758. const float *pPixels = (float *)data.data();
  2759. // To find roughly the center for compute, divide the pixel count in half,
  2760. // truncate to next lowest power of 16 (4x4), which is the repeating period
  2761. // and then add 10 to reach the point the test expects
  2762. UINT centerIndex = (((UINT64)(width * height * depth)/2) & ~0xF) + 10;
  2763. UINT offsetCenter = centerIndex * pixelSize;
  2764. LogCommentFmt(L"Verifying derivatives in compute shader results");
  2765. VerifyDerivResults(pPixels, offsetCenter);
  2766. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2767. // Disable CS so mesh goes forward
  2768. pShaderOp->CS = nullptr;
  2769. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2770. test->Test->GetReadBackData("U1", &data);
  2771. pPixels = (float *)data.data();
  2772. centerIndex = (((UINT64)(mwidth * mheight * mdepth)/2) & ~0xF) + 10;
  2773. offsetCenter = centerIndex * pixelSize;
  2774. LogCommentFmt(L"Verifying derivatives in mesh shader results");
  2775. VerifyDerivResults(pPixels, offsetCenter);
  2776. test->Test->GetReadBackData("U2", &data);
  2777. pPixels = (float *)data.data();
  2778. LogCommentFmt(L"Verifying derivatives in amplification shader results");
  2779. VerifyDerivResults(pPixels, offsetCenter);
  2780. }
  2781. }
  2782. // Final test with not divisible by 4 dispatch size just to make sure it runs
  2783. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2784. S.Arguments = "-D DISPATCHX=3 -D DISPATCHY=3 -D DISPATCHZ=3 "
  2785. "-D MESHDISPATCHX=3 -D MESHDISPATCHY=3 -D MESHDISPATCHZ=3";
  2786. pShaderOp->DispatchX = 3;
  2787. pShaderOp->DispatchY = 3;
  2788. pShaderOp->DispatchZ = 3;
  2789. // Test Compute Shader
  2790. pShaderOp->CS = CS;
  2791. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2792. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2793. pShaderOp->CS = nullptr;
  2794. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2795. }
  2796. }
  2797. // Verify the results for the quad starting with the given index
  2798. void VerifyQuadReadResults(const UINT *pPixels, UINT quadIndex) {
  2799. for (UINT i = 0; i < 4; i++) {
  2800. UINT ix = quadIndex + i;
  2801. VERIFY_ARE_EQUAL(pPixels[4*ix + 0], ix); // ReadLaneAt own quad index
  2802. VERIFY_ARE_EQUAL(pPixels[4*ix + 1], (ix^1));// ReadAcrossX
  2803. VERIFY_ARE_EQUAL(pPixels[4*ix + 2], (ix^2));// ReadAcrossY
  2804. VERIFY_ARE_EQUAL(pPixels[4*ix + 3], (ix^3));// ReadAcrossDiagonal
  2805. }
  2806. }
  2807. TEST_F(ExecutionTest, QuadReadTest) {
  2808. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2809. CComPtr<IStream> pStream;
  2810. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2811. CComPtr<ID3D12Device> pDevice;
  2812. if (!CreateDevice(&pDevice))
  2813. return;
  2814. if (GetTestParamUseWARP(UseWarpByDefault())) {
  2815. WEX::Logging::Log::Comment(L"WARP does not support QuadRead in compute shaders.");
  2816. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2817. return;
  2818. }
  2819. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2820. std::make_shared<st::ShaderOpSet>();
  2821. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2822. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("QuadRead");
  2823. LPCSTR CS = pShaderOp->CS;
  2824. struct Dispatch {
  2825. int x, y, z;
  2826. int mx, my, mz;
  2827. };
  2828. //std::vector<std::tuple<int, int, int, int, int>> dispatches =
  2829. std::vector<Dispatch> dispatches =
  2830. {
  2831. {32, 32, 1, 8, 8, 1},
  2832. {64, 4, 1, 64, 2, 1},
  2833. {1, 4, 64, 1, 4, 32},
  2834. {64, 1, 1, 64, 1, 1},
  2835. {1, 64, 1, 1, 64, 1},
  2836. {1, 1, 64, 1, 1, 64},
  2837. {16, 16, 3, 4, 4, 3},
  2838. {32, 3, 8, 8, 3, 2},
  2839. {3, 1, 64, 3, 1, 32}
  2840. };
  2841. for (Dispatch &D : dispatches) {
  2842. UINT width = D.x;
  2843. UINT height = D.y;
  2844. UINT depth = D.z;
  2845. UINT mwidth = D.mx;
  2846. UINT mheight = D.my;
  2847. UINT mdepth = D.mz;
  2848. // format compiler args
  2849. char compilerOptions[256];
  2850. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2851. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2852. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2853. width, height, depth, mwidth, mheight, mdepth));
  2854. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2855. S.Arguments = compilerOptions;
  2856. pShaderOp->DispatchX = width;
  2857. pShaderOp->DispatchY = height;
  2858. pShaderOp->DispatchZ = depth;
  2859. // Test Compute Shader
  2860. pShaderOp->CS = CS;
  2861. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2862. MappedData data;
  2863. test->Test->GetReadBackData("U0", &data);
  2864. const UINT *pPixels = (UINT *)data.data();
  2865. // To find roughly the center for compute, divide the pixel count in half
  2866. // and truncate to next lowest power of 4 to start at a quad
  2867. UINT offsetCenter = ((UINT64)(width * height * depth)/2) & ~0x3;
  2868. // Test first, second and center quads
  2869. LogCommentFmt(L"Verifying QuadRead* in compute shader results");
  2870. VerifyQuadReadResults(pPixels, 0);
  2871. VerifyQuadReadResults(pPixels, 4);
  2872. VerifyQuadReadResults(pPixels, offsetCenter);
  2873. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2874. offsetCenter = ((UINT64)(mwidth * mheight * mdepth)/2) & ~0x3;
  2875. // Disable CS so mesh goes forward
  2876. pShaderOp->CS = nullptr;
  2877. test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2878. test->Test->GetReadBackData("U1", &data);
  2879. pPixels = (UINT *)data.data();
  2880. // Test first, second and center quads
  2881. LogCommentFmt(L"Verifying QuadRead* in mesh shader results");
  2882. VerifyQuadReadResults(pPixels, 0);
  2883. VerifyQuadReadResults(pPixels, 4);
  2884. VerifyQuadReadResults(pPixels, offsetCenter);
  2885. test->Test->GetReadBackData("U2", &data);
  2886. pPixels = (UINT *)data.data();
  2887. // Test first, second and center quads
  2888. LogCommentFmt(L"Verifying QuadRead* in amplification shader results");
  2889. VerifyQuadReadResults(pPixels, 0);
  2890. VerifyQuadReadResults(pPixels, 4);
  2891. VerifyQuadReadResults(pPixels, offsetCenter);
  2892. }
  2893. }
  2894. }
  2895. void VerifySampleResults(const UINT *pPixels) {
  2896. UINT xlod = 0;
  2897. UINT ylod = 0;
  2898. // Each pixel contains 4 samples and 4 LOD calculations.
  2899. // 2 of these (called 'left' and 'right') have X values that vary and a constant Y
  2900. // 2 others (called 'top' and 'bot') have Y values that vary and a constant X
  2901. // Only of the X variant sample results and one of the Y variant results
  2902. // are actually reported for the pixel.
  2903. // The other 2 serve as "helpers" to the other pixels in the quad.
  2904. // On the left side of the quad, the 'left' samples are reported.
  2905. // Op the top of the quad, the 'top' samples are reported and so on.
  2906. // The varying coordinate values alternate between zero and a
  2907. // value whose magnitude increases with the index.
  2908. // As a result, the LOD level should steadily increas.
  2909. // Due to vagaries of implementation, the same derivatives
  2910. // in both directions might result in different levels for different locations
  2911. // in the quad. So only comparisons between sample results and LOD calculations
  2912. // and ensuring that the LOD increased and reaches the max can be tested reliably.
  2913. for (unsigned i = 0; i < 64; i++) {
  2914. // CalculateLOD and Sample from texture with mip levels containing LOD index should match
  2915. VERIFY_ARE_EQUAL(pPixels[4*i + 0], pPixels[4*i + 1]);
  2916. VERIFY_ARE_EQUAL(pPixels[4*i + 2], pPixels[4*i + 3]);
  2917. // Make sure LODs are ever climbing as magnitudes increase
  2918. VERIFY_IS_TRUE(pPixels[4*i] >= xlod);
  2919. xlod = pPixels[4*i];
  2920. VERIFY_IS_TRUE(pPixels[4*i + 2] >= ylod);
  2921. ylod = pPixels[4*i + 2];
  2922. }
  2923. // Make sure we reached the max lod level for both tracks
  2924. VERIFY_ARE_EQUAL(xlod, 6);
  2925. VERIFY_ARE_EQUAL(ylod, 6);
  2926. }
  2927. TEST_F(ExecutionTest, ComputeSampleTest) {
  2928. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2929. CComPtr<IStream> pStream;
  2930. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2931. CComPtr<ID3D12Device> pDevice;
  2932. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2933. return;
  2934. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2935. std::make_shared<st::ShaderOpSet>();
  2936. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2937. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("ComputeSample");
  2938. D3D12_RESOURCE_DESC &texDesc = pShaderOp->GetResourceByName("T0")->Desc;
  2939. UINT texWidth = (UINT)texDesc.Width;
  2940. UINT texHeight = (UINT)texDesc.Height;
  2941. // Initialize texture with the LOD number in each corresponding mip level
  2942. auto SampleInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2943. VERIFY_ARE_EQUAL(0, _stricmp(Name, "T0"));
  2944. size_t size = sizeof(float) * texWidth * texHeight * 2;
  2945. Data.resize(size);
  2946. float *pPrimitives = (float *)Data.data();
  2947. float lod = 0.0;
  2948. int ix = 0;
  2949. while (texHeight > 0 && texWidth > 0) {
  2950. if(!texHeight) texHeight = 1;
  2951. if(!texWidth) texWidth = 1;
  2952. for (size_t j = 0; j < texHeight; ++j) {
  2953. for (size_t i = 0; i < texWidth; ++i) {
  2954. pPrimitives[ix++] = lod;
  2955. }
  2956. }
  2957. lod += 1.0;
  2958. texHeight >>= 1;
  2959. texWidth >>= 1;
  2960. }
  2961. };
  2962. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2963. MappedData data;
  2964. test->Test->GetReadBackData("U0", &data);
  2965. const UINT *pPixels = (UINT *)data.data();
  2966. VerifySampleResults(pPixels);
  2967. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2968. // Disable CS so mesh goes forward
  2969. pShaderOp->CS = nullptr;
  2970. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2971. }
  2972. }
  2973. // Executing a simple binop to verify shadel model 6.1 support; runs with
  2974. // ShaderModel61.CoreRequirement
  2975. TEST_F(ExecutionTest, BasicShaderModel61) {
  2976. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  2977. }
  2978. // Executing a simple binop to verify shadel model 6.3 support; runs with
  2979. // ShaderModel63.CoreRequirement
  2980. TEST_F(ExecutionTest, BasicShaderModel63) {
  2981. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  2982. }
  2983. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  2984. WEX::TestExecution::SetVerifyOutput verifySettings(
  2985. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2986. CComPtr<ID3D12Device> pDevice;
  2987. if (!CreateDevice(&pDevice, shaderModel)) {
  2988. return;
  2989. }
  2990. char *pShaderModelStr;
  2991. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  2992. pShaderModelStr = "cs_6_1";
  2993. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  2994. pShaderModelStr = "cs_6_3";
  2995. } else {
  2996. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  2997. pShaderModelStr = nullptr;
  2998. }
  2999. const char shaderTemplate[] =
  3000. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  3001. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  3002. "[numthreads(8,8,1)]"
  3003. "void main(uint GI : SV_GroupIndex) {"
  3004. " SBinaryOp l = g_buf[GI];"
  3005. " l.output = l.input1 + l.input2;"
  3006. " g_buf[GI] = l;"
  3007. "}";
  3008. char shader[sizeof(shaderTemplate) + 50];
  3009. // Run simple shader with float data types
  3010. char* sTy = "float";
  3011. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  3012. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3013. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  3014. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  3015. // Run simple shader with double data types
  3016. if (DoesDeviceSupportDouble(pDevice)) {
  3017. sTy = "double";
  3018. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  3019. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3020. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  3021. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  3022. }
  3023. else {
  3024. // Optional feature, so it's correct to not support it if declared as such.
  3025. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  3026. }
  3027. // Run simple shader with int64 types
  3028. if (DoesDeviceSupportInt64(pDevice)) {
  3029. sTy = "int64_t";
  3030. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  3031. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3032. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  3033. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  3034. }
  3035. else {
  3036. // Optional feature, so it's correct to not support it if declared as such.
  3037. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  3038. }
  3039. }
  3040. template <class Ty>
  3041. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  3042. DXASSERT_NOMSG("Unsupported type");
  3043. return "";
  3044. }
  3045. template <>
  3046. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  3047. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  3048. }
  3049. template <>
  3050. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  3051. return BasicShaderModelTest_GetFormatString<float>();
  3052. }
  3053. template <>
  3054. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  3055. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  3056. }
  3057. template <class Ty>
  3058. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  3059. Ty *pInputDataPairs, unsigned inputDataCount) {
  3060. struct SBinaryOp {
  3061. Ty input1;
  3062. Ty input2;
  3063. Ty output;
  3064. };
  3065. CComPtr<IStream> pStream;
  3066. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3067. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3068. pDevice, m_support, pStream, "BinaryFPOp",
  3069. // this callbacked is called when the test is creating the resource to run the test
  3070. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3071. UNREFERENCED_PARAMETER(Name);
  3072. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  3073. pShaderOp->Shaders.at(0).Text = pShader;
  3074. size_t size = sizeof(SBinaryOp) * inputDataCount;
  3075. Data.resize(size);
  3076. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  3077. Ty *pIn = pInputDataPairs;
  3078. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  3079. SBinaryOp *p = &pPrimitives[i];
  3080. p->input1 = pIn[0];
  3081. p->input2 = pIn[1];
  3082. }
  3083. });
  3084. VERIFY_SUCCEEDED(S_OK);
  3085. MappedData data;
  3086. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3087. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  3088. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  3089. Ty *pIn = pInputDataPairs;
  3090. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  3091. Ty expValue = pIn[0] + pIn[1];
  3092. SBinaryOp *p = &pPrimitives[i];
  3093. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  3094. VERIFY_ARE_EQUAL(p->output, expValue);
  3095. }
  3096. }
  3097. // Resource structure for data-driven tests.
  3098. struct SUnaryFPOp {
  3099. float input;
  3100. float output;
  3101. };
  3102. struct SBinaryFPOp {
  3103. float input1;
  3104. float input2;
  3105. float output1;
  3106. float output2;
  3107. };
  3108. struct STertiaryFPOp {
  3109. float input1;
  3110. float input2;
  3111. float input3;
  3112. float output;
  3113. };
  3114. struct SUnaryHalfOp {
  3115. uint16_t input;
  3116. uint16_t output;
  3117. };
  3118. struct SBinaryHalfOp {
  3119. uint16_t input1;
  3120. uint16_t input2;
  3121. uint16_t output1;
  3122. uint16_t output2;
  3123. };
  3124. struct STertiaryHalfOp {
  3125. uint16_t input1;
  3126. uint16_t input2;
  3127. uint16_t input3;
  3128. uint16_t output;
  3129. };
  3130. struct SUnaryIntOp {
  3131. int input;
  3132. int output;
  3133. };
  3134. struct SUnaryUintOp {
  3135. unsigned int input;
  3136. unsigned int output;
  3137. };
  3138. struct SBinaryIntOp {
  3139. int input1;
  3140. int input2;
  3141. int output1;
  3142. int output2;
  3143. };
  3144. struct STertiaryIntOp {
  3145. int input1;
  3146. int input2;
  3147. int input3;
  3148. int output;
  3149. };
  3150. struct SBinaryUintOp {
  3151. unsigned int input1;
  3152. unsigned int input2;
  3153. unsigned int output1;
  3154. unsigned int output2;
  3155. };
  3156. struct STertiaryUintOp {
  3157. unsigned int input1;
  3158. unsigned int input2;
  3159. unsigned int input3;
  3160. unsigned int output;
  3161. };
  3162. struct SUnaryInt16Op {
  3163. short input;
  3164. short output;
  3165. };
  3166. struct SUnaryUint16Op {
  3167. unsigned short input;
  3168. unsigned short output;
  3169. };
  3170. struct SBinaryInt16Op {
  3171. short input1;
  3172. short input2;
  3173. short output1;
  3174. short output2;
  3175. };
  3176. struct STertiaryInt16Op {
  3177. short input1;
  3178. short input2;
  3179. short input3;
  3180. short output;
  3181. };
  3182. struct SBinaryUint16Op {
  3183. unsigned short input1;
  3184. unsigned short input2;
  3185. unsigned short output1;
  3186. unsigned short output2;
  3187. };
  3188. struct STertiaryUint16Op {
  3189. unsigned short input1;
  3190. unsigned short input2;
  3191. unsigned short input3;
  3192. unsigned short output;
  3193. };
  3194. // representation for HLSL float vectors
  3195. struct SDotOp {
  3196. XMFLOAT4 input1;
  3197. XMFLOAT4 input2;
  3198. float o_dot2;
  3199. float o_dot3;
  3200. float o_dot4;
  3201. };
  3202. struct Half2
  3203. {
  3204. uint16_t x;
  3205. uint16_t y;
  3206. Half2() = default;
  3207. Half2(const Half2&) = default;
  3208. Half2& operator=(const Half2&) = default;
  3209. Half2(Half2&&) = default;
  3210. Half2& operator=(Half2&&) = default;
  3211. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  3212. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  3213. };
  3214. struct SDot2AddHalfOp {
  3215. Half2 input1;
  3216. Half2 input2;
  3217. float acc;
  3218. float result;
  3219. };
  3220. struct SDot4AddI8PackedOp {
  3221. uint32_t input1;
  3222. uint32_t input2;
  3223. int32_t acc;
  3224. int32_t result;
  3225. };
  3226. struct SDot4AddU8PackedOp {
  3227. uint32_t input1;
  3228. uint32_t input2;
  3229. uint32_t acc;
  3230. uint32_t result;
  3231. };
  3232. struct SMsad4 {
  3233. unsigned int ref;
  3234. XMUINT2 src;
  3235. XMUINT4 accum;
  3236. XMUINT4 result;
  3237. };
  3238. struct SPackUnpackOpOutPacked
  3239. {
  3240. uint32_t packedUint32;
  3241. uint32_t packedInt32;
  3242. uint32_t packedUint16;
  3243. uint32_t packedInt16;
  3244. uint32_t packedClampedUint32;
  3245. uint32_t packedClampedInt32;
  3246. uint32_t packedClampedUint16;
  3247. uint32_t packedClampedInt16;
  3248. };
  3249. struct SPackUnpackOpOutUnpacked {
  3250. std::array<uint32_t, 4> outputUint32;
  3251. std::array<int32_t, 4> outputInt32;
  3252. std::array<uint16_t, 4> outputUint16;
  3253. std::array<int16_t, 4> outputInt16;
  3254. std::array<uint32_t, 4> outputClampedUint32;
  3255. std::array<int32_t, 4> outputClampedInt32;
  3256. std::array<uint16_t, 4> outputClampedUint16;
  3257. std::array<int16_t, 4> outputClampedInt16;
  3258. };
  3259. // Parameter representation for taef data-driven tests
  3260. struct TableParameter {
  3261. LPCWSTR m_name;
  3262. enum TableParameterType {
  3263. INT8,
  3264. INT16,
  3265. INT32,
  3266. UINT,
  3267. FLOAT,
  3268. HALF,
  3269. DOUBLE,
  3270. STRING,
  3271. BOOL,
  3272. INT8_TABLE,
  3273. INT16_TABLE,
  3274. INT32_TABLE,
  3275. FLOAT_TABLE,
  3276. HALF_TABLE,
  3277. DOUBLE_TABLE,
  3278. STRING_TABLE,
  3279. UINT8_TABLE,
  3280. UINT16_TABLE,
  3281. UINT32_TABLE,
  3282. BOOL_TABLE
  3283. };
  3284. TableParameterType m_type;
  3285. bool m_required; // required parameter
  3286. int8_t m_int8;
  3287. int16_t m_int16;
  3288. int m_int32;
  3289. unsigned int m_uint;
  3290. float m_float;
  3291. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  3292. double m_double;
  3293. bool m_bool;
  3294. WEX::Common::String m_str;
  3295. std::vector<int8_t> m_int8Table;
  3296. std::vector<int16_t> m_int16Table;
  3297. std::vector<int> m_int32Table;
  3298. std::vector<uint8_t> m_uint8Table;
  3299. std::vector<uint16_t> m_uint16Table;
  3300. std::vector<unsigned int> m_uint32Table;
  3301. std::vector<float> m_floatTable;
  3302. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  3303. std::vector<double> m_doubleTable;
  3304. std::vector<bool> m_boolTable;
  3305. std::vector<WEX::Common::String> m_StringTable;
  3306. };
  3307. class TableParameterHandler {
  3308. private:
  3309. HRESULT ParseTableRow();
  3310. public:
  3311. TableParameter* m_table;
  3312. size_t m_tableSize;
  3313. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  3314. clearTableParameter();
  3315. VERIFY_SUCCEEDED(ParseTableRow());
  3316. }
  3317. TableParameter* GetTableParamByName(LPCWSTR name) {
  3318. for (size_t i = 0; i < m_tableSize; ++i) {
  3319. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3320. return &m_table[i];
  3321. }
  3322. }
  3323. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3324. return nullptr;
  3325. }
  3326. void clearTableParameter() {
  3327. for (size_t i = 0; i < m_tableSize; ++i) {
  3328. m_table[i].m_int32 = 0;
  3329. m_table[i].m_uint = 0;
  3330. m_table[i].m_double = 0;
  3331. m_table[i].m_bool = false;
  3332. m_table[i].m_str = WEX::Common::String();
  3333. }
  3334. }
  3335. template <class T1>
  3336. std::vector<T1> *GetDataArray(LPCWSTR name) {
  3337. return nullptr;
  3338. }
  3339. template <>
  3340. std::vector<int> *GetDataArray(LPCWSTR name) {
  3341. for (size_t i = 0; i < m_tableSize; ++i) {
  3342. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3343. return &(m_table[i].m_int32Table);
  3344. }
  3345. }
  3346. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3347. return nullptr;
  3348. }
  3349. template <>
  3350. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  3351. for (size_t i = 0; i < m_tableSize; ++i) {
  3352. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3353. return &(m_table[i].m_int8Table);
  3354. }
  3355. }
  3356. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3357. return nullptr;
  3358. }
  3359. template <>
  3360. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  3361. for (size_t i = 0; i < m_tableSize; ++i) {
  3362. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3363. return &(m_table[i].m_int16Table);
  3364. }
  3365. }
  3366. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3367. return nullptr;
  3368. }
  3369. template <>
  3370. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  3371. for (size_t i = 0; i < m_tableSize; ++i) {
  3372. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3373. return &(m_table[i].m_uint32Table);
  3374. }
  3375. }
  3376. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3377. return nullptr;
  3378. }
  3379. template <>
  3380. std::vector<float> *GetDataArray(LPCWSTR name) {
  3381. for (size_t i = 0; i < m_tableSize; ++i) {
  3382. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3383. return &(m_table[i].m_floatTable);
  3384. }
  3385. }
  3386. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3387. return nullptr;
  3388. }
  3389. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  3390. template <>
  3391. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  3392. for (size_t i = 0; i < m_tableSize; ++i) {
  3393. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3394. return &(m_table[i].m_halfTable);
  3395. }
  3396. }
  3397. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3398. return nullptr;
  3399. }
  3400. template <>
  3401. std::vector<double> *GetDataArray(LPCWSTR name) {
  3402. for (size_t i = 0; i < m_tableSize; ++i) {
  3403. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3404. return &(m_table[i].m_doubleTable);
  3405. }
  3406. }
  3407. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3408. return nullptr;
  3409. }
  3410. template <>
  3411. std::vector<bool> *GetDataArray(LPCWSTR name) {
  3412. for (size_t i = 0; i < m_tableSize; ++i) {
  3413. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3414. return &(m_table[i].m_boolTable);
  3415. }
  3416. }
  3417. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3418. return nullptr;
  3419. }
  3420. };
  3421. static TableParameter UnaryFPOpParameters[] = {
  3422. { L"ShaderOp.Target", TableParameter::STRING, true },
  3423. { L"ShaderOp.Text", TableParameter::STRING, true },
  3424. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3425. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3426. { L"Validation.Type", TableParameter::STRING, true },
  3427. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3428. { L"Warp.Version", TableParameter::UINT, false }
  3429. };
  3430. static TableParameter BinaryFPOpParameters[] = {
  3431. { L"ShaderOp.Target", TableParameter::STRING, true },
  3432. { L"ShaderOp.Text", TableParameter::STRING, true },
  3433. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3434. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3435. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3436. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  3437. { L"Validation.Type", TableParameter::STRING, true },
  3438. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3439. };
  3440. static TableParameter TertiaryFPOpParameters[] = {
  3441. { L"ShaderOp.Target", TableParameter::STRING, true },
  3442. { L"ShaderOp.Text", TableParameter::STRING, true },
  3443. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3444. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3445. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3446. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3447. { L"Validation.Type", TableParameter::STRING, true },
  3448. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3449. };
  3450. static TableParameter UnaryHalfOpParameters[] = {
  3451. { L"ShaderOp.Target", TableParameter::STRING, true },
  3452. { L"ShaderOp.Text", TableParameter::STRING, true },
  3453. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3454. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3455. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3456. { L"Validation.Type", TableParameter::STRING, true },
  3457. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3458. { L"Warp.Version", TableParameter::UINT, false }
  3459. };
  3460. static TableParameter BinaryHalfOpParameters[] = {
  3461. { L"ShaderOp.Target", TableParameter::STRING, true },
  3462. { L"ShaderOp.Text", TableParameter::STRING, true },
  3463. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3464. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3465. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3466. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3467. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  3468. { L"Validation.Type", TableParameter::STRING, true },
  3469. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3470. };
  3471. static TableParameter TertiaryHalfOpParameters[] = {
  3472. { L"ShaderOp.Target", TableParameter::STRING, true },
  3473. { L"ShaderOp.Text", TableParameter::STRING, true },
  3474. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3475. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3476. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3477. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  3478. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3479. { L"Validation.Type", TableParameter::STRING, true },
  3480. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3481. };
  3482. static TableParameter UnaryIntOpParameters[] = {
  3483. { L"ShaderOp.Target", TableParameter::STRING, true },
  3484. { L"ShaderOp.Text", TableParameter::STRING, true },
  3485. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3486. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3487. { L"Validation.Tolerance", TableParameter::INT32, true },
  3488. };
  3489. static TableParameter UnaryUintOpParameters[] = {
  3490. { L"ShaderOp.Target", TableParameter::STRING, true },
  3491. { L"ShaderOp.Text", TableParameter::STRING, true },
  3492. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3493. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3494. { L"Validation.Tolerance", TableParameter::INT32, true },
  3495. };
  3496. static TableParameter BinaryIntOpParameters[] = {
  3497. { L"ShaderOp.Target", TableParameter::STRING, true },
  3498. { L"ShaderOp.Text", TableParameter::STRING, true },
  3499. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3500. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3501. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3502. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  3503. { L"Validation.Tolerance", TableParameter::INT32, true },
  3504. };
  3505. static TableParameter TertiaryIntOpParameters[] = {
  3506. { L"ShaderOp.Target", TableParameter::STRING, true },
  3507. { L"ShaderOp.Text", TableParameter::STRING, true },
  3508. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3509. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3510. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3511. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3512. { L"Validation.Tolerance", TableParameter::INT32, true },
  3513. };
  3514. static TableParameter BinaryUintOpParameters[] = {
  3515. { L"ShaderOp.Target", TableParameter::STRING, true },
  3516. { L"ShaderOp.Text", TableParameter::STRING, true },
  3517. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3518. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3519. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3520. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  3521. { L"Validation.Tolerance", TableParameter::INT32, true },
  3522. };
  3523. static TableParameter TertiaryUintOpParameters[] = {
  3524. { L"ShaderOp.Target", TableParameter::STRING, true },
  3525. { L"ShaderOp.Text", TableParameter::STRING, true },
  3526. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3527. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3528. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3529. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3530. { L"Validation.Tolerance", TableParameter::INT32, true },
  3531. };
  3532. static TableParameter UnaryInt16OpParameters[] = {
  3533. { L"ShaderOp.Target", TableParameter::STRING, true },
  3534. { L"ShaderOp.Text", TableParameter::STRING, true },
  3535. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3536. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3537. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3538. { L"Validation.Tolerance", TableParameter::INT32, true },
  3539. };
  3540. static TableParameter UnaryUint16OpParameters[] = {
  3541. { L"ShaderOp.Target", TableParameter::STRING, true },
  3542. { L"ShaderOp.Text", TableParameter::STRING, true },
  3543. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3544. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3545. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3546. { L"Validation.Tolerance", TableParameter::INT32, true },
  3547. };
  3548. static TableParameter BinaryInt16OpParameters[] = {
  3549. { L"ShaderOp.Target", TableParameter::STRING, true },
  3550. { L"ShaderOp.Text", TableParameter::STRING, true },
  3551. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3552. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3553. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3554. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3555. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  3556. { L"Validation.Tolerance", TableParameter::INT32, true },
  3557. };
  3558. static TableParameter TertiaryInt16OpParameters[] = {
  3559. { L"ShaderOp.Target", TableParameter::STRING, true },
  3560. { L"ShaderOp.Text", TableParameter::STRING, true },
  3561. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3562. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3563. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3564. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  3565. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3566. { L"Validation.Tolerance", TableParameter::INT32, true },
  3567. };
  3568. static TableParameter BinaryUint16OpParameters[] = {
  3569. { L"ShaderOp.Target", TableParameter::STRING, true },
  3570. { L"ShaderOp.Text", TableParameter::STRING, true },
  3571. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3572. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3573. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3574. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3575. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  3576. { L"Validation.Tolerance", TableParameter::INT32, true },
  3577. };
  3578. static TableParameter TertiaryUint16OpParameters[] = {
  3579. { L"ShaderOp.Target", TableParameter::STRING, true },
  3580. { L"ShaderOp.Text", TableParameter::STRING, true },
  3581. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3582. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3583. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3584. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  3585. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3586. { L"Validation.Tolerance", TableParameter::INT32, true },
  3587. };
  3588. static TableParameter DotOpParameters[] = {
  3589. { L"ShaderOp.Target", TableParameter::STRING, true },
  3590. { L"ShaderOp.Text", TableParameter::STRING, true },
  3591. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3592. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3593. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3594. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  3595. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  3596. { L"Validation.Type", TableParameter::STRING, true },
  3597. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3598. };
  3599. static TableParameter Dot2AddHalfOpParameters[] = {
  3600. { L"ShaderOp.Target", TableParameter::STRING, true },
  3601. { L"ShaderOp.Text", TableParameter::STRING, true },
  3602. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3603. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3604. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3605. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3606. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3607. { L"Validation.Type", TableParameter::STRING, true },
  3608. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3609. };
  3610. static TableParameter Dot4AddI8PackedOpParameters[] = {
  3611. { L"ShaderOp.Target", TableParameter::STRING, true },
  3612. { L"ShaderOp.Text", TableParameter::STRING, true },
  3613. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3614. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3615. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3616. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3617. };
  3618. static TableParameter Dot4AddU8PackedOpParameters[] = {
  3619. { L"ShaderOp.Target", TableParameter::STRING, true },
  3620. { L"ShaderOp.Text", TableParameter::STRING, true },
  3621. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3622. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3623. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3624. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3625. };
  3626. static TableParameter Msad4OpParameters[] = {
  3627. { L"ShaderOp.Text", TableParameter::STRING, true },
  3628. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3629. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  3630. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3631. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3632. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  3633. };
  3634. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  3635. { L"ShaderOp.Name", TableParameter::STRING, true },
  3636. { L"ShaderOp.Text", TableParameter::STRING, true },
  3637. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3638. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3639. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3640. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3641. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3642. };
  3643. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  3644. { L"ShaderOp.Name", TableParameter::STRING, true },
  3645. { L"ShaderOp.Text", TableParameter::STRING, true },
  3646. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3647. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3648. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3649. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3650. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3651. };
  3652. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  3653. { L"ShaderOp.Name", TableParameter::STRING, true },
  3654. { L"ShaderOp.Text", TableParameter::STRING, true },
  3655. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3656. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3657. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3658. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3659. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3660. };
  3661. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  3662. { L"ShaderOp.Name", TableParameter::STRING, true },
  3663. { L"ShaderOp.Text", TableParameter::STRING, true },
  3664. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3665. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3666. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3667. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3668. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3669. };
  3670. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  3671. { L"ShaderOp.Name", TableParameter::STRING, true },
  3672. { L"ShaderOp.Target", TableParameter::STRING, true },
  3673. { L"ShaderOp.Text", TableParameter::STRING, true },
  3674. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  3675. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  3676. };
  3677. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  3678. { L"ShaderOp.Name", TableParameter::STRING, true },
  3679. { L"ShaderOp.Target", TableParameter::STRING, true },
  3680. { L"ShaderOp.Text", TableParameter::STRING, true },
  3681. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  3682. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  3683. };
  3684. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  3685. { L"ShaderOp.Name", TableParameter::STRING, true },
  3686. { L"ShaderOp.Text", TableParameter::STRING, true },
  3687. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3688. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  3689. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  3690. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  3691. };
  3692. static TableParameter CBufferTestHalfParameters[] = {
  3693. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  3694. };
  3695. static TableParameter DenormBinaryFPOpParameters[] = {
  3696. { L"ShaderOp.Target", TableParameter::STRING, true },
  3697. { L"ShaderOp.Text", TableParameter::STRING, true },
  3698. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3699. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3700. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3701. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3702. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3703. { L"Validation.Type", TableParameter::STRING, true },
  3704. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3705. };
  3706. static TableParameter DenormTertiaryFPOpParameters[] = {
  3707. { L"ShaderOp.Target", TableParameter::STRING, true },
  3708. { L"ShaderOp.Text", TableParameter::STRING, true },
  3709. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3710. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3711. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3712. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3713. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3714. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3715. { L"Validation.Type", TableParameter::STRING, true },
  3716. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3717. };
  3718. static TableParameter PackUnpackOpParameters[] = {
  3719. { L"ShaderOp.Text", TableParameter::STRING, true },
  3720. { L"Validation.Type", TableParameter::STRING, true },
  3721. { L"Validation.Tolerance", TableParameter::UINT, true },
  3722. { L"Validation.Input", TableParameter::UINT32_TABLE, true },
  3723. };
  3724. static bool IsHexString(PCWSTR str, uint16_t *value) {
  3725. std::wstring wString(str);
  3726. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3727. LPCWSTR wstr = wString.c_str();
  3728. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  3729. *value = (uint16_t)wcstol(wstr, NULL, 0);
  3730. return true;
  3731. }
  3732. return false;
  3733. }
  3734. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  3735. std::wstring wString(str);
  3736. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3737. PCWSTR wstr = wString.data();
  3738. if (_wcsicmp(wstr, L"NaN") == 0) {
  3739. value = NAN;
  3740. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  3741. value = -(INFINITY);
  3742. } else if (_wcsicmp(wstr, L"inf") == 0) {
  3743. value = INFINITY;
  3744. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  3745. value = -(FLT_MIN / 2);
  3746. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  3747. value = FLT_MIN / 2;
  3748. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  3749. _wcsicmp(wstr, L"-0") == 0) {
  3750. value = -0.0f;
  3751. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  3752. _wcsicmp(wstr, L"0") == 0) {
  3753. value = 0.0f;
  3754. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  3755. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  3756. value = (float&)temp_i;
  3757. }
  3758. else {
  3759. // evaluate the expression of wstring
  3760. double val = _wtof(wstr);
  3761. if (val == 0) {
  3762. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  3763. return E_FAIL;
  3764. }
  3765. value = (float)val;
  3766. }
  3767. return S_OK;
  3768. }
  3769. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  3770. std::wstring wString(str);
  3771. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3772. PCWSTR wstr = wString.data();
  3773. // evaluate the expression of string
  3774. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  3775. value = 0;
  3776. return S_OK;
  3777. }
  3778. int val = _wtoi(wstr);
  3779. if (val == 0) {
  3780. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3781. return E_FAIL;
  3782. }
  3783. value = val;
  3784. return S_OK;
  3785. }
  3786. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3787. std::wstring wString(str);
  3788. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3789. PCWSTR wstr = wString.data();
  3790. // evaluate the expression of string
  3791. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3792. value = 0;
  3793. return S_OK;
  3794. }
  3795. wchar_t *end;
  3796. unsigned int val = std::wcstoul(wstr, &end, 0);
  3797. if (val == 0) {
  3798. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3799. return E_FAIL;
  3800. }
  3801. value = val;
  3802. return S_OK;
  3803. }
  3804. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3805. std::wstring wstr(str);
  3806. size_t curPosition = 0;
  3807. // parse a string of dot product separated by commas
  3808. for (size_t i = 0; i < count; ++i) {
  3809. size_t nextPosition = wstr.find(L",", curPosition);
  3810. if (FAILED(ParseDataToFloat(
  3811. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3812. *(ptr + i)))) {
  3813. return E_FAIL;
  3814. }
  3815. curPosition = nextPosition + 1;
  3816. }
  3817. return S_OK;
  3818. }
  3819. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3820. std::wstring wstr(str);
  3821. size_t curPosition = 0;
  3822. // parse a string of dot product separated by commas
  3823. for (size_t i = 0; i < count; ++i) {
  3824. size_t nextPosition = wstr.find(L",", curPosition);
  3825. float floatValue;
  3826. if (FAILED(ParseDataToFloat(
  3827. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3828. return E_FAIL;
  3829. }
  3830. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3831. curPosition = nextPosition + 1;
  3832. }
  3833. return S_OK;
  3834. }
  3835. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3836. std::wstring wstr(str);
  3837. size_t curPosition = 0;
  3838. // parse a string of dot product separated by commas
  3839. for (size_t i = 0; i < count; ++i) {
  3840. size_t nextPosition = wstr.find(L",", curPosition);
  3841. if (FAILED(ParseDataToUint(
  3842. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3843. *(ptr + i)))) {
  3844. return E_FAIL;
  3845. }
  3846. curPosition = nextPosition + 1;
  3847. }
  3848. return S_OK;
  3849. }
  3850. HRESULT TableParameterHandler::ParseTableRow() {
  3851. TableParameter *table = m_table;
  3852. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3853. switch (table[i].m_type) {
  3854. case TableParameter::INT8:
  3855. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3856. table[i].m_int32)) && table[i].m_required) {
  3857. // TryGetValue does not suppport reading from int16
  3858. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3859. return E_FAIL;
  3860. }
  3861. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3862. break;
  3863. case TableParameter::INT16:
  3864. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3865. table[i].m_int32)) && table[i].m_required) {
  3866. // TryGetValue does not suppport reading from int16
  3867. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3868. return E_FAIL;
  3869. }
  3870. table[i].m_int16 = (short)(table[i].m_int32);
  3871. break;
  3872. case TableParameter::INT32:
  3873. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3874. table[i].m_int32)) && table[i].m_required) {
  3875. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3876. return E_FAIL;
  3877. }
  3878. break;
  3879. case TableParameter::UINT:
  3880. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3881. table[i].m_uint)) && table[i].m_required) {
  3882. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3883. return E_FAIL;
  3884. }
  3885. break;
  3886. case TableParameter::DOUBLE:
  3887. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3888. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3889. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3890. return E_FAIL;
  3891. }
  3892. break;
  3893. case TableParameter::STRING:
  3894. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3895. table[i].m_str)) && table[i].m_required) {
  3896. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3897. return E_FAIL;
  3898. }
  3899. break;
  3900. case TableParameter::BOOL:
  3901. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3902. table[i].m_str)) && table[i].m_bool) {
  3903. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3904. return E_FAIL;
  3905. }
  3906. break;
  3907. case TableParameter::INT8_TABLE: {
  3908. WEX::TestExecution::TestDataArray<int> tempTable;
  3909. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3910. table[i].m_name, tempTable)) && table[i].m_required) {
  3911. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3912. return E_FAIL;
  3913. }
  3914. // TryGetValue does not suppport reading from int8
  3915. table[i].m_int8Table.resize(tempTable.GetSize());
  3916. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3917. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  3918. }
  3919. break;
  3920. }
  3921. case TableParameter::INT16_TABLE: {
  3922. WEX::TestExecution::TestDataArray<int> tempTable;
  3923. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3924. table[i].m_name, tempTable)) && table[i].m_required) {
  3925. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3926. return E_FAIL;
  3927. }
  3928. // TryGetValue does not suppport reading from int8
  3929. table[i].m_int16Table.resize(tempTable.GetSize());
  3930. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3931. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  3932. }
  3933. break;
  3934. }case TableParameter::INT32_TABLE: {
  3935. WEX::TestExecution::TestDataArray<int> tempTable;
  3936. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3937. table[i].m_name, tempTable)) && table[i].m_required) {
  3938. // TryGetValue does not suppport reading from int8
  3939. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3940. return E_FAIL;
  3941. }
  3942. table[i].m_int32Table.resize(tempTable.GetSize());
  3943. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3944. table[i].m_int32Table[j] = tempTable[j];
  3945. }
  3946. break;
  3947. }
  3948. case TableParameter::UINT8_TABLE: {
  3949. WEX::TestExecution::TestDataArray<int> tempTable;
  3950. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3951. table[i].m_name, tempTable)) && table[i].m_required) {
  3952. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3953. return E_FAIL;
  3954. }
  3955. // TryGetValue does not suppport reading from int8
  3956. table[i].m_int8Table.resize(tempTable.GetSize());
  3957. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3958. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  3959. }
  3960. break;
  3961. }
  3962. case TableParameter::UINT16_TABLE: {
  3963. WEX::TestExecution::TestDataArray<int> tempTable;
  3964. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3965. table[i].m_name, tempTable)) && table[i].m_required) {
  3966. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3967. return E_FAIL;
  3968. }
  3969. // TryGetValue does not suppport reading from int8
  3970. table[i].m_uint16Table.resize(tempTable.GetSize());
  3971. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3972. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  3973. }
  3974. break;
  3975. }
  3976. case TableParameter::UINT32_TABLE: {
  3977. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  3978. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3979. table[i].m_name, tempTable)) && table[i].m_required) {
  3980. // TryGetValue does not suppport reading from int8
  3981. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3982. return E_FAIL;
  3983. }
  3984. table[i].m_uint32Table.resize(tempTable.GetSize());
  3985. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3986. table[i].m_uint32Table[j] = tempTable[j];
  3987. }
  3988. break;
  3989. }
  3990. case TableParameter::FLOAT_TABLE: {
  3991. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3992. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3993. table[i].m_name, tempTable)) && table[i].m_required) {
  3994. // TryGetValue does not suppport reading from int8
  3995. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3996. return E_FAIL;
  3997. }
  3998. table[i].m_floatTable.resize(tempTable.GetSize());
  3999. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4000. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  4001. }
  4002. break;
  4003. }
  4004. case TableParameter::HALF_TABLE: {
  4005. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4006. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4007. table[i].m_name, tempTable)) && table[i].m_required) {
  4008. // TryGetValue does not suppport reading from int8
  4009. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4010. return E_FAIL;
  4011. }
  4012. table[i].m_halfTable.resize(tempTable.GetSize());
  4013. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4014. uint16_t value = 0;
  4015. if (IsHexString(tempTable[j], &value)) {
  4016. table[i].m_halfTable[j] = value;
  4017. }
  4018. else {
  4019. float val;
  4020. ParseDataToFloat(tempTable[j], val);
  4021. if (isdenorm(val))
  4022. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  4023. else
  4024. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  4025. }
  4026. }
  4027. break;
  4028. }
  4029. case TableParameter::DOUBLE_TABLE: {
  4030. WEX::TestExecution::TestDataArray<double> tempTable;
  4031. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4032. table[i].m_name, tempTable)) && table[i].m_required) {
  4033. // TryGetValue does not suppport reading from int8
  4034. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4035. return E_FAIL;
  4036. }
  4037. table[i].m_doubleTable.resize(tempTable.GetSize());
  4038. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4039. table[i].m_doubleTable[j] = tempTable[j];
  4040. }
  4041. break;
  4042. }
  4043. case TableParameter::BOOL_TABLE: {
  4044. WEX::TestExecution::TestDataArray<bool> tempTable;
  4045. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4046. table[i].m_name, tempTable)) && table[i].m_required) {
  4047. // TryGetValue does not suppport reading from int8
  4048. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4049. return E_FAIL;
  4050. }
  4051. table[i].m_boolTable.resize(tempTable.GetSize());
  4052. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4053. table[i].m_boolTable[j] = tempTable[j];
  4054. }
  4055. break;
  4056. }
  4057. case TableParameter::STRING_TABLE: {
  4058. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4059. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4060. table[i].m_name, tempTable)) && table[i].m_required) {
  4061. // TryGetValue does not suppport reading from int8
  4062. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4063. return E_FAIL;
  4064. }
  4065. table[i].m_StringTable.resize(tempTable.GetSize());
  4066. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4067. table[i].m_StringTable[j] = tempTable[j];
  4068. }
  4069. break;
  4070. }
  4071. default:
  4072. DXASSERT_NOMSG("Invalid Parameter Type");
  4073. }
  4074. if (errno == ERANGE) {
  4075. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  4076. return E_FAIL;
  4077. }
  4078. }
  4079. return S_OK;
  4080. }
  4081. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  4082. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4083. }
  4084. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  4085. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4086. }
  4087. static void VerifyOutputWithExpectedValueUInt4(XMUINT4 output, XMUINT4 ref) {
  4088. VERIFY_ARE_EQUAL(output.x, ref.x);
  4089. VERIFY_ARE_EQUAL(output.y, ref.y);
  4090. VERIFY_ARE_EQUAL(output.z, ref.z);
  4091. VERIFY_ARE_EQUAL(output.w, ref.w);
  4092. }
  4093. static void VerifyOutputWithExpectedValueFloat(
  4094. float output, float ref, LPCWSTR type, double tolerance,
  4095. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4096. if (_wcsicmp(type, L"Relative") == 0) {
  4097. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  4098. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4099. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  4100. } else if (_wcsicmp(type, L"ULP") == 0) {
  4101. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  4102. } else {
  4103. LogErrorFmt(L"Failed to read comparison type %S", type);
  4104. }
  4105. }
  4106. static bool CompareOutputWithExpectedValueFloat(
  4107. float output, float ref, LPCWSTR type, double tolerance,
  4108. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4109. if (_wcsicmp(type, L"Relative") == 0) {
  4110. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  4111. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4112. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  4113. } else if (_wcsicmp(type, L"ULP") == 0) {
  4114. return CompareFloatULP(output, ref, (int)tolerance, mode);
  4115. } else {
  4116. LogErrorFmt(L"Failed to read comparison type %S", type);
  4117. return false;
  4118. }
  4119. }
  4120. static void VerifyOutputWithExpectedValueHalf(
  4121. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  4122. if (_wcsicmp(type, L"Relative") == 0) {
  4123. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  4124. }
  4125. else if (_wcsicmp(type, L"Epsilon") == 0) {
  4126. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  4127. }
  4128. else if (_wcsicmp(type, L"ULP") == 0) {
  4129. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  4130. }
  4131. else {
  4132. LogErrorFmt(L"Failed to read comparison type %S", type);
  4133. }
  4134. }
  4135. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  4136. WEX::TestExecution::SetVerifyOutput verifySettings(
  4137. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4138. CComPtr<IStream> pStream;
  4139. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4140. CComPtr<ID3D12Device> pDevice;
  4141. if (!CreateDevice(&pDevice)) {
  4142. return;
  4143. }
  4144. // Read data from the table
  4145. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  4146. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  4147. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4148. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4149. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4150. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4151. return;
  4152. }
  4153. std::vector<float> *Validation_Input =
  4154. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4155. std::vector<float> *Validation_Expected =
  4156. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4157. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4158. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4159. size_t count = Validation_Input->size();
  4160. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4161. pDevice, m_support, pStream, "UnaryFPOp",
  4162. // this callbacked is called when the test
  4163. // is creating the resource to run the test
  4164. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4165. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4166. size_t size = sizeof(SUnaryFPOp) * count;
  4167. Data.resize(size);
  4168. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  4169. for (size_t i = 0; i < count; ++i) {
  4170. SUnaryFPOp *p = &pPrimitives[i];
  4171. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4172. }
  4173. // use shader from data table
  4174. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4175. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4176. });
  4177. MappedData data;
  4178. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4179. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  4180. WEX::TestExecution::DisableVerifyExceptions dve;
  4181. for (unsigned i = 0; i < count; ++i) {
  4182. SUnaryFPOp *p = &pPrimitives[i];
  4183. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4184. LogCommentFmt(
  4185. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  4186. p->input, p->output, val);
  4187. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  4188. }
  4189. }
  4190. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  4191. WEX::TestExecution::SetVerifyOutput verifySettings(
  4192. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4193. CComPtr<IStream> pStream;
  4194. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4195. CComPtr<ID3D12Device> pDevice;
  4196. if (!CreateDevice(&pDevice)) {
  4197. return;
  4198. }
  4199. // Read data from the table
  4200. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  4201. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  4202. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4203. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4204. std::vector<float> *Validation_Input1 =
  4205. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4206. std::vector<float> *Validation_Input2 =
  4207. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4208. std::vector<float> *Validation_Expected1 =
  4209. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4210. std::vector<float> *Validation_Expected2 =
  4211. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  4212. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4213. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4214. size_t count = Validation_Input1->size();
  4215. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4216. pDevice, m_support, pStream, "BinaryFPOp",
  4217. // this callbacked is called when the test
  4218. // is creating the resource to run the test
  4219. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4220. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4221. size_t size = sizeof(SBinaryFPOp) * count;
  4222. Data.resize(size);
  4223. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4224. for (size_t i = 0; i < count; ++i) {
  4225. SBinaryFPOp *p = &pPrimitives[i];
  4226. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4227. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4228. }
  4229. // use shader from data table
  4230. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4231. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4232. });
  4233. MappedData data;
  4234. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4235. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4236. WEX::TestExecution::DisableVerifyExceptions dve;
  4237. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4238. if (numExpected == 2) {
  4239. for (unsigned i = 0; i < count; ++i) {
  4240. SBinaryFPOp *p = &pPrimitives[i];
  4241. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4242. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4243. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4244. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  4245. i, p->input1, p->input2, p->output1, val1, p->output2,
  4246. val2);
  4247. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4248. Validation_Tolerance);
  4249. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  4250. Validation_Tolerance);
  4251. }
  4252. }
  4253. else if (numExpected == 1) {
  4254. for (unsigned i = 0; i < count; ++i) {
  4255. SBinaryFPOp *p = &pPrimitives[i];
  4256. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4257. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4258. L"%6.8f, expected1 = %6.8f",
  4259. i, p->input1, p->input2, p->output1, val1);
  4260. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4261. Validation_Tolerance);
  4262. }
  4263. }
  4264. else {
  4265. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4266. }
  4267. }
  4268. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  4269. WEX::TestExecution::SetVerifyOutput verifySettings(
  4270. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4271. CComPtr<IStream> pStream;
  4272. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4273. CComPtr<ID3D12Device> pDevice;
  4274. if (!CreateDevice(&pDevice)) {
  4275. return;
  4276. }
  4277. // Read data from the table
  4278. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  4279. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  4280. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4281. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4282. std::vector<float> *Validation_Input1 =
  4283. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4284. std::vector<float> *Validation_Input2 =
  4285. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4286. std::vector<float> *Validation_Input3 =
  4287. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  4288. std::vector<float> *Validation_Expected =
  4289. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4290. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4291. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4292. size_t count = Validation_Input1->size();
  4293. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4294. pDevice, m_support, pStream, "TertiaryFPOp",
  4295. // this callbacked is called when the test
  4296. // is creating the resource to run the test
  4297. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4298. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4299. size_t size = sizeof(STertiaryFPOp) * count;
  4300. Data.resize(size);
  4301. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  4302. for (size_t i = 0; i < count; ++i) {
  4303. STertiaryFPOp *p = &pPrimitives[i];
  4304. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4305. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4306. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4307. }
  4308. // use shader from data table
  4309. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4310. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4311. });
  4312. MappedData data;
  4313. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4314. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  4315. WEX::TestExecution::DisableVerifyExceptions dve;
  4316. for (unsigned i = 0; i < count; ++i) {
  4317. STertiaryFPOp *p = &pPrimitives[i];
  4318. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4319. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  4320. L"%6.8f, expected = %6.8f",
  4321. i, p->input1, p->input2, p->input3, p->output, val);
  4322. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  4323. Validation_Tolerance);
  4324. }
  4325. }
  4326. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  4327. WEX::TestExecution::SetVerifyOutput verifySettings(
  4328. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4329. CComPtr<IStream> pStream;
  4330. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4331. CComPtr<ID3D12Device> pDevice;
  4332. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4333. return;
  4334. }
  4335. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4336. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4337. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4338. return;
  4339. }
  4340. // Read data from the table
  4341. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  4342. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  4343. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4344. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4345. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4346. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4347. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4348. return;
  4349. }
  4350. std::vector<uint16_t> *Validation_Input =
  4351. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4352. std::vector<uint16_t> *Validation_Expected =
  4353. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4354. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4355. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4356. size_t count = Validation_Input->size();
  4357. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4358. pDevice, m_support, pStream, "UnaryFPOp",
  4359. // this callbacked is called when the test
  4360. // is creating the resource to run the test
  4361. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4362. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4363. size_t size = sizeof(SUnaryHalfOp) * count;
  4364. Data.resize(size);
  4365. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  4366. for (size_t i = 0; i < count; ++i) {
  4367. SUnaryHalfOp *p = &pPrimitives[i];
  4368. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4369. }
  4370. // use shader from data table
  4371. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4372. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4373. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4374. });
  4375. MappedData data;
  4376. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4377. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  4378. WEX::TestExecution::DisableVerifyExceptions dve;
  4379. for (unsigned i = 0; i < count; ++i) {
  4380. SUnaryHalfOp *p = &pPrimitives[i];
  4381. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  4382. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4383. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4384. i, ConvertFloat16ToFloat32(p->input), p->input,
  4385. ConvertFloat16ToFloat32(p->output), p->output,
  4386. ConvertFloat16ToFloat32(expected), expected);
  4387. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4388. }
  4389. }
  4390. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  4391. WEX::TestExecution::SetVerifyOutput verifySettings(
  4392. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4393. CComPtr<IStream> pStream;
  4394. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4395. CComPtr<ID3D12Device> pDevice;
  4396. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4397. return;
  4398. }
  4399. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4400. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4401. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4402. return;
  4403. }
  4404. // Read data from the table
  4405. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  4406. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  4407. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4408. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4409. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4410. std::vector<uint16_t> *Validation_Input1 =
  4411. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4412. std::vector<uint16_t> *Validation_Input2 =
  4413. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4414. std::vector<uint16_t> *Validation_Expected1 =
  4415. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4416. std::vector<uint16_t> *Validation_Expected2 =
  4417. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  4418. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4419. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4420. size_t count = Validation_Input1->size();
  4421. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4422. pDevice, m_support, pStream, "BinaryFPOp",
  4423. // this callbacked is called when the test
  4424. // is creating the resource to run the test
  4425. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4426. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4427. size_t size = sizeof(SBinaryHalfOp) * count;
  4428. Data.resize(size);
  4429. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  4430. for (size_t i = 0; i < count; ++i) {
  4431. SBinaryHalfOp *p = &pPrimitives[i];
  4432. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4433. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4434. }
  4435. // use shader from data table
  4436. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4437. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4438. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4439. });
  4440. MappedData data;
  4441. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4442. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  4443. WEX::TestExecution::DisableVerifyExceptions dve;
  4444. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4445. if (numExpected == 2) {
  4446. for (unsigned i = 0; i < count; ++i) {
  4447. SBinaryHalfOp *p = &pPrimitives[i];
  4448. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  4449. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  4450. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  4451. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  4452. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4453. ConvertFloat16ToFloat32(p->input2), p->input2,
  4454. ConvertFloat16ToFloat32(p->output1), p->output1,
  4455. ConvertFloat16ToFloat32(p->output2), p->output2,
  4456. ConvertFloat16ToFloat32(expected1), expected1,
  4457. ConvertFloat16ToFloat32(expected2), expected2);
  4458. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  4459. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  4460. }
  4461. }
  4462. else if (numExpected == 1) {
  4463. for (unsigned i = 0; i < count; ++i) {
  4464. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  4465. SBinaryHalfOp *p = &pPrimitives[i];
  4466. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4467. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4468. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4469. ConvertFloat16ToFloat32(p->output1), p->output1,
  4470. ConvertFloat16ToFloat32(expected), expected);
  4471. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  4472. }
  4473. }
  4474. else {
  4475. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4476. }
  4477. }
  4478. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  4479. WEX::TestExecution::SetVerifyOutput verifySettings(
  4480. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4481. CComPtr<IStream> pStream;
  4482. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4483. CComPtr<ID3D12Device> pDevice;
  4484. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4485. return;
  4486. }
  4487. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4488. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4489. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4490. return;
  4491. }
  4492. // Read data from the table
  4493. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  4494. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  4495. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4496. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4497. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4498. std::vector<uint16_t> *Validation_Input1 =
  4499. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4500. std::vector<uint16_t> *Validation_Input2 =
  4501. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4502. std::vector<uint16_t> *Validation_Input3 =
  4503. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  4504. std::vector<uint16_t> *Validation_Expected =
  4505. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4506. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4507. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4508. size_t count = Validation_Input1->size();
  4509. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4510. pDevice, m_support, pStream, "TertiaryFPOp",
  4511. // this callbacked is called when the test
  4512. // is creating the resource to run the test
  4513. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4514. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4515. size_t size = sizeof(STertiaryHalfOp) * count;
  4516. Data.resize(size);
  4517. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  4518. for (size_t i = 0; i < count; ++i) {
  4519. STertiaryHalfOp *p = &pPrimitives[i];
  4520. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4521. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4522. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4523. }
  4524. // use shader from data table
  4525. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4526. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4527. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4528. });
  4529. MappedData data;
  4530. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4531. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  4532. WEX::TestExecution::DisableVerifyExceptions dve;
  4533. for (unsigned i = 0; i < count; ++i) {
  4534. STertiaryHalfOp *p = &pPrimitives[i];
  4535. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  4536. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  4537. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4538. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4539. ConvertFloat16ToFloat32(p->input2), p->input2,
  4540. ConvertFloat16ToFloat32(p->input3), p->input3,
  4541. ConvertFloat16ToFloat32(p->output), p->output,
  4542. ConvertFloat16ToFloat32(expected), expected);
  4543. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4544. }
  4545. }
  4546. TEST_F(ExecutionTest, UnaryIntOpTest) {
  4547. WEX::TestExecution::SetVerifyOutput verifySettings(
  4548. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4549. CComPtr<IStream> pStream;
  4550. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4551. CComPtr<ID3D12Device> pDevice;
  4552. if (!CreateDevice(&pDevice)) {
  4553. return;
  4554. }
  4555. // Read data from the table
  4556. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  4557. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  4558. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4559. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4560. std::vector<int> *Validation_Input =
  4561. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4562. std::vector<int> *Validation_Expected =
  4563. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4564. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4565. size_t count = Validation_Input->size();
  4566. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4567. pDevice, m_support, pStream, "UnaryIntOp",
  4568. // this callbacked is called when the test
  4569. // is creating the resource to run the test
  4570. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4571. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4572. size_t size = sizeof(SUnaryIntOp) * count;
  4573. Data.resize(size);
  4574. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  4575. for (size_t i = 0; i < count; ++i) {
  4576. SUnaryIntOp *p = &pPrimitives[i];
  4577. int val = (*Validation_Input)[i % Validation_Input->size()];
  4578. p->input = val;
  4579. }
  4580. // use shader data table
  4581. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4582. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4583. });
  4584. MappedData data;
  4585. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4586. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  4587. WEX::TestExecution::DisableVerifyExceptions dve;
  4588. for (unsigned i = 0; i < count; ++i) {
  4589. SUnaryIntOp *p = &pPrimitives[i];
  4590. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4591. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  4592. L"expected = %11i(0x%08x)",
  4593. i, p->input, p->input, p->output, p->output, val, val);
  4594. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4595. }
  4596. }
  4597. TEST_F(ExecutionTest, UnaryUintOpTest) {
  4598. WEX::TestExecution::SetVerifyOutput verifySettings(
  4599. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4600. CComPtr<IStream> pStream;
  4601. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4602. CComPtr<ID3D12Device> pDevice;
  4603. if (!CreateDevice(&pDevice)) {
  4604. return;
  4605. }
  4606. // Read data from the table
  4607. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  4608. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  4609. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4610. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4611. std::vector<unsigned int> *Validation_Input =
  4612. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4613. std::vector<unsigned int> *Validation_Expected =
  4614. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4615. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4616. size_t count = Validation_Input->size();
  4617. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4618. pDevice, m_support, pStream, "UnaryUintOp",
  4619. // this callbacked is called when the test
  4620. // is creating the resource to run the test
  4621. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4622. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4623. size_t size = sizeof(SUnaryUintOp) * count;
  4624. Data.resize(size);
  4625. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  4626. for (size_t i = 0; i < count; ++i) {
  4627. SUnaryUintOp *p = &pPrimitives[i];
  4628. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  4629. p->input = val;
  4630. }
  4631. // use shader data table
  4632. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4633. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4634. });
  4635. MappedData data;
  4636. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4637. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  4638. WEX::TestExecution::DisableVerifyExceptions dve;
  4639. for (unsigned i = 0; i < count; ++i) {
  4640. SUnaryUintOp *p = &pPrimitives[i];
  4641. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4642. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  4643. L"expected = %11u(0x%08x)",
  4644. i, p->input, p->input, p->output, p->output, val, val);
  4645. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4646. }
  4647. }
  4648. TEST_F(ExecutionTest, BinaryIntOpTest) {
  4649. WEX::TestExecution::SetVerifyOutput verifySettings(
  4650. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4651. CComPtr<IStream> pStream;
  4652. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4653. CComPtr<ID3D12Device> pDevice;
  4654. if (!CreateDevice(&pDevice)) {
  4655. return;
  4656. }
  4657. // Read data from the table
  4658. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  4659. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  4660. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4661. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4662. std::vector<int> *Validation_Input1 =
  4663. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4664. std::vector<int> *Validation_Input2 =
  4665. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4666. std::vector<int> *Validation_Expected1 =
  4667. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4668. std::vector<int> *Validation_Expected2 =
  4669. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  4670. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4671. size_t count = Validation_Input1->size();
  4672. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4673. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4674. pDevice, m_support, pStream, "BinaryIntOp",
  4675. // this callbacked is called when the test
  4676. // is creating the resource to run the test
  4677. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4678. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4679. size_t size = sizeof(SBinaryIntOp) * count;
  4680. Data.resize(size);
  4681. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  4682. for (size_t i = 0; i < count; ++i) {
  4683. SBinaryIntOp *p = &pPrimitives[i];
  4684. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4685. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4686. p->input1 = val1;
  4687. p->input2 = val2;
  4688. }
  4689. // use shader from data table
  4690. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4691. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4692. });
  4693. MappedData data;
  4694. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4695. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  4696. WEX::TestExecution::DisableVerifyExceptions dve;
  4697. if (numExpected == 2) {
  4698. for (unsigned i = 0; i < count; ++i) {
  4699. SBinaryIntOp *p = &pPrimitives[i];
  4700. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4701. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4702. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4703. L"%11i(0x%08x), output1 = "
  4704. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  4705. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  4706. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4707. p->output1, val1, val1, p->output2, p->output2, val2,
  4708. val2);
  4709. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4710. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4711. }
  4712. }
  4713. else if (numExpected == 1) {
  4714. for (unsigned i = 0; i < count; ++i) {
  4715. SBinaryIntOp *p = &pPrimitives[i];
  4716. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4717. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4718. L"%11i(0x%08x), output = "
  4719. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  4720. p->input1, p->input1, p->input2, p->input2,
  4721. p->output1, p->output1, val1, val1);
  4722. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4723. }
  4724. }
  4725. else {
  4726. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4727. }
  4728. }
  4729. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  4730. WEX::TestExecution::SetVerifyOutput verifySettings(
  4731. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4732. CComPtr<IStream> pStream;
  4733. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4734. CComPtr<ID3D12Device> pDevice;
  4735. if (!CreateDevice(&pDevice)) {
  4736. return;
  4737. }
  4738. // Read data from the table
  4739. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  4740. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  4741. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4742. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4743. std::vector<int> *Validation_Input1 =
  4744. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4745. std::vector<int> *Validation_Input2 =
  4746. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4747. std::vector<int> *Validation_Input3 =
  4748. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4749. std::vector<int> *Validation_Expected =
  4750. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4751. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4752. size_t count = Validation_Input1->size();
  4753. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4754. pDevice, m_support, pStream, "TertiaryIntOp",
  4755. // this callbacked is called when the test
  4756. // is creating the resource to run the test
  4757. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4758. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4759. size_t size = sizeof(STertiaryIntOp) * count;
  4760. Data.resize(size);
  4761. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  4762. for (size_t i = 0; i < count; ++i) {
  4763. STertiaryIntOp *p = &pPrimitives[i];
  4764. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4765. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4766. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4767. p->input1 = val1;
  4768. p->input2 = val2;
  4769. p->input3 = val3;
  4770. }
  4771. // use shader from data table
  4772. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4773. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4774. });
  4775. MappedData data;
  4776. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4777. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  4778. WEX::TestExecution::DisableVerifyExceptions dve;
  4779. for (unsigned i = 0; i < count; ++i) {
  4780. STertiaryIntOp *p = &pPrimitives[i];
  4781. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4782. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4783. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4784. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4785. i, p->input1, p->input1, p->input2, p->input2,
  4786. p->input3, p->input3, p->output, p->output, val1,
  4787. val1);
  4788. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4789. }
  4790. }
  4791. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4792. WEX::TestExecution::SetVerifyOutput verifySettings(
  4793. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4794. CComPtr<IStream> pStream;
  4795. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4796. CComPtr<ID3D12Device> pDevice;
  4797. if (!CreateDevice(&pDevice)) {
  4798. return;
  4799. }
  4800. // Read data from the table
  4801. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4802. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4803. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4804. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4805. std::vector<unsigned int> *Validation_Input1 =
  4806. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4807. std::vector<unsigned int> *Validation_Input2 =
  4808. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4809. std::vector<unsigned int> *Validation_Expected1 =
  4810. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4811. std::vector<unsigned int> *Validation_Expected2 =
  4812. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4813. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4814. size_t count = Validation_Input1->size();
  4815. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4816. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4817. pDevice, m_support, pStream, "BinaryUintOp",
  4818. // this callbacked is called when the test
  4819. // is creating the resource to run the test
  4820. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4821. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4822. size_t size = sizeof(SBinaryUintOp) * count;
  4823. Data.resize(size);
  4824. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4825. for (size_t i = 0; i < count; ++i) {
  4826. SBinaryUintOp *p = &pPrimitives[i];
  4827. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4828. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4829. p->input1 = val1;
  4830. p->input2 = val2;
  4831. }
  4832. // use shader from data table
  4833. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4834. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4835. });
  4836. MappedData data;
  4837. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4838. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4839. WEX::TestExecution::DisableVerifyExceptions dve;
  4840. if (numExpected == 2) {
  4841. for (unsigned i = 0; i < count; ++i) {
  4842. SBinaryUintOp *p = &pPrimitives[i];
  4843. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4844. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4845. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4846. L"%11u(0x%08x), output1 = "
  4847. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4848. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4849. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4850. p->output1, val1, val1, p->output2, p->output2, val2,
  4851. val2);
  4852. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4853. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4854. }
  4855. }
  4856. else if (numExpected == 1) {
  4857. for (unsigned i = 0; i < count; ++i) {
  4858. SBinaryUintOp *p = &pPrimitives[i];
  4859. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4860. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4861. L"%11u(0x%08x), output = "
  4862. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4863. p->input1, p->input1, p->input2, p->input2,
  4864. p->output1, p->output1, val1, val1);
  4865. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4866. }
  4867. }
  4868. else {
  4869. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4870. }
  4871. }
  4872. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4873. WEX::TestExecution::SetVerifyOutput verifySettings(
  4874. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4875. CComPtr<IStream> pStream;
  4876. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4877. CComPtr<ID3D12Device> pDevice;
  4878. if (!CreateDevice(&pDevice)) {
  4879. return;
  4880. }
  4881. // Read data from the table
  4882. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4883. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4884. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4885. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4886. std::vector<unsigned int> *Validation_Input1 =
  4887. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4888. std::vector<unsigned int> *Validation_Input2 =
  4889. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4890. std::vector<unsigned int> *Validation_Input3 =
  4891. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4892. std::vector<unsigned int> *Validation_Expected =
  4893. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4894. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4895. size_t count = Validation_Input1->size();
  4896. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4897. pDevice, m_support, pStream, "TertiaryUintOp",
  4898. // this callbacked is called when the test
  4899. // is creating the resource to run the test
  4900. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4901. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4902. size_t size = sizeof(STertiaryUintOp) * count;
  4903. Data.resize(size);
  4904. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4905. for (size_t i = 0; i < count; ++i) {
  4906. STertiaryUintOp *p = &pPrimitives[i];
  4907. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4908. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4909. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4910. p->input1 = val1;
  4911. p->input2 = val2;
  4912. p->input3 = val3;
  4913. }
  4914. // use shader from data table
  4915. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4916. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4917. });
  4918. MappedData data;
  4919. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4920. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  4921. WEX::TestExecution::DisableVerifyExceptions dve;
  4922. for (unsigned i = 0; i < count; ++i) {
  4923. STertiaryUintOp *p = &pPrimitives[i];
  4924. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4925. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4926. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  4927. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4928. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4929. p->output, p->output, val1, val1);
  4930. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4931. }
  4932. }
  4933. // 16 bit integer type tests
  4934. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  4935. WEX::TestExecution::SetVerifyOutput verifySettings(
  4936. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4937. CComPtr<IStream> pStream;
  4938. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4939. CComPtr<ID3D12Device> pDevice;
  4940. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4941. return;
  4942. }
  4943. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4944. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4945. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4946. return;
  4947. }
  4948. // Read data from the table
  4949. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  4950. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  4951. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4952. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4953. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4954. std::vector<short> *Validation_Input =
  4955. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4956. std::vector<short> *Validation_Expected =
  4957. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4958. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4959. size_t count = Validation_Input->size();
  4960. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4961. pDevice, m_support, pStream, "UnaryIntOp",
  4962. // this callbacked is called when the test
  4963. // is creating the resource to run the test
  4964. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4965. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4966. size_t size = sizeof(SUnaryInt16Op) * count;
  4967. Data.resize(size);
  4968. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  4969. for (size_t i = 0; i < count; ++i) {
  4970. SUnaryInt16Op *p = &pPrimitives[i];
  4971. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4972. }
  4973. // use shader data table
  4974. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4975. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4976. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4977. });
  4978. MappedData data;
  4979. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4980. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  4981. WEX::TestExecution::DisableVerifyExceptions dve;
  4982. for (unsigned i = 0; i < count; ++i) {
  4983. SUnaryInt16Op *p = &pPrimitives[i];
  4984. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  4985. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  4986. L"expected = %5hi(0x%08x)",
  4987. i, p->input, p->input, p->output, p->output, val, val);
  4988. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4989. }
  4990. }
  4991. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  4992. WEX::TestExecution::SetVerifyOutput verifySettings(
  4993. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4994. CComPtr<IStream> pStream;
  4995. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4996. CComPtr<ID3D12Device> pDevice;
  4997. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4998. return;
  4999. }
  5000. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5001. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5002. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5003. return;
  5004. }
  5005. // Read data from the table
  5006. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  5007. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  5008. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5009. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5010. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5011. std::vector<unsigned short> *Validation_Input =
  5012. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5013. std::vector<unsigned short> *Validation_Expected =
  5014. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5015. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5016. size_t count = Validation_Input->size();
  5017. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5018. pDevice, m_support, pStream, "UnaryUintOp",
  5019. // this callbacked is called when the test
  5020. // is creating the resource to run the test
  5021. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5022. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  5023. size_t size = sizeof(SUnaryUint16Op) * count;
  5024. Data.resize(size);
  5025. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  5026. for (size_t i = 0; i < count; ++i) {
  5027. SUnaryUint16Op *p = &pPrimitives[i];
  5028. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5029. }
  5030. // use shader data table
  5031. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5032. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5033. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5034. });
  5035. MappedData data;
  5036. test->Test->GetReadBackData("SUnaryUintOp", &data);
  5037. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  5038. WEX::TestExecution::DisableVerifyExceptions dve;
  5039. for (unsigned i = 0; i < count; ++i) {
  5040. SUnaryUint16Op *p = &pPrimitives[i];
  5041. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5042. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  5043. L"expected = %5hu(0x%08x)",
  5044. i, p->input, p->input, p->output, p->output, val, val);
  5045. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5046. }
  5047. }
  5048. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  5049. WEX::TestExecution::SetVerifyOutput verifySettings(
  5050. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5051. CComPtr<IStream> pStream;
  5052. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5053. CComPtr<ID3D12Device> pDevice;
  5054. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5055. return;
  5056. }
  5057. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5058. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5059. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5060. return;
  5061. }
  5062. // Read data from the table
  5063. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  5064. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  5065. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5066. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5067. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5068. std::vector<short> *Validation_Input1 =
  5069. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5070. std::vector<short> *Validation_Input2 =
  5071. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5072. std::vector<short> *Validation_Expected1 =
  5073. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5074. std::vector<short> *Validation_Expected2 =
  5075. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  5076. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5077. size_t count = Validation_Input1->size();
  5078. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5079. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5080. pDevice, m_support, pStream, "BinaryIntOp",
  5081. // this callbacked is called when the test
  5082. // is creating the resource to run the test
  5083. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5084. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  5085. size_t size = sizeof(SBinaryInt16Op) * count;
  5086. Data.resize(size);
  5087. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  5088. for (size_t i = 0; i < count; ++i) {
  5089. SBinaryInt16Op *p = &pPrimitives[i];
  5090. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5091. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5092. }
  5093. // use shader from data table
  5094. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5095. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5096. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5097. });
  5098. MappedData data;
  5099. test->Test->GetReadBackData("SBinaryIntOp", &data);
  5100. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  5101. WEX::TestExecution::DisableVerifyExceptions dve;
  5102. if (numExpected == 2) {
  5103. for (unsigned i = 0; i < count; ++i) {
  5104. SBinaryInt16Op *p = &pPrimitives[i];
  5105. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5106. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5107. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5108. L"%5hi(0x%08x), output1 = "
  5109. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  5110. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  5111. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5112. p->output1, val1, val1, p->output2, p->output2, val2,
  5113. val2);
  5114. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5115. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5116. }
  5117. }
  5118. else if (numExpected == 1) {
  5119. for (unsigned i = 0; i < count; ++i) {
  5120. SBinaryInt16Op *p = &pPrimitives[i];
  5121. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5122. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5123. L"%5hi(0x%08x), output = "
  5124. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  5125. p->input1, p->input1, p->input2, p->input2,
  5126. p->output1, p->output1, val1, val1);
  5127. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5128. }
  5129. }
  5130. else {
  5131. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5132. }
  5133. }
  5134. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  5135. WEX::TestExecution::SetVerifyOutput verifySettings(
  5136. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5137. CComPtr<IStream> pStream;
  5138. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5139. CComPtr<ID3D12Device> pDevice;
  5140. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5141. return;
  5142. }
  5143. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5144. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5145. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5146. return;
  5147. }
  5148. // Read data from the table
  5149. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  5150. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  5151. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5152. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5153. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5154. std::vector<short> *Validation_Input1 =
  5155. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5156. std::vector<short> *Validation_Input2 =
  5157. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5158. std::vector<short> *Validation_Input3 =
  5159. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  5160. std::vector<short> *Validation_Expected =
  5161. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5162. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5163. size_t count = Validation_Input1->size();
  5164. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5165. pDevice, m_support, pStream, "TertiaryIntOp",
  5166. // this callbacked is called when the test
  5167. // is creating the resource to run the test
  5168. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5169. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  5170. size_t size = sizeof(STertiaryInt16Op) * count;
  5171. Data.resize(size);
  5172. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  5173. for (size_t i = 0; i < count; ++i) {
  5174. STertiaryInt16Op *p = &pPrimitives[i];
  5175. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5176. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5177. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5178. }
  5179. // use shader from data table
  5180. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5181. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5182. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5183. });
  5184. MappedData data;
  5185. test->Test->GetReadBackData("STertiaryIntOp", &data);
  5186. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  5187. WEX::TestExecution::DisableVerifyExceptions dve;
  5188. for (unsigned i = 0; i < count; ++i) {
  5189. STertiaryInt16Op *p = &pPrimitives[i];
  5190. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5191. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  5192. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  5193. L"%11i(0x%08x), expected = %11i(0x%08x)",
  5194. i, p->input1, p->input1, p->input2, p->input2,
  5195. p->input3, p->input3, p->output, p->output, val1,
  5196. val1);
  5197. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5198. }
  5199. }
  5200. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  5201. WEX::TestExecution::SetVerifyOutput verifySettings(
  5202. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5203. CComPtr<IStream> pStream;
  5204. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5205. CComPtr<ID3D12Device> pDevice;
  5206. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5207. return;
  5208. }
  5209. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5210. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5211. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5212. return;
  5213. }
  5214. // Read data from the table
  5215. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  5216. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  5217. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5218. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5219. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5220. std::vector<unsigned short> *Validation_Input1 =
  5221. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5222. std::vector<unsigned short> *Validation_Input2 =
  5223. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5224. std::vector<unsigned short> *Validation_Expected1 =
  5225. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5226. std::vector<unsigned short> *Validation_Expected2 =
  5227. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  5228. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5229. size_t count = Validation_Input1->size();
  5230. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5231. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5232. pDevice, m_support, pStream, "BinaryUintOp",
  5233. // this callbacked is called when the test
  5234. // is creating the resource to run the test
  5235. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5236. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  5237. size_t size = sizeof(SBinaryUint16Op) * count;
  5238. Data.resize(size);
  5239. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  5240. for (size_t i = 0; i < count; ++i) {
  5241. SBinaryUint16Op *p = &pPrimitives[i];
  5242. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5243. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5244. }
  5245. // use shader from data table
  5246. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5247. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5248. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5249. });
  5250. MappedData data;
  5251. test->Test->GetReadBackData("SBinaryUintOp", &data);
  5252. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  5253. WEX::TestExecution::DisableVerifyExceptions dve;
  5254. if (numExpected == 2) {
  5255. for (unsigned i = 0; i < count; ++i) {
  5256. SBinaryUint16Op *p = &pPrimitives[i];
  5257. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5258. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5259. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5260. L"%5hu(0x%08x), output1 = "
  5261. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  5262. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  5263. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5264. p->output1, val1, val1, p->output2, p->output2, val2,
  5265. val2);
  5266. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5267. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5268. }
  5269. }
  5270. else if (numExpected == 1) {
  5271. for (unsigned i = 0; i < count; ++i) {
  5272. SBinaryUint16Op *p = &pPrimitives[i];
  5273. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5274. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5275. L"%5hu(0x%08x), output = "
  5276. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5277. p->input1, p->input1, p->input2, p->input2,
  5278. p->output1, p->output1, val1, val1);
  5279. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5280. }
  5281. }
  5282. else {
  5283. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5284. }
  5285. }
  5286. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  5287. WEX::TestExecution::SetVerifyOutput verifySettings(
  5288. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5289. CComPtr<IStream> pStream;
  5290. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5291. CComPtr<ID3D12Device> pDevice;
  5292. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5293. return;
  5294. }
  5295. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5296. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5297. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5298. return;
  5299. }
  5300. // Read data from the table
  5301. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  5302. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  5303. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5304. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5305. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5306. std::vector<unsigned short> *Validation_Input1 =
  5307. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5308. std::vector<unsigned short> *Validation_Input2 =
  5309. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5310. std::vector<unsigned short> *Validation_Input3 =
  5311. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  5312. std::vector<unsigned short> *Validation_Expected =
  5313. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5314. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5315. size_t count = Validation_Input1->size();
  5316. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5317. pDevice, m_support, pStream, "TertiaryUintOp",
  5318. // this callbacked is called when the test
  5319. // is creating the resource to run the test
  5320. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5321. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  5322. size_t size = sizeof(STertiaryUint16Op) * count;
  5323. Data.resize(size);
  5324. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  5325. for (size_t i = 0; i < count; ++i) {
  5326. STertiaryUint16Op *p = &pPrimitives[i];
  5327. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5328. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5329. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5330. }
  5331. // use shader from data table
  5332. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5333. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5334. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5335. });
  5336. MappedData data;
  5337. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5338. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  5339. WEX::TestExecution::DisableVerifyExceptions dve;
  5340. for (unsigned i = 0; i < count; ++i) {
  5341. STertiaryUint16Op *p = &pPrimitives[i];
  5342. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5343. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5344. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  5345. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5346. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5347. p->output, p->output, val1, val1);
  5348. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5349. }
  5350. }
  5351. TEST_F(ExecutionTest, DotTest) {
  5352. WEX::TestExecution::SetVerifyOutput verifySettings(
  5353. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5354. CComPtr<IStream> pStream;
  5355. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5356. CComPtr<ID3D12Device> pDevice;
  5357. if (!CreateDevice(&pDevice)) {
  5358. return;
  5359. }
  5360. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  5361. TableParameterHandler handler(DotOpParameters, tableSize);
  5362. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5363. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5364. std::vector<WEX::Common::String> *Validation_Input1 =
  5365. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5366. std::vector<WEX::Common::String> *Validation_Input2 =
  5367. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5368. std::vector<WEX::Common::String> *Validation_dot2 =
  5369. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5370. std::vector<WEX::Common::String> *Validation_dot3 =
  5371. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  5372. std::vector<WEX::Common::String> *Validation_dot4 =
  5373. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  5374. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5375. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5376. size_t count = Validation_Input1->size();
  5377. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5378. pDevice, m_support, pStream, "DotOp",
  5379. // this callbacked is called when the test
  5380. // is creating the resource to run the test
  5381. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5382. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  5383. size_t size = sizeof(SDotOp) * count;
  5384. Data.resize(size);
  5385. SDotOp *pPrimitives = (SDotOp*)Data.data();
  5386. for (size_t i = 0; i < count; ++i) {
  5387. SDotOp *p = &pPrimitives[i];
  5388. XMFLOAT4 val1,val2;
  5389. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  5390. (float *)&val1, 4));
  5391. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  5392. (float *)&val2, 4));
  5393. p->input1 = val1;
  5394. p->input2 = val2;
  5395. }
  5396. // use shader from data table
  5397. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5398. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5399. });
  5400. MappedData data;
  5401. test->Test->GetReadBackData("SDotOp", &data);
  5402. SDotOp *pPrimitives = (SDotOp*)data.data();
  5403. WEX::TestExecution::DisableVerifyExceptions dve;
  5404. for (size_t i = 0; i < count; ++i) {
  5405. SDotOp *p = &pPrimitives[i];
  5406. float dot2, dot3, dot4;
  5407. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  5408. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  5409. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  5410. LogCommentFmt(
  5411. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  5412. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  5413. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  5414. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  5415. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  5416. p->o_dot4, dot4);
  5417. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  5418. tolerance);
  5419. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  5420. tolerance);
  5421. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  5422. tolerance);
  5423. }
  5424. }
  5425. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  5426. WEX::TestExecution::SetVerifyOutput verifySettings(
  5427. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5428. CComPtr<IStream> pStream;
  5429. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5430. CComPtr<ID3D12Device> pDevice;
  5431. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5432. return;
  5433. }
  5434. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5435. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5436. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5437. return;
  5438. }
  5439. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  5440. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  5441. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5442. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5443. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5444. std::vector<WEX::Common::String> *validation_input1 =
  5445. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5446. std::vector<WEX::Common::String> *validation_input2 =
  5447. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5448. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  5449. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  5450. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5451. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5452. size_t count = validation_input1->size();
  5453. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5454. pDevice, m_support, pStream, "Dot2AddHalfOp",
  5455. // this callback is called when the test
  5456. // is creating the resource to run the test
  5457. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5458. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  5459. size_t size = sizeof(SDot2AddHalfOp) * count;
  5460. Data.resize(size);
  5461. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  5462. for (size_t i = 0; i < count; ++i) {
  5463. SDot2AddHalfOp *p = &pPrimitives[i];
  5464. Half2 val1,val2;
  5465. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  5466. (uint16_t *)&val1, 2));
  5467. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  5468. (uint16_t *)&val2, 2));
  5469. p->input1 = val1;
  5470. p->input2 = val2;
  5471. p->acc = (*validation_acc)[i];
  5472. }
  5473. // use shader from data table
  5474. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5475. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5476. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5477. });
  5478. MappedData data;
  5479. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  5480. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  5481. WEX::TestExecution::DisableVerifyExceptions dve;
  5482. for (size_t i = 0; i < count; ++i) {
  5483. SDot2AddHalfOp *p = &pPrimitives[i];
  5484. float expectedResult = (*validation_result)[i];
  5485. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  5486. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  5487. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  5488. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  5489. LogCommentFmt(
  5490. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  5491. L"result = %f, result_expected = %f",
  5492. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  5493. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  5494. }
  5495. }
  5496. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  5497. WEX::TestExecution::SetVerifyOutput verifySettings(
  5498. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5499. CComPtr<IStream> pStream;
  5500. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5501. CComPtr<ID3D12Device> pDevice;
  5502. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5503. return;
  5504. }
  5505. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  5506. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  5507. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5508. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5509. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5510. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5511. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  5512. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  5513. size_t count = validation_input1->size();
  5514. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5515. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  5516. // this callback is called when the test
  5517. // is creating the resource to run the test
  5518. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5519. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  5520. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  5521. Data.resize(size);
  5522. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  5523. for (size_t i = 0; i < count; ++i) {
  5524. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5525. p->input1 = (*validation_input1)[i];
  5526. p->input2 = (*validation_input2)[i];
  5527. p->acc = (*validation_acc)[i];
  5528. }
  5529. // use shader from data table
  5530. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5531. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5532. });
  5533. MappedData data;
  5534. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  5535. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  5536. WEX::TestExecution::DisableVerifyExceptions dve;
  5537. for (size_t i = 0; i < count; ++i) {
  5538. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5539. int32_t expectedResult = (*validation_result)[i];
  5540. LogCommentFmt(
  5541. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  5542. L"result = %d, result_expected = %d",
  5543. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5544. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  5545. }
  5546. }
  5547. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  5548. WEX::TestExecution::SetVerifyOutput verifySettings(
  5549. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5550. CComPtr<IStream> pStream;
  5551. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5552. CComPtr<ID3D12Device> pDevice;
  5553. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5554. return;
  5555. }
  5556. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  5557. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  5558. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5559. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5560. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5561. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5562. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  5563. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  5564. size_t count = validation_input1->size();
  5565. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5566. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  5567. // this callback is called when the test
  5568. // is creating the resource to run the test
  5569. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5570. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  5571. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  5572. Data.resize(size);
  5573. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  5574. for (size_t i = 0; i < count; ++i) {
  5575. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5576. p->input1 = (*validation_input1)[i];
  5577. p->input2 = (*validation_input2)[i];
  5578. p->acc = (*validation_acc)[i];
  5579. }
  5580. // use shader from data table
  5581. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5582. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5583. });
  5584. MappedData data;
  5585. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  5586. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  5587. WEX::TestExecution::DisableVerifyExceptions dve;
  5588. for (size_t i = 0; i < count; ++i) {
  5589. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5590. uint32_t expectedResult = (*validation_result)[i];
  5591. LogCommentFmt(
  5592. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  5593. L"result = %u, result_expected = %u, ",
  5594. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5595. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  5596. }
  5597. }
  5598. TEST_F(ExecutionTest, Msad4Test) {
  5599. WEX::TestExecution::SetVerifyOutput verifySettings(
  5600. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5601. CComPtr<IStream> pStream;
  5602. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5603. CComPtr<ID3D12Device> pDevice;
  5604. if (!CreateDevice(&pDevice)) {
  5605. return;
  5606. }
  5607. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  5608. TableParameterHandler handler(Msad4OpParameters, tableSize);
  5609. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5610. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5611. std::vector<unsigned int> *Validation_Reference =
  5612. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5613. std::vector<WEX::Common::String> *Validation_Source =
  5614. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5615. std::vector<WEX::Common::String> *Validation_Accum =
  5616. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  5617. std::vector<WEX::Common::String> *Validation_Expected =
  5618. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5619. size_t count = Validation_Expected->size();
  5620. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5621. pDevice, m_support, pStream, "Msad4",
  5622. // this callbacked is called when the test
  5623. // is creating the resource to run the test
  5624. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5625. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  5626. size_t size = sizeof(SMsad4) * count;
  5627. Data.resize(size);
  5628. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  5629. for (size_t i = 0; i < count; ++i) {
  5630. SMsad4 *p = &pPrimitives[i];
  5631. XMUINT2 src;
  5632. XMUINT4 accum;
  5633. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  5634. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  5635. p->ref = (*Validation_Reference)[i];
  5636. p->src = src;
  5637. p->accum = accum;
  5638. }
  5639. // use shader from data table
  5640. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5641. });
  5642. MappedData data;
  5643. test->Test->GetReadBackData("SMsad4", &data);
  5644. SMsad4 *pPrimitives = (SMsad4*)data.data();
  5645. WEX::TestExecution::DisableVerifyExceptions dve;
  5646. for (size_t i = 0; i < count; ++i) {
  5647. SMsad4 *p = &pPrimitives[i];
  5648. XMUINT4 result;
  5649. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  5650. (unsigned int *)&result, 4));
  5651. LogCommentFmt(
  5652. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  5653. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5654. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5655. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  5656. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  5657. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  5658. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  5659. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  5660. result.x, result.x, result.y, result.y, result.z, result.z,
  5661. result.w, result.w);
  5662. int toleranceInt = (int)tolerance;
  5663. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  5664. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  5665. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  5666. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  5667. }
  5668. }
  5669. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  5670. WEX::TestExecution::SetVerifyOutput verifySettings(
  5671. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5672. CComPtr<IStream> pStream;
  5673. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5674. CComPtr<ID3D12Device> pDevice;
  5675. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5676. return;
  5677. }
  5678. // Read data from the table
  5679. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  5680. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  5681. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5682. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5683. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5684. std::vector<WEX::Common::String> *Validation_Input1 =
  5685. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5686. std::vector<WEX::Common::String> *Validation_Input2 =
  5687. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5688. std::vector<WEX::Common::String> *Validation_Expected1 =
  5689. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5690. // two expected outputs for any mode
  5691. std::vector<WEX::Common::String> *Validation_Expected2 =
  5692. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5693. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5694. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5695. size_t count = Validation_Input1->size();
  5696. using namespace hlsl::DXIL;
  5697. Float32DenormMode mode = Float32DenormMode::Any;
  5698. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5699. mode = Float32DenormMode::Preserve;
  5700. }
  5701. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5702. mode = Float32DenormMode::FTZ;
  5703. }
  5704. if (mode == Float32DenormMode::Any) {
  5705. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5706. "must have same number of expected values");
  5707. }
  5708. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5709. pDevice, m_support, pStream, "BinaryFPOp",
  5710. // this callbacked is called when the test
  5711. // is creating the resource to run the test
  5712. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5713. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  5714. size_t size = sizeof(SBinaryFPOp) * count;
  5715. Data.resize(size);
  5716. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  5717. for (size_t i = 0; i < count; ++i) {
  5718. SBinaryFPOp *p = &pPrimitives[i];
  5719. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5720. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5721. float val1, val2;
  5722. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5723. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5724. p->input1 = val1;
  5725. p->input2 = val2;
  5726. }
  5727. // use shader from data table
  5728. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5729. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5730. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5731. });
  5732. MappedData data;
  5733. test->Test->GetReadBackData("SBinaryFPOp", &data);
  5734. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  5735. WEX::TestExecution::DisableVerifyExceptions dve;
  5736. for (unsigned i = 0; i < count; ++i) {
  5737. SBinaryFPOp *p = &pPrimitives[i];
  5738. if (mode == Float32DenormMode::Any) {
  5739. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5740. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5741. float val1;
  5742. float val2;
  5743. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5744. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5745. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5746. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5747. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  5748. VERIFY_IS_TRUE(
  5749. CompareOutputWithExpectedValueFloat(
  5750. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  5751. CompareOutputWithExpectedValueFloat(
  5752. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  5753. }
  5754. else {
  5755. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5756. float val1;
  5757. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5758. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5759. L"%6.8f, expected = %6.8f(%a)",
  5760. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  5761. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  5762. Validation_Tolerance, mode);
  5763. }
  5764. }
  5765. }
  5766. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  5767. WEX::TestExecution::SetVerifyOutput verifySettings(
  5768. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5769. CComPtr<IStream> pStream;
  5770. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5771. CComPtr<ID3D12Device> pDevice;
  5772. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5773. return;
  5774. }
  5775. // Read data from the table
  5776. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  5777. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  5778. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5779. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5780. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5781. std::vector<WEX::Common::String> *Validation_Input1 =
  5782. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5783. std::vector<WEX::Common::String> *Validation_Input2 =
  5784. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5785. std::vector<WEX::Common::String> *Validation_Input3 =
  5786. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5787. std::vector<WEX::Common::String> *Validation_Expected1 =
  5788. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5789. // two expected outputs for any mode
  5790. std::vector<WEX::Common::String> *Validation_Expected2 =
  5791. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5792. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5793. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5794. size_t count = Validation_Input1->size();
  5795. using namespace hlsl::DXIL;
  5796. Float32DenormMode mode = Float32DenormMode::Any;
  5797. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5798. mode = Float32DenormMode::Preserve;
  5799. }
  5800. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5801. mode = Float32DenormMode::FTZ;
  5802. }
  5803. if (mode == Float32DenormMode::Any) {
  5804. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5805. "must have same number of expected values");
  5806. }
  5807. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5808. pDevice, m_support, pStream, "TertiaryFPOp",
  5809. // this callbacked is called when the test
  5810. // is creating the resource to run the test
  5811. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5812. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5813. size_t size = sizeof(STertiaryFPOp) * count;
  5814. Data.resize(size);
  5815. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5816. for (size_t i = 0; i < count; ++i) {
  5817. STertiaryFPOp *p = &pPrimitives[i];
  5818. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5819. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5820. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5821. float val1, val2, val3;
  5822. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5823. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5824. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5825. p->input1 = val1;
  5826. p->input2 = val2;
  5827. p->input3 = val3;
  5828. }
  5829. // use shader from data table
  5830. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5831. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5832. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5833. });
  5834. MappedData data;
  5835. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5836. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5837. WEX::TestExecution::DisableVerifyExceptions dve;
  5838. for (unsigned i = 0; i < count; ++i) {
  5839. STertiaryFPOp *p = &pPrimitives[i];
  5840. if (mode == Float32DenormMode::Any) {
  5841. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5842. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5843. float val1;
  5844. float val2;
  5845. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5846. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5847. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5848. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5849. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5850. VERIFY_IS_TRUE(
  5851. CompareOutputWithExpectedValueFloat(
  5852. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5853. CompareOutputWithExpectedValueFloat(
  5854. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5855. }
  5856. else {
  5857. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5858. float val1;
  5859. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5860. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5861. L"%6.8f, expected = %6.8f(%a)",
  5862. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5863. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5864. Validation_Tolerance, mode);
  5865. }
  5866. }
  5867. }
  5868. // Setup for wave intrinsics tests
  5869. enum class ShaderOpKind {
  5870. WaveSum,
  5871. WaveProduct,
  5872. WaveActiveMax,
  5873. WaveActiveMin,
  5874. WaveCountBits,
  5875. WaveActiveAllEqual,
  5876. WaveActiveAnyTrue,
  5877. WaveActiveAllTrue,
  5878. WaveActiveBitOr,
  5879. WaveActiveBitAnd,
  5880. WaveActiveBitXor,
  5881. ShaderOpInvalid
  5882. };
  5883. struct ShaderOpKindPair {
  5884. LPCWSTR name;
  5885. ShaderOpKind kind;
  5886. };
  5887. static ShaderOpKindPair ShaderOpKindTable[] = {
  5888. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5889. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5890. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5891. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5892. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5893. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5894. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5895. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5896. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5897. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5898. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5899. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5900. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5901. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5902. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5903. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5904. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5905. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  5906. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  5907. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  5908. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  5909. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  5910. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  5911. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  5912. };
  5913. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  5914. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  5915. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  5916. return ShaderOpKindTable[i].kind;
  5917. }
  5918. }
  5919. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  5920. return ShaderOpKind::ShaderOpInvalid;
  5921. }
  5922. template <typename InType, typename OutType, ShaderOpKind kind>
  5923. struct computeExpected {
  5924. OutType operator()(const std::vector<InType> &inputs,
  5925. const std::vector<int> &masks, int maskValue,
  5926. unsigned int index) {
  5927. return 0;
  5928. }
  5929. };
  5930. template <typename InType, typename OutType>
  5931. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  5932. OutType operator()(const std::vector<InType> &inputs,
  5933. const std::vector<int> &masks, int maskValue,
  5934. unsigned int index) {
  5935. OutType sum = 0;
  5936. for (size_t i = 0; i < index; ++i) {
  5937. if (masks.at(i) == maskValue) {
  5938. sum += inputs.at(i);
  5939. }
  5940. }
  5941. return sum;
  5942. }
  5943. };
  5944. template <typename InType, typename OutType>
  5945. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  5946. OutType operator()(const std::vector<InType> &inputs,
  5947. const std::vector<int> &masks, int maskValue,
  5948. unsigned int index) {
  5949. OutType prod = 1;
  5950. for (size_t i = 0; i < index; ++i) {
  5951. if (masks.at(i) == maskValue) {
  5952. prod *= inputs.at(i);
  5953. }
  5954. }
  5955. return prod;
  5956. }
  5957. };
  5958. template <typename InType, typename OutType>
  5959. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  5960. OutType operator()(const std::vector<InType> &inputs,
  5961. const std::vector<int> &masks, int maskValue,
  5962. unsigned int index) {
  5963. OutType maximum = std::numeric_limits<OutType>::min();
  5964. for (size_t i = 0; i < index; ++i) {
  5965. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  5966. maximum = inputs.at(i);
  5967. }
  5968. return maximum;
  5969. }
  5970. };
  5971. template <typename InType, typename OutType>
  5972. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  5973. OutType operator()(const std::vector<InType> &inputs,
  5974. const std::vector<int> &masks, int maskValue,
  5975. unsigned int index) {
  5976. OutType minimum = std::numeric_limits<OutType>::max();
  5977. for (size_t i = 0; i < index; ++i) {
  5978. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  5979. minimum = inputs.at(i);
  5980. }
  5981. return minimum;
  5982. }
  5983. };
  5984. template <typename InType, typename OutType>
  5985. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  5986. OutType operator()(const std::vector<InType> &inputs,
  5987. const std::vector<int> &masks, int maskValue,
  5988. unsigned int index) {
  5989. OutType count = 0;
  5990. for (size_t i = 0; i < index; ++i) {
  5991. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  5992. count++;
  5993. }
  5994. }
  5995. return count;
  5996. }
  5997. };
  5998. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  5999. // So we cannot use c++ bool type to represent bool in HLSL
  6000. // HLSL returns 0 for false and 1 for true
  6001. template <typename InType, typename OutType>
  6002. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  6003. OutType operator()(const std::vector<InType> &inputs,
  6004. const std::vector<int> &masks, int maskValue,
  6005. unsigned int index) {
  6006. for (size_t i = 0; i < index; ++i) {
  6007. if (masks.at(i) == maskValue && inputs.at(i) != 0) {
  6008. return 1;
  6009. }
  6010. }
  6011. return 0;
  6012. }
  6013. };
  6014. template <typename InType, typename OutType>
  6015. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  6016. OutType operator()(const std::vector<InType> &inputs,
  6017. const std::vector<int> &masks, int maskValue,
  6018. unsigned int index) {
  6019. for (size_t i = 0; i < index; ++i) {
  6020. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  6021. return 0;
  6022. }
  6023. }
  6024. return 1;
  6025. }
  6026. };
  6027. template <typename InType, typename OutType>
  6028. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  6029. OutType operator()(const std::vector<InType> &inputs,
  6030. const std::vector<int> &masks, int maskValue,
  6031. unsigned int index) {
  6032. const InType *val = nullptr;
  6033. for (size_t i = 0; i < index; ++i) {
  6034. if (masks.at(i) == maskValue) {
  6035. if (val && *val != inputs.at(i)) {
  6036. return 0;
  6037. }
  6038. val = &inputs.at(i);
  6039. }
  6040. }
  6041. return 1;
  6042. }
  6043. };
  6044. template <typename InType, typename OutType>
  6045. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  6046. OutType operator()(const std::vector<InType> &inputs,
  6047. const std::vector<int> &masks, int maskValue,
  6048. unsigned int index) {
  6049. OutType bits = 0x00000000;
  6050. for (size_t i = 0; i < index; ++i) {
  6051. if (masks.at(i) == maskValue) {
  6052. bits |= inputs.at(i);
  6053. }
  6054. }
  6055. return bits;
  6056. }
  6057. };
  6058. template <typename InType, typename OutType>
  6059. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  6060. OutType operator()(const std::vector<InType> &inputs,
  6061. const std::vector<int> &masks, int maskValue,
  6062. unsigned int index) {
  6063. OutType bits = 0xffffffff;
  6064. for (size_t i = 0; i < index; ++i) {
  6065. if (masks.at(i) == maskValue) {
  6066. bits &= inputs.at(i);
  6067. }
  6068. }
  6069. return bits;
  6070. }
  6071. };
  6072. template <typename InType, typename OutType>
  6073. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  6074. OutType operator()(const std::vector<InType> &inputs,
  6075. const std::vector<int> &masks, int maskValue,
  6076. unsigned int index) {
  6077. OutType bits = 0x00000000;
  6078. for (size_t i = 0; i < index; ++i) {
  6079. if (masks.at(i) == maskValue) {
  6080. bits ^= inputs.at(i);
  6081. }
  6082. }
  6083. return bits;
  6084. }
  6085. };
  6086. // Mask functions used to control active lanes
  6087. static int MaskAll(int i) {
  6088. UNREFERENCED_PARAMETER(i);
  6089. return 1;
  6090. }
  6091. static int MaskEveryOther(int i) {
  6092. return i % 2 == 0 ? 1 : 0;
  6093. }
  6094. static int MaskEveryThird(int i) {
  6095. return i % 3 == 0 ? 1 : 0;
  6096. }
  6097. typedef int(*MaskFunction)(int);
  6098. static MaskFunction MaskFunctionTable[] = {
  6099. MaskAll, MaskEveryOther, MaskEveryThird
  6100. };
  6101. template <typename InType, typename OutType>
  6102. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  6103. const std::vector<int> &masks,
  6104. int maskValue, unsigned int index,
  6105. LPCWSTR str) {
  6106. ShaderOpKind kind = GetShaderOpKind(str);
  6107. switch (kind) {
  6108. case ShaderOpKind::WaveSum:
  6109. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  6110. case ShaderOpKind::WaveProduct:
  6111. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  6112. case ShaderOpKind::WaveActiveMax:
  6113. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  6114. case ShaderOpKind::WaveActiveMin:
  6115. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  6116. case ShaderOpKind::WaveCountBits:
  6117. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  6118. case ShaderOpKind::WaveActiveBitOr:
  6119. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  6120. case ShaderOpKind::WaveActiveBitAnd:
  6121. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  6122. case ShaderOpKind::WaveActiveBitXor:
  6123. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  6124. case ShaderOpKind::WaveActiveAnyTrue:
  6125. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  6126. case ShaderOpKind::WaveActiveAllTrue:
  6127. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  6128. case ShaderOpKind::WaveActiveAllEqual:
  6129. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  6130. default:
  6131. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  6132. return (OutType) 0;
  6133. }
  6134. };
  6135. // A framework for testing individual wave intrinsics tests.
  6136. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  6137. template <class T1, class T2>
  6138. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  6139. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  6140. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6141. // Resource representation for compute shader
  6142. // firstLaneId is used to group different waves
  6143. // laneIndex is used to identify lane within the wave.
  6144. // Lane ids are not necessarily in same order as thread ids.
  6145. struct PerThreadData {
  6146. unsigned firstLaneId;
  6147. unsigned laneIndex;
  6148. int mask;
  6149. T1 input;
  6150. T2 output;
  6151. };
  6152. unsigned int NumThreadsX = 8;
  6153. unsigned int NumThreadsY = 12;
  6154. unsigned int NumThreadsZ = 1;
  6155. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6156. static const unsigned int DispatchGroupCount = 1;
  6157. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  6158. CComPtr<IStream> pStream;
  6159. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6160. CComPtr<ID3D12Device> pDevice;
  6161. if (!CreateDevice(&pDevice)) {
  6162. return;
  6163. }
  6164. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6165. // Optional feature, so it's correct to not support it if declared as such.
  6166. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6167. return;
  6168. }
  6169. TableParameterHandler handler(pParameterList, numParameter);
  6170. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  6171. // Obtain the list of input lists
  6172. std::vector<std::vector<T1>*> InputDataList;
  6173. for (unsigned int i = 0;
  6174. i < numInputSet; ++i) {
  6175. std::wstring inputName = L"Validation.InputSet";
  6176. inputName.append(std::to_wstring(i + 1));
  6177. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  6178. }
  6179. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  6180. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6181. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6182. // Running compute shader for each input set with different masks
  6183. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  6184. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  6185. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  6186. pDevice, m_support, "WaveIntrinsicsOp",
  6187. // this callbacked is called when the test
  6188. // is creating the resource to run the test
  6189. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6190. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  6191. size_t size = sizeof(PerThreadData) * ThreadCount;
  6192. Data.resize(size);
  6193. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  6194. // 4 different inputs for each operation test
  6195. size_t index = 0;
  6196. std::vector<T1> *IntList = InputDataList[setIndex];
  6197. while (index < ThreadCount) {
  6198. PerThreadData *p = &pPrimitives[index];
  6199. p->firstLaneId = 0xFFFFBFFF;
  6200. p->laneIndex = 0xFFFFBFFF;
  6201. p->mask = MaskFunctionTable[maskIndex]((int)index);
  6202. p->input = (*IntList)[index % IntList->size()];
  6203. p->output = 0xFFFFBFFF;
  6204. index++;
  6205. }
  6206. // use shader from data table
  6207. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6208. }, ShaderOpSet);
  6209. // Check the value
  6210. MappedData data;
  6211. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  6212. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  6213. WEX::TestExecution::DisableVerifyExceptions dve;
  6214. // Grouping data by waves
  6215. std::vector<int> firstLaneIds;
  6216. for (size_t i = 0; i < ThreadCount; ++i) {
  6217. PerThreadData *p = &pPrimitives[i];
  6218. int firstLaneId = p->firstLaneId;
  6219. if (!contains(firstLaneIds, firstLaneId)) {
  6220. firstLaneIds.push_back(firstLaneId);
  6221. }
  6222. }
  6223. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  6224. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6225. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  6226. }
  6227. for (size_t i = 0; i < ThreadCount; ++i) {
  6228. PerThreadData *p = &pPrimitives[i];
  6229. waves[p->firstLaneId].get()->push_back(p);
  6230. }
  6231. // validate for each wave
  6232. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6233. // collect inputs and masks for a given wave
  6234. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  6235. std::vector<T1> inputList(waveData->size());
  6236. std::vector<int> maskList(waveData->size(), -1);
  6237. std::vector<T2> outputList(waveData->size());
  6238. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  6239. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6240. unsigned laneID = waveData->at(j)->laneIndex;
  6241. // ensure that each lane ID is unique and within the range
  6242. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  6243. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  6244. maskList.at(laneID) = waveData->at(j)->mask;
  6245. inputList.at(laneID) = waveData->at(j)->input;
  6246. outputList.at(laneID) = waveData->at(j)->output;
  6247. }
  6248. std::wstring inputStr = L"Wave Inputs: ";
  6249. std::wstring maskStr = L"Wave Masks: ";
  6250. std::wstring outputStr = L"Wave Outputs: ";
  6251. // append input string and mask string in lane id order
  6252. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6253. maskStr.append(std::to_wstring(maskList.at(j)));
  6254. maskStr.append(L" ");
  6255. inputStr.append(std::to_wstring(inputList.at(j)));
  6256. inputStr.append(L" ");
  6257. outputStr.append(std::to_wstring(outputList.at(j)));
  6258. outputStr.append(L" ");
  6259. }
  6260. LogCommentFmt(inputStr.data());
  6261. LogCommentFmt(maskStr.data());
  6262. LogCommentFmt(outputStr.data());
  6263. LogCommentFmt(L"\n");
  6264. // Compute expected output for a given inputs, masks, and index
  6265. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  6266. T2 expected;
  6267. // WaveActive is equivalent to WavePrefix lane # lane count
  6268. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  6269. if (maskList.at(laneIndex) == 1) {
  6270. expected = computeExpectedWithShaderOp<T1, T2>(
  6271. inputList, maskList, 1, index,
  6272. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6273. }
  6274. else {
  6275. expected = computeExpectedWithShaderOp<T1, T2>(
  6276. inputList, maskList, 0, index,
  6277. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6278. }
  6279. // TODO: use different comparison for floating point inputs
  6280. bool equal = outputList.at(laneIndex) == expected;
  6281. if (!equal) {
  6282. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  6283. }
  6284. VERIFY_IS_TRUE(equal);
  6285. }
  6286. }
  6287. }
  6288. }
  6289. }
  6290. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  6291. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  6292. if (GetTestParamUseWARP(true) &&
  6293. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6294. return;
  6295. }
  6296. WaveIntrinsicsActivePrefixTest<int, int>(
  6297. WaveIntrinsicsActiveIntParameters,
  6298. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  6299. /*isPrefix*/ false);
  6300. }
  6301. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  6302. if (GetTestParamUseWARP(true) &&
  6303. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6304. return;
  6305. }
  6306. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6307. WaveIntrinsicsActiveUintParameters,
  6308. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  6309. /*isPrefix*/ false);
  6310. }
  6311. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  6312. if (GetTestParamUseWARP(true) &&
  6313. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6314. return;
  6315. }
  6316. WaveIntrinsicsActivePrefixTest<int, int>(
  6317. WaveIntrinsicsPrefixIntParameters,
  6318. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  6319. /*isPrefix*/ true);
  6320. }
  6321. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  6322. if (GetTestParamUseWARP(true) &&
  6323. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6324. return;
  6325. }
  6326. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6327. WaveIntrinsicsPrefixUintParameters,
  6328. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  6329. /*isPrefix*/ true);
  6330. }
  6331. template <typename T>
  6332. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  6333. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6334. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6335. return static_cast<T>(1);
  6336. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6337. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  6338. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6339. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  6340. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6341. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  6342. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6343. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6344. return static_cast<T>(0);
  6345. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6346. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6347. return static_cast<T>(-1);
  6348. } else {
  6349. return static_cast<T>(0);
  6350. }
  6351. }
  6352. template <typename T>
  6353. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  6354. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6355. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6356. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  6357. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6358. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  6359. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  6360. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6361. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6362. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  6363. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6364. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  6365. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  6366. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6367. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  6368. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  6369. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6370. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6371. // For CountBits, each lane contributes a boolean value. The test input is
  6372. // a zero or non-zero integer. If the input is a non-zero value then the
  6373. // condition is true, thus we contribute one to the bit count.
  6374. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  6375. } else {
  6376. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  6377. }
  6378. }
  6379. template <class T>
  6380. void
  6381. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  6382. size_t numParameters) {
  6383. WEX::TestExecution::SetVerifyOutput
  6384. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6385. struct PerThreadData {
  6386. uint32_t key;
  6387. uint32_t firstLaneId;
  6388. uint32_t laneId;
  6389. uint32_t mask;
  6390. T value;
  6391. T result;
  6392. };
  6393. constexpr size_t NumThreadsX = 8;
  6394. constexpr size_t NumThreadsY = 12;
  6395. constexpr size_t NumThreadsZ = 1;
  6396. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6397. constexpr size_t DispatchGroupSize = 1;
  6398. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  6399. CComPtr<IStream> pStream;
  6400. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6401. CComPtr<ID3D12Device> pDevice;
  6402. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  6403. return;
  6404. }
  6405. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6406. // Optional feature, so it's correct to not support it if declared as such.
  6407. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6408. return;
  6409. }
  6410. std::shared_ptr<st::ShaderOpSet>
  6411. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6412. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6413. TableParameterHandler handler(pParameterList, numParameters);
  6414. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6415. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  6416. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  6417. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  6418. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  6419. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  6420. std::shared_ptr<ShaderOpTestResult> test =
  6421. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  6422. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  6423. UNREFERENCED_PARAMETER(name);
  6424. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  6425. data.resize(dataSize);
  6426. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  6427. for (size_t i = 0; i != ThreadCount; ++i) {
  6428. pThreadData[i].key = keys->at(i % keys->size());
  6429. pThreadData[i].value = values->at(i % values->size());
  6430. pThreadData[i].firstLaneId = 0xdeadbeef;
  6431. pThreadData[i].laneId = 0xdeadbeef;
  6432. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  6433. pThreadData[i].result = 0xdeadbeef;
  6434. }
  6435. pShaderOp->Shaders.at(0).Text = shaderSource;
  6436. pShaderOp->Shaders.at(0).Target = shaderProfile;
  6437. }, ShaderOpSet);
  6438. MappedData mappedData;
  6439. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  6440. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  6441. // Partition our data into waves
  6442. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  6443. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  6444. PerThreadData *elt = &resultData[i];
  6445. // Basic sanity checks
  6446. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  6447. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  6448. waves[elt->firstLaneId].push_back(elt);
  6449. }
  6450. // Verify each wave
  6451. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  6452. for (auto &w : waves) {
  6453. std::vector<PerThreadData *> &waveData = w.second;
  6454. struct {
  6455. bool operator()(PerThreadData *a, PerThreadData *b) const {
  6456. return (a->laneId < b->laneId);
  6457. }
  6458. } compare;
  6459. // Need to sort based on the lane id
  6460. std::sort(waveData.begin(), waveData.end(), compare);
  6461. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  6462. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  6463. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  6464. PerThreadData *data = waveData[i];
  6465. // Compute prefix operation over each previous lane element that has the
  6466. // same key value, and is part of the same active thread group
  6467. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  6468. for (unsigned j = 0; j < i; ++j) {
  6469. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  6470. accum = refFn(accum, waveData[j]->value);
  6471. }
  6472. }
  6473. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  6474. VERIFY_IS_TRUE(accum == data->result);
  6475. }
  6476. LogCommentFmt(L"\n");
  6477. }
  6478. }
  6479. }
  6480. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  6481. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  6482. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  6483. }
  6484. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  6485. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  6486. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  6487. }
  6488. TEST_F(ExecutionTest, CBufferTestHalf) {
  6489. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6490. CComPtr<IStream> pStream;
  6491. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6492. // Single operation test at the moment.
  6493. CComPtr<ID3D12Device> pDevice;
  6494. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  6495. return;
  6496. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6497. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6498. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6499. return;
  6500. }
  6501. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  6502. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  6503. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6504. UNREFERENCED_PARAMETER(pShaderOp);
  6505. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  6506. // use shader from data table.
  6507. Data.resize(sizeof(InputData));
  6508. uint16_t *pData = (uint16_t *)Data.data();
  6509. for (size_t i = 0; i < 4; ++i, ++pData) {
  6510. *pData = InputData[i];
  6511. }
  6512. });
  6513. {
  6514. MappedData data;
  6515. test->Test->GetReadBackData("RTarget", &data);
  6516. const uint16_t *pPixels = (uint16_t *)data.data();
  6517. for (int i = 0; i < 4; ++i) {
  6518. uint16_t output = *(pPixels + i);
  6519. float outputFloat = ConvertFloat16ToFloat32(output);
  6520. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  6521. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  6522. i, inputFloat, InputData[i], outputFloat, output);
  6523. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  6524. }
  6525. }
  6526. }
  6527. TEST_F(ExecutionTest, BarycentricsTest) {
  6528. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6529. CComPtr<IStream> pStream;
  6530. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6531. CComPtr<ID3D12Device> pDevice;
  6532. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  6533. return;
  6534. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  6535. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  6536. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6537. return;
  6538. }
  6539. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  6540. MappedData data;
  6541. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  6542. UINT width = (UINT)D.Width;
  6543. UINT height = D.Height;
  6544. UINT pixelSize = GetByteSizeForFormat(D.Format);
  6545. test->Test->GetReadBackData("RTarget", &data);
  6546. //const uint8_t *pPixels = (uint8_t *)data.data();
  6547. const float *pPixels = (float *)data.data();
  6548. // Get the vertex of barycentric coordinate using VBuffer
  6549. MappedData triangleData;
  6550. test->Test->GetReadBackData("VBuffer", &triangleData);
  6551. const float *pTriangleData = (float*)triangleData.data();
  6552. // get the size of the input data
  6553. unsigned triangleVertexSizeInFloat = 0;
  6554. for (auto element : test->ShaderOp->InputElements)
  6555. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  6556. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  6557. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  6558. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  6559. XMFLOAT3 barycentricWeights[4] = {
  6560. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  6561. XMFLOAT3(0.5f, 0.25f, 0.25f),
  6562. XMFLOAT3(0.25f, 0.5f, 0.25f),
  6563. XMFLOAT3(0.25f, 0.25f, 0.50f)
  6564. };
  6565. float tolerance = 0.001f;
  6566. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  6567. float w0 = barycentricWeights[i].x;
  6568. float w1 = barycentricWeights[i].y;
  6569. float w2 = barycentricWeights[i].z;
  6570. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  6571. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  6572. // map from x1 y1 to rtv pixels
  6573. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  6574. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  6575. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  6576. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  6577. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  6578. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  6579. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  6580. }
  6581. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  6582. }
  6583. static const char RawBufferTestShaderDeclarations[] =
  6584. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  6585. "typedef COMPONENT_TYPE scalar; \r\n"
  6586. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  6587. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  6588. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  6589. "\r\n"
  6590. "struct TestData { \r\n"
  6591. " scalar v1; \r\n"
  6592. " vector2 v2; \r\n"
  6593. " vector3 v3; \r\n"
  6594. " vector4 v4; \r\n"
  6595. "}; \r\n"
  6596. "\r\n"
  6597. "struct UavData {\r\n"
  6598. " TestData input; \r\n"
  6599. " TestData output; \r\n"
  6600. " TestData srvOut; \r\n"
  6601. "}; \r\n"
  6602. "\r\n"
  6603. "ByteAddressBuffer srv0 : register(t0); \r\n"
  6604. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  6605. "ByteAddressBuffer srv2 : register(t2); \r\n"
  6606. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  6607. "\r\n"
  6608. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  6609. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  6610. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  6611. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  6612. static const char RawBufferTestShaderBody[] =
  6613. " // offset of 'out' in 'UavData'\r\n"
  6614. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  6615. "\r\n"
  6616. " // offset of 'srv_out' in 'UavData'\r\n"
  6617. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  6618. "\r\n"
  6619. " // offsets within the 'Data' struct\r\n"
  6620. " const int v1_offset = 0; \r\n"
  6621. " const int v2_offset = COMPONENT_SIZE; \r\n"
  6622. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  6623. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  6624. "\r\n"
  6625. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  6626. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  6627. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  6628. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  6629. "\r\n"
  6630. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  6631. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  6632. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  6633. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  6634. "\r\n"
  6635. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  6636. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  6637. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  6638. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  6639. "\r\n"
  6640. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  6641. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  6642. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  6643. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  6644. "\r\n"
  6645. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  6646. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  6647. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  6648. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  6649. "\r\n"
  6650. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  6651. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  6652. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  6653. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  6654. "\r\n"
  6655. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  6656. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  6657. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  6658. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  6659. "\r\n"
  6660. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  6661. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  6662. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  6663. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  6664. static const char RawBufferTestComputeShaderTemplate[] =
  6665. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6666. "[numthreads(1, 1, 1)]\r\n"
  6667. "void main(uint GI : SV_GroupIndex) {\r\n"
  6668. "%s\r\n" // <- RawBufferTestShaderBody
  6669. "};";
  6670. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  6671. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6672. "struct PSInput { \r\n"
  6673. " float4 pos : SV_POSITION; \r\n"
  6674. "}; \r\n"
  6675. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  6676. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  6677. "%s\r\n" // <- RawBufferTestShaderBody
  6678. " } \r\n"
  6679. " return uint4(1, 2, 3, 4); \r\n"
  6680. "};";
  6681. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  6682. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6683. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  6684. }
  6685. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  6686. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6687. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  6688. }
  6689. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  6690. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6691. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6692. }
  6693. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  6694. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6695. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6696. }
  6697. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  6698. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6699. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  6700. }
  6701. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  6702. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6703. RawBufferLdStTestData<uint16_t> halfData;
  6704. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  6705. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6706. }
  6707. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  6708. }
  6709. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  6710. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6711. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  6712. }
  6713. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  6714. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6715. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  6716. }
  6717. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  6718. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6719. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  6720. }
  6721. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  6722. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6723. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  6724. }
  6725. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  6726. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6727. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  6728. }
  6729. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  6730. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6731. RawBufferLdStTestData<uint16_t> halfData;
  6732. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  6733. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6734. }
  6735. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  6736. }
  6737. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6738. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  6739. char *&sTy, char *&additionalOptions) {
  6740. if (!CreateDevice(&pDevice, shaderModel)) {
  6741. return false;
  6742. }
  6743. additionalOptions = "";
  6744. switch (dataType) {
  6745. case RawBufferLdStType::I64:
  6746. if (!DoesDeviceSupportInt64(pDevice)) {
  6747. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  6748. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6749. return false;
  6750. }
  6751. sTy = "int64_t";
  6752. break;
  6753. case RawBufferLdStType::Double:
  6754. if (!DoesDeviceSupportDouble(pDevice)) {
  6755. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  6756. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6757. return false;
  6758. }
  6759. sTy = "double";
  6760. break;
  6761. case RawBufferLdStType::I16:
  6762. case RawBufferLdStType::Half:
  6763. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6764. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6765. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6766. return false;
  6767. }
  6768. additionalOptions = "-enable-16bit-types";
  6769. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  6770. break;
  6771. case RawBufferLdStType::I32:
  6772. sTy = "int32_t";
  6773. break;
  6774. case RawBufferLdStType::Float:
  6775. sTy = "float";
  6776. break;
  6777. default:
  6778. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  6779. }
  6780. // read shader config
  6781. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6782. return true;
  6783. }
  6784. template <class Ty>
  6785. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6786. // read buffers back & verify expected values
  6787. static const int UavBufferCount = 4;
  6788. char bufferName[11] = "UAVBufferX";
  6789. for (unsigned i = 0; i < UavBufferCount; i++) {
  6790. MappedData dataUav;
  6791. RawBufferLdStUavData<Ty> *pOutData;
  6792. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6793. test->GetReadBackData(bufferName, &dataUav);
  6794. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6795. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6796. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6797. // scalar
  6798. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6799. // vector 2
  6800. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6801. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6802. // vector 3
  6803. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6804. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6805. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6806. // vector 4
  6807. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6808. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6809. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6810. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6811. // verify SRV Store
  6812. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6813. // scalar
  6814. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6815. // vector 2
  6816. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6817. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6818. // vector 3
  6819. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6820. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6821. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6822. // vector 4
  6823. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6824. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6825. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6826. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6827. }
  6828. }
  6829. template <class Ty>
  6830. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6831. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6832. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6833. CComPtr<ID3D12Device> pDevice;
  6834. CComPtr<IStream> pStream;
  6835. char *sTy, *additionalOptions;
  6836. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6837. return;
  6838. }
  6839. // format shader source
  6840. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6841. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6842. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6843. // format compiler args
  6844. char compilerOptions[256];
  6845. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6846. // run the shader
  6847. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6848. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6849. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6850. (Name[9] >= '0' && Name[9] <= '3'));
  6851. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6852. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6853. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6854. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6855. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6856. });
  6857. // verify expected values
  6858. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6859. }
  6860. template <class Ty>
  6861. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6862. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6863. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6864. CComPtr<ID3D12Device> pDevice;
  6865. CComPtr<IStream> pStream;
  6866. char *sTy, *additionalOptions;
  6867. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6868. return;
  6869. }
  6870. // format shader source
  6871. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6872. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6873. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6874. // format compiler args
  6875. char compilerOptions[256];
  6876. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6877. // run the shader
  6878. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6879. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6880. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6881. (Name[9] >= '0' && Name[9] <= '3'));
  6882. // pixel shader is at index 1, vertex shader at index 0
  6883. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6884. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6885. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6886. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6887. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6888. });
  6889. // verify expected values
  6890. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6891. }
  6892. template<typename T>
  6893. uint32_t pack(std::array<T, 4> unpackedVals)
  6894. {
  6895. uint32_t dst = 0;
  6896. constexpr uint32_t bitMask = 0xFF;
  6897. for (uint32_t i = 0U; i < 4U; ++i)
  6898. {
  6899. dst |= (unpackedVals[i] & bitMask) << (i * 8);
  6900. }
  6901. return dst;
  6902. }
  6903. template <typename T>
  6904. uint32_t pack_clamp_u8(std::array<T, 4> unpackedVals)
  6905. {
  6906. int32_t clamp_min = std::numeric_limits<uint8_t>::min();
  6907. int32_t clamp_max = std::numeric_limits<uint8_t>::max();
  6908. uint32_t dst = 0;
  6909. for (uint32_t i = 0U; i < 4U; ++i)
  6910. {
  6911. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6912. dst |= ((uint8_t)clamped) << (i * 8);
  6913. }
  6914. return dst;
  6915. }
  6916. template <typename T>
  6917. uint32_t pack_clamp_s8(std::array<T, 4> unpackedVals)
  6918. {
  6919. int32_t clamp_min = std::numeric_limits<int8_t>::min();
  6920. int32_t clamp_max = std::numeric_limits<int8_t>::max();
  6921. uint32_t dst = 0;
  6922. for (uint32_t i = 0U; i < 4U; ++i)
  6923. {
  6924. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6925. dst |= ((uint8_t)clamped) << (i * 8);
  6926. }
  6927. return dst;
  6928. }
  6929. template<typename T>
  6930. std::array<T, 4> unpack_u(uint32_t packedVal)
  6931. {
  6932. std::array<T, 4> ret;
  6933. ret[0] = (uint8_t)((packedVal & 0x000000FF) >> 0 );
  6934. ret[1] = (uint8_t)((packedVal & 0x0000FF00) >> 8 );
  6935. ret[2] = (uint8_t)((packedVal & 0x00FF0000) >> 16);
  6936. ret[3] = (uint8_t)((packedVal & 0xFF000000) >> 24);
  6937. return ret;
  6938. }
  6939. template<typename T>
  6940. std::array<T, 4> unpack_s(uint32_t packedVal)
  6941. {
  6942. std::array<T, 4> ret;
  6943. ret[0] = (int8_t)((packedVal & 0x000000FF) >> 0 );
  6944. ret[1] = (int8_t)((packedVal & 0x0000FF00) >> 8 );
  6945. ret[2] = (int8_t)((packedVal & 0x00FF0000) >> 16);
  6946. ret[3] = (int8_t)((packedVal & 0xFF000000) >> 24);
  6947. return ret;
  6948. }
  6949. TEST_F(ExecutionTest, PackUnpackTest) {
  6950. WEX::TestExecution::SetVerifyOutput verifySettings(
  6951. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6952. CComPtr<IStream> pStream;
  6953. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6954. CComPtr<ID3D12Device> pDevice;
  6955. #ifdef PACKUNPACK_PLACEHOLDER
  6956. string args = "-enable-16bit-types -DPACKUNPACK_PLACEHOLDER";
  6957. string target = "cs_6_2";
  6958. if (!CreateDevice(&pDevice)) {
  6959. return;
  6960. }
  6961. #else
  6962. string args = "-enable-16bit-types";
  6963. string target = "cs_6_6";
  6964. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  6965. return;
  6966. }
  6967. #endif
  6968. int tableSize = sizeof(PackUnpackOpParameters) / sizeof(TableParameter);
  6969. TableParameterHandler handler(PackUnpackOpParameters, tableSize);
  6970. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6971. std::vector<uint32_t> *validation_input = &handler.GetTableParamByName(L"Validation.Input")->m_uint32Table;
  6972. uint32_t validation_tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_uint;
  6973. size_t count = validation_input->size();
  6974. std::vector<SPackUnpackOpOutPacked> expectedPacked(count / 4);
  6975. std::vector<SPackUnpackOpOutUnpacked> expectedUnpacked(count / 4);
  6976. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  6977. pDevice, m_support, pStream, "PackUnpackOp",
  6978. // this callback is called when the test
  6979. // is creating the resource to run the test
  6980. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6981. if (0 == _stricmp(Name, "g_bufIn"))
  6982. {
  6983. size_t size = sizeof(uint32_t) * 4 * count;
  6984. Data.resize(size);
  6985. uint32_t *pPrimitives = (uint32_t*)Data.data();
  6986. for (size_t i = 0; i < count / 4; ++i) {
  6987. uint32_t *p = &pPrimitives[i * 4];
  6988. uint32_t x = (*validation_input)[i * 4 + 0];
  6989. uint32_t y = (*validation_input)[i * 4 + 1];
  6990. uint32_t z = (*validation_input)[i * 4 + 2];
  6991. uint32_t w = (*validation_input)[i * 4 + 3];
  6992. p[0] = x;
  6993. p[1] = y;
  6994. p[2] = z;
  6995. p[3] = w;
  6996. std::array<uint32_t, 4> inputUint32 = { x, y, z, w };
  6997. std::array<int32_t, 4> inputInt32 = { (int32_t)x, (int32_t)y, (int32_t)z, (int32_t)w };
  6998. std::array<uint16_t, 4> inputUint16 = { (uint16_t)x, (uint16_t)y, (uint16_t)z, (uint16_t)w };
  6999. std::array<int16_t, 4> inputInt16 = { (int16_t)x, (int16_t)y, (int16_t)z, (int16_t)w };
  7000. // Pack unclamped
  7001. expectedPacked[i].packedUint32 = pack(inputUint32);
  7002. expectedPacked[i].packedInt32 = pack(inputInt32);
  7003. expectedPacked[i].packedUint16 = pack(inputUint16);
  7004. expectedPacked[i].packedInt16 = pack(inputInt16);
  7005. // pack clamped
  7006. expectedPacked[i].packedClampedUint32 = pack_clamp_u8(inputInt32);
  7007. expectedPacked[i].packedClampedInt32 = pack_clamp_s8(inputInt32);
  7008. expectedPacked[i].packedClampedUint16 = pack_clamp_u8(inputInt16);
  7009. expectedPacked[i].packedClampedInt16 = pack_clamp_s8(inputInt16);
  7010. // unpack
  7011. expectedUnpacked[i].outputUint32 = unpack_u<uint32_t>(expectedPacked[i].packedUint32);
  7012. expectedUnpacked[i].outputInt32 = unpack_s<int32_t >(expectedPacked[i].packedInt32 );
  7013. expectedUnpacked[i].outputUint16 = unpack_u<uint16_t>(expectedPacked[i].packedUint16);
  7014. expectedUnpacked[i].outputInt16 = unpack_s<int16_t >(expectedPacked[i].packedInt16 );
  7015. expectedUnpacked[i].outputClampedUint32 = unpack_u<uint32_t>(expectedPacked[i].packedClampedUint32);
  7016. expectedUnpacked[i].outputClampedInt32 = unpack_s<int32_t >(expectedPacked[i].packedClampedInt32 );
  7017. expectedUnpacked[i].outputClampedUint16 = unpack_u<uint16_t>(expectedPacked[i].packedClampedUint16);
  7018. expectedUnpacked[i].outputClampedInt16 = unpack_s<int16_t >(expectedPacked[i].packedClampedInt16 );
  7019. }
  7020. }
  7021. else
  7022. {
  7023. std::fill(Data.begin(), Data.end(), 0);
  7024. }
  7025. // use shader from data table
  7026. pShaderOp->Shaders.at(0).Target = target.c_str();
  7027. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  7028. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7029. });
  7030. MappedData packedData;
  7031. test->Test->GetReadBackData("g_bufOutPacked", &packedData);
  7032. SPackUnpackOpOutPacked *readBackPacked = (SPackUnpackOpOutPacked *)packedData.data();
  7033. MappedData unpackedData;
  7034. test->Test->GetReadBackData("g_bufOutPackedUnpacked", &unpackedData);
  7035. SPackUnpackOpOutUnpacked *readBackUnpacked = (SPackUnpackOpOutUnpacked *)unpackedData.data();
  7036. for (size_t i = 0; i < count / 4; ++i)
  7037. {
  7038. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint32, expectedPacked[i].packedUint32, validation_tolerance);
  7039. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt32 , expectedPacked[i].packedInt32 , validation_tolerance);
  7040. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint16, expectedPacked[i].packedUint16, validation_tolerance);
  7041. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt16 , expectedPacked[i].packedInt16 , validation_tolerance);
  7042. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint32, expectedPacked[i].packedClampedUint32, validation_tolerance);
  7043. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt32 , expectedPacked[i].packedClampedInt32 , validation_tolerance);
  7044. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint16, expectedPacked[i].packedClampedUint16, validation_tolerance);
  7045. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt16 , expectedPacked[i].packedClampedInt16 , validation_tolerance);
  7046. for (uint32_t j = 0; j < 4; ++j)
  7047. {
  7048. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint32[j], expectedUnpacked[i].outputUint32[j], validation_tolerance);
  7049. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt32 [j], expectedUnpacked[i].outputInt32 [j], validation_tolerance);
  7050. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint16[j], expectedUnpacked[i].outputUint16[j], validation_tolerance);
  7051. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt16 [j], expectedUnpacked[i].outputInt16 [j], validation_tolerance);
  7052. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint32[j], expectedUnpacked[i].outputClampedUint32[j], validation_tolerance);
  7053. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt32 [j], expectedUnpacked[i].outputClampedInt32 [j], validation_tolerance);
  7054. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint16[j], expectedUnpacked[i].outputClampedUint16[j], validation_tolerance);
  7055. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt16 [j], expectedUnpacked[i].outputClampedInt16 [j], validation_tolerance);
  7056. }
  7057. }
  7058. }
  7059. // This test expects a <pShader> that retrieves a signal value from each of a few
  7060. // resources that are initialized here. <isDynamic> determines if it uses the
  7061. // 6.6 Dynamic Resources feature.
  7062. // Values are read back from the result UAV and compared to the expected signals
  7063. void ExecutionTest::RunResourceTest(ID3D12Device *pDevice, const char *pShader,
  7064. const wchar_t *sm, bool isDynamic) {
  7065. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7066. const int NumSRVs = 3;
  7067. const int NumUAVs = 4;
  7068. const int NumResources = NumSRVs + NumUAVs;
  7069. const int NumSamplers = 2;
  7070. const int valueSize = 16;
  7071. static const int DispatchGroupX = 1;
  7072. static const int DispatchGroupY = 1;
  7073. static const int DispatchGroupZ = 1;
  7074. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  7075. CComPtr<ID3D12CommandQueue> pCommandQueue;
  7076. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  7077. FenceObj FO;
  7078. size_t valueSizeInBytes = valueSize * sizeof(float);
  7079. CreateComputeCommandQueue(pDevice, L"DynamicResourcesTest Command Queue", &pCommandQueue);
  7080. InitFenceObj(pDevice, &FO);
  7081. // Create root signature.
  7082. CComPtr<ID3D12RootSignature> pRootSignature;
  7083. if (!isDynamic) {
  7084. // Not dynamic, create a range for each resource and from them, the root signature
  7085. CD3DX12_DESCRIPTOR_RANGE ranges[NumResources];
  7086. CD3DX12_DESCRIPTOR_RANGE srange[NumSamplers];
  7087. for (int i = 0; i < NumSRVs; i++)
  7088. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, i, 0);
  7089. for (int i = NumSRVs; i < NumResources; i++)
  7090. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, i - NumSRVs, 0);
  7091. for (int i = 0; i < NumSamplers; i++)
  7092. srange[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, i, 0);
  7093. CreateRootSignatureFromRanges(pDevice, &pRootSignature, ranges, NumResources, srange, NumSamplers);
  7094. } else {
  7095. // Dynamic just requires the flags indicating that the builtin arrays should be accessible
  7096. #if !defined(D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)
  7097. #define D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x400
  7098. #define D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x800
  7099. #endif
  7100. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  7101. rootSignatureDesc.Init(0, nullptr, 0, nullptr,
  7102. D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
  7103. D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
  7104. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  7105. }
  7106. // Create pipeline state object.
  7107. CComPtr<ID3D12PipelineState> pComputeState;
  7108. CreateComputePSO(pDevice, pRootSignature, pShader, sm, &pComputeState);
  7109. // Create a command allocator and list for compute.
  7110. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  7111. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  7112. // Set up SRV resources
  7113. CComPtr<ID3D12Resource> pSRVResources[NumSRVs];
  7114. CComPtr<ID3D12Resource> pUAVResources[NumUAVs];
  7115. CComPtr<ID3D12Resource> pUploadResources[NumResources];
  7116. {
  7117. D3D12_RESOURCE_DESC bufDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  7118. float values[valueSize];
  7119. for (int i = 0; i < NumSRVs - 1; i++) {
  7120. for (int j = 0; j < valueSize; j++)
  7121. values[j] = 10.0 + i;
  7122. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufDesc,
  7123. &pSRVResources[i], &pUploadResources[i]);
  7124. }
  7125. D3D12_RESOURCE_DESC tex2dDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 4, 4);
  7126. for (int j = 0; j < valueSize; j++)
  7127. values[j] = 10.0 + (NumSRVs - 1);
  7128. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex2dDesc,
  7129. &pSRVResources[NumSRVs - 1], &pUploadResources[NumSRVs - 1]);
  7130. }
  7131. // Set up UAV resources
  7132. CComPtr<ID3D12Resource> pReadBuffer;
  7133. float values[valueSize];
  7134. for (int i = 0; i < NumUAVs - 2; i++) {
  7135. for (int j = 0; j < valueSize; j++)
  7136. values[j] = 20.0 + i;
  7137. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7138. &pUAVResources[i], &pUploadResources[NumSRVs + i]);
  7139. }
  7140. for (int j = 0; j < valueSize; j++)
  7141. values[j] = 20.0 + (NumUAVs - 1);
  7142. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7143. &pUAVResources[NumUAVs - 2], &pUploadResources[NumResources - 2], &pReadBuffer);
  7144. for (int j = 0; j < valueSize; j++)
  7145. values[j] = 20.0 + (NumUAVs - 2);
  7146. D3D12_RESOURCE_DESC tex1dDesc = CD3DX12_RESOURCE_DESC::Tex1D(DXGI_FORMAT_R32_FLOAT, valueSize, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  7147. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex1dDesc,
  7148. &pUAVResources[NumUAVs - 1], &pUploadResources[NumResources - 1]);
  7149. // Close the command list and execute it to perform the GPU setup.
  7150. pCommandList->Close();
  7151. ExecuteCommandList(pCommandQueue, pCommandList);
  7152. WaitForSignal(pCommandQueue, FO);
  7153. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  7154. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  7155. CComPtr<ID3D12DescriptorHeap> pResHeap;
  7156. CComPtr<ID3D12DescriptorHeap> pSampHeap;
  7157. CreateDefaultDescHeaps(pDevice, NumSRVs + NumUAVs, NumSamplers, &pResHeap, &pSampHeap);
  7158. // Create Rootsignature and descriptor tables
  7159. {
  7160. ID3D12DescriptorHeap *descHeaps[2] = {pResHeap, pSampHeap};
  7161. pCommandList->SetDescriptorHeaps(2, descHeaps);
  7162. pCommandList->SetComputeRootSignature(pRootSignature);
  7163. if (!isDynamic) {
  7164. // Only non-dynamic resources require descriptortables
  7165. pCommandList->SetComputeRootDescriptorTable(0, pResHeap->GetGPUDescriptorHandleForHeapStart());
  7166. pCommandList->SetComputeRootDescriptorTable(1, pSampHeap->GetGPUDescriptorHandleForHeapStart());
  7167. }
  7168. }
  7169. CD3DX12_CPU_DESCRIPTOR_HANDLE baseHandle(pResHeap->GetCPUDescriptorHandleForHeapStart());
  7170. // Create SRVs
  7171. CreateRawSRV(pDevice, baseHandle, valueSize, pSRVResources[0]);
  7172. CreateStructSRV(pDevice, baseHandle, valueSize, sizeof(float), pSRVResources[1]);
  7173. CreateTex2DSRV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pSRVResources[2]);
  7174. // Create UAVs
  7175. CreateRawUAV(pDevice, baseHandle, valueSize, pUAVResources[0]);
  7176. CreateStructUAV(pDevice, baseHandle, valueSize, sizeof(float), pUAVResources[1]);
  7177. CreateTypedUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[2]);
  7178. CreateTex1DUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[3]);
  7179. D3D12_FILTER filters[] = {D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT};
  7180. float borderColors[] = {30.0, 31.0};
  7181. CreateDefaultSamplers(pDevice, pSampHeap->GetCPUDescriptorHandleForHeapStart(),
  7182. filters, borderColors, NumSamplers);
  7183. // Run the compute shader and copy the results back to readable memory.
  7184. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  7185. RecordTransitionBarrier(pCommandList, pUAVResources[NumUAVs - 2], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  7186. pCommandList->CopyResource(pReadBuffer, pUAVResources[NumUAVs - 2]);
  7187. pCommandList->Close();
  7188. ExecuteCommandList(pCommandQueue, pCommandList);
  7189. WaitForSignal(pCommandQueue, FO);
  7190. MappedData data(pReadBuffer, valueSize*sizeof(float));
  7191. const float *pData = (float*)data.data();
  7192. LogCommentFmt(L"Verify bound resources are properly selected");
  7193. VERIFY_ARE_EQUAL(pData[0], 10);
  7194. VERIFY_ARE_EQUAL(pData[1], 11);
  7195. VERIFY_ARE_EQUAL(pData[2], 12);
  7196. VERIFY_ARE_EQUAL(pData[3], 20);
  7197. VERIFY_ARE_EQUAL(pData[4], 21);
  7198. VERIFY_ARE_EQUAL(pData[5], 22);
  7199. VERIFY_ARE_EQUAL(pData[6], 30);
  7200. VERIFY_ARE_EQUAL(pData[7], 1); // samplecmp 1 means it matched 31
  7201. }
  7202. TEST_F(ExecutionTest, SignatureResourcesTest) {
  7203. std::string pShader =
  7204. "ByteAddressBuffer g_rawBuf : register(t0);\n"
  7205. "StructuredBuffer<float> g_structBuf : register(t1);\n"
  7206. "Texture2D<float> g_tex : register(t2);\n"
  7207. "RWByteAddressBuffer g_rwRawBuf : register(u0);\n"
  7208. "RWStructuredBuffer<float> g_rwStructBuf : register(u1);\n"
  7209. "RWBuffer<float> g_result : register(u2);\n"
  7210. "RWTexture1D<float> g_rwTex : register(u3);\n"
  7211. "SamplerState g_samp : register(s0);\n"
  7212. "SamplerComparisonState g_sampCmp : register(s1);\n"
  7213. "[NumThreads(1, 1, 1)]\n"
  7214. "void main(uint ix : SV_GroupIndex) {\n"
  7215. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7216. " g_result[1] = g_structBuf.Load(0);\n"
  7217. " g_result[2] = g_tex.Load(0);\n"
  7218. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7219. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7220. " g_result[5] = g_rwTex.Load(0);\n"
  7221. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7222. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7223. "}\n";
  7224. CComPtr<ID3D12Device> pDevice;
  7225. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7226. return;
  7227. RunResourceTest(pDevice, pShader.c_str(), L"cs_6_6", /*isDynamic*/false);
  7228. }
  7229. TEST_F(ExecutionTest, DynamicResourcesTest) {
  7230. static const char pShader[] =
  7231. "static ByteAddressBuffer g_rawBuf = ResourceDescriptorHeap[0];\n"
  7232. "static StructuredBuffer<float> g_structBuf = ResourceDescriptorHeap[1];\n"
  7233. "static Texture2D<float> g_tex = ResourceDescriptorHeap[2];\n"
  7234. "static RWByteAddressBuffer g_rwRawBuf = ResourceDescriptorHeap[3];\n"
  7235. "static RWStructuredBuffer<float> g_rwStructBuf = ResourceDescriptorHeap[4];\n"
  7236. "static RWBuffer<float> g_result = ResourceDescriptorHeap[5];\n"
  7237. "static RWTexture1D<float> g_rwTex = ResourceDescriptorHeap[6];\n"
  7238. "static SamplerState g_samp = SamplerDescriptorHeap[0];\n"
  7239. "static SamplerComparisonState g_sampCmp = SamplerDescriptorHeap[1];\n"
  7240. "[NumThreads(1, 1, 1)]\n"
  7241. "void main(uint ix : SV_GroupIndex) {\n"
  7242. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7243. " g_result[1] = g_structBuf.Load(0);\n"
  7244. " g_result[2] = g_tex.Load(0);\n"
  7245. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7246. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7247. " g_result[5] = g_rwTex.Load(0);\n"
  7248. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7249. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7250. "}\n";
  7251. CComPtr<ID3D12Device> pDevice;
  7252. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7253. return;
  7254. RunResourceTest(pDevice, pShader, L"cs_6_6", /*isDynamic*/true);
  7255. }
  7256. #define MAX_WAVESIZE 128
  7257. #define strinfigy2(arg) #arg
  7258. #define strinfigy(arg) strinfigy2(arg)
  7259. void ExecutionTest::WaveSizeTest() {
  7260. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7261. CComPtr<ID3D12Device> pDevice;
  7262. CComPtr<IStream> pStream;
  7263. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7264. return;
  7265. }
  7266. // Check Wave support
  7267. if (!DoesDeviceSupportWaveOps(pDevice)) {
  7268. // Optional feature, so it's correct to not support it if declared as such.
  7269. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  7270. return;
  7271. }
  7272. // read shader config
  7273. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7274. // Get supported wave sizes
  7275. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waveOpts;
  7276. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &waveOpts, sizeof(waveOpts)));
  7277. UINT minWaveSize = waveOpts.WaveLaneCountMin;
  7278. UINT maxWaveSize = waveOpts.WaveLaneCountMax;
  7279. DXASSERT_NOMSG(minWaveSize <= maxWaveSize);
  7280. DXASSERT((minWaveSize & (minWaveSize - 1)) == 0, "must be a power of 2");
  7281. DXASSERT((maxWaveSize & (maxWaveSize - 1)) == 0, "must be a power of 2");
  7282. // format shader source
  7283. const char waveSizeTestShader[] =
  7284. "struct TestData { \r\n"
  7285. " uint count; \r\n"
  7286. "}; \r\n"
  7287. "RWStructuredBuffer<TestData> data : register(u0); \r\n"
  7288. "\r\n"
  7289. "// Note: WAVESIZE will be defined via compiler option -D\r\n"
  7290. "[wavesize(WAVESIZE)]\r\n"
  7291. "[numthreads(" strinfigy(MAX_WAVESIZE) "*2,1,1)]\r\n"
  7292. "void main(uint3 tid : SV_DispatchThreadID ) { \r\n"
  7293. " data[tid.x].count = WaveActiveSum(1); \r\n"
  7294. "}\r\n";
  7295. struct WaveSizeTestData {
  7296. uint32_t count;
  7297. };
  7298. for (UINT waveSize = minWaveSize; waveSize <= maxWaveSize; waveSize *= 2) {
  7299. // format compiler args
  7300. char compilerOptions[32];
  7301. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D WAVESIZE=%d", waveSize) != -1);
  7302. // run the shader
  7303. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "WaveSizeTest",
  7304. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7305. VERIFY_IS_TRUE((0 == strncmp(Name, "UAVBuffer0", 10)));
  7306. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  7307. pShaderOp->Shaders.at(0).Text = waveSizeTestShader;
  7308. VERIFY_IS_TRUE(sizeof(WaveSizeTestData)*MAX_WAVESIZE <= Data.size());
  7309. WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
  7310. memset(&pInData, sizeof(WaveSizeTestData)*MAX_WAVESIZE, 0);
  7311. });
  7312. // verify expected values
  7313. MappedData dataUav;
  7314. WaveSizeTestData *pOutData;
  7315. test->Test->GetReadBackData("UAVBuffer0", &dataUav);
  7316. VERIFY_ARE_EQUAL(sizeof(WaveSizeTestData)*MAX_WAVESIZE, dataUav.size());
  7317. pOutData = (WaveSizeTestData*)dataUav.data();
  7318. LogCommentFmt(L"Verifying test result for wave size %d", waveSize);
  7319. for (unsigned i = 0; i < MAX_WAVESIZE; i++) {
  7320. if (!VERIFY_ARE_EQUAL(pOutData[i].count, waveSize))
  7321. break;
  7322. }
  7323. }
  7324. }
  7325. // Atomic operation testing
  7326. // Atomic tests take a single integer index as input and contort it into some
  7327. // kind of interesting contributor to the operation in question.
  7328. // So each vertex, pixel, thread, or other will have a unique index that produces
  7329. // a contributing value to the calculation which is stored in a small resource
  7330. // For arithmetic or bitwise operations, each contributor accumulates to the same
  7331. // location in the resource indexed by the operation type. Addition is in index 0
  7332. // umin/umax are in 1 and 2 and so on.
  7333. // To make sure that the most significant bits are involved in the calculation,
  7334. // particularly in the case of 64-bit values, each contributing value is duplicated
  7335. // to the lower and upper halves of the value. There is an exception to this when
  7336. // addition exceeds the available size and also for compare and exchange explained below.
  7337. // For compare and exchange operations, 64 output locations are shared by the various lanes.
  7338. // Each lane attempts to write to a location that is shared with several others.
  7339. // The first one to write to it determines its contents, which will be the lane index <ix>
  7340. // in the upper bits and the output location index in the lower bits.
  7341. // This ensures that the compare operations consider the upper bits in the comparison.
  7342. // The initial compare store is followed by a compare exchange that compares for the
  7343. // value the current lane would have assigned there. Finally, the output of the cmpxchg
  7344. // is used to determine if the current lane should perform the final unconditional exchange.
  7345. // The values are verified by checking the lower bits for the matching location index
  7346. // and ensuring that the upper bits undergoing the same transformation result in the location index.
  7347. // For lane index <ix> the location is calculated and final result assigned as if by this code:
  7348. // g_outputBuf[(ix/3)%64] = (ix << shBits) | ((ix/3)%64);
  7349. bool AtomicResultMatches(const BYTE *uResults, uint64_t gold, size_t size) {
  7350. if (memcmp(uResults, &gold, size)) {
  7351. if (size == 4)
  7352. LogCommentFmt(L" value %d is not %d", ((uint32_t*)uResults)[0], (uint32_t)gold);
  7353. else
  7354. LogCommentFmt(L" value %lld is not %lld", ((uint64_t*)uResults)[0], gold);
  7355. return false;
  7356. }
  7357. return true;
  7358. }
  7359. // Used to duplicate the lower half bits into the upper half bits of an integer
  7360. // To verify that the full value is being considered, many tests duplicate the results into the upper half
  7361. #define SHIFT(val, bits) (((val)&((1ULL<<(bits))-1ULL)) | ((val) << (bits)))
  7362. // Symbolic constants for the results
  7363. #define ADD_IDX 0
  7364. #define UMIN_IDX 1
  7365. #define UMAX_IDX 2
  7366. #define AND_IDX 3
  7367. #define OR_IDX 4
  7368. #define XOR_IDX 5
  7369. #define SMIN_IDX 0
  7370. #define SMAX_IDX 1
  7371. // Verify results for atomic operations. <uResults> and <sResults> are pointers to
  7372. // the readback resource sections containing unsigned and signed integers respectively.
  7373. // <pXchg> is a poiner to the readback resource containing the results of the compare
  7374. // and exchange operations tests. <stride> is the number of bytes between results for
  7375. // all of the results pointers. <maxIdx> is the number of indices that went into the results
  7376. // which is used to determine what the results should be. <bitSize> is the size in bits of
  7377. // the produced results, either 32 or 64.
  7378. void VerifyAtomicResults(const BYTE *uResults, const BYTE *sResults,
  7379. const BYTE *pXchg, size_t stride, size_t maxIdx, size_t bitSize) {
  7380. // Each atomic test performs the test on the value in the lower half
  7381. // and also duplicated in the upper half of the value. The SHIFT macros account for this.
  7382. // This is to verify that the upper bits are considered
  7383. size_t shBits = bitSize/2;
  7384. size_t byteSize = bitSize/8;
  7385. // Test ADD Operation
  7386. // ADD just sums all the indices. The result should the sum of the highest and lowest indices
  7387. // multiplied by half the number of sums.
  7388. size_t addResult = (maxIdx)*(maxIdx-1)/2;
  7389. LogCommentFmt(L"Verifying %d-bit integer atomic add", bitSize);
  7390. // For 32-bit values, the sum exceeds the 16 bit limit, so we can't duplicate
  7391. // That's fine, the duplication is really for 64-bit values.
  7392. if (bitSize < 64)
  7393. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, addResult, byteSize));
  7394. else
  7395. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, SHIFT(addResult, shBits), byteSize));
  7396. // Test MIN and MAX Operations
  7397. // The result of a simple min and max of any sequence of indices would be fairly uninteresting
  7398. // and certain erroneous behavior might mistakenly produce the correct results.
  7399. // To make it interesting, the contributing values will change depending on the evenness of the index.
  7400. // On an even index, min and max operate on the bitflipped index. For signed compares, this is
  7401. // interpretted as a negative value and for unsigned, a very high value.
  7402. // For unsigned min/max, index 0 will be bitflipped to ~0, which is interpretted as the maximum
  7403. // Because zero is manipulated, this leaves 1 as the lowest value.
  7404. LogCommentFmt(L"Verifying %d-bit integer atomic umin", bitSize);
  7405. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMIN_IDX, SHIFT(1ULL, shBits), byteSize)); // UMin
  7406. LogCommentFmt(L"Verifying %d-bit integer atomic umax", bitSize);
  7407. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMAX_IDX, ~0ULL, byteSize)); // UMax
  7408. // For signed min/max, the index just before the last will be bitflipped (maxIndex is always even).
  7409. // This is interpretted as -maxIndex and will be the lowest
  7410. // The maxIndex will be unaltered and interpretted as the highest.
  7411. LogCommentFmt(L"Verifying %d-bit integer atomic smin", bitSize);
  7412. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMIN_IDX, SHIFT(-(maxIdx-1), shBits), byteSize)); // SMin
  7413. LogCommentFmt(L"Verifying %d-bit integer atomic smax", bitSize);
  7414. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMAX_IDX, SHIFT(maxIdx-1, shBits), byteSize)); // SMax
  7415. // Test AND and OR operations.
  7416. // For AND operations, all indices are bitflipped and ANDed to the previous result.
  7417. // This means that the highest bits, which are never set by the contributing indices will be set
  7418. // for all the indices, so they will be set in the final result.
  7419. // For OR operations, the indices are ORed to the previous result unaltered
  7420. // This means that any bit that is set in any index will be set in the final OR result.
  7421. // In practice, this means that the cumulative result of the AND and OR operations
  7422. // are bitflipped versions of each other.
  7423. // Finding the most significant set bit by the max index or next power of two (pot)
  7424. // gives us the pivot point for these results
  7425. size_t nextPot = 1ULL << (bitSize - 1);
  7426. for (;nextPot && !((maxIdx-1) & (nextPot)); nextPot >>= 1) {}
  7427. nextPot <<= 1;
  7428. LogCommentFmt(L"Verifying %d-bit integer atomic and", bitSize);
  7429. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*AND_IDX, ~SHIFT(nextPot-1, shBits), byteSize)); // And
  7430. LogCommentFmt(L"Verifying %d-bit integer atomic or", bitSize);
  7431. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*OR_IDX, SHIFT(nextPot-1, shBits), byteSize)); // Or
  7432. // Test XOR operation
  7433. // For XOR operations, a 1 is shifted by the number of spaces equal to the index and XORed
  7434. // to the previous result. Because this would rapidely shift off the end of the value,
  7435. // giving undefined and uninteresting results, the index is moduloed to a value that will
  7436. // fit within the type size.
  7437. // Because many of the tests use total numbers of lanes that can be evenly divisible by 32 or 64,
  7438. // these values aren't used for the modulo since the expected result might be zero,
  7439. // which could be encountered through erroneous behavior.
  7440. // Instead, one less than the type size in bits is used for the modulo.
  7441. // Even though we don't know the actual order these operations are performed,
  7442. // indices that make up a contiguous sequence of 31 or 63 values can be thought of as one of a series of "passes".
  7443. // Each "pass" sets or clears the bits depending on what's already there.
  7444. // if the number of the pass is odd, the bits are being unset and all above the mod position should be set.
  7445. // If even, the bits are in the process of being set and bits below the mod position should be set.
  7446. size_t xorResult = ((1ULL<<((maxIdx)%(bitSize-1))) -1);
  7447. if (((maxIdx/(bitSize-1))&1)) {
  7448. xorResult ^= ~0ULL;
  7449. // The XOR above may set uninvolved upper bits, messing up the compare. So AND off the uninvolved bits.
  7450. xorResult &= ((1ULL<<(bitSize-1)) - 1);
  7451. }
  7452. LogCommentFmt(L"Verifying %d-bit integer atomic xor", bitSize);
  7453. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*XOR_IDX, xorResult, byteSize));
  7454. // Test CMP/XCHG Operations
  7455. // This tests CompareStore, CompareExchange, and Exchange operations.
  7456. // Unlike above, every lane isn't contributing to the same resource location
  7457. // Instead, every lane competes with a few others to update the same resource location.
  7458. // The first lane to find the contents of their location uninitialized will
  7459. // update it. To verify that upper bits are considered in the comparison and
  7460. // in the assignment, the value stored in the lowest bits is the location index.
  7461. // This ensures that part will be the same for each of the competing lanes.
  7462. // The uppermost bits are updated with the index of the lane that got there first.
  7463. // Subsequent calls to CompareExchange will verify this value matches and alter
  7464. // the content slightly. Finally, a simple check of the output value to what
  7465. // the current lane would expect and a call to exchange will update the value once more
  7466. // To verify this has gone through properly, the upper portion is converted as
  7467. // if to calculate the location index and compared with the location index.
  7468. // It could be the index of any of several lanes that assign to that location,
  7469. // but this ensures that it is not any lane outside of that group.
  7470. // The lower bits are compared to the location index as well.
  7471. LogCommentFmt(L"Verifying %d-bit integer atomic cmp/xchg results", bitSize);
  7472. for (size_t i = 0; i < 64; i++) {
  7473. uint64_t val = *((uint64_t*)(pXchg + i*stride));
  7474. // Verify lower bits match location index exactly
  7475. VERIFY_ARE_EQUAL(i, val & ((1ULL << shBits) - 1ULL));
  7476. // Verify that upper bits contain original index that transforms to location index
  7477. VERIFY_ARE_EQUAL(((val >> shBits)/3)%64, i);
  7478. }
  7479. }
  7480. void VerifyAtomicsRawTest(std::shared_ptr<ShaderOpTestResult> test,
  7481. size_t maxIdx, size_t bitSize) {
  7482. size_t stride = 8;
  7483. // struct mirroring that in the shader
  7484. struct AtomicStuff {
  7485. float prepad[2][3];
  7486. UINT uintEl[4];
  7487. int sintEl[4];
  7488. struct useless {
  7489. uint32_t unused[3];
  7490. } postpad;
  7491. float last;
  7492. };
  7493. MappedData uintData, xchgData;
  7494. test->Test->GetReadBackData("U0", &uintData);
  7495. test->Test->GetReadBackData("U1", &xchgData);
  7496. const AtomicStuff *pStruct = (AtomicStuff *)uintData.data();
  7497. const AtomicStuff *pStrXchg = (AtomicStuff *)xchgData.data();
  7498. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWStructuredBuffer resource", bitSize);
  7499. VerifyAtomicResults((const BYTE*)&(pStruct[0].uintEl[2]), (const BYTE*)&(pStruct[1].sintEl[2]),
  7500. (const BYTE*)&(pStrXchg[0].uintEl[2]), sizeof(AtomicStuff), maxIdx, bitSize);
  7501. const BYTE *pUint = nullptr;
  7502. const BYTE *pXchg = nullptr;
  7503. test->Test->GetReadBackData("U2", &uintData);
  7504. test->Test->GetReadBackData("U3", &xchgData);
  7505. pUint = (BYTE *)uintData.data();
  7506. pXchg = (BYTE *)xchgData.data();
  7507. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWByteAddressBuffer resource", bitSize);
  7508. VerifyAtomicResults(pUint, pUint + stride*6,
  7509. pXchg, stride, maxIdx, bitSize);
  7510. }
  7511. void VerifyAtomicsTypedTest(std::shared_ptr<ShaderOpTestResult> test,
  7512. size_t maxIdx, size_t bitSize) {
  7513. size_t stride = 8;
  7514. MappedData uintData, sintData, xchgData;
  7515. const BYTE *pUint = nullptr;
  7516. const BYTE *pSint = nullptr;
  7517. const BYTE *pXchg = nullptr;
  7518. // Typed resources can't share between 32 and 64 bits
  7519. if (bitSize == 32) {
  7520. test->Test->GetReadBackData("U4", &uintData);
  7521. test->Test->GetReadBackData("U5", &sintData);
  7522. test->Test->GetReadBackData("U6", &xchgData);
  7523. } else {
  7524. test->Test->GetReadBackData("U12", &uintData);
  7525. test->Test->GetReadBackData("U13", &sintData);
  7526. test->Test->GetReadBackData("U14", &xchgData);
  7527. }
  7528. pUint = (BYTE *)uintData.data();
  7529. pSint = (BYTE *)sintData.data();
  7530. pXchg = (BYTE *)xchgData.data();
  7531. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWBuffer resource", bitSize);
  7532. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7533. // Typed resources can't share between 32 and 64 bits
  7534. if (bitSize == 32) {
  7535. test->Test->GetReadBackData("U7", &uintData);
  7536. test->Test->GetReadBackData("U8", &sintData);
  7537. test->Test->GetReadBackData("U9", &xchgData);
  7538. } else {
  7539. test->Test->GetReadBackData("U15", &uintData);
  7540. test->Test->GetReadBackData("U16", &sintData);
  7541. test->Test->GetReadBackData("U17", &xchgData);
  7542. }
  7543. pUint = (BYTE *)uintData.data();
  7544. pSint = (BYTE *)sintData.data();
  7545. pXchg = (BYTE *)xchgData.data();
  7546. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWTexture resource", bitSize);
  7547. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7548. }
  7549. void VerifyAtomicsSharedTest(std::shared_ptr<ShaderOpTestResult> test,
  7550. size_t maxIdx, size_t bitSize) {
  7551. size_t stride = 8;
  7552. MappedData uintData, xchgData;
  7553. const BYTE *pUint = nullptr;
  7554. const BYTE *pXchg = nullptr;
  7555. test->Test->GetReadBackData("U10", &uintData);
  7556. test->Test->GetReadBackData("U11", &xchgData);
  7557. pUint = (BYTE *)uintData.data();
  7558. pXchg = (BYTE *)xchgData.data();
  7559. LogCommentFmt(L"Verifying %d-bit integer atomic operations on groupshared variables", bitSize);
  7560. VerifyAtomicResults(pUint, pUint + stride*6,
  7561. pXchg, stride, maxIdx, bitSize);
  7562. }
  7563. void VerifyAtomicsTest(std::shared_ptr<ShaderOpTestResult> test,
  7564. size_t maxIdx, size_t bitSize) {
  7565. VerifyAtomicsRawTest(test, maxIdx, bitSize);
  7566. VerifyAtomicsTypedTest(test, maxIdx, bitSize);
  7567. }
  7568. TEST_F(ExecutionTest, AtomicsTest) {
  7569. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7570. CComPtr<IStream> pStream;
  7571. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7572. CComPtr<ID3D12Device> pDevice;
  7573. if (!CreateDevice(&pDevice))
  7574. return;
  7575. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7576. std::make_shared<st::ShaderOpSet>();
  7577. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7578. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7579. // Test compute shader
  7580. LogCommentFmt(L"Verifying 32-bit integer atomic operations in compute shader");
  7581. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7582. VerifyAtomicsTest(test, 32*32, 32);
  7583. VerifyAtomicsSharedTest(test, 32*32, 32);
  7584. // Test mesh shader if available
  7585. pShaderOp->CS = nullptr;
  7586. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7587. LogCommentFmt(L"Verifying 32-bit integer atomic operations in amp/mesh/pixel shaders");
  7588. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7589. VerifyAtomicsTest(test, 8*8*2 + 8*8*2 + 64*64, 32);
  7590. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 32);
  7591. }
  7592. // Test Vertex + Pixel shader
  7593. pShaderOp->MS = nullptr;
  7594. LogCommentFmt(L"Verifying 32-bit integer atomic operations in vert/pixel shaders");
  7595. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7596. VerifyAtomicsTest(test, 64*64+6, 32);
  7597. }
  7598. TEST_F(ExecutionTest, Atomics64Test) {
  7599. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7600. CComPtr<IStream> pStream;
  7601. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7602. CComPtr<ID3D12Device> pDevice;
  7603. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7604. return;
  7605. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7606. std::make_shared<st::ShaderOpSet>();
  7607. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7608. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7609. // Reassign shader stages to 64-bit versions
  7610. // Collect 64-bit shaders
  7611. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7612. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7613. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7614. if (!strcmp(S.Name, "CS64")) CS64 = S.Name;
  7615. if (!strcmp(S.Name, "VS64")) VS64 = S.Name;
  7616. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7617. if (!strcmp(S.Name, "AS64")) AS64 = S.Name;
  7618. if (!strcmp(S.Name, "MS64")) MS64 = S.Name;
  7619. }
  7620. pShaderOp->CS = CS64;
  7621. pShaderOp->VS = VS64;
  7622. pShaderOp->PS = PS64;
  7623. pShaderOp->AS = AS64;
  7624. pShaderOp->MS = MS64;
  7625. // Test compute shader
  7626. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in compute shader");
  7627. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7628. VerifyAtomicsRawTest(test, 32*32, 64);
  7629. // Test mesh shader if available
  7630. pShaderOp->CS = nullptr;
  7631. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7632. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in amp/mesh/pixel shader");
  7633. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7634. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7635. }
  7636. // Test Vertex + Pixel shader
  7637. pShaderOp->MS = nullptr;
  7638. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in vert/pixel shader");
  7639. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7640. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7641. }
  7642. TEST_F(ExecutionTest, AtomicsTyped64Test) {
  7643. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7644. CComPtr<IStream> pStream;
  7645. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7646. CComPtr<ID3D12Device> pDevice;
  7647. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7648. return;
  7649. if (!DoesDeviceSupportInt64(pDevice)) {
  7650. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7651. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7652. return;
  7653. }
  7654. if (!DoesDeviceSupportTyped64Atomics(pDevice)) {
  7655. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on typed resources.");
  7656. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7657. return;
  7658. }
  7659. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7660. std::make_shared<st::ShaderOpSet>();
  7661. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7662. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7663. // Reassign shader stages to 64-bit versions
  7664. // Collect 64-bit shaders
  7665. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7666. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7667. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7668. if (!strcmp(S.Name, "CSTY64")) CS64 = S.Name;
  7669. if (!strcmp(S.Name, "VSTY64")) VS64 = S.Name;
  7670. if (!strcmp(S.Name, "PSTY64")) PS64 = S.Name;
  7671. if (!strcmp(S.Name, "ASTY64")) AS64 = S.Name;
  7672. if (!strcmp(S.Name, "MSTY64")) MS64 = S.Name;
  7673. }
  7674. pShaderOp->CS = CS64;
  7675. pShaderOp->VS = VS64;
  7676. pShaderOp->PS = PS64;
  7677. pShaderOp->AS = AS64;
  7678. pShaderOp->MS = MS64;
  7679. // Test compute shader
  7680. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in compute shader");
  7681. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7682. VerifyAtomicsTypedTest(test, 32*32, 64);
  7683. // Test mesh shader if available
  7684. pShaderOp->CS = nullptr;
  7685. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7686. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in amp/mesh/pixel shader");
  7687. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7688. VerifyAtomicsTypedTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7689. }
  7690. // Test Vertex + Pixel shader
  7691. pShaderOp->MS = nullptr;
  7692. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in vert/pixel shader");
  7693. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7694. VerifyAtomicsTypedTest(test, 64*64+6, 64);
  7695. }
  7696. TEST_F(ExecutionTest, AtomicsShared64Test) {
  7697. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7698. CComPtr<IStream> pStream;
  7699. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7700. CComPtr<ID3D12Device> pDevice;
  7701. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7702. return;
  7703. if (!DoesDeviceSupportInt64(pDevice)) {
  7704. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7705. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7706. return;
  7707. }
  7708. if (!DoesDeviceSupportShared64Atomics(pDevice)) {
  7709. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on groupshared variables.");
  7710. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7711. return;
  7712. }
  7713. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7714. std::make_shared<st::ShaderOpSet>();
  7715. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7716. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7717. // Reassign shader stages to 64-bit versions
  7718. // Collect 64-bit shaders
  7719. LPCSTR CS64 = nullptr, PS64 = nullptr;
  7720. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7721. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7722. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7723. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7724. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7725. if (!strcmp(S.Name, "ASSH64")) AS64 = S.Name;
  7726. if (!strcmp(S.Name, "MSSH64")) MS64 = S.Name;
  7727. }
  7728. pShaderOp->CS = CS64;
  7729. pShaderOp->PS = PS64;
  7730. pShaderOp->AS = AS64;
  7731. pShaderOp->MS = MS64;
  7732. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in compute shader");
  7733. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7734. VerifyAtomicsSharedTest(test, 32*32, 64);
  7735. // Test mesh shader if available
  7736. pShaderOp->CS = nullptr;
  7737. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7738. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in amp/mesh/pixel shader");
  7739. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7740. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 64);
  7741. }
  7742. }
  7743. // Float Atomics
  7744. // These operations are almost the same as for the 32-bit and 64-bit integer tests
  7745. // The difference is that there is no need to verify the upper bits.
  7746. // So there is no storing of different parts in upper and lower halves.
  7747. // Additionally, the only operations that are supported on floats
  7748. // are compare and exchange operations. So that's all that is tested here.
  7749. // Just as above, a number of lanes are assigned the same output value.
  7750. // Unlike above, one location is needed for the result of the special NaN test
  7751. // For this reason, the conversion is reduced by one and shifted by one to leave
  7752. // the zero-indexed location available.
  7753. // Verify results for a particular set of atomics results
  7754. void VerifyAtomicFloatResults(const float *results, size_t maxIdx) {
  7755. // The first entry is for NaN to ensure that compares between NaNs succeed
  7756. // The sentinal value is 0.123, for which this compare is sufficient.
  7757. VERIFY_IS_TRUE(results[0] >= 0.120 && results[0] < 0.125);
  7758. // Start at 1 because 0 is just for NaN tests
  7759. for (size_t i = 1; i < 64; i++) {
  7760. VERIFY_ARE_EQUAL((int(results[i])/3)%63 + 1, i);
  7761. }
  7762. }
  7763. void VerifyAtomicsFloatSharedTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7764. MappedData Data;
  7765. const float *pData = nullptr;
  7766. test->Test->GetReadBackData("U4", &Data);
  7767. pData = (float *)Data.data();
  7768. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on groupshared variables");
  7769. VerifyAtomicFloatResults(pData, maxIdx);
  7770. }
  7771. void VerifyAtomicsFloatTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7772. // struct mirroring that in the shader
  7773. struct AtomicStuff {
  7774. float prepad[2][3];
  7775. float fltEl[2];
  7776. struct useless {
  7777. uint32_t unused[3];
  7778. } postpad;
  7779. };
  7780. // Test Compute Shader
  7781. MappedData Data;
  7782. const float *pData = nullptr;
  7783. test->Test->GetReadBackData("U0", &Data);
  7784. const AtomicStuff *pStructData = (AtomicStuff *)Data.data();
  7785. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWStructuredBuffer resources");
  7786. VERIFY_IS_TRUE(pStructData[0].fltEl[1] >= 0.120 && pStructData[0].fltEl[1] < 0.125);
  7787. for (size_t i = 1; i < 64; i++) {
  7788. VERIFY_ARE_EQUAL((int(pStructData[i].fltEl[1])/3)%63 + 1, i);
  7789. }
  7790. test->Test->GetReadBackData("U1", &Data);
  7791. pData = (float *)Data.data();
  7792. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWByteAddressBuffer resources");
  7793. VerifyAtomicFloatResults(pData, maxIdx);
  7794. test->Test->GetReadBackData("U2", &Data);
  7795. pData = (float *)Data.data();
  7796. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWBuffer resources");
  7797. VerifyAtomicFloatResults(pData, maxIdx);
  7798. test->Test->GetReadBackData("U3", &Data);
  7799. pData = (float *)Data.data();
  7800. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWTexture resources");
  7801. VerifyAtomicFloatResults(pData, maxIdx);
  7802. }
  7803. TEST_F(ExecutionTest, AtomicsFloatTest) {
  7804. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7805. CComPtr<IStream> pStream;
  7806. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7807. CComPtr<ID3D12Device> pDevice;
  7808. if (!CreateDevice(&pDevice))
  7809. return;
  7810. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7811. std::make_shared<st::ShaderOpSet>();
  7812. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7813. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("FloatAtomics");
  7814. // Test compute shader
  7815. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in compute shader");
  7816. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7817. VerifyAtomicsFloatTest(test, 32*32);
  7818. VerifyAtomicsFloatSharedTest(test, 32*32);
  7819. // Test mesh shader if available
  7820. pShaderOp->CS = nullptr;
  7821. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7822. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in amp/mesh/pixel shaders");
  7823. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7824. VerifyAtomicsFloatTest(test, 8*8*2 + 8*8*2 + 64*64);
  7825. VerifyAtomicsFloatSharedTest(test, 8*8*2 + 8*8*2);
  7826. }
  7827. // Test Vertex + Pixel shader
  7828. pShaderOp->MS = nullptr;
  7829. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in vert/pixel shaders");
  7830. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7831. VerifyAtomicsFloatTest(test, 64*64+6);
  7832. }
  7833. // The IsHelperLane test renders 3-pixel triangle into 16x16 render target restricted
  7834. // to 2x2 viewport alligned at (0,0) which guarantees it will run in a single quad.
  7835. //
  7836. // Pixels to be rendered*
  7837. // (0,0)* (0,1)*
  7838. // (1,0) (1,1)*
  7839. //
  7840. // Pixel (1,0) is not rendered and is in helper lane.
  7841. //
  7842. // Each thread will use ddx_fine and ddy_fine to read the IsHelperLane() values from other threads.
  7843. // The bottom right pixel will write the results into the UAV buffer.
  7844. //
  7845. // Then the top level pixel (0,0) is discarded and the process above is repeated.
  7846. //
  7847. // Runs with shader models 6.0 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  7848. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6).
  7849. //
  7850. TEST_F(ExecutionTest, HelperLaneTest) {
  7851. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7852. CComPtr<IStream> pStream;
  7853. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7854. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  7855. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7856. #ifdef ISHELPERLANE_PLACEHOLDER
  7857. string args = "-DISHELPERLANE_PLACEHOLDER";
  7858. #else
  7859. string args = "";
  7860. #endif
  7861. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_6 };
  7862. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  7863. D3D_SHADER_MODEL sm = TestShaderModels[i];
  7864. LogCommentFmt(L"Verifying IsHelperLane in shader model 6.%1u", ((UINT)sm & 0x0f));
  7865. CComPtr<ID3D12Device> pDevice;
  7866. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */))
  7867. continue;
  7868. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestNoWave",
  7869. // this callbacked is called when the test is creating the resource to run the test
  7870. [&](LPCSTR Name, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  7871. VERIFY_IS_TRUE(0 == _stricmp(Name, "UAVBuffer0"));
  7872. std::fill(Data.begin(), Data.end(), 0xCC);
  7873. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7874. pShaderOp->Shaders.at(1).Arguments = args.c_str();
  7875. }, ShaderOpSet);
  7876. struct HelperLaneTestResult {
  7877. int32_t is_helper_00;
  7878. int32_t is_helper_10;
  7879. int32_t is_helper_01;
  7880. int32_t is_helper_11;
  7881. };
  7882. MappedData uavData;
  7883. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  7884. HelperLaneTestResult* pTestResults = (HelperLaneTestResult*)uavData.data();
  7885. MappedData renderData;
  7886. test->Test->GetReadBackData("RTarget", &renderData);
  7887. const uint32_t* pPixels = (uint32_t*)renderData.data();
  7888. // before discard
  7889. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_00, 0);
  7890. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_10, 0);
  7891. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_01, 1);
  7892. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_11, 0);
  7893. // after discard
  7894. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_00, 1);
  7895. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_10, 0);
  7896. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_01, 1);
  7897. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_11, 0);
  7898. UNREFERENCED_PARAMETER(pPixels);
  7899. }
  7900. }
  7901. struct HelperLaneWaveTestResult60 {
  7902. // 6.0 wave ops
  7903. int32_t anyTrue;
  7904. int32_t allTrue;
  7905. XMUINT4 ballot;
  7906. int32_t waterfallLoopCount;
  7907. int32_t allEqual;
  7908. int32_t countBits;
  7909. int32_t sum;
  7910. int32_t product;
  7911. int32_t bitAnd;
  7912. int32_t bitOr;
  7913. int32_t bitXor;
  7914. int32_t min;
  7915. int32_t max;
  7916. int32_t prefixCountBits;
  7917. int32_t prefixProduct;
  7918. int32_t prefixSum;
  7919. };
  7920. struct HelperLaneQuadTestResult {
  7921. int32_t is_helper_this;
  7922. int32_t is_helper_across_X;
  7923. int32_t is_helper_across_Y;
  7924. int32_t is_helper_across_Diag;
  7925. };
  7926. struct HelperLaneWaveTestResult65 {
  7927. // 6.5 wave ops
  7928. XMUINT4 match;
  7929. int32_t mpCountBits;
  7930. int32_t mpSum;
  7931. int32_t mpProduct;
  7932. int32_t mpBitAnd;
  7933. int32_t mpBitOr;
  7934. int32_t mpBitXor;
  7935. };
  7936. struct HelperLaneWaveTestResult {
  7937. HelperLaneWaveTestResult60 sm60;
  7938. HelperLaneQuadTestResult sm60_quad;
  7939. HelperLaneWaveTestResult65 sm65;
  7940. };
  7941. struct foo { int32_t a; int32_t b; int32_t c; };
  7942. struct bar { foo f; int32_t d; XMUINT4 g; };
  7943. foo f = {1, 2, 3};
  7944. bar b = { { 1, 2, 3 }, 0, { 1, 2, 3, 4 } };
  7945. HelperLaneWaveTestResult HelperLane_CS_ExpectedResults = {
  7946. // HelperLaneWaveTestResult60
  7947. { 0, 1, { 0x7, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  7948. // HelperLaneQuadTestResult
  7949. { 0, 0, 0, 0 },
  7950. // HelperLaneWaveTestResult65
  7951. { {0x7, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  7952. };
  7953. HelperLaneWaveTestResult HelperLane_VS_ExpectedResults = HelperLane_CS_ExpectedResults;
  7954. HelperLaneWaveTestResult HelperLane_PS_ExpectedResults = {
  7955. // HelperLaneWaveTestResult60
  7956. { 0, 1, { 0xB, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  7957. // HelperLaneQuadTestResult
  7958. { 0, 1, 0, 0 },
  7959. // HelperLaneWaveTestResult65
  7960. { {0xB, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  7961. };
  7962. HelperLaneWaveTestResult HelperLane_PSAfterDiscard_ExpectedResults = {
  7963. // HelperLaneWaveTestResult60
  7964. { 0, 1, { 0xA, 0, 0, 0 }, 2, 1, 2, 8, 16, 1, 0, 0, 10, 1, 1, 4, 2 },
  7965. // HelperLaneQuadTestResult
  7966. { 0, 1, 0, 1 },
  7967. // HelperLaneWaveTestResult65
  7968. { {0xA, 0, 0, 0}, 1, 2, 4, 1, 0, 0 }
  7969. };
  7970. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, uint32_t expectedValue, uint32_t actualValue) {
  7971. bool matches = (expectedValue == actualValue);
  7972. LogCommentFmt(L"%s%s, expected = %u, actual = %u", matches ? L" - " : L"FAILED: ", testDesc, expectedValue, actualValue);
  7973. return matches;
  7974. }
  7975. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, XMUINT4 expectedValue, XMUINT4 actualValue) {
  7976. bool matches = (expectedValue.x == actualValue.x && expectedValue.y == actualValue.y &&
  7977. expectedValue.z == actualValue.z && expectedValue.w == actualValue.w);
  7978. LogCommentFmt(L"%s%s, expected = (0x%X,0x%X,0x%X,0x%X), actual = (0x%X,0x%X,0x%X,0x%X)", matches ? L" - " : L"FAILED: ", testDesc,
  7979. expectedValue.x, expectedValue.y, expectedValue.z, expectedValue.w, actualValue.x, actualValue.y, actualValue.z, actualValue.w);
  7980. return matches;
  7981. }
  7982. bool VerifyHelperLaneWaveResults(ExecutionTest::D3D_SHADER_MODEL sm, HelperLaneWaveTestResult& testResults, HelperLaneWaveTestResult& expectedResults, bool verifyQuads) {
  7983. bool passed = true;
  7984. {
  7985. HelperLaneWaveTestResult60& tr60 = testResults.sm60;
  7986. HelperLaneWaveTestResult60& tr60exp = expectedResults.sm60;
  7987. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAnyTrue(IsHelperLane())", tr60exp.anyTrue, tr60.anyTrue);
  7988. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllTrue(!IsHelperLane())", tr60exp.allTrue, tr60.allTrue);
  7989. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBallot(true) has exactly 3 bits set", tr60exp.ballot, tr60.ballot);
  7990. passed &= HelperLaneResultLogAndVerify(L"!WaveReadLaneFirst(IsHelperLane()) && WaveIsFirstLane() in a waterfall loop", tr60exp.waterfallLoopCount, tr60.waterfallLoopCount);
  7991. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllEqual(IsHelperLane())", tr60exp.allEqual, tr60.allEqual);
  7992. passed &= HelperLaneResultLogAndVerify(L"WaveActiveCountBits(true)", tr60exp.countBits, tr60.countBits);
  7993. passed &= HelperLaneResultLogAndVerify(L"WaveActiveSum(4)", tr60exp.sum, tr60.sum);
  7994. passed &= HelperLaneResultLogAndVerify(L"WaveActiveProduct(4)", tr60exp.product, tr60.product);
  7995. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitAnd(!IsHelperLane())", tr60exp.bitAnd, tr60.bitAnd);
  7996. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitOr(IsHelperLane())", tr60exp.bitOr, tr60.bitOr);
  7997. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitXor(IsHelperLane())", tr60exp.bitXor, tr60.bitXor);
  7998. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMin(IsHelperLane() ? 1 : 10)", tr60exp.min, tr60.min);
  7999. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMax(IsHelperLane() ? 10 : 1)", tr60exp.max, tr60.max);
  8000. passed &= HelperLaneResultLogAndVerify(L"WavePrefixCountBits(1)", tr60exp.prefixCountBits, tr60.prefixCountBits);
  8001. passed &= HelperLaneResultLogAndVerify(L"WavePrefixProduct(4)", tr60exp.prefixProduct, tr60.prefixProduct);
  8002. passed &= HelperLaneResultLogAndVerify(L"WavePrefixSum(2)", tr60exp.prefixSum, tr60.prefixSum);
  8003. }
  8004. if (verifyQuads) {
  8005. HelperLaneQuadTestResult& quad_tr = testResults.sm60_quad;
  8006. HelperLaneQuadTestResult& quad_tr_exp = expectedResults.sm60_quad;
  8007. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 3 / pixel (1,1) - IsHelperLane()", quad_tr_exp.is_helper_this, quad_tr.is_helper_this);
  8008. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 2 / pixel (0,1) - IsHelperLane()", quad_tr_exp.is_helper_across_X, quad_tr.is_helper_across_X);
  8009. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 1 / pixel (1,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Y, quad_tr.is_helper_across_Y);
  8010. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 0 / pixel (0,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Diag, quad_tr.is_helper_across_Diag);
  8011. }
  8012. if (sm >= D3D_SHADER_MODEL_6_5) {
  8013. HelperLaneWaveTestResult65& tr65 = testResults.sm65;
  8014. HelperLaneWaveTestResult65& tr65exp = expectedResults.sm65;
  8015. passed &= HelperLaneResultLogAndVerify(L"WaveMatch(true) has exactly 3 bits set", tr65exp.match, tr65.match);
  8016. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixCountBits(1, no_masked_bits)", tr65exp.mpCountBits, tr65.mpCountBits);
  8017. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixSum(2, no_masked_bits)", tr65exp.mpSum, tr65.mpSum);
  8018. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixProduct(4, no_masked_bits)", tr65exp.mpProduct, tr65.mpProduct);
  8019. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixAnd(IsHelperLane() ? 0 : 1, no_masked_bits)", tr65exp.mpBitAnd, tr65.mpBitAnd);
  8020. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixOr(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitOr, tr65.mpBitOr);
  8021. passed &= HelperLaneResultLogAndVerify(L"verify WaveMultiPrefixXor(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitXor, tr65.mpBitXor);
  8022. }
  8023. return passed;
  8024. }
  8025. void CleanUAVBuffer0Buffer(LPCSTR BufferName, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  8026. VERIFY_IS_TRUE(0 == _stricmp(BufferName, "UAVBuffer0"));
  8027. std::fill(Data.begin(), Data.end(), 0xCC);
  8028. }
  8029. //
  8030. // The IsHelperLane test that use Wave intrinsics to verify IsHelperLane() and Wave operations on active lanes.
  8031. //
  8032. // Runs with shader models 6.0, 6.5 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  8033. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6) and the shader model 6.5 wave intrinsics (sm >= 6.5).
  8034. //
  8035. // For compute and vertex shaders IsHelperLane() always returns false and might be optimized away in the front end.
  8036. // However it can be exposed to the driver in CS/VS through an exported function in a library so drivers need
  8037. // to be prepared to handle it. For this reason the test is compiled with disabled optimizations (/Od).
  8038. // The tests are also validating that wave intrinsics operate correctly with 3 threads in a CS or 3 vertices
  8039. // in a VS where the rest of the lanes in the wave are not active (dead lanes).
  8040. //
  8041. TEST_F(ExecutionTest, HelperLaneTestWave) {
  8042. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  8043. CComPtr<IStream> pStream;
  8044. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  8045. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  8046. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8047. st::ShaderOp* pShaderOp = ShaderOpSet->GetShaderOp("HelperLaneTestWave");
  8048. #ifdef ISHELPERLANE_PLACEHOLDER
  8049. LPCSTR args = "/Od -DISHELPERLANE_PLACEHOLDER";
  8050. #else
  8051. LPCSTR args = "/Od";
  8052. #endif
  8053. if (args[0]) {
  8054. for (st::ShaderOpShader& S : pShaderOp->Shaders)
  8055. S.Arguments = args;
  8056. }
  8057. bool testPassed = true;
  8058. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_5, D3D_SHADER_MODEL_6_6 };
  8059. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  8060. D3D_SHADER_MODEL sm = TestShaderModels[i];
  8061. LogCommentFmt(L"\r\nVerifying IsHelperLane using Wave intrinsics in shader model 6.%1u", ((UINT)sm & 0x0f));
  8062. bool smPassed = true;
  8063. CComPtr<ID3D12Device> pDevice;
  8064. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */)) {
  8065. continue;
  8066. }
  8067. if (!DoesDeviceSupportWaveOps(pDevice)) {
  8068. LogCommentFmt(L"Device does not support wave operations in shader model 6.%1u", ((UINT)sm & 0x0f));
  8069. continue;
  8070. }
  8071. if (sm >= D3D_SHADER_MODEL_6_5) {
  8072. // Reassign shader stages to 6.5 versions
  8073. LPCSTR CS65 = nullptr, VS65 = nullptr, PS65 = nullptr;
  8074. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8075. if (!strcmp(S.Name, "CS65")) CS65 = S.Name;
  8076. if (!strcmp(S.Name, "VS65")) VS65 = S.Name;
  8077. if (!strcmp(S.Name, "PS65")) PS65 = S.Name;
  8078. }
  8079. pShaderOp->CS = CS65;
  8080. pShaderOp->VS = VS65;
  8081. pShaderOp->PS = PS65;
  8082. }
  8083. const unsigned CS_INDEX = 0, VS_INDEX = 0, PS_INDEX = 1, PS_INDEX_AFTER_DISCARD = 2;
  8084. // Test Compute shader
  8085. {
  8086. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave",
  8087. CleanUAVBuffer0Buffer, ShaderOpSet);
  8088. MappedData uavData;
  8089. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8090. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8091. LogCommentFmt(L"\r\nCompute shader");
  8092. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[CS_INDEX], HelperLane_CS_ExpectedResults, true);
  8093. }
  8094. // Test Vertex + Pixel shader
  8095. {
  8096. pShaderOp->CS = nullptr;
  8097. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave", CleanUAVBuffer0Buffer, ShaderOpSet);
  8098. MappedData uavData;
  8099. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8100. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8101. LogCommentFmt(L"\r\nVertex shader");
  8102. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[VS_INDEX], HelperLane_VS_ExpectedResults, false);
  8103. LogCommentFmt(L"\r\nPixel shader");
  8104. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX], HelperLane_PS_ExpectedResults, true);
  8105. LogCommentFmt(L"\r\nPixel shader with discarded pixel");
  8106. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX_AFTER_DISCARD], HelperLane_PSAfterDiscard_ExpectedResults, true);
  8107. MappedData renderData;
  8108. test->Test->GetReadBackData("RTarget", &renderData);
  8109. const uint32_t* pPixels = (uint32_t*)renderData.data();
  8110. UNREFERENCED_PARAMETER(pPixels);
  8111. }
  8112. testPassed &= smPassed;
  8113. }
  8114. VERIFY_ARE_EQUAL(testPassed, true);
  8115. }
  8116. #ifndef _HLK_CONF
  8117. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  8118. char **pReadBackDump) {
  8119. std::stringstream str;
  8120. unsigned count = 0;
  8121. for (auto &R : pShaderOp->Resources) {
  8122. if (!R.ReadBack)
  8123. continue;
  8124. ++count;
  8125. str << "Resource: " << R.Name << "\r\n";
  8126. // Find a descriptor that can tell us how to dump this resource.
  8127. bool found = false;
  8128. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  8129. for (auto &D : Heaps.Descriptors) {
  8130. if (_stricmp(D.ResName, R.Name) != 0) {
  8131. continue;
  8132. }
  8133. found = true;
  8134. if (_stricmp(D.Kind, "UAV") != 0) {
  8135. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  8136. break;
  8137. }
  8138. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  8139. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  8140. break;
  8141. }
  8142. // We can map back to the structure if a structured buffer via the shader, but
  8143. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  8144. MappedData data;
  8145. pTest->GetReadBackData(R.Name, &data);
  8146. uint32_t *pData = (uint32_t *)data.data();
  8147. size_t u32_count = R.Desc.Width / sizeof(uint32_t);
  8148. for (size_t i = 0; i < u32_count; ++i) {
  8149. float f = *(float *)pData;
  8150. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  8151. << std::dec << " " << f << "\r\n";
  8152. ++pData;
  8153. }
  8154. break;
  8155. }
  8156. if (found) break;
  8157. }
  8158. if (!found) {
  8159. str << "Unable to find a view for the resource.\r\n";
  8160. }
  8161. }
  8162. str << "Resources read back: " << count << "\r\n";
  8163. std::string s(str.str());
  8164. CComHeapPtr<char> pDump;
  8165. if (!pDump.Allocate(s.size() + 1))
  8166. throw std::bad_alloc();
  8167. memcpy(pDump.m_pData, s.data(), s.size());
  8168. pDump.m_pData[s.size()] = '\0';
  8169. *pReadBackDump = pDump.Detach();
  8170. }
  8171. // This is the exported interface by use from HLSLHost.exe.
  8172. // It's exclusive with the use of the DLL as a TAEF target.
  8173. extern "C" {
  8174. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  8175. HRESULT hr = EnableExperimentalShaderModels();
  8176. if (FAILED(hr)) {
  8177. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  8178. }
  8179. return S_OK;
  8180. }
  8181. __declspec(dllexport) HRESULT WINAPI
  8182. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  8183. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  8184. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  8185. HRESULT hr;
  8186. if (pReadBackDump) *pReadBackDump = nullptr;
  8187. st::SetOutputFn(pStrCtx, pOutputStrFn);
  8188. CComPtr<ID3D12InfoQueue> pInfoQueue;
  8189. CComHeapPtr<char> pDump;
  8190. bool FilterCreation = false;
  8191. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  8192. // Creation is largely driven by inputs, so don't log create/destroy messages.
  8193. pInfoQueue->PushEmptyStorageFilter();
  8194. pInfoQueue->PushEmptyRetrievalFilter();
  8195. if (FilterCreation) {
  8196. D3D12_INFO_QUEUE_FILTER filter;
  8197. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  8198. ZeroMemory(&filter, sizeof(filter));
  8199. filter.DenyList.NumCategories = _countof(denyCategories);
  8200. filter.DenyList.pCategoryList = denyCategories;
  8201. pInfoQueue->PushStorageFilter(&filter);
  8202. }
  8203. }
  8204. else {
  8205. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  8206. }
  8207. try {
  8208. dxc::DxcDllSupport m_support;
  8209. m_support.Initialize();
  8210. const char *pName = nullptr;
  8211. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, strlen(pText));
  8212. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  8213. std::make_shared<st::ShaderOpSet>();
  8214. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8215. st::ShaderOp *pShaderOp;
  8216. if (pName == nullptr) {
  8217. if (ShaderOpSet->ShaderOps.size() != 1) {
  8218. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  8219. return E_FAIL;
  8220. }
  8221. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  8222. }
  8223. else {
  8224. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  8225. }
  8226. if (pShaderOp == nullptr) {
  8227. std::string msg = "Unable to find shader op ";
  8228. msg += pName;
  8229. msg += "; available ops";
  8230. const char sep = ':';
  8231. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  8232. msg += sep;
  8233. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  8234. }
  8235. CA2W msgWide(msg.c_str());
  8236. pOutputStrFn(pStrCtx, msgWide);
  8237. return E_FAIL;
  8238. }
  8239. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  8240. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  8241. test->SetDxcSupport(&m_support);
  8242. test->RunShaderOp(pShaderOp);
  8243. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  8244. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  8245. if (!pShaderOp->IsCompute()) {
  8246. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  8247. test->GetPipelineStats(&stats);
  8248. wchar_t statsText[400];
  8249. StringCchPrintfW(statsText, _countof(statsText),
  8250. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  8251. L"Vertex shader invocations: %I64u\r\n"
  8252. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  8253. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  8254. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  8255. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  8256. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  8257. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  8258. stats.DSInvocations, stats.CSInvocations);
  8259. pOutputStrFn(pStrCtx, statsText);
  8260. }
  8261. if (pReadBackDump) {
  8262. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  8263. }
  8264. hr = S_OK;
  8265. }
  8266. catch (const CAtlException &E)
  8267. {
  8268. hr = E.m_hr;
  8269. }
  8270. catch (const std::bad_alloc &)
  8271. {
  8272. hr = E_OUTOFMEMORY;
  8273. }
  8274. catch (const std::exception &)
  8275. {
  8276. hr = E_FAIL;
  8277. }
  8278. // Drain the device message queue if available.
  8279. if (pInfoQueue != nullptr) {
  8280. wchar_t buf[200];
  8281. StringCchPrintfW(buf, _countof(buf),
  8282. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  8283. L"allowed/denied by storage filter=%u/%u "
  8284. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  8285. (unsigned)pInfoQueue->GetNumStoredMessages(),
  8286. (unsigned)pInfoQueue->GetMessageCountLimit(),
  8287. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  8288. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  8289. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  8290. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  8291. pOutputStrFn(pStrCtx, buf);
  8292. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  8293. pInfoQueue->ClearStoredMessages();
  8294. pInfoQueue->PopRetrievalFilter();
  8295. pInfoQueue->PopStorageFilter();
  8296. if (FilterCreation) {
  8297. pInfoQueue->PopStorageFilter();
  8298. }
  8299. }
  8300. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  8301. return hr;
  8302. }
  8303. }
  8304. #endif
  8305. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  8306. // Do not remove the line above - it is used by TranslateExecutionTest.py