ExecutionTest.cpp 389 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499
  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. ////////////////////////////////////////////////////////////
  13. // Define this until fallback implementation is complete.
  14. #define ISHELPERLANE_PLACEHOLDER
  15. ////////////////////////////////////////////////////////////
  16. #include <algorithm>
  17. #include <memory>
  18. #include <array>
  19. #include <vector>
  20. #include <string>
  21. #include <map>
  22. #include <unordered_set>
  23. #include <strstream>
  24. #include <iomanip>
  25. #include "dxc/Test/CompilationResult.h"
  26. #include "dxc/Test/HLSLTestData.h"
  27. #include <Shlwapi.h>
  28. #include <atlcoll.h>
  29. #include <locale>
  30. #include <algorithm>
  31. #undef _read
  32. #include "WexTestClass.h"
  33. #include "dxc/Test/HlslTestUtils.h"
  34. #include "dxc/Test/DxcTestUtils.h"
  35. #include "dxc/Support/Global.h"
  36. #include "dxc/Support/WinIncludes.h"
  37. #include "dxc/Support/FileIOHelper.h"
  38. #include "dxc/Support/Unicode.h"
  39. //
  40. // d3d12.h and dxgi1_4.h are included in the Windows 10 SDK
  41. // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899120(v=vs.85).aspx
  42. // https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
  43. //
  44. #include <d3d12.h>
  45. #include <dxgi1_4.h>
  46. #include <DXGIDebug.h>
  47. #include "dxc/Support/d3dx12.h"
  48. #include <DirectXMath.h>
  49. #include <strsafe.h>
  50. #include <d3dcompiler.h>
  51. #include <wincodec.h>
  52. #include "ShaderOpTest.h"
  53. #pragma comment(lib, "d3dcompiler.lib")
  54. #pragma comment(lib, "windowscodecs.lib")
  55. #pragma comment(lib, "dxguid.lib")
  56. #pragma comment(lib, "version.lib")
  57. // A more recent Windows SDK than currently required is needed for these.
  58. typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)(
  59. UINT NumFeatures,
  60. __in_ecount(NumFeatures) const IID* pIIDs,
  61. __in_ecount_opt(NumFeatures) void* pConfigurationStructs,
  62. __in_ecount_opt(NumFeatures) UINT* pConfigurationStructSizes);
  63. static const GUID D3D12ExperimentalShaderModelsID = { /* 76f5573e-f13a-40f5-b297-81ce9e18933f */
  64. 0x76f5573e,
  65. 0xf13a,
  66. 0x40f5,
  67. { 0xb2, 0x97, 0x81, 0xce, 0x9e, 0x18, 0x93, 0x3f }
  68. };
  69. using namespace DirectX;
  70. using namespace hlsl_test;
  71. template <typename TSequence, typename T>
  72. static bool contains(TSequence s, const T &val) {
  73. return std::cend(s) != std::find(std::cbegin(s), std::cend(s), val);
  74. }
  75. template <typename InputIterator, typename T>
  76. static bool contains(InputIterator b, InputIterator e, const T &val) {
  77. return e != std::find(b, e, val);
  78. }
  79. static HRESULT EnableExperimentalShaderModels() {
  80. HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
  81. if (hRuntime == NULL) {
  82. return HRESULT_FROM_WIN32(GetLastError());
  83. }
  84. D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
  85. (D3D12EnableExperimentalFeaturesFn)GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures");
  86. if (pD3D12EnableExperimentalFeatures == nullptr) {
  87. FreeLibrary(hRuntime);
  88. return HRESULT_FROM_WIN32(GetLastError());
  89. }
  90. HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
  91. FreeLibrary(hRuntime);
  92. return hr;
  93. }
  94. static HRESULT ReportLiveObjects() {
  95. CComPtr<IDXGIDebug1> pDebug;
  96. IFR(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)));
  97. IFR(pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL));
  98. return S_OK;
  99. }
  100. static void WriteInfoQueueMessages(void *pStrCtx, st::OutputStringFn pOutputStrFn, ID3D12InfoQueue *pInfoQueue) {
  101. bool allMessagesOK = true;
  102. UINT64 count = pInfoQueue->GetNumStoredMessages();
  103. CAtlArray<BYTE> message;
  104. for (UINT64 i = 0; i < count; ++i) {
  105. // 'GetMessageA' rather than 'GetMessage' is an artifact of user32 headers.
  106. SIZE_T msgLen = 0;
  107. if (FAILED(pInfoQueue->GetMessageA(i, nullptr, &msgLen))) {
  108. allMessagesOK = false;
  109. continue;
  110. }
  111. if (message.GetCount() < msgLen) {
  112. if (!message.SetCount(msgLen)) {
  113. allMessagesOK = false;
  114. continue;
  115. }
  116. }
  117. D3D12_MESSAGE *pMessage = (D3D12_MESSAGE *)message.GetData();
  118. if (FAILED(pInfoQueue->GetMessageA(i, pMessage, &msgLen))) {
  119. allMessagesOK = false;
  120. continue;
  121. }
  122. CA2W msgW(pMessage->pDescription, CP_ACP);
  123. pOutputStrFn(pStrCtx, msgW.m_psz);
  124. pOutputStrFn(pStrCtx, L"\r\n");
  125. }
  126. if (!allMessagesOK) {
  127. pOutputStrFn(pStrCtx, L"Failed to retrieve some messages.\r\n");
  128. }
  129. }
  130. class CComContext {
  131. private:
  132. bool m_init;
  133. public:
  134. CComContext() : m_init(false) {}
  135. ~CComContext() { Dispose(); }
  136. void Dispose() { if (!m_init) return; m_init = false; CoUninitialize(); }
  137. HRESULT Init() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { m_init = true; } return hr; }
  138. };
  139. static void SavePixelsToFile(LPCVOID pPixels, DXGI_FORMAT format, UINT32 m_width, UINT32 m_height, LPCWSTR pFileName) {
  140. CComContext ctx;
  141. CComPtr<IWICImagingFactory> pFactory;
  142. CComPtr<IWICBitmap> pBitmap;
  143. CComPtr<IWICBitmapEncoder> pEncoder;
  144. CComPtr<IWICBitmapFrameEncode> pFrameEncode;
  145. CComPtr<hlsl::AbstractMemoryStream> pStream;
  146. CComPtr<IMalloc> pMalloc;
  147. struct PF {
  148. DXGI_FORMAT Format;
  149. GUID PixelFormat;
  150. UINT32 PixelSize;
  151. bool operator==(DXGI_FORMAT F) const {
  152. return F == Format;
  153. }
  154. } Vals[] = {
  155. // Add more pixel format mappings as needed.
  156. { DXGI_FORMAT_R8G8B8A8_UNORM, GUID_WICPixelFormat32bppRGBA, 4 }
  157. };
  158. PF *pFormat = std::find(Vals, Vals + _countof(Vals), format);
  159. VERIFY_SUCCEEDED(ctx.Init());
  160. VERIFY_SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory));
  161. VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
  162. VERIFY_SUCCEEDED(hlsl::CreateMemoryStream(pMalloc, &pStream));
  163. VERIFY_ARE_NOT_EQUAL(pFormat, Vals + _countof(Vals));
  164. VERIFY_SUCCEEDED(pFactory->CreateBitmapFromMemory(m_width, m_height, pFormat->PixelFormat, m_width * pFormat->PixelSize, m_width * m_height * pFormat->PixelSize, (BYTE *)pPixels, &pBitmap));
  165. VERIFY_SUCCEEDED(pFactory->CreateEncoder(GUID_ContainerFormatBmp, nullptr, &pEncoder));
  166. VERIFY_SUCCEEDED(pEncoder->Initialize(pStream, WICBitmapEncoderNoCache));
  167. VERIFY_SUCCEEDED(pEncoder->CreateNewFrame(&pFrameEncode, nullptr));
  168. VERIFY_SUCCEEDED(pFrameEncode->Initialize(nullptr));
  169. VERIFY_SUCCEEDED(pFrameEncode->WriteSource(pBitmap, nullptr));
  170. VERIFY_SUCCEEDED(pFrameEncode->Commit());
  171. VERIFY_SUCCEEDED(pEncoder->Commit());
  172. hlsl::WriteBinaryFile(pFileName, pStream->GetPtr(), pStream->GetPtrSize());
  173. }
  174. // Checks if the given warp version supports the given operation.
  175. bool IsValidWarpDllVersion(unsigned int minBuildNumber) {
  176. HMODULE pLibrary = LoadLibrary("D3D10Warp.dll");
  177. if (pLibrary) {
  178. char path[MAX_PATH];
  179. DWORD length = GetModuleFileName(pLibrary, path, MAX_PATH);
  180. if (length) {
  181. DWORD dwVerHnd = 0;
  182. DWORD dwVersionInfoSize = GetFileVersionInfoSize(path, &dwVerHnd);
  183. std::unique_ptr<int[]> VffInfo(new int[dwVersionInfoSize]);
  184. if (GetFileVersionInfo(path, NULL, dwVersionInfoSize, VffInfo.get())) {
  185. LPVOID versionInfo;
  186. UINT size;
  187. if (VerQueryValue(VffInfo.get(), "\\", &versionInfo, &size)) {
  188. if (size) {
  189. VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)versionInfo;
  190. unsigned int warpBuildNumber = verInfo->dwFileVersionLS >> 16 & 0xffff;
  191. if (verInfo->dwSignature == 0xFEEF04BD && warpBuildNumber >= minBuildNumber) {
  192. return true;
  193. }
  194. }
  195. }
  196. }
  197. }
  198. FreeLibrary(pLibrary);
  199. }
  200. return false;
  201. }
  202. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS2
  203. #define D3D12_FEATURE_D3D12_OPTIONS3 ((D3D12_FEATURE)21)
  204. #define NTDDI_WIN10_RS3 0x0A000004 /* ABRACADABRA_WIN10_RS2 */
  205. typedef
  206. enum D3D12_COMMAND_LIST_SUPPORT_FLAGS
  207. {
  208. D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0,
  209. D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT = (1 << D3D12_COMMAND_LIST_TYPE_DIRECT),
  210. D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE = (1 << D3D12_COMMAND_LIST_TYPE_BUNDLE),
  211. D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE = (1 << D3D12_COMMAND_LIST_TYPE_COMPUTE),
  212. D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY = (1 << D3D12_COMMAND_LIST_TYPE_COPY),
  213. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE = (1 << 4),
  214. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS = (1 << 5)
  215. } D3D12_COMMAND_LIST_SUPPORT_FLAGS;
  216. typedef
  217. enum D3D12_VIEW_INSTANCING_TIER
  218. {
  219. D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0,
  220. D3D12_VIEW_INSTANCING_TIER_1 = 1,
  221. D3D12_VIEW_INSTANCING_TIER_2 = 2,
  222. D3D12_VIEW_INSTANCING_TIER_3 = 3
  223. } D3D12_VIEW_INSTANCING_TIER;
  224. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS3
  225. {
  226. _Out_ BOOL CopyQueueTimestampQueriesSupported;
  227. _Out_ BOOL CastingFullyTypedFormatSupported;
  228. _Out_ DWORD WriteBufferImmediateSupportFlags;
  229. _Out_ D3D12_VIEW_INSTANCING_TIER ViewInstancingTier;
  230. _Out_ BOOL BarycentricsSupported;
  231. } D3D12_FEATURE_DATA_D3D12_OPTIONS3;
  232. #endif
  233. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS3
  234. #define D3D12_FEATURE_D3D12_OPTIONS4 ((D3D12_FEATURE)23)
  235. typedef enum D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER
  236. {
  237. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_0,
  238. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1,
  239. } D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER;
  240. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS4
  241. {
  242. _Out_ BOOL ReservedBufferPlacementSupported;
  243. _Out_ D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER SharedResourceCompatibilityTier;
  244. _Out_ BOOL Native16BitShaderOpsSupported;
  245. } D3D12_FEATURE_DATA_D3D12_OPTIONS4;
  246. #endif
  247. // Virtual class to compute the expected result given a set of inputs
  248. struct TableParameter;
  249. class ExecutionTest {
  250. public:
  251. // By default, ignore these tests, which require a recent build to run properly.
  252. BEGIN_TEST_CLASS(ExecutionTest)
  253. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  254. TEST_CLASS_PROPERTY(L"Ignore", L"true")
  255. TEST_METHOD_PROPERTY(L"Priority", L"0")
  256. END_TEST_CLASS()
  257. TEST_CLASS_SETUP(ExecutionTestClassSetup)
  258. TEST_METHOD(BasicComputeTest);
  259. TEST_METHOD(BasicTriangleTest);
  260. TEST_METHOD(BasicTriangleOpTest);
  261. BEGIN_TEST_METHOD(BasicTriangleOpTestHalf)
  262. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  263. END_TEST_METHOD()
  264. TEST_METHOD(OutOfBoundsTest);
  265. TEST_METHOD(SaturateTest);
  266. TEST_METHOD(SignTest);
  267. TEST_METHOD(Int64Test);
  268. TEST_METHOD(LifetimeIntrinsicTest)
  269. TEST_METHOD(WaveIntrinsicsTest);
  270. TEST_METHOD(WaveIntrinsicsDDITest);
  271. TEST_METHOD(WaveIntrinsicsInPSTest);
  272. TEST_METHOD(WaveSizeTest);
  273. TEST_METHOD(PartialDerivTest);
  274. TEST_METHOD(DerivativesTest);
  275. TEST_METHOD(ComputeSampleTest);
  276. TEST_METHOD(AtomicsTest);
  277. TEST_METHOD(Atomics64Test);
  278. TEST_METHOD(AtomicsTyped64Test);
  279. TEST_METHOD(AtomicsShared64Test);
  280. TEST_METHOD(AtomicsFloatTest);
  281. TEST_METHOD(HelperLaneTest);
  282. BEGIN_TEST_METHOD(HelperLaneTestWave)
  283. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp handles this
  284. END_TEST_METHOD(HelperLaneTestWave)
  285. TEST_METHOD(SignatureResourcesTest)
  286. TEST_METHOD(DynamicResourcesTest)
  287. TEST_METHOD(QuadReadTest)
  288. BEGIN_TEST_METHOD(CBufferTestHalf)
  289. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  290. END_TEST_METHOD()
  291. TEST_METHOD(BasicShaderModel61);
  292. BEGIN_TEST_METHOD(BasicShaderModel63)
  293. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  294. END_TEST_METHOD()
  295. BEGIN_TEST_METHOD(WaveIntrinsicsActiveIntTest)
  296. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveIntTable")
  297. END_TEST_METHOD()
  298. BEGIN_TEST_METHOD(WaveIntrinsicsActiveUintTest)
  299. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveUintTable")
  300. END_TEST_METHOD()
  301. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixIntTest)
  302. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixIntTable")
  303. END_TEST_METHOD()
  304. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixUintTest)
  305. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixUintTable")
  306. END_TEST_METHOD()
  307. BEGIN_TEST_METHOD(WaveIntrinsicsSM65IntTest)
  308. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixIntTable")
  309. END_TEST_METHOD()
  310. BEGIN_TEST_METHOD(WaveIntrinsicsSM65UintTest)
  311. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixUintTable")
  312. END_TEST_METHOD()
  313. // TAEF data-driven tests.
  314. BEGIN_TEST_METHOD(UnaryFloatOpTest)
  315. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
  316. END_TEST_METHOD()
  317. BEGIN_TEST_METHOD(BinaryFloatOpTest)
  318. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
  319. END_TEST_METHOD()
  320. BEGIN_TEST_METHOD(TertiaryFloatOpTest)
  321. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
  322. END_TEST_METHOD()
  323. BEGIN_TEST_METHOD(UnaryHalfOpTest)
  324. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
  325. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  326. END_TEST_METHOD()
  327. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  328. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  329. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  330. END_TEST_METHOD()
  331. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  332. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  333. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  334. END_TEST_METHOD()
  335. BEGIN_TEST_METHOD(UnaryIntOpTest)
  336. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  337. END_TEST_METHOD()
  338. BEGIN_TEST_METHOD(BinaryIntOpTest)
  339. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  340. END_TEST_METHOD()
  341. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  342. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  343. END_TEST_METHOD()
  344. BEGIN_TEST_METHOD(UnaryUintOpTest)
  345. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  346. END_TEST_METHOD()
  347. BEGIN_TEST_METHOD(BinaryUintOpTest)
  348. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  349. END_TEST_METHOD()
  350. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  351. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  352. END_TEST_METHOD()
  353. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  354. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  355. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  356. END_TEST_METHOD()
  357. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  358. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  359. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  360. END_TEST_METHOD()
  361. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  362. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  363. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  364. END_TEST_METHOD()
  365. BEGIN_TEST_METHOD(UnaryUint16OpTest)
  366. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  367. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  368. END_TEST_METHOD()
  369. BEGIN_TEST_METHOD(BinaryUint16OpTest)
  370. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  371. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  372. END_TEST_METHOD()
  373. BEGIN_TEST_METHOD(TertiaryUint16OpTest)
  374. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  375. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  376. END_TEST_METHOD()
  377. BEGIN_TEST_METHOD(DotTest)
  378. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  379. END_TEST_METHOD()
  380. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  381. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  382. END_TEST_METHOD()
  383. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  384. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  385. END_TEST_METHOD()
  386. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  387. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  388. END_TEST_METHOD()
  389. BEGIN_TEST_METHOD(Msad4Test)
  390. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  391. END_TEST_METHOD()
  392. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  393. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  394. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  395. END_TEST_METHOD()
  396. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  397. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  398. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  399. END_TEST_METHOD()
  400. TEST_METHOD(BarycentricsTest);
  401. TEST_METHOD(ComputeRawBufferLdStI32);
  402. TEST_METHOD(ComputeRawBufferLdStFloat);
  403. BEGIN_TEST_METHOD(ComputeRawBufferLdStI64)
  404. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  405. END_TEST_METHOD()
  406. BEGIN_TEST_METHOD(ComputeRawBufferLdStDouble)
  407. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  408. END_TEST_METHOD()
  409. BEGIN_TEST_METHOD(ComputeRawBufferLdStI16)
  410. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  411. END_TEST_METHOD()
  412. BEGIN_TEST_METHOD(ComputeRawBufferLdStHalf)
  413. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  414. END_TEST_METHOD()
  415. TEST_METHOD(GraphicsRawBufferLdStI32);
  416. TEST_METHOD(GraphicsRawBufferLdStFloat);
  417. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI64)
  418. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  419. END_TEST_METHOD()
  420. BEGIN_TEST_METHOD(GraphicsRawBufferLdStDouble)
  421. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  422. END_TEST_METHOD()
  423. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI16)
  424. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  425. END_TEST_METHOD()
  426. BEGIN_TEST_METHOD(GraphicsRawBufferLdStHalf)
  427. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  428. END_TEST_METHOD()
  429. BEGIN_TEST_METHOD(PackUnpackTest)
  430. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#PackUnpackOpTable")
  431. END_TEST_METHOD()
  432. dxc::DxcDllSupport m_support;
  433. VersionSupportInfo m_ver;
  434. bool m_ExperimentalModeEnabled = false;
  435. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  436. // Do not remove the following line - it is used by TranslateExecutionTest.py
  437. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  438. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  439. // require the Windows 10 SDK.
  440. typedef enum D3D_SHADER_MODEL {
  441. D3D_SHADER_MODEL_5_1 = 0x51,
  442. D3D_SHADER_MODEL_6_0 = 0x60,
  443. D3D_SHADER_MODEL_6_1 = 0x61,
  444. D3D_SHADER_MODEL_6_2 = 0x62,
  445. D3D_SHADER_MODEL_6_3 = 0x63,
  446. D3D_SHADER_MODEL_6_4 = 0x64,
  447. D3D_SHADER_MODEL_6_5 = 0x65,
  448. D3D_SHADER_MODEL_6_6 = 0x66,
  449. } D3D_SHADER_MODEL;
  450. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  451. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  452. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  453. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  454. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  455. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  456. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  457. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  458. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  459. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  460. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  461. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  462. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  463. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  464. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  465. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  466. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_CO
  467. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  468. #else
  469. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  470. #endif
  471. bool UseDxbc() {
  472. #ifdef _HLK_CONF
  473. return false;
  474. #else
  475. return GetTestParamBool(L"DXBC");
  476. #endif
  477. }
  478. bool UseWarpByDefault() {
  479. #ifdef _HLK_CONF
  480. return false;
  481. #else
  482. return true;
  483. #endif
  484. }
  485. bool UseDebugIfaces() {
  486. return true;
  487. }
  488. bool SaveImages() {
  489. return GetTestParamBool(L"SaveImages");
  490. }
  491. void RunResourceTest(ID3D12Device *pDevice, const char *pShader, const wchar_t *sm, bool isDynamic);
  492. template <class T1, class T2>
  493. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  494. size_t numParameter, bool isPrefix);
  495. template <typename T>
  496. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  497. size_t numParameters);
  498. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  499. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  500. enum class RawBufferLdStType {
  501. I32,
  502. Float,
  503. I64,
  504. Double,
  505. I16,
  506. Half
  507. };
  508. template <class Ty>
  509. struct RawBufferLdStTestData {
  510. Ty v1, v2[2], v3[3], v4[4];
  511. };
  512. template <class Ty>
  513. struct RawBufferLdStUavData {
  514. RawBufferLdStTestData<Ty> input, output, srvOut;
  515. };
  516. template <class Ty>
  517. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  518. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  519. template <class Ty>
  520. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  521. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  522. template <class Ty>
  523. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  524. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  525. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  526. template <class Ty>
  527. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  528. template <class Ty>
  529. const wchar_t* BasicShaderModelTest_GetFormatString();
  530. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  531. VERIFY_SUCCEEDED(m_support.Initialize());
  532. CComPtr<IDxcCompiler> pCompiler;
  533. CComPtr<IDxcLibrary> pLibrary;
  534. CComPtr<IDxcBlobEncoding> pTextBlob;
  535. CComPtr<IDxcOperationResult> pResult;
  536. HRESULT resultCode;
  537. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  538. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  539. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  540. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, pOptions, numOptions, nullptr, 0, nullptr, &pResult));
  541. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  542. if (FAILED(resultCode)) {
  543. CComPtr<IDxcBlobEncoding> errors;
  544. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  545. #ifndef _HLK_CONF
  546. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  547. #endif
  548. }
  549. VERIFY_SUCCEEDED(resultCode);
  550. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  551. }
  552. void CreateCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue, D3D12_COMMAND_LIST_TYPE type) {
  553. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  554. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  555. queueDesc.Type = type;
  556. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  557. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  558. }
  559. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  560. CreateCommandQueue(pDevice, pName, ppCommandQueue, D3D12_COMMAND_LIST_TYPE_COMPUTE);
  561. }
  562. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, LPCWSTR pTargetProfile, ID3D12PipelineState **ppComputeState, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  563. CComPtr<ID3DBlob> pComputeShader;
  564. // Load and compile shaders.
  565. if (UseDxbc()) {
  566. #ifndef _HLK_CONF
  567. DXBCFromText(pShader, L"main", pTargetProfile, &pComputeShader);
  568. #endif
  569. }
  570. else {
  571. CompileFromText(pShader, L"main", pTargetProfile, &pComputeShader, pOptions, numOptions);
  572. }
  573. // Describe and create the compute pipeline state object (PSO).
  574. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  575. computePsoDesc.pRootSignature = pRootSignature;
  576. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  577. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  578. }
  579. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  580. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true,
  581. bool enableRayTracing = false) {
  582. if (testModel > HIGHEST_SHADER_MODEL) {
  583. UINT minor = (UINT)testModel & 0x0f;
  584. LogCommentFmt(L"Installed SDK does not support "
  585. L"shader model 6.%1u", minor);
  586. if (skipUnsupported) {
  587. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  588. }
  589. return false;
  590. }
  591. const D3D_FEATURE_LEVEL FeatureLevelRequired = enableRayTracing ? D3D_FEATURE_LEVEL_12_0 : D3D_FEATURE_LEVEL_11_0;
  592. CComPtr<IDXGIFactory4> factory;
  593. CComPtr<ID3D12Device> pDevice;
  594. *ppDevice = nullptr;
  595. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  596. if (GetTestParamUseWARP(UseWarpByDefault())) {
  597. CComPtr<IDXGIAdapter> warpAdapter;
  598. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  599. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  600. IID_PPV_ARGS(&pDevice));
  601. if (FAILED(createHR)) {
  602. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  603. if (skipUnsupported) {
  604. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  605. }
  606. return false;
  607. }
  608. } else {
  609. CComPtr<IDXGIAdapter1> hardwareAdapter;
  610. WEX::Common::String AdapterValue;
  611. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  612. AdapterValue);
  613. if (SUCCEEDED(hr)) {
  614. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  615. } else {
  616. WEX::Logging::Log::Comment(
  617. L"Using default hardware adapter with D3D12 support.");
  618. }
  619. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  620. IID_PPV_ARGS(&pDevice)));
  621. }
  622. // retrieve adapter information
  623. LUID adapterID = pDevice->GetAdapterLuid();
  624. CComPtr<IDXGIAdapter> adapter;
  625. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  626. DXGI_ADAPTER_DESC AdapterDesc;
  627. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  628. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  629. if (pDevice == nullptr)
  630. return false;
  631. if (!UseDxbc()) {
  632. // Check for DXIL support.
  633. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  634. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  635. } D3D12_FEATURE_DATA_SHADER_MODEL;
  636. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  637. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  638. SMData.HighestShaderModel = testModel;
  639. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
  640. (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
  641. if (SMData.HighestShaderModel < testModel) {
  642. UINT minor = (UINT)testModel & 0x0f;
  643. LogCommentFmt(L"The selected device does not support "
  644. L"shader model 6.%1u", minor);
  645. if (skipUnsupported) {
  646. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  647. }
  648. return false;
  649. }
  650. }
  651. if (UseDebugIfaces()) {
  652. CComPtr<ID3D12InfoQueue> pInfoQueue;
  653. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  654. pInfoQueue->SetMuteDebugOutput(FALSE);
  655. }
  656. }
  657. *ppDevice = pDevice.Detach();
  658. return true;
  659. }
  660. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  661. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  662. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  663. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  664. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  665. }
  666. void CreateGraphicsCommandQueueAndList(
  667. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  668. ID3D12CommandAllocator **ppAllocator,
  669. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  670. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  671. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  672. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  673. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  674. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  675. IID_PPV_ARGS(ppCommandList)));
  676. }
  677. void CreateGraphicsPSO(ID3D12Device *pDevice,
  678. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  679. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  680. ID3D12PipelineState **ppPSO) {
  681. CComPtr<ID3DBlob> vertexShader;
  682. CComPtr<ID3DBlob> pixelShader;
  683. if (UseDxbc()) {
  684. #ifndef _HLK_CONF
  685. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  686. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  687. #endif
  688. } else {
  689. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  690. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  691. }
  692. // Describe and create the graphics pipeline state object (PSO).
  693. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  694. psoDesc.InputLayout = *pInputLayout;
  695. psoDesc.pRootSignature = pRootSignature;
  696. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  697. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  698. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  699. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  700. psoDesc.DepthStencilState.DepthEnable = FALSE;
  701. psoDesc.DepthStencilState.StencilEnable = FALSE;
  702. psoDesc.SampleMask = UINT_MAX;
  703. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  704. psoDesc.NumRenderTargets = 1;
  705. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  706. psoDesc.SampleDesc.Count = 1;
  707. VERIFY_SUCCEEDED(
  708. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  709. }
  710. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  711. ID3D12DescriptorHeap *pHeap, UINT width,
  712. UINT height,
  713. ID3D12Resource **ppRenderTarget,
  714. ID3D12Resource **ppBuffer) {
  715. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  716. const size_t formatElementSize = 4;
  717. CComPtr<ID3D12Resource> pRenderTarget;
  718. CComPtr<ID3D12Resource> pBuffer;
  719. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  720. pHeap->GetCPUDescriptorHandleForHeapStart());
  721. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  722. CD3DX12_RESOURCE_DESC rtDesc(
  723. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  724. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  725. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  726. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  727. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  728. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  729. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  730. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  731. // resource.
  732. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  733. CD3DX12_RESOURCE_DESC readDesc(
  734. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  735. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  736. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  737. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  738. *ppRenderTarget = pRenderTarget.Detach();
  739. *ppBuffer = pBuffer.Detach();
  740. }
  741. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  742. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  743. ID3D12RootSignature **pRootSig) {
  744. CComPtr<ID3DBlob> signature;
  745. CComPtr<ID3DBlob> error;
  746. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  747. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  748. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  749. IID_PPV_ARGS(pRootSig)));
  750. }
  751. void CreateRootSignatureFromRanges(ID3D12Device *pDevice, ID3D12RootSignature **pRootSig,
  752. CD3DX12_DESCRIPTOR_RANGE *resRanges, UINT resCt,
  753. CD3DX12_DESCRIPTOR_RANGE *sampRanges = nullptr, UINT sampCt = 0,
  754. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
  755. CD3DX12_ROOT_PARAMETER rootParameters[2];
  756. rootParameters[0].InitAsDescriptorTable(resCt, resRanges, D3D12_SHADER_VISIBILITY_ALL);
  757. rootParameters[1].InitAsDescriptorTable(sampCt, sampRanges, D3D12_SHADER_VISIBILITY_ALL);
  758. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  759. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, flags);
  760. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, pRootSig);
  761. }
  762. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  763. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  764. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  765. rtvHeapDesc.NumDescriptors = numDescriptors;
  766. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  767. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  768. VERIFY_SUCCEEDED(
  769. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  770. if (rtvDescriptorSize != nullptr) {
  771. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  772. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  773. }
  774. }
  775. void CreateTestResources(ID3D12Device *pDevice,
  776. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  777. UINT32 valueSizeInBytes, D3D12_RESOURCE_DESC resDesc,
  778. ID3D12Resource **ppResource,
  779. ID3D12Resource **ppUploadResource,
  780. ID3D12Resource **ppReadBuffer = nullptr) {
  781. CComPtr<ID3D12Resource> pResource;
  782. CComPtr<ID3D12Resource> pReadBuffer;
  783. CComPtr<ID3D12Resource> pUploadResource;
  784. D3D12_SUBRESOURCE_DATA transferData;
  785. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  786. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  787. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  788. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  789. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  790. pDevice->GetCopyableFootprints(&resDesc, 0, 1/*mipleveles*/, 0, nullptr, nullptr, nullptr, &uploadBufferDesc.Width);
  791. uploadBufferDesc.Height = 1;
  792. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  793. &defaultHeapProperties,
  794. D3D12_HEAP_FLAG_NONE,
  795. &resDesc,
  796. D3D12_RESOURCE_STATE_COPY_DEST,
  797. nullptr,
  798. IID_PPV_ARGS(&pResource)));
  799. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  800. &uploadHeapProperties,
  801. D3D12_HEAP_FLAG_NONE,
  802. &uploadBufferDesc,
  803. D3D12_RESOURCE_STATE_GENERIC_READ,
  804. nullptr,
  805. IID_PPV_ARGS(&pUploadResource)));
  806. if (ppReadBuffer)
  807. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  808. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  809. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  810. transferData.pData = values;
  811. transferData.RowPitch = valueSizeInBytes/resDesc.Height;
  812. transferData.SlicePitch = valueSizeInBytes;
  813. UpdateSubresources<1>(pCommandList, pResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  814. if (resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
  815. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  816. else
  817. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
  818. *ppResource = pResource.Detach();
  819. *ppUploadResource = pUploadResource.Detach();
  820. if (ppReadBuffer)
  821. *ppReadBuffer = pReadBuffer.Detach();
  822. }
  823. void CreateTestUavs(ID3D12Device *pDevice,
  824. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  825. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  826. ID3D12Resource **ppUploadResource = nullptr,
  827. ID3D12Resource **ppReadBuffer = nullptr) {
  828. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  829. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufferDesc,
  830. ppUavResource, ppUploadResource, ppReadBuffer);
  831. }
  832. // Create and return descriptor heaps for the given device
  833. // with the given number of resources and samples.
  834. // using some reasonable defaults
  835. void CreateDefaultDescHeaps(ID3D12Device *pDevice,
  836. int NumResources, int NumSamplers,
  837. ID3D12DescriptorHeap **ppResHeap, ID3D12DescriptorHeap **ppSampHeap) {
  838. // Describe and create descriptor heaps.
  839. ID3D12DescriptorHeap *pResHeap, *pSampHeap;
  840. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  841. heapDesc.NumDescriptors = NumResources;
  842. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  843. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  844. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pResHeap)));
  845. heapDesc.NumDescriptors = NumSamplers;
  846. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
  847. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pSampHeap)));
  848. *ppResHeap = pResHeap;
  849. *ppSampHeap = pSampHeap;
  850. }
  851. void CreateSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  852. DXGI_FORMAT format, D3D12_SRV_DIMENSION viewDimension, UINT numElements, UINT stride,
  853. const CComPtr<ID3D12Resource> pResource) {
  854. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  855. // Create SRV
  856. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  857. srvDesc.Format = format;
  858. srvDesc.ViewDimension = viewDimension;
  859. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  860. switch (viewDimension) {
  861. case D3D12_SRV_DIMENSION_BUFFER:
  862. srvDesc.Buffer.FirstElement = 0;
  863. srvDesc.Buffer.NumElements = numElements;
  864. srvDesc.Buffer.StructureByteStride = stride;
  865. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  866. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
  867. else
  868. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
  869. break;
  870. case D3D12_SRV_DIMENSION_TEXTURE1D:
  871. srvDesc.Texture1D.MostDetailedMip = 0;
  872. srvDesc.Texture1D.MipLevels = 1;
  873. srvDesc.Texture1D.ResourceMinLODClamp = 0;
  874. break;
  875. case D3D12_SRV_DIMENSION_TEXTURE2D:
  876. srvDesc.Texture2D.MostDetailedMip = 0;
  877. srvDesc.Texture2D.MipLevels = 1;
  878. srvDesc.Texture2D.PlaneSlice = 0;
  879. srvDesc.Texture2D.ResourceMinLODClamp = 0;
  880. break;
  881. }
  882. pDevice->CreateShaderResourceView(pResource, &srvDesc, baseHandle);
  883. baseHandle.Offset(descriptorSize);
  884. }
  885. void CreateRawSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  886. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  887. CreateSRV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  888. }
  889. void CreateStructSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  890. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  891. CreateSRV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_SRV_DIMENSION_BUFFER, numElements, stride, pResource);
  892. }
  893. void CreateTypedSRV(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_BUFFER, numElements, 0, pResource);
  896. }
  897. void CreateTex1DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  898. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  899. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  900. }
  901. void CreateTex2DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  902. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  903. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  904. }
  905. void CreateUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  906. DXGI_FORMAT format, D3D12_UAV_DIMENSION viewDimension, UINT numElements, UINT stride,
  907. const CComPtr<ID3D12Resource> pResource) {
  908. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  909. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  910. uavDesc.Format = format;
  911. uavDesc.ViewDimension = viewDimension;
  912. switch (viewDimension) {
  913. case D3D12_UAV_DIMENSION_BUFFER:
  914. uavDesc.Buffer.FirstElement = 0;
  915. uavDesc.Buffer.NumElements = numElements;
  916. uavDesc.Buffer.StructureByteStride = stride;
  917. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  918. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  919. else
  920. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  921. break;
  922. case D3D12_UAV_DIMENSION_TEXTURE1D:
  923. uavDesc.Texture1D.MipSlice = 0;
  924. break;
  925. case D3D12_UAV_DIMENSION_TEXTURE2D:
  926. uavDesc.Texture2D.MipSlice = 0;
  927. uavDesc.Texture2D.PlaneSlice = 0;
  928. break;
  929. }
  930. pDevice->CreateUnorderedAccessView(pResource, nullptr, &uavDesc, baseHandle);
  931. baseHandle.Offset(descriptorSize);
  932. }
  933. void CreateRawUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  934. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  935. CreateUAV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  936. }
  937. void CreateStructUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  938. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  939. CreateUAV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_UAV_DIMENSION_BUFFER, numElements, stride, pResource);
  940. }
  941. void CreateTypedUAV(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_BUFFER, numElements, 0, pResource);
  944. }
  945. void CreateTex1DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  946. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  947. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  948. }
  949. void CreateTex2DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  950. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  951. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  952. }
  953. // Create Samplers for <pDevice> given the filter and border color information provided
  954. // using some reasonable defaults
  955. void CreateDefaultSamplers(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  956. D3D12_FILTER filters[], float BorderColors[], int NumSamplers) {
  957. CD3DX12_CPU_DESCRIPTOR_HANDLE sampHandle(heapStart);
  958. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
  959. D3D12_SAMPLER_DESC sampDesc = {};
  960. sampDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  961. sampDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  962. sampDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  963. sampDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  964. sampDesc.MipLODBias = 0;
  965. sampDesc.MaxAnisotropy = 1;
  966. sampDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_EQUAL;
  967. sampDesc.MinLOD = 0;
  968. sampDesc.MaxLOD = 0;
  969. for (int i = 0; i < NumSamplers; i++) {
  970. sampDesc.Filter = filters[i];
  971. for (int j = 0; j < 4; j++)
  972. sampDesc.BorderColor[j] = BorderColors[i];
  973. pDevice->CreateSampler(&sampDesc, sampHandle);
  974. sampHandle = sampHandle.Offset(descriptorSize);
  975. }
  976. }
  977. template <typename TVertex, int len>
  978. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  979. ID3D12Resource **ppVertexBuffer,
  980. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  981. size_t vertexBufferSize = sizeof(vertices);
  982. CComPtr<ID3D12Resource> pVertexBuffer;
  983. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  984. CD3DX12_RESOURCE_DESC bufferDesc(
  985. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  986. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  987. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  988. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  989. IID_PPV_ARGS(&pVertexBuffer)));
  990. UINT8 *pVertexDataBegin;
  991. CD3DX12_RANGE readRange(0, 0);
  992. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  993. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  994. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  995. pVertexBuffer->Unmap(0, nullptr);
  996. // Initialize the vertex buffer view.
  997. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  998. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  999. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  1000. *ppVertexBuffer = pVertexBuffer.Detach();
  1001. }
  1002. // Requires Anniversary Edition headers, so simplifying things for current setup.
  1003. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  1004. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  1005. BOOL WaveOps;
  1006. UINT WaveLaneCountMin;
  1007. UINT WaveLaneCountMax;
  1008. UINT TotalLaneCount;
  1009. BOOL ExpandedComputeResourceStates;
  1010. BOOL Int64ShaderOps;
  1011. };
  1012. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  1013. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1014. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1015. return false;
  1016. return O.Int64ShaderOps != FALSE;
  1017. }
  1018. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  1019. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  1020. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  1021. return false;
  1022. return O.DoublePrecisionFloatShaderOps != FALSE;
  1023. }
  1024. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  1025. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1026. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1027. return false;
  1028. return O.WaveOps != FALSE;
  1029. }
  1030. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  1031. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  1032. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  1033. return false;
  1034. return O.BarycentricsSupported != FALSE;
  1035. }
  1036. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  1037. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  1038. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  1039. return false;
  1040. return O.Native16BitShaderOpsSupported != FALSE;
  1041. }
  1042. bool DoesDeviceSupportMeshShaders(ID3D12Device *pDevice) {
  1043. #if defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB
  1044. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1045. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))))
  1046. return false;
  1047. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
  1048. #else
  1049. return false;
  1050. #endif
  1051. }
  1052. bool DoesDeviceSupportRayTracing(ID3D12Device *pDevice) {
  1053. #if WDK_NTDDI_VERSION > NTDDI_WIN10_RS4
  1054. D3D12_FEATURE_DATA_D3D12_OPTIONS5 O5;
  1055. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS5, &O5, sizeof(O5))))
  1056. return false;
  1057. return O5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
  1058. #else
  1059. return false;
  1060. #endif
  1061. }
  1062. // Replace with appropriate WDK check when available
  1063. #define SM66_RUNTIME_SUPPORT 0
  1064. bool DoesDeviceSupportMeshAmpDerivatives(ID3D12Device *pDevice) {
  1065. #if SM66_RUNTIME_SUPPORT
  1066. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1067. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1068. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))) ||
  1069. FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1070. return false;
  1071. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED &&
  1072. O9.DerivativesInMeshAndAmplificationShadersSupported != FALSE;
  1073. #else
  1074. return false;
  1075. #endif
  1076. }
  1077. bool DoesDeviceSupportTyped64Atomics(ID3D12Device *pDevice) {
  1078. #if SM66_RUNTIME_SUPPORT
  1079. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1080. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1081. return false;
  1082. return O9.AtomicInt64OnTypedResourceSupported != FALSE;
  1083. #else
  1084. return false;
  1085. #endif
  1086. }
  1087. bool DoesDeviceSupportShared64Atomics(ID3D12Device *pDevice) {
  1088. #if SM66_RUNTIME_SUPPORT
  1089. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1090. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1091. return false;
  1092. return O9.AtomicInt64OnGroupSharedSupported != FALSE;
  1093. #else
  1094. return false;
  1095. #endif
  1096. }
  1097. #ifndef _HLK_CONF
  1098. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  1099. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  1100. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  1101. CComPtr<ID3DBlob> pErrors;
  1102. D3D_SHADER_MACRO d3dMacro[2];
  1103. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  1104. d3dMacro[0].Definition = "1";
  1105. d3dMacro[0].Name = "USING_DXBC";
  1106. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  1107. if (pErrors != nullptr) {
  1108. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  1109. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  1110. }
  1111. VERIFY_SUCCEEDED(hr);
  1112. }
  1113. #endif
  1114. HRESULT EnableDebugLayer() {
  1115. // The debug layer does net yet validate DXIL programs that require rewriting,
  1116. // but basic logging should work properly.
  1117. HRESULT hr = S_FALSE;
  1118. if (UseDebugIfaces()) {
  1119. CComPtr<ID3D12Debug> debugController;
  1120. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  1121. if (SUCCEEDED(hr)) {
  1122. debugController->EnableDebugLayer();
  1123. hr = S_OK;
  1124. }
  1125. }
  1126. return hr;
  1127. }
  1128. #ifndef _HLK_CONF
  1129. HRESULT EnableExperimentalMode() {
  1130. if (m_ExperimentalModeEnabled) {
  1131. return S_OK;
  1132. }
  1133. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1134. return S_FALSE;
  1135. }
  1136. HRESULT hr = EnableExperimentalShaderModels();
  1137. if (SUCCEEDED(hr)) {
  1138. m_ExperimentalModeEnabled = true;
  1139. }
  1140. return hr;
  1141. }
  1142. #endif
  1143. struct FenceObj {
  1144. HANDLE m_fenceEvent = NULL;
  1145. CComPtr<ID3D12Fence> m_fence;
  1146. UINT64 m_fenceValue;
  1147. ~FenceObj() {
  1148. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  1149. }
  1150. };
  1151. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  1152. pObj->m_fenceValue = 1;
  1153. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  1154. IID_PPV_ARGS(&pObj->m_fence)));
  1155. // Create an event handle to use for frame synchronization.
  1156. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  1157. if (pObj->m_fenceEvent == nullptr) {
  1158. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  1159. }
  1160. }
  1161. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  1162. VERIFY_SUCCEEDED(m_support.Initialize());
  1163. CComPtr<IDxcLibrary> pLibrary;
  1164. CComPtr<IDxcBlobEncoding> pBlob;
  1165. CComPtr<IStream> pStream;
  1166. std::wstring path = GetPathToHlslDataFile(relativePath);
  1167. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  1168. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  1169. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  1170. *ppStream = pStream.Detach();
  1171. }
  1172. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  1173. ID3D12DescriptorHeap *pRtvHeap,
  1174. UINT rtvDescriptorSize,
  1175. UINT instanceCount,
  1176. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  1177. ID3D12RootSignature *pRootSig,
  1178. ID3D12Resource *pRenderTarget,
  1179. ID3D12Resource *pReadBuffer) {
  1180. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  1181. D3D12_VIEWPORT viewport;
  1182. D3D12_RECT scissorRect;
  1183. memset(&viewport, 0, sizeof(viewport));
  1184. viewport.Height = (float)rtDesc.Height;
  1185. viewport.Width = (float)rtDesc.Width;
  1186. viewport.MaxDepth = 1.0f;
  1187. memset(&scissorRect, 0, sizeof(scissorRect));
  1188. scissorRect.right = (long)rtDesc.Width;
  1189. scissorRect.bottom = rtDesc.Height;
  1190. if (pRootSig != nullptr) {
  1191. pList->SetGraphicsRootSignature(pRootSig);
  1192. }
  1193. pList->RSSetViewports(1, &viewport);
  1194. pList->RSSetScissorRects(1, &scissorRect);
  1195. // Indicate that the buffer will be used as a render target.
  1196. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  1197. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  1198. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  1199. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  1200. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  1201. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  1202. pList->DrawInstanced(3, instanceCount, 0, 0);
  1203. // Transition to copy source and copy into read-back buffer.
  1204. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1205. // Copy into read-back buffer.
  1206. UINT64 rowPitch = rtDesc.Width * 4;
  1207. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  1208. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  1209. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  1210. Footprint.Offset = 0;
  1211. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  1212. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  1213. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  1214. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  1215. }
  1216. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  1217. void RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR shader, D3D_SHADER_MODEL shaderModel, bool useLibTarget, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1218. void RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1219. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1220. void RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1221. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions);
  1222. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  1223. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  1224. pCommandList->SetDescriptorHeaps(1, pHeaps);
  1225. }
  1226. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  1227. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  1228. }
  1229. };
  1230. #define WAVE_INTRINSIC_DXBC_GUARD \
  1231. "#ifdef USING_DXBC\r\n" \
  1232. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  1233. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  1234. "bool WaveIsFirstLane() { return true; }\r\n" \
  1235. "uint WaveGetLaneCount() { return 1; }\r\n" \
  1236. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  1237. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  1238. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  1239. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  1240. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  1241. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  1242. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  1243. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  1244. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  1245. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  1246. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  1247. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  1248. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  1249. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  1250. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  1251. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  1252. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  1253. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  1254. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  1255. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  1256. "#endif\r\n"
  1257. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  1258. size_t count) {
  1259. values.resize(count); // one element per dispatch group, in bytes
  1260. for (size_t i = 0; i < count; ++i) {
  1261. values[i] = (uint32_t)i;
  1262. }
  1263. }
  1264. bool ExecutionTest::ExecutionTestClassSetup() {
  1265. #ifdef _HLK_CONF
  1266. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1267. VERIFY_SUCCEEDED(m_support.Initialize());
  1268. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1269. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1270. if (m_EnableDebugLayer) {
  1271. EnableDebugLayer();
  1272. }
  1273. return true;
  1274. #else
  1275. HRESULT hr = EnableExperimentalMode();
  1276. if (FAILED(hr)) {
  1277. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1278. }
  1279. else if (hr == S_FALSE) {
  1280. LogCommentFmt(L"Experimental mode not enabled.");
  1281. }
  1282. else {
  1283. LogCommentFmt(L"Experimental mode enabled.");
  1284. }
  1285. hr = EnableDebugLayer();
  1286. if (FAILED(hr)) {
  1287. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1288. }
  1289. else {
  1290. LogCommentFmt(L"Debug layer enabled.");
  1291. }
  1292. return true;
  1293. #endif
  1294. }
  1295. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1296. static const int DispatchGroupX = 1;
  1297. static const int DispatchGroupY = 1;
  1298. static const int DispatchGroupZ = 1;
  1299. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1300. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1301. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1302. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1303. UINT uavDescriptorSize;
  1304. FenceObj FO;
  1305. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1306. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1307. InitFenceObj(pDevice, &FO);
  1308. // Describe and create a UAV descriptor heap.
  1309. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1310. heapDesc.NumDescriptors = 1;
  1311. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1312. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1313. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1314. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1315. // Create root signature.
  1316. CComPtr<ID3D12RootSignature> pRootSignature;
  1317. {
  1318. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1319. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1320. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1321. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1322. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1323. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1324. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1325. }
  1326. // Create pipeline state object.
  1327. CComPtr<ID3D12PipelineState> pComputeState;
  1328. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1329. // Create a command allocator and list for compute.
  1330. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1331. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1332. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1333. // Set up UAV resource.
  1334. CComPtr<ID3D12Resource> pUavResource;
  1335. CComPtr<ID3D12Resource> pReadBuffer;
  1336. CComPtr<ID3D12Resource> pUploadResource;
  1337. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1338. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1339. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1340. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1341. // Close the command list and execute it to perform the GPU setup.
  1342. pCommandList->Close();
  1343. ExecuteCommandList(pCommandQueue, pCommandList);
  1344. WaitForSignal(pCommandQueue, FO);
  1345. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1346. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1347. // Run the compute shader and copy the results back to readable memory.
  1348. {
  1349. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1350. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1351. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1352. uavDesc.Buffer.FirstElement = 0;
  1353. uavDesc.Buffer.NumElements = (UINT)values.size();
  1354. uavDesc.Buffer.StructureByteStride = 0;
  1355. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1356. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1357. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1358. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1359. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1360. SetDescriptorHeap(pCommandList, pUavHeap);
  1361. pCommandList->SetComputeRootSignature(pRootSignature);
  1362. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1363. }
  1364. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1365. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1366. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1367. pCommandList->Close();
  1368. ExecuteCommandList(pCommandQueue, pCommandList);
  1369. WaitForSignal(pCommandQueue, FO);
  1370. {
  1371. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1372. uint32_t *pData = (uint32_t *)mappedData.data();
  1373. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1374. }
  1375. WaitForSignal(pCommandQueue, FO);
  1376. }
  1377. void ExecutionTest::RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1378. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1379. // Create command queue.
  1380. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1381. CreateComputeCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue);
  1382. FenceObj FO;
  1383. InitFenceObj(pDevice, &FO);
  1384. // Compile shader "main" and create pipeline state object.
  1385. CComPtr<ID3D12PipelineState> pComputeState;
  1386. CreateComputePSO(pDevice, pRootSignature, pShader, pTargetProfile, &pComputeState, pOptions, numOptions);
  1387. // Create a command allocator and list for compute.
  1388. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1389. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1390. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1391. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1392. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1393. // Set up UAV resource.
  1394. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1395. CComPtr<ID3D12Resource> pUavResource;
  1396. CComPtr<ID3D12Resource> pReadBuffer;
  1397. CComPtr<ID3D12Resource> pUploadResource;
  1398. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1399. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunLifetimeIntrinsicTest UAV"));
  1400. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunLifetimeIntrinsicTest UAV Read Buffer"));
  1401. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunLifetimeIntrinsicTest UAV Upload Buffer"));
  1402. // Close the command list and execute it to perform the GPU setup.
  1403. pCommandList->Close();
  1404. ExecuteCommandList(pCommandQueue, pCommandList);
  1405. WaitForSignal(pCommandQueue, FO);
  1406. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1407. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1408. // Run the compute shader and copy the results back to readable memory.
  1409. {
  1410. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1411. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1412. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1413. uavDesc.Buffer.FirstElement = 0;
  1414. uavDesc.Buffer.NumElements = (UINT)values.size();
  1415. uavDesc.Buffer.StructureByteStride = 0;
  1416. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1417. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1418. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1419. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1420. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1421. SetDescriptorHeap(pCommandList, pUavHeap);
  1422. pCommandList->SetComputeRootSignature(pRootSignature);
  1423. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1424. }
  1425. static const int DispatchGroupX = 1;
  1426. static const int DispatchGroupY = 1;
  1427. static const int DispatchGroupZ = 1;
  1428. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1429. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1430. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1431. pCommandList->Close();
  1432. ExecuteCommandList(pCommandQueue, pCommandList);
  1433. WaitForSignal(pCommandQueue, FO);
  1434. {
  1435. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1436. uint32_t *pData = (uint32_t *)mappedData.data();
  1437. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1438. }
  1439. WaitForSignal(pCommandQueue, FO);
  1440. }
  1441. void ExecutionTest::RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1442. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions) {
  1443. // Create command queue.
  1444. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1445. CreateCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue, D3D12_COMMAND_LIST_TYPE_DIRECT);
  1446. FenceObj FO;
  1447. InitFenceObj(pDevice, &FO);
  1448. // Compile raygen shader.
  1449. CComPtr<ID3DBlob> pShaderLib;
  1450. CompileFromText(pShader, L"RayGen", pTargetProfile, &pShaderLib, pOptions, numOptions);
  1451. // Describe and create the RT pipeline state object (RTPSO).
  1452. CD3DX12_STATE_OBJECT_DESC stateObjectDesc(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
  1453. auto lib = stateObjectDesc.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
  1454. CD3DX12_SHADER_BYTECODE byteCode(pShaderLib);
  1455. lib->SetDXILLibrary(&byteCode);
  1456. lib->DefineExport(L"RayGen");
  1457. const int payloadCount = 4;
  1458. const int attributeCount = 2;
  1459. const int maxRecursion = 2;
  1460. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT>()->Config(payloadCount * sizeof(float), attributeCount * sizeof(float));
  1461. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT>()->Config(maxRecursion);
  1462. // Create (local!) root sig subobject and associate with shader.
  1463. auto localRootSigSubObj = stateObjectDesc.CreateSubobject<CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT>();
  1464. localRootSigSubObj->SetRootSignature(pRootSignature);
  1465. auto x = stateObjectDesc.CreateSubobject<CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT>();
  1466. x->SetSubobjectToAssociate(*localRootSigSubObj);
  1467. x->AddExport(L"RayGen");
  1468. CComPtr<ID3D12StateObject> pStateObject;
  1469. VERIFY_SUCCEEDED(pDevice->CreateStateObject(stateObjectDesc, IID_PPV_ARGS(&pStateObject)));
  1470. // Create a command allocator and list.
  1471. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1472. CComPtr<ID3D12GraphicsCommandList4> pCommandList;
  1473. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator)));
  1474. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, nullptr, IID_PPV_ARGS(&pCommandList)));
  1475. pCommandList->SetPipelineState1(pStateObject);
  1476. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1477. // Close the command list and execute it to kick-off compilation in the driver.
  1478. // NOTE: We don't care about anything else, so we're not setting up any resources and don't actually execute the shader.
  1479. pCommandList->Close();
  1480. ExecuteCommandList(pCommandQueue, pCommandList);
  1481. WaitForSignal(pCommandQueue, FO);
  1482. }
  1483. void ExecutionTest::RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR pShader, D3D_SHADER_MODEL shaderModel, bool useLibTarget,
  1484. LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1485. LPCWSTR pTargetProfile;
  1486. switch (shaderModel) {
  1487. default: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_0"; break; // Default to 6.3 for lib, 6.0 otherwise.
  1488. case D3D_SHADER_MODEL_6_0: pTargetProfile = useLibTarget ? L"lib_6_0" : L"cs_6_0"; break;
  1489. case D3D_SHADER_MODEL_6_3: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_3"; break;
  1490. case D3D_SHADER_MODEL_6_5: pTargetProfile = useLibTarget ? L"lib_6_5" : L"cs_6_5"; break;
  1491. case D3D_SHADER_MODEL_6_6: pTargetProfile = useLibTarget ? L"lib_6_6" : L"cs_6_6"; break;
  1492. }
  1493. // Describe a UAV descriptor heap.
  1494. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1495. heapDesc.NumDescriptors = 1;
  1496. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1497. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1498. // Create the UAV descriptor heap.
  1499. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1500. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1501. // Create root signature.
  1502. CComPtr<ID3D12RootSignature> pRootSignature;
  1503. {
  1504. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1505. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1506. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1507. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1508. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1509. D3D12_ROOT_SIGNATURE_FLAGS rootSigFlag = useLibTarget ? D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE : D3D12_ROOT_SIGNATURE_FLAG_NONE;
  1510. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSigFlag);
  1511. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1512. }
  1513. if (useLibTarget)
  1514. RunLifetimeIntrinsicLibTest(reinterpret_cast<ID3D12Device5*>(pDevice), pShader, pRootSignature, pTargetProfile, pOptions, numOptions);
  1515. else
  1516. RunLifetimeIntrinsicComputeTest(pDevice, pShader, pUavHeap, pRootSignature, pTargetProfile, pOptions, numOptions, values);
  1517. }
  1518. TEST_F(ExecutionTest, LifetimeIntrinsicTest) {
  1519. // The only thing we test here is that existence of lifetime intrinsics or
  1520. // their fallback replacement (store undef or store zeroinitializer) do not
  1521. // cause any issues in the runtime and driver stack.
  1522. // The easiest way to force placement of intrinsics is to create an array in
  1523. // a local scope that is dynamically indexed. It must not be optimized away,
  1524. // so we do some bogus initialization that prevents this. Since all the code
  1525. // is guarded by a conditional that is dynamically always false, the actual
  1526. // effect of the shader is that the same value that was read is written back.
  1527. static const char* pShader = R"(
  1528. RWByteAddressBuffer g_bab : register(u0);
  1529. void fn(uint GI) {
  1530. const uint addr = GI * 4;
  1531. const int val = g_bab.Load(addr);
  1532. int res = val;
  1533. if (val < 0) { // Never true.
  1534. int arr[200];
  1535. for (int i = 0; i < 200; ++i) {
  1536. arr[i] = arr[val - i];
  1537. }
  1538. res += arr[val];
  1539. }
  1540. g_bab.Store(addr, (uint)res);
  1541. }
  1542. [numthreads(8,8,1)]
  1543. void main(uint GI : SV_GroupIndex) {
  1544. fn(GI);
  1545. }
  1546. [shader("raygeneration")]
  1547. void RayGen() {
  1548. const uint d = DispatchRaysIndex().x;
  1549. const uint g = g > 64 ? 63 : g;
  1550. fn(g);
  1551. }
  1552. )";
  1553. static const int NumThreadsX = 8;
  1554. static const int NumThreadsY = 8;
  1555. static const int NumThreadsZ = 1;
  1556. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1557. static const int DispatchGroupCount = 1;
  1558. // TODO: There's probably a lot of things in the rest of this test that could be stripped away.
  1559. CComPtr<ID3D12Device5> pDevice;
  1560. if (!CreateDevice(reinterpret_cast<ID3D12Device**>(&pDevice), D3D_SHADER_MODEL_6_6, true, true)) {
  1561. WEX::Logging::Log::Comment(L"Lifetime test not run pre 6.6");
  1562. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  1563. return;
  1564. }
  1565. std::vector<uint32_t> values;
  1566. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1567. // Run a number of tests for different configurations that will cause
  1568. // lifetime intrinsics to be placed directly, be replaced by a zeroinitializer
  1569. // store, or be replaced by an undef store.
  1570. LPCWSTR pOptions15[] = {L"/validator-version 1.5"};
  1571. LPCWSTR pOptions16[] = {L"/validator-version 1.6", L"/Vd"};
  1572. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1573. // Test regular shader with zeroinitializer store.
  1574. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions15, _countof(pOptions15), values);
  1575. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1576. if (DoesDeviceSupportRayTracing(pDevice)) {
  1577. // Test library with zeroinitializer store.
  1578. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions15, _countof(pOptions15), values);
  1579. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1580. }
  1581. // Testing SM 6.6 and validator version 1.6 requires experimental shaders
  1582. // being turned on.
  1583. if (!m_ExperimentalModeEnabled)
  1584. return;
  1585. // Test regular shader with undef store.
  1586. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions16, _countof(pOptions16), values);
  1587. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1588. if (DoesDeviceSupportRayTracing(pDevice)) {
  1589. // Test library with undef store.
  1590. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions16, _countof(pOptions16), values);
  1591. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1592. }
  1593. // Test regular shader with lifetime intrinsics.
  1594. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, false, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1595. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1596. if (DoesDeviceSupportRayTracing(pDevice)) {
  1597. // Test library with lifetime intrinsics.
  1598. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, true, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1599. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1600. }
  1601. }
  1602. TEST_F(ExecutionTest, BasicComputeTest) {
  1603. #ifndef _HLK_CONF
  1604. //
  1605. // BasicComputeTest is a simple compute shader that can be used as the basis
  1606. // for more interesting compute execution tests.
  1607. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1608. // rendering code paths for comparison.
  1609. //
  1610. static const char pShader[] =
  1611. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1612. "[numthreads(8,8,1)]\r\n"
  1613. "void main(uint GI : SV_GroupIndex) {"
  1614. " uint addr = GI * 4;\r\n"
  1615. " uint val = g_bab.Load(addr);\r\n"
  1616. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1617. " g_bab.Store(addr, val + 1);\r\n"
  1618. "}";
  1619. static const int NumThreadsX = 8;
  1620. static const int NumThreadsY = 8;
  1621. static const int NumThreadsZ = 1;
  1622. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1623. static const int DispatchGroupCount = 1;
  1624. CComPtr<ID3D12Device> pDevice;
  1625. if (!CreateDevice(&pDevice))
  1626. return;
  1627. std::vector<uint32_t> values;
  1628. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1629. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1630. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1631. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1632. #endif
  1633. }
  1634. TEST_F(ExecutionTest, BasicTriangleTest) {
  1635. #ifndef _HLK_CONF
  1636. static const UINT FrameCount = 2;
  1637. static const UINT m_width = 320;
  1638. static const UINT m_height = 200;
  1639. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1640. struct Vertex {
  1641. XMFLOAT3 position;
  1642. XMFLOAT4 color;
  1643. };
  1644. // Pipeline objects.
  1645. CComPtr<ID3D12Device> pDevice;
  1646. CComPtr<ID3D12Resource> pRenderTarget;
  1647. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1648. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1649. CComPtr<ID3D12RootSignature> pRootSig;
  1650. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1651. CComPtr<ID3D12PipelineState> pPipelineState;
  1652. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1653. CComPtr<ID3D12Resource> pReadBuffer;
  1654. UINT rtvDescriptorSize;
  1655. CComPtr<ID3D12Resource> pVertexBuffer;
  1656. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1657. // Synchronization objects.
  1658. FenceObj FO;
  1659. // Shaders.
  1660. static const char pShaders[] =
  1661. "struct PSInput {\r\n"
  1662. " float4 position : SV_POSITION;\r\n"
  1663. " float4 color : COLOR;\r\n"
  1664. "};\r\n\r\n"
  1665. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1666. " PSInput result;\r\n"
  1667. "\r\n"
  1668. " result.position = position;\r\n"
  1669. " result.color = color;\r\n"
  1670. " return result;\r\n"
  1671. "}\r\n\r\n"
  1672. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1673. " return 1; //input.color;\r\n"
  1674. "};\r\n";
  1675. if (!CreateDevice(&pDevice))
  1676. return;
  1677. struct BasicTestChecker {
  1678. CComPtr<ID3D12Device> m_pDevice;
  1679. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1680. bool m_OK = false;
  1681. void SetOK(bool value) { m_OK = value; }
  1682. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1683. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1684. return;
  1685. m_pInfoQueue->PushEmptyStorageFilter();
  1686. m_pInfoQueue->PushEmptyRetrievalFilter();
  1687. }
  1688. ~BasicTestChecker() {
  1689. if (!m_OK && m_pInfoQueue != nullptr) {
  1690. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1691. bool invalidBytecodeFound = false;
  1692. CAtlArray<BYTE> m_pBytes;
  1693. for (UINT64 i = 0; i < count; ++i) {
  1694. SIZE_T len = 0;
  1695. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1696. continue;
  1697. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1698. continue;
  1699. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1700. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1701. continue;
  1702. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1703. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1704. invalidBytecodeFound = true;
  1705. break;
  1706. }
  1707. }
  1708. if (invalidBytecodeFound) {
  1709. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1710. L"typically indicates that experimental mode "
  1711. L"is not set up properly.");
  1712. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1713. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1714. }
  1715. }
  1716. else {
  1717. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1718. L"queue - dumping complete queue.");
  1719. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1720. }
  1721. }
  1722. }
  1723. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1724. LogCommentFmt(L"%s", pMsg);
  1725. }
  1726. };
  1727. BasicTestChecker BTC(pDevice);
  1728. {
  1729. InitFenceObj(pDevice, &FO);
  1730. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1731. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1732. // Create an empty root signature.
  1733. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1734. rootSignatureDesc.Init(
  1735. 0, nullptr, 0, nullptr,
  1736. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1737. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1738. // Create the pipeline state, which includes compiling and loading shaders.
  1739. // Define the vertex input layout.
  1740. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1741. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1742. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1743. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1744. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1745. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1746. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1747. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1748. &pCommandAllocator, &pCommandList,
  1749. pPipelineState);
  1750. // Define the geometry for a triangle.
  1751. Vertex triangleVertices[] = {
  1752. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1753. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1754. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1755. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1756. WaitForSignal(pCommandQueue, FO);
  1757. }
  1758. // Render and execute the command list.
  1759. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1760. &vertexBufferView, pRootSig, pRenderTarget,
  1761. pReadBuffer);
  1762. VERIFY_SUCCEEDED(pCommandList->Close());
  1763. ExecuteCommandList(pCommandQueue, pCommandList);
  1764. // Wait for previous frame.
  1765. WaitForSignal(pCommandQueue, FO);
  1766. // At this point, we've verified that execution succeeded with DXIL.
  1767. BTC.SetOK(true);
  1768. // Read back to CPU and examine contents.
  1769. {
  1770. MappedData data(pReadBuffer, m_width * m_height * 4);
  1771. const uint32_t *pPixels = (uint32_t *)data.data();
  1772. if (SaveImages()) {
  1773. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1774. }
  1775. uint32_t top = pPixels[m_width / 2]; // Top center.
  1776. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1777. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1778. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1779. }
  1780. #endif
  1781. }
  1782. TEST_F(ExecutionTest, Int64Test) {
  1783. static const char pShader[] =
  1784. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1785. "[numthreads(8,8,1)]\r\n"
  1786. "void main(uint GI : SV_GroupIndex) {"
  1787. " uint addr = GI * 4;\r\n"
  1788. " uint val = g_bab.Load(addr);\r\n"
  1789. " uint64_t u64 = val;\r\n"
  1790. " u64 *= val;\r\n"
  1791. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1792. "}";
  1793. static const int NumThreadsX = 8;
  1794. static const int NumThreadsY = 8;
  1795. static const int NumThreadsZ = 1;
  1796. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1797. static const int DispatchGroupCount = 1;
  1798. CComPtr<ID3D12Device> pDevice;
  1799. if (!CreateDevice(&pDevice))
  1800. return;
  1801. if (!DoesDeviceSupportInt64(pDevice)) {
  1802. // Optional feature, so it's correct to not support it if declared as such.
  1803. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1804. return;
  1805. }
  1806. std::vector<uint32_t> values;
  1807. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1808. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1809. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1810. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1811. }
  1812. TEST_F(ExecutionTest, SignTest) {
  1813. static const char pShader[] =
  1814. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1815. "[numthreads(8,1,1)]\r\n"
  1816. "void main(uint GI : SV_GroupIndex) {"
  1817. " uint addr = GI * 4;\r\n"
  1818. " int val = g_bab.Load(addr);\r\n"
  1819. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1820. "}";
  1821. static const int NumThreadsX = 8;
  1822. static const int NumThreadsY = 1;
  1823. static const int NumThreadsZ = 1;
  1824. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1825. static const int DispatchGroupCount = 1;
  1826. CComPtr<ID3D12Device> pDevice;
  1827. if (!CreateDevice(&pDevice))
  1828. return;
  1829. const uint32_t neg1 = (uint32_t)-1;
  1830. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1831. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1832. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1833. VERIFY_ARE_EQUAL(values[0], neg1);
  1834. VERIFY_ARE_EQUAL(values[1], neg1);
  1835. VERIFY_ARE_EQUAL(values[2], neg1);
  1836. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1837. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1838. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1839. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1840. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1841. }
  1842. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1843. #ifndef _HLK_CONF
  1844. CComPtr<ID3D12Device> pDevice;
  1845. if (!CreateDevice(&pDevice))
  1846. return;
  1847. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1848. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1849. return;
  1850. bool waveSupported = O.WaveOps;
  1851. UINT laneCountMin = O.WaveLaneCountMin;
  1852. UINT laneCountMax = O.WaveLaneCountMax;
  1853. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1854. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1855. if (waveSupported) {
  1856. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1857. }
  1858. else {
  1859. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1860. }
  1861. #endif
  1862. }
  1863. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1864. #ifndef _HLK_CONF
  1865. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1866. struct PerThreadData {
  1867. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1868. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1869. uint32_t pfBC, pfSum, pfProd;
  1870. uint32_t ballot[4];
  1871. uint32_t diver; // divergent value, used in calculation
  1872. int32_t i_diver; // divergent value, used in calculation
  1873. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1874. int32_t i_pfSum, i_pfProd;
  1875. };
  1876. static const char pShader[] =
  1877. WAVE_INTRINSIC_DXBC_GUARD
  1878. "struct PerThreadData {\r\n"
  1879. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1880. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1881. " uint pfBC, pfSum, pfProd;\r\n"
  1882. " uint4 ballot;\r\n"
  1883. " uint diver;\r\n"
  1884. " int i_diver;\r\n"
  1885. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1886. " int i_pfSum, i_pfProd;\r\n"
  1887. "};\r\n"
  1888. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1889. "[numthreads(8,8,1)]\r\n"
  1890. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1891. " PerThreadData pts = g_sb[GI];\r\n"
  1892. " uint diver = GTID.x + 2;\r\n"
  1893. " pts.diver = diver;\r\n"
  1894. " pts.flags = 0;\r\n"
  1895. " pts.preds = 0;\r\n"
  1896. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1897. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1898. " pts.laneCount = WaveGetLaneCount();\r\n"
  1899. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1900. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1901. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1902. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1903. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1904. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1905. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1906. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1907. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1908. "\r\n"
  1909. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1910. " pts.allSum = WaveActiveSum(diver);\r\n"
  1911. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1912. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1913. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1914. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1915. " pts.allMin = WaveActiveMin(diver);\r\n"
  1916. " pts.allMax = WaveActiveMax(diver);\r\n"
  1917. "\r\n"
  1918. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1919. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1920. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1921. "\r\n"
  1922. " int i_diver = pts.i_diver;\r\n"
  1923. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1924. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1925. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1926. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1927. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1928. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1929. "\r\n"
  1930. " g_sb[GI] = pts;\r\n"
  1931. "}";
  1932. static const int NumtheadsX = 8;
  1933. static const int NumtheadsY = 8;
  1934. static const int NumtheadsZ = 1;
  1935. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1936. static const int DispatchGroupCount = 1;
  1937. CComPtr<ID3D12Device> pDevice;
  1938. if (!CreateDevice(&pDevice))
  1939. return;
  1940. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1941. // Optional feature, so it's correct to not support it if declared as such.
  1942. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1943. return;
  1944. }
  1945. std::vector<PerThreadData> values;
  1946. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1947. for (size_t i = 0; i < values.size(); ++i) {
  1948. memset(&values[i], 0, sizeof(PerThreadData));
  1949. values[i].id = i;
  1950. values[i].i_diver = (int)i;
  1951. values[i].i_diver *= (i % 2) ? 1 : -1;
  1952. }
  1953. static const int DispatchGroupX = 1;
  1954. static const int DispatchGroupY = 1;
  1955. static const int DispatchGroupZ = 1;
  1956. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1957. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1958. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1959. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1960. UINT uavDescriptorSize;
  1961. FenceObj FO;
  1962. bool dxbc = UseDxbc();
  1963. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1964. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1965. InitFenceObj(pDevice, &FO);
  1966. // Describe and create a UAV descriptor heap.
  1967. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1968. heapDesc.NumDescriptors = 1;
  1969. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1970. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1971. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1972. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1973. // Create root signature.
  1974. CComPtr<ID3D12RootSignature> pRootSignature;
  1975. {
  1976. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1977. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1978. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1979. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1980. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1981. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1982. CComPtr<ID3DBlob> signature;
  1983. CComPtr<ID3DBlob> error;
  1984. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  1985. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  1986. }
  1987. // Create pipeline state object.
  1988. CComPtr<ID3D12PipelineState> pComputeState;
  1989. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1990. // Create a command allocator and list for compute.
  1991. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1992. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1993. // Set up UAV resource.
  1994. CComPtr<ID3D12Resource> pUavResource;
  1995. CComPtr<ID3D12Resource> pReadBuffer;
  1996. CComPtr<ID3D12Resource> pUploadResource;
  1997. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1998. // Close the command list and execute it to perform the GPU setup.
  1999. pCommandList->Close();
  2000. ExecuteCommandList(pCommandQueue, pCommandList);
  2001. WaitForSignal(pCommandQueue, FO);
  2002. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2003. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  2004. // Run the compute shader and copy the results back to readable memory.
  2005. {
  2006. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2007. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2008. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2009. uavDesc.Buffer.FirstElement = 0;
  2010. uavDesc.Buffer.NumElements = values.size();
  2011. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  2012. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2013. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2014. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2015. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2016. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  2017. SetDescriptorHeap(pCommandList, pUavHeap);
  2018. pCommandList->SetComputeRootSignature(pRootSignature);
  2019. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  2020. }
  2021. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  2022. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2023. pCommandList->CopyResource(pReadBuffer, pUavResource);
  2024. pCommandList->Close();
  2025. ExecuteCommandList(pCommandQueue, pCommandList);
  2026. WaitForSignal(pCommandQueue, FO);
  2027. {
  2028. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  2029. PerThreadData *pData = (PerThreadData *)mappedData.data();
  2030. memcpy(values.data(), pData, valueSizeInBytes);
  2031. // Gather some general data.
  2032. // The 'firstLaneId' captures a unique number per first-lane per wave.
  2033. // Counting the number distinct firstLaneIds gives us the number of waves.
  2034. std::vector<uint32_t> firstLaneIds;
  2035. for (size_t i = 0; i < values.size(); ++i) {
  2036. PerThreadData &pts = values[i];
  2037. uint32_t firstLaneId = pts.firstLaneId;
  2038. if (!contains(firstLaneIds, firstLaneId)) {
  2039. firstLaneIds.push_back(firstLaneId);
  2040. }
  2041. }
  2042. // Waves should cover 4 threads or more.
  2043. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  2044. if (!dxbc) {
  2045. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  2046. }
  2047. // Now, group threads into waves.
  2048. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  2049. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  2050. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  2051. }
  2052. for (size_t i = 0; i < values.size(); ++i) {
  2053. PerThreadData &pts = values[i];
  2054. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2055. wave->push_back(&pts);
  2056. }
  2057. // Verify that all the wave values are coherent across the wave.
  2058. for (size_t i = 0; i < values.size(); ++i) {
  2059. PerThreadData &pts = values[i];
  2060. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2061. // Sort the lanes by increasing lane ID.
  2062. struct LaneIdOrderPred {
  2063. bool operator()(PerThreadData *a, PerThreadData *b) {
  2064. return a->laneIndex < b->laneIndex;
  2065. }
  2066. };
  2067. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  2068. // Verify some interesting properties of the first lane.
  2069. uint32_t pfBC, pfSum, pfProd;
  2070. int32_t i_pfSum, i_pfProd;
  2071. int32_t i_allMax, i_allMin;
  2072. {
  2073. PerThreadData *ptdFirst = wave->front();
  2074. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  2075. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  2076. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  2077. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  2078. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  2079. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  2080. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  2081. pfSum = ptdFirst->diver;
  2082. pfProd = ptdFirst->diver;
  2083. i_pfSum = ptdFirst->i_diver;
  2084. i_pfProd = ptdFirst->i_diver;
  2085. i_allMax = i_allMin = ptdFirst->i_diver;
  2086. }
  2087. // Calculate values which take into consideration all lanes.
  2088. uint32_t preds = 0;
  2089. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  2090. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  2091. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  2092. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  2093. uint32_t ballot[4] = { 0, 0, 0, 0 };
  2094. int32_t i_allSum = 0, i_allProd = 1;
  2095. for (size_t n = 0; n < wave->size(); ++n) {
  2096. std::vector<PerThreadData *> &lanes = *wave.get();
  2097. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  2098. if (lanes[n]->diver == 1) preds |= (1 << 0);
  2099. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  2100. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  2101. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  2102. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  2103. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  2104. if (lanes[n]->diver > 3) {
  2105. // This is the uint4 result layout:
  2106. // .x -> bits 0 .. 31
  2107. // .y -> bits 32 .. 63
  2108. // .z -> bits 64 .. 95
  2109. // .w -> bits 96 ..127
  2110. uint32_t component = lanes[n]->laneIndex / 32;
  2111. uint32_t bit = lanes[n]->laneIndex % 32;
  2112. ballot[component] |= 1 << bit;
  2113. }
  2114. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  2115. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  2116. i_allProd *= lanes[n]->i_diver;
  2117. i_allSum += lanes[n]->i_diver;
  2118. }
  2119. for (size_t n = 1; n < wave->size(); ++n) {
  2120. // 'All' operations are uniform across the wave.
  2121. std::vector<PerThreadData *> &lanes = *wave.get();
  2122. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  2123. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  2124. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  2125. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  2126. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  2127. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  2128. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  2129. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  2130. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  2131. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  2132. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  2133. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  2134. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  2135. // first-lane reads and uniform reads are uniform across the wave.
  2136. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  2137. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  2138. // the lane count is uniform across the wave.
  2139. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  2140. // The predicates are uniform across the wave.
  2141. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  2142. // the lane index is distinct per thread.
  2143. for (size_t prior = 0; prior < n; ++prior) {
  2144. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  2145. }
  2146. // Ballot results are uniform across the wave.
  2147. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  2148. // Keep running total of prefix calculation. Prefix values are exclusive to
  2149. // the executing lane.
  2150. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  2151. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  2152. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  2153. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  2154. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  2155. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  2156. pfSum += lanes[n]->diver;
  2157. pfProd *= lanes[n]->diver;
  2158. i_pfSum += lanes[n]->i_diver;
  2159. i_pfProd *= lanes[n]->i_diver;
  2160. }
  2161. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  2162. }
  2163. // Compare each value of each per-thread element.
  2164. for (size_t i = 0; i < values.size(); ++i) {
  2165. PerThreadData &pts = values[i];
  2166. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  2167. }
  2168. }
  2169. #endif
  2170. }
  2171. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  2172. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  2173. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2174. struct Vertex {
  2175. XMFLOAT3 position;
  2176. };
  2177. struct PerPixelData {
  2178. XMFLOAT4 position;
  2179. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  2180. uint32_t id0, id1, id2, id3;
  2181. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  2182. };
  2183. const UINT RTWidth = 128;
  2184. const UINT RTHeight = 128;
  2185. // Shaders.
  2186. static const char pShaders[] =
  2187. WAVE_INTRINSIC_DXBC_GUARD
  2188. "struct PSInput {\r\n"
  2189. " float4 position : SV_POSITION;\r\n"
  2190. "};\r\n\r\n"
  2191. "PSInput VSMain(float4 position : POSITION) {\r\n"
  2192. " PSInput result;\r\n"
  2193. "\r\n"
  2194. " result.position = position;\r\n"
  2195. " return result;\r\n"
  2196. "}\r\n\r\n"
  2197. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  2198. "struct PerPixelData {\r\n"
  2199. " float4 position;\r\n"
  2200. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  2201. " uint id0, id1, id2, id3;\r\n"
  2202. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  2203. "};\r\n"
  2204. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  2205. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  2206. " uint one = 1;\r\n"
  2207. " PerPixelData d;\r\n"
  2208. " d.position = input.position;\r\n"
  2209. " d.id = pos_to_id(input.position);\r\n"
  2210. " d.flags = 0;\r\n"
  2211. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  2212. " d.laneIndex = WaveGetLaneIndex();\r\n"
  2213. " d.laneCount = WaveGetLaneCount();\r\n"
  2214. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  2215. " d.sum1 = WaveActiveSum(one);\r\n"
  2216. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  2217. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  2218. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  2219. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  2220. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  2221. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  2222. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  2223. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  2224. " g_sb.Append(d);\r\n"
  2225. " return 1;\r\n"
  2226. "};\r\n";
  2227. CComPtr<ID3D12Device> pDevice;
  2228. CComPtr<ID3D12CommandQueue> pCommandQueue;
  2229. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  2230. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  2231. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  2232. CComPtr<ID3D12PipelineState> pPSO;
  2233. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  2234. UINT uavDescriptorSize, rtvDescriptorSize;
  2235. CComPtr<ID3D12Resource> pVertexBuffer;
  2236. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  2237. if (!CreateDevice(&pDevice))
  2238. return;
  2239. if (!DoesDeviceSupportWaveOps(pDevice)) {
  2240. // Optional feature, so it's correct to not support it if declared as such.
  2241. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  2242. return;
  2243. }
  2244. FenceObj FO;
  2245. InitFenceObj(pDevice, &FO);
  2246. // Describe and create a UAV descriptor heap.
  2247. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  2248. heapDesc.NumDescriptors = 1;
  2249. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  2250. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  2251. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  2252. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2253. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  2254. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  2255. // Create root signature: one UAV.
  2256. CComPtr<ID3D12RootSignature> pRootSignature;
  2257. {
  2258. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2259. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  2260. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2261. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2262. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2263. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  2264. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  2265. }
  2266. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  2267. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  2268. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  2269. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  2270. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  2271. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  2272. &pCommandList, pPSO);
  2273. // Single triangle covering half the target.
  2274. Vertex vertices[] = {
  2275. { { -1.0f, 1.0f, 0.0f } },
  2276. { { 1.0f, 1.0f, 0.0f } },
  2277. { { -1.0f, -1.0f, 0.0f } } };
  2278. const UINT TriangleCount = _countof(vertices) / 3;
  2279. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  2280. bool dxbc = UseDxbc();
  2281. // Set up UAV resource.
  2282. std::vector<PerPixelData> values;
  2283. values.resize(RTWidth * RTHeight * 2);
  2284. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  2285. memset(values.data(), 0, valueSizeInBytes);
  2286. CComPtr<ID3D12Resource> pUavResource;
  2287. CComPtr<ID3D12Resource> pUavReadBuffer;
  2288. CComPtr<ID3D12Resource> pUploadResource;
  2289. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pUavReadBuffer);
  2290. // Set up the append counter resource.
  2291. CComPtr<ID3D12Resource> pUavCounterResource;
  2292. CComPtr<ID3D12Resource> pReadCounterBuffer;
  2293. CComPtr<ID3D12Resource> pUploadCounterResource;
  2294. BYTE zero[sizeof(UINT)] = { 0 };
  2295. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pUploadCounterResource, &pReadCounterBuffer);
  2296. // Close the command list and execute it to perform the GPU setup.
  2297. pCommandList->Close();
  2298. ExecuteCommandList(pCommandQueue, pCommandList);
  2299. WaitForSignal(pCommandQueue, FO);
  2300. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2301. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  2302. pCommandList->SetGraphicsRootSignature(pRootSignature);
  2303. SetDescriptorHeap(pCommandList, pUavHeap);
  2304. {
  2305. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2306. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2307. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2308. uavDesc.Buffer.FirstElement = 0;
  2309. uavDesc.Buffer.NumElements = (UINT)values.size();
  2310. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  2311. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2312. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2313. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2314. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2315. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  2316. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  2317. }
  2318. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  2319. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2320. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2321. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  2322. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  2323. VERIFY_SUCCEEDED(pCommandList->Close());
  2324. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  2325. ExecuteCommandList(pCommandQueue, pCommandList);
  2326. WaitForSignal(pCommandQueue, FO);
  2327. {
  2328. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  2329. const uint32_t *pPixels = (uint32_t *)data.data();
  2330. if (SaveImages()) {
  2331. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  2332. }
  2333. }
  2334. uint32_t appendCount;
  2335. {
  2336. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  2337. appendCount = *((uint32_t *)mappedData.data());
  2338. LogCommentFmt(L"%u elements in append buffer", appendCount);
  2339. }
  2340. {
  2341. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  2342. PerPixelData *pData = (PerPixelData *)mappedData.data();
  2343. memcpy(values.data(), pData, valueSizeInBytes);
  2344. // DXBC is handy to test pipeline setup, but interesting functions are
  2345. // stubbed out, so there is no point in further validation.
  2346. if (dxbc)
  2347. return;
  2348. uint32_t maxActiveLaneCount = 0;
  2349. uint32_t maxLaneCount = 0;
  2350. for (uint32_t i = 0; i < appendCount; ++i) {
  2351. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  2352. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  2353. }
  2354. uint32_t peerOfHelperLanes = 0;
  2355. for (uint32_t i = 0; i < appendCount; ++i) {
  2356. if (values[i].sum1 != maxActiveLaneCount) {
  2357. ++peerOfHelperLanes;
  2358. }
  2359. }
  2360. LogCommentFmt(
  2361. L"Found: %u threads. Waves reported up to %u total lanes, up "
  2362. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  2363. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  2364. // Group threads into quad invocations.
  2365. uint32_t singlePixelCount = 0;
  2366. uint32_t multiPixelCount = 0;
  2367. std::unordered_set<uint32_t> ids;
  2368. std::multimap<uint32_t, PerPixelData *> idGroups;
  2369. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  2370. for (uint32_t i = 0; i < appendCount; ++i) {
  2371. ids.insert(values[i].id);
  2372. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  2373. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  2374. }
  2375. for (uint32_t id : ids) {
  2376. if (idGroups.count(id) == 1)
  2377. ++singlePixelCount;
  2378. else
  2379. ++multiPixelCount;
  2380. }
  2381. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  2382. singlePixelCount, multiPixelCount);
  2383. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  2384. // Where every pixel is distinct, it's very straightforward to validate.
  2385. {
  2386. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  2387. while (cur != end) {
  2388. bool simpleWave = true;
  2389. uint32_t firstId = (*cur).first;
  2390. auto groupEnd = cur;
  2391. while (groupEnd != end && (*groupEnd).first == firstId) {
  2392. if (idGroups.count((*groupEnd).second->id) > 1)
  2393. simpleWave = false;
  2394. ++groupEnd;
  2395. }
  2396. if (simpleWave) {
  2397. // Break the wave into quads.
  2398. struct QuadData {
  2399. unsigned count;
  2400. PerPixelData *data[4];
  2401. };
  2402. std::map<uint32_t, QuadData> quads;
  2403. for (auto i = cur; i != groupEnd; ++i) {
  2404. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  2405. uint32_t laneId = (*i).second->id;
  2406. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  2407. (*i).second->id2, (*i).second->id3};
  2408. // Since this is a simple wave, each lane has an unique id and
  2409. // therefore should not have any ids in there.
  2410. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  2411. // check if QuadReadLaneAt is returning same values in a single quad.
  2412. bool newQuad = true;
  2413. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  2414. auto match = quads.find(laneIds[quadIndex]);
  2415. if (match != quads.end()) {
  2416. (*match).second.data[(*match).second.count++] = (*i).second;
  2417. newQuad = false;
  2418. break;
  2419. }
  2420. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  2421. if (quadMemberData != idGroups.end()) {
  2422. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  2423. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  2424. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  2425. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  2426. }
  2427. }
  2428. if (newQuad) {
  2429. QuadData qdata;
  2430. qdata.count = 1;
  2431. qdata.data[0] = (*i).second;
  2432. quads.insert(std::make_pair(laneId, qdata));
  2433. }
  2434. }
  2435. for (auto quadPair : quads) {
  2436. unsigned count = quadPair.second.count;
  2437. // There could be only one pixel data on the edge of the triangle
  2438. if (count < 2) continue;
  2439. PerPixelData **data = quadPair.second.data;
  2440. bool isTop[4];
  2441. bool isLeft[4];
  2442. PerPixelData helperData;
  2443. memset(&helperData, sizeof(helperData), 0);
  2444. PerPixelData *layout[4]; // tl,tr,bl,br
  2445. memset(layout, sizeof(layout), 0);
  2446. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  2447. int idx = top ? 0 : 2;
  2448. idx += left ? 0 : 1;
  2449. return &layout[idx];
  2450. };
  2451. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  2452. PerPixelData **pResult = fnToLayout(top, left);
  2453. if (*pResult == nullptr) return &helperData;
  2454. return *pResult;
  2455. };
  2456. VERIFY_IS_TRUE(count <= 4);
  2457. if (count == 2) {
  2458. isTop[0] = data[0]->position.y < data[1]->position.y;
  2459. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  2460. isLeft[0] = data[0]->position.x < data[1]->position.x;
  2461. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  2462. }
  2463. else {
  2464. // with at least three samples, we have distinct x and y coordinates.
  2465. float left = std::min(data[0]->position.x, data[1]->position.x);
  2466. left = std::min(data[2]->position.x, left);
  2467. float top = std::min(data[0]->position.y, data[1]->position.y);
  2468. top = std::min(data[2]->position.y, top);
  2469. for (unsigned i = 0; i < count; ++i) {
  2470. isTop[i] = data[i]->position.y == top;
  2471. isLeft[i] = data[i]->position.x == left;
  2472. }
  2473. }
  2474. for (unsigned i = 0; i < count; ++i) {
  2475. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  2476. }
  2477. // Finally, we have a proper quad reconstructed. Validate.
  2478. for (unsigned i = 0; i < count; ++i) {
  2479. PerPixelData *d = data[i];
  2480. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  2481. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  2482. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  2483. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  2484. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  2485. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  2486. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  2487. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2488. }
  2489. }
  2490. }
  2491. cur = groupEnd;
  2492. }
  2493. }
  2494. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2495. //
  2496. // Consider: for pixels that were shaded multiple times, check whether
  2497. // some grouping of threads into quads satisfies all value requirements.
  2498. }
  2499. }
  2500. struct ShaderOpTestResult {
  2501. st::ShaderOp *ShaderOp;
  2502. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2503. std::shared_ptr<st::ShaderOpTest> Test;
  2504. };
  2505. struct SPrimitives {
  2506. float f_float;
  2507. float f_float2;
  2508. float f_float_o;
  2509. float f_float2_o;
  2510. };
  2511. std::shared_ptr<ShaderOpTestResult>
  2512. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2513. LPCSTR pName,
  2514. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2515. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2516. st::ShaderOp *pShaderOp;
  2517. if (pName == nullptr) {
  2518. if (ShaderOpSet->ShaderOps.size() != 1) {
  2519. VERIFY_FAIL(L"Expected a single shader operation.");
  2520. }
  2521. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2522. }
  2523. else {
  2524. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2525. }
  2526. if (pShaderOp == nullptr) {
  2527. std::string msg = "Unable to find shader op ";
  2528. msg += pName;
  2529. msg += "; available ops";
  2530. const char sep = ':';
  2531. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2532. msg += sep;
  2533. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2534. }
  2535. CA2W msgWide(msg.c_str());
  2536. VERIFY_FAIL(msgWide.m_psz);
  2537. }
  2538. // This won't actually be used since we're supplying the device,
  2539. // but let's make it consistent.
  2540. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2541. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2542. test->SetDxcSupport(&support);
  2543. test->SetInitCallback(pInitCallback);
  2544. test->SetDevice(pDevice);
  2545. test->RunShaderOp(pShaderOp);
  2546. std::shared_ptr<ShaderOpTestResult> result =
  2547. std::make_shared<ShaderOpTestResult>();
  2548. result->ShaderOpSet = ShaderOpSet;
  2549. result->Test = test;
  2550. result->ShaderOp = pShaderOp;
  2551. return result;
  2552. }
  2553. std::shared_ptr<ShaderOpTestResult>
  2554. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2555. IStream *pStream, LPCSTR pName,
  2556. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2557. DXASSERT_NOMSG(pStream != nullptr);
  2558. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2559. std::make_shared<st::ShaderOpSet>();
  2560. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2561. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2562. }
  2563. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2564. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2565. CComPtr<IStream> pStream;
  2566. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2567. // Single operation test at the moment.
  2568. CComPtr<ID3D12Device> pDevice;
  2569. if (!CreateDevice(&pDevice))
  2570. return;
  2571. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2572. MappedData data;
  2573. // Read back to CPU and examine contents - should get pure red.
  2574. {
  2575. MappedData data;
  2576. test->Test->GetReadBackData("RTarget", &data);
  2577. const uint32_t *pPixels = (uint32_t *)data.data();
  2578. uint32_t first = *pPixels;
  2579. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2580. }
  2581. }
  2582. TEST_F(ExecutionTest, SaturateTest) {
  2583. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2584. CComPtr<IStream> pStream;
  2585. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2586. // Single operation test at the moment.
  2587. CComPtr<ID3D12Device> pDevice;
  2588. if (!CreateDevice(&pDevice))
  2589. return;
  2590. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2591. MappedData data;
  2592. test->Test->GetReadBackData("U0", &data);
  2593. const float *pValues = (float *)data.data();
  2594. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2595. const float ExpectedCases[9] = {
  2596. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2597. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2598. 0.0f // nan
  2599. };
  2600. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2601. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2602. ++pValues;
  2603. }
  2604. }
  2605. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2606. #ifdef _HLK_CONF
  2607. UNREFERENCED_PARAMETER(ShaderOpName);
  2608. UNREFERENCED_PARAMETER(FileName);
  2609. UNREFERENCED_PARAMETER(testModel);
  2610. #else
  2611. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2612. CComPtr<IStream> pStream;
  2613. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2614. // Single operation test at the moment.
  2615. CComPtr<ID3D12Device> pDevice;
  2616. if (!CreateDevice(&pDevice, testModel))
  2617. return;
  2618. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2619. MappedData data;
  2620. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2621. UINT width = (UINT64)D.Width;
  2622. UINT height = (UINT64)D.Height;
  2623. test->Test->GetReadBackData("RTarget", &data);
  2624. const uint32_t *pPixels = (uint32_t *)data.data();
  2625. if (SaveImages()) {
  2626. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2627. }
  2628. uint32_t top = pPixels[width / 2]; // Top center.
  2629. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2630. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2631. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2632. // This is the basic validation test for shader operations, so it's good to
  2633. // check this here at least for this one test case.
  2634. data.reset();
  2635. test.reset();
  2636. ReportLiveObjects();
  2637. #endif
  2638. }
  2639. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2640. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2641. }
  2642. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2643. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2644. }
  2645. void VerifyDerivResults(const float *pPixels, UINT offsetCenter) {
  2646. // pixel at the center
  2647. float CenterDDXFine = pPixels[offsetCenter];
  2648. float CenterDDYFine = pPixels[offsetCenter + 1];
  2649. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2650. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2651. LogCommentFmt(
  2652. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2653. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2654. // The texture for the 9 pixels in the center should look like the following
  2655. // 256 32 64
  2656. // 2048 256 512
  2657. // 1 .125 .25
  2658. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2659. // So for fine derivatives there can be up to two possible results for the center pixel,
  2660. // while for coarse derivatives there can be up to six possible results.
  2661. int ulpTolerance = 1;
  2662. // 512 - 256 or 2048 - 256
  2663. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2664. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2665. // 256 - 32 or 256 - .125
  2666. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2667. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2668. if (top && left) {
  2669. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2670. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2671. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2672. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2673. }
  2674. else if (top) { // top right quad
  2675. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2676. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2677. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2678. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2679. }
  2680. else if (left) { // bottom left quad
  2681. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2682. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2683. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2684. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2685. }
  2686. else { // bottom right
  2687. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2688. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2689. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2690. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2691. }
  2692. }
  2693. // Rendering two right triangles forming a square and assigning a texture value
  2694. // for each pixel to calculate derivates.
  2695. TEST_F(ExecutionTest, PartialDerivTest) {
  2696. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2697. CComPtr<IStream> pStream;
  2698. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2699. CComPtr<ID3D12Device> pDevice;
  2700. if (!CreateDevice(&pDevice))
  2701. return;
  2702. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2703. MappedData data;
  2704. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2705. UINT width = (UINT)D.Width;
  2706. UINT height = D.Height;
  2707. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2708. test->Test->GetReadBackData("RTarget", &data);
  2709. const float *pPixels = (float *)data.data();
  2710. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2711. UINT offsetCenter = centerIndex * pixelSize;
  2712. VerifyDerivResults(pPixels, offsetCenter);
  2713. }
  2714. TEST_F(ExecutionTest, DerivativesTest) {
  2715. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2716. CComPtr<IStream> pStream;
  2717. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2718. CComPtr<ID3D12Device> pDevice;
  2719. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2720. return;
  2721. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2722. std::make_shared<st::ShaderOpSet>();
  2723. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2724. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Derivatives");
  2725. LPCSTR CS = pShaderOp->CS;
  2726. struct Dispatch {
  2727. int x, y, z;
  2728. int mx, my, mz;
  2729. };
  2730. std::vector<Dispatch> dispatches =
  2731. {
  2732. {32, 32, 1, 8, 8, 1},
  2733. {64, 4, 1, 64, 2, 1},
  2734. {1, 4, 64, 1, 4, 32},
  2735. {64, 1, 1, 64, 1, 1},
  2736. {1, 64, 1, 1, 64, 1},
  2737. {1, 1, 64, 1, 1, 64},
  2738. {16, 16, 3, 4, 4, 3},
  2739. {32, 3, 8, 8, 3, 2},
  2740. {3, 1, 64, 3, 1, 32}
  2741. };
  2742. char compilerOptions[256];
  2743. for (Dispatch &D : dispatches) {
  2744. UINT width = D.x;
  2745. UINT height = D.y;
  2746. UINT depth = D.z;
  2747. UINT mwidth = D.mx;
  2748. UINT mheight = D.my;
  2749. UINT mdepth = D.mz;
  2750. UINT pixelSize = 4; // always float4
  2751. // format compiler args
  2752. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2753. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2754. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2755. width, height, depth, mwidth, mheight, mdepth));
  2756. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2757. S.Arguments = compilerOptions;
  2758. pShaderOp->DispatchX = width;
  2759. pShaderOp->DispatchY = height;
  2760. pShaderOp->DispatchZ = depth;
  2761. // Test Compute Shader
  2762. pShaderOp->CS = CS;
  2763. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2764. MappedData data;
  2765. test->Test->GetReadBackData("U0", &data);
  2766. const float *pPixels = (float *)data.data();
  2767. // To find roughly the center for compute, divide the pixel count in half,
  2768. // truncate to next lowest power of 16 (4x4), which is the repeating period
  2769. // and then add 10 to reach the point the test expects
  2770. UINT centerIndex = (((UINT64)(width * height * depth)/2) & ~0xF) + 10;
  2771. UINT offsetCenter = centerIndex * pixelSize;
  2772. LogCommentFmt(L"Verifying derivatives in compute shader results");
  2773. VerifyDerivResults(pPixels, offsetCenter);
  2774. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2775. // Disable CS so mesh goes forward
  2776. pShaderOp->CS = nullptr;
  2777. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2778. test->Test->GetReadBackData("U1", &data);
  2779. pPixels = (float *)data.data();
  2780. centerIndex = (((UINT64)(mwidth * mheight * mdepth)/2) & ~0xF) + 10;
  2781. offsetCenter = centerIndex * pixelSize;
  2782. LogCommentFmt(L"Verifying derivatives in mesh shader results");
  2783. VerifyDerivResults(pPixels, offsetCenter);
  2784. test->Test->GetReadBackData("U2", &data);
  2785. pPixels = (float *)data.data();
  2786. LogCommentFmt(L"Verifying derivatives in amplification shader results");
  2787. VerifyDerivResults(pPixels, offsetCenter);
  2788. }
  2789. }
  2790. // Final test with not divisible by 4 dispatch size just to make sure it runs
  2791. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2792. S.Arguments = "-D DISPATCHX=3 -D DISPATCHY=3 -D DISPATCHZ=3 "
  2793. "-D MESHDISPATCHX=3 -D MESHDISPATCHY=3 -D MESHDISPATCHZ=3";
  2794. pShaderOp->DispatchX = 3;
  2795. pShaderOp->DispatchY = 3;
  2796. pShaderOp->DispatchZ = 3;
  2797. // Test Compute Shader
  2798. pShaderOp->CS = CS;
  2799. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2800. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2801. pShaderOp->CS = nullptr;
  2802. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2803. }
  2804. }
  2805. // Verify the results for the quad starting with the given index
  2806. void VerifyQuadReadResults(const UINT *pPixels, UINT quadIndex) {
  2807. for (UINT i = 0; i < 4; i++) {
  2808. UINT ix = quadIndex + i;
  2809. VERIFY_ARE_EQUAL(pPixels[4*ix + 0], ix); // ReadLaneAt own quad index
  2810. VERIFY_ARE_EQUAL(pPixels[4*ix + 1], (ix^1));// ReadAcrossX
  2811. VERIFY_ARE_EQUAL(pPixels[4*ix + 2], (ix^2));// ReadAcrossY
  2812. VERIFY_ARE_EQUAL(pPixels[4*ix + 3], (ix^3));// ReadAcrossDiagonal
  2813. }
  2814. }
  2815. TEST_F(ExecutionTest, QuadReadTest) {
  2816. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2817. CComPtr<IStream> pStream;
  2818. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2819. CComPtr<ID3D12Device> pDevice;
  2820. if (!CreateDevice(&pDevice))
  2821. return;
  2822. if (GetTestParamUseWARP(UseWarpByDefault())) {
  2823. WEX::Logging::Log::Comment(L"WARP does not support QuadRead in compute shaders.");
  2824. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2825. return;
  2826. }
  2827. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2828. std::make_shared<st::ShaderOpSet>();
  2829. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2830. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("QuadRead");
  2831. LPCSTR CS = pShaderOp->CS;
  2832. struct Dispatch {
  2833. int x, y, z;
  2834. int mx, my, mz;
  2835. };
  2836. //std::vector<std::tuple<int, int, int, int, int>> dispatches =
  2837. std::vector<Dispatch> dispatches =
  2838. {
  2839. {32, 32, 1, 8, 8, 1},
  2840. {64, 4, 1, 64, 2, 1},
  2841. {1, 4, 64, 1, 4, 32},
  2842. {64, 1, 1, 64, 1, 1},
  2843. {1, 64, 1, 1, 64, 1},
  2844. {1, 1, 64, 1, 1, 64},
  2845. {16, 16, 3, 4, 4, 3},
  2846. {32, 3, 8, 8, 3, 2},
  2847. {3, 1, 64, 3, 1, 32}
  2848. };
  2849. for (Dispatch &D : dispatches) {
  2850. UINT width = D.x;
  2851. UINT height = D.y;
  2852. UINT depth = D.z;
  2853. UINT mwidth = D.mx;
  2854. UINT mheight = D.my;
  2855. UINT mdepth = D.mz;
  2856. // format compiler args
  2857. char compilerOptions[256];
  2858. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2859. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2860. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2861. width, height, depth, mwidth, mheight, mdepth));
  2862. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2863. S.Arguments = compilerOptions;
  2864. pShaderOp->DispatchX = width;
  2865. pShaderOp->DispatchY = height;
  2866. pShaderOp->DispatchZ = depth;
  2867. // Test Compute Shader
  2868. pShaderOp->CS = CS;
  2869. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2870. MappedData data;
  2871. test->Test->GetReadBackData("U0", &data);
  2872. const UINT *pPixels = (UINT *)data.data();
  2873. // To find roughly the center for compute, divide the pixel count in half
  2874. // and truncate to next lowest power of 4 to start at a quad
  2875. UINT offsetCenter = ((UINT64)(width * height * depth)/2) & ~0x3;
  2876. // Test first, second and center quads
  2877. LogCommentFmt(L"Verifying QuadRead* in compute shader results");
  2878. VerifyQuadReadResults(pPixels, 0);
  2879. VerifyQuadReadResults(pPixels, 4);
  2880. VerifyQuadReadResults(pPixels, offsetCenter);
  2881. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2882. offsetCenter = ((UINT64)(mwidth * mheight * mdepth)/2) & ~0x3;
  2883. // Disable CS so mesh goes forward
  2884. pShaderOp->CS = nullptr;
  2885. test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2886. test->Test->GetReadBackData("U1", &data);
  2887. pPixels = (UINT *)data.data();
  2888. // Test first, second and center quads
  2889. LogCommentFmt(L"Verifying QuadRead* in mesh shader results");
  2890. VerifyQuadReadResults(pPixels, 0);
  2891. VerifyQuadReadResults(pPixels, 4);
  2892. VerifyQuadReadResults(pPixels, offsetCenter);
  2893. test->Test->GetReadBackData("U2", &data);
  2894. pPixels = (UINT *)data.data();
  2895. // Test first, second and center quads
  2896. LogCommentFmt(L"Verifying QuadRead* in amplification shader results");
  2897. VerifyQuadReadResults(pPixels, 0);
  2898. VerifyQuadReadResults(pPixels, 4);
  2899. VerifyQuadReadResults(pPixels, offsetCenter);
  2900. }
  2901. }
  2902. }
  2903. void VerifySampleResults(const UINT *pPixels) {
  2904. UINT xlod = 0;
  2905. UINT ylod = 0;
  2906. // Each pixel contains 4 samples and 4 LOD calculations.
  2907. // 2 of these (called 'left' and 'right') have X values that vary and a constant Y
  2908. // 2 others (called 'top' and 'bot') have Y values that vary and a constant X
  2909. // Only of the X variant sample results and one of the Y variant results
  2910. // are actually reported for the pixel.
  2911. // The other 2 serve as "helpers" to the other pixels in the quad.
  2912. // On the left side of the quad, the 'left' samples are reported.
  2913. // Op the top of the quad, the 'top' samples are reported and so on.
  2914. // The varying coordinate values alternate between zero and a
  2915. // value whose magnitude increases with the index.
  2916. // As a result, the LOD level should steadily increas.
  2917. // Due to vagaries of implementation, the same derivatives
  2918. // in both directions might result in different levels for different locations
  2919. // in the quad. So only comparisons between sample results and LOD calculations
  2920. // and ensuring that the LOD increased and reaches the max can be tested reliably.
  2921. for (unsigned i = 0; i < 64; i++) {
  2922. // CalculateLOD and Sample from texture with mip levels containing LOD index should match
  2923. VERIFY_ARE_EQUAL(pPixels[4*i + 0], pPixels[4*i + 1]);
  2924. VERIFY_ARE_EQUAL(pPixels[4*i + 2], pPixels[4*i + 3]);
  2925. // Make sure LODs are ever climbing as magnitudes increase
  2926. VERIFY_IS_TRUE(pPixels[4*i] >= xlod);
  2927. xlod = pPixels[4*i];
  2928. VERIFY_IS_TRUE(pPixels[4*i + 2] >= ylod);
  2929. ylod = pPixels[4*i + 2];
  2930. }
  2931. // Make sure we reached the max lod level for both tracks
  2932. VERIFY_ARE_EQUAL(xlod, 6);
  2933. VERIFY_ARE_EQUAL(ylod, 6);
  2934. }
  2935. TEST_F(ExecutionTest, ComputeSampleTest) {
  2936. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2937. CComPtr<IStream> pStream;
  2938. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2939. CComPtr<ID3D12Device> pDevice;
  2940. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2941. return;
  2942. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2943. std::make_shared<st::ShaderOpSet>();
  2944. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2945. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("ComputeSample");
  2946. D3D12_RESOURCE_DESC &texDesc = pShaderOp->GetResourceByName("T0")->Desc;
  2947. UINT texWidth = (UINT)texDesc.Width;
  2948. UINT texHeight = (UINT)texDesc.Height;
  2949. // Initialize texture with the LOD number in each corresponding mip level
  2950. auto SampleInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2951. VERIFY_ARE_EQUAL(0, _stricmp(Name, "T0"));
  2952. size_t size = sizeof(float) * texWidth * texHeight * 2;
  2953. Data.resize(size);
  2954. float *pPrimitives = (float *)Data.data();
  2955. float lod = 0.0;
  2956. int ix = 0;
  2957. while (texHeight > 0 && texWidth > 0) {
  2958. if(!texHeight) texHeight = 1;
  2959. if(!texWidth) texWidth = 1;
  2960. for (size_t j = 0; j < texHeight; ++j) {
  2961. for (size_t i = 0; i < texWidth; ++i) {
  2962. pPrimitives[ix++] = lod;
  2963. }
  2964. }
  2965. lod += 1.0;
  2966. texHeight >>= 1;
  2967. texWidth >>= 1;
  2968. }
  2969. };
  2970. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2971. MappedData data;
  2972. test->Test->GetReadBackData("U0", &data);
  2973. const UINT *pPixels = (UINT *)data.data();
  2974. VerifySampleResults(pPixels);
  2975. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2976. // Disable CS so mesh goes forward
  2977. pShaderOp->CS = nullptr;
  2978. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2979. }
  2980. }
  2981. // Executing a simple binop to verify shadel model 6.1 support; runs with
  2982. // ShaderModel61.CoreRequirement
  2983. TEST_F(ExecutionTest, BasicShaderModel61) {
  2984. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  2985. }
  2986. // Executing a simple binop to verify shadel model 6.3 support; runs with
  2987. // ShaderModel63.CoreRequirement
  2988. TEST_F(ExecutionTest, BasicShaderModel63) {
  2989. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  2990. }
  2991. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  2992. WEX::TestExecution::SetVerifyOutput verifySettings(
  2993. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2994. CComPtr<ID3D12Device> pDevice;
  2995. if (!CreateDevice(&pDevice, shaderModel)) {
  2996. return;
  2997. }
  2998. char *pShaderModelStr;
  2999. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  3000. pShaderModelStr = "cs_6_1";
  3001. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  3002. pShaderModelStr = "cs_6_3";
  3003. } else {
  3004. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  3005. pShaderModelStr = nullptr;
  3006. }
  3007. const char shaderTemplate[] =
  3008. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  3009. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  3010. "[numthreads(8,8,1)]"
  3011. "void main(uint GI : SV_GroupIndex) {"
  3012. " SBinaryOp l = g_buf[GI];"
  3013. " l.output = l.input1 + l.input2;"
  3014. " g_buf[GI] = l;"
  3015. "}";
  3016. char shader[sizeof(shaderTemplate) + 50];
  3017. // Run simple shader with float data types
  3018. char* sTy = "float";
  3019. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  3020. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3021. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  3022. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  3023. // Run simple shader with double data types
  3024. if (DoesDeviceSupportDouble(pDevice)) {
  3025. sTy = "double";
  3026. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  3027. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3028. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  3029. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  3030. }
  3031. else {
  3032. // Optional feature, so it's correct to not support it if declared as such.
  3033. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  3034. }
  3035. // Run simple shader with int64 types
  3036. if (DoesDeviceSupportInt64(pDevice)) {
  3037. sTy = "int64_t";
  3038. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  3039. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3040. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  3041. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  3042. }
  3043. else {
  3044. // Optional feature, so it's correct to not support it if declared as such.
  3045. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  3046. }
  3047. }
  3048. template <class Ty>
  3049. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  3050. DXASSERT_NOMSG("Unsupported type");
  3051. return "";
  3052. }
  3053. template <>
  3054. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  3055. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  3056. }
  3057. template <>
  3058. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  3059. return BasicShaderModelTest_GetFormatString<float>();
  3060. }
  3061. template <>
  3062. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  3063. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  3064. }
  3065. template <class Ty>
  3066. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  3067. Ty *pInputDataPairs, unsigned inputDataCount) {
  3068. struct SBinaryOp {
  3069. Ty input1;
  3070. Ty input2;
  3071. Ty output;
  3072. };
  3073. CComPtr<IStream> pStream;
  3074. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3075. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3076. pDevice, m_support, pStream, "BinaryFPOp",
  3077. // this callbacked is called when the test is creating the resource to run the test
  3078. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3079. UNREFERENCED_PARAMETER(Name);
  3080. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  3081. pShaderOp->Shaders.at(0).Text = pShader;
  3082. size_t size = sizeof(SBinaryOp) * inputDataCount;
  3083. Data.resize(size);
  3084. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  3085. Ty *pIn = pInputDataPairs;
  3086. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  3087. SBinaryOp *p = &pPrimitives[i];
  3088. p->input1 = pIn[0];
  3089. p->input2 = pIn[1];
  3090. }
  3091. });
  3092. VERIFY_SUCCEEDED(S_OK);
  3093. MappedData data;
  3094. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3095. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  3096. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  3097. Ty *pIn = pInputDataPairs;
  3098. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  3099. Ty expValue = pIn[0] + pIn[1];
  3100. SBinaryOp *p = &pPrimitives[i];
  3101. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  3102. VERIFY_ARE_EQUAL(p->output, expValue);
  3103. }
  3104. }
  3105. // Resource structure for data-driven tests.
  3106. struct SUnaryFPOp {
  3107. float input;
  3108. float output;
  3109. };
  3110. struct SBinaryFPOp {
  3111. float input1;
  3112. float input2;
  3113. float output1;
  3114. float output2;
  3115. };
  3116. struct STertiaryFPOp {
  3117. float input1;
  3118. float input2;
  3119. float input3;
  3120. float output;
  3121. };
  3122. struct SUnaryHalfOp {
  3123. uint16_t input;
  3124. uint16_t output;
  3125. };
  3126. struct SBinaryHalfOp {
  3127. uint16_t input1;
  3128. uint16_t input2;
  3129. uint16_t output1;
  3130. uint16_t output2;
  3131. };
  3132. struct STertiaryHalfOp {
  3133. uint16_t input1;
  3134. uint16_t input2;
  3135. uint16_t input3;
  3136. uint16_t output;
  3137. };
  3138. struct SUnaryIntOp {
  3139. int input;
  3140. int output;
  3141. };
  3142. struct SUnaryUintOp {
  3143. unsigned int input;
  3144. unsigned int output;
  3145. };
  3146. struct SBinaryIntOp {
  3147. int input1;
  3148. int input2;
  3149. int output1;
  3150. int output2;
  3151. };
  3152. struct STertiaryIntOp {
  3153. int input1;
  3154. int input2;
  3155. int input3;
  3156. int output;
  3157. };
  3158. struct SBinaryUintOp {
  3159. unsigned int input1;
  3160. unsigned int input2;
  3161. unsigned int output1;
  3162. unsigned int output2;
  3163. };
  3164. struct STertiaryUintOp {
  3165. unsigned int input1;
  3166. unsigned int input2;
  3167. unsigned int input3;
  3168. unsigned int output;
  3169. };
  3170. struct SUnaryInt16Op {
  3171. short input;
  3172. short output;
  3173. };
  3174. struct SUnaryUint16Op {
  3175. unsigned short input;
  3176. unsigned short output;
  3177. };
  3178. struct SBinaryInt16Op {
  3179. short input1;
  3180. short input2;
  3181. short output1;
  3182. short output2;
  3183. };
  3184. struct STertiaryInt16Op {
  3185. short input1;
  3186. short input2;
  3187. short input3;
  3188. short output;
  3189. };
  3190. struct SBinaryUint16Op {
  3191. unsigned short input1;
  3192. unsigned short input2;
  3193. unsigned short output1;
  3194. unsigned short output2;
  3195. };
  3196. struct STertiaryUint16Op {
  3197. unsigned short input1;
  3198. unsigned short input2;
  3199. unsigned short input3;
  3200. unsigned short output;
  3201. };
  3202. // representation for HLSL float vectors
  3203. struct SDotOp {
  3204. XMFLOAT4 input1;
  3205. XMFLOAT4 input2;
  3206. float o_dot2;
  3207. float o_dot3;
  3208. float o_dot4;
  3209. };
  3210. struct Half2
  3211. {
  3212. uint16_t x;
  3213. uint16_t y;
  3214. Half2() = default;
  3215. Half2(const Half2&) = default;
  3216. Half2& operator=(const Half2&) = default;
  3217. Half2(Half2&&) = default;
  3218. Half2& operator=(Half2&&) = default;
  3219. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  3220. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  3221. };
  3222. struct SDot2AddHalfOp {
  3223. Half2 input1;
  3224. Half2 input2;
  3225. float acc;
  3226. float result;
  3227. };
  3228. struct SDot4AddI8PackedOp {
  3229. uint32_t input1;
  3230. uint32_t input2;
  3231. int32_t acc;
  3232. int32_t result;
  3233. };
  3234. struct SDot4AddU8PackedOp {
  3235. uint32_t input1;
  3236. uint32_t input2;
  3237. uint32_t acc;
  3238. uint32_t result;
  3239. };
  3240. struct SMsad4 {
  3241. unsigned int ref;
  3242. XMUINT2 src;
  3243. XMUINT4 accum;
  3244. XMUINT4 result;
  3245. };
  3246. struct SPackUnpackOpOutPacked
  3247. {
  3248. uint32_t packedUint32;
  3249. uint32_t packedInt32;
  3250. uint32_t packedUint16;
  3251. uint32_t packedInt16;
  3252. uint32_t packedClampedUint32;
  3253. uint32_t packedClampedInt32;
  3254. uint32_t packedClampedUint16;
  3255. uint32_t packedClampedInt16;
  3256. };
  3257. struct SPackUnpackOpOutUnpacked {
  3258. std::array<uint32_t, 4> outputUint32;
  3259. std::array<int32_t, 4> outputInt32;
  3260. std::array<uint16_t, 4> outputUint16;
  3261. std::array<int16_t, 4> outputInt16;
  3262. std::array<uint32_t, 4> outputClampedUint32;
  3263. std::array<int32_t, 4> outputClampedInt32;
  3264. std::array<uint16_t, 4> outputClampedUint16;
  3265. std::array<int16_t, 4> outputClampedInt16;
  3266. };
  3267. // Parameter representation for taef data-driven tests
  3268. struct TableParameter {
  3269. LPCWSTR m_name;
  3270. enum TableParameterType {
  3271. INT8,
  3272. INT16,
  3273. INT32,
  3274. UINT,
  3275. FLOAT,
  3276. HALF,
  3277. DOUBLE,
  3278. STRING,
  3279. BOOL,
  3280. INT8_TABLE,
  3281. INT16_TABLE,
  3282. INT32_TABLE,
  3283. FLOAT_TABLE,
  3284. HALF_TABLE,
  3285. DOUBLE_TABLE,
  3286. STRING_TABLE,
  3287. UINT8_TABLE,
  3288. UINT16_TABLE,
  3289. UINT32_TABLE,
  3290. BOOL_TABLE
  3291. };
  3292. TableParameterType m_type;
  3293. bool m_required; // required parameter
  3294. int8_t m_int8;
  3295. int16_t m_int16;
  3296. int m_int32;
  3297. unsigned int m_uint;
  3298. float m_float;
  3299. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  3300. double m_double;
  3301. bool m_bool;
  3302. WEX::Common::String m_str;
  3303. std::vector<int8_t> m_int8Table;
  3304. std::vector<int16_t> m_int16Table;
  3305. std::vector<int> m_int32Table;
  3306. std::vector<uint8_t> m_uint8Table;
  3307. std::vector<uint16_t> m_uint16Table;
  3308. std::vector<unsigned int> m_uint32Table;
  3309. std::vector<float> m_floatTable;
  3310. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  3311. std::vector<double> m_doubleTable;
  3312. std::vector<bool> m_boolTable;
  3313. std::vector<WEX::Common::String> m_StringTable;
  3314. };
  3315. class TableParameterHandler {
  3316. private:
  3317. HRESULT ParseTableRow();
  3318. public:
  3319. TableParameter* m_table;
  3320. size_t m_tableSize;
  3321. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  3322. clearTableParameter();
  3323. VERIFY_SUCCEEDED(ParseTableRow());
  3324. }
  3325. TableParameter* GetTableParamByName(LPCWSTR name) {
  3326. for (size_t i = 0; i < m_tableSize; ++i) {
  3327. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3328. return &m_table[i];
  3329. }
  3330. }
  3331. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3332. return nullptr;
  3333. }
  3334. void clearTableParameter() {
  3335. for (size_t i = 0; i < m_tableSize; ++i) {
  3336. m_table[i].m_int32 = 0;
  3337. m_table[i].m_uint = 0;
  3338. m_table[i].m_double = 0;
  3339. m_table[i].m_bool = false;
  3340. m_table[i].m_str = WEX::Common::String();
  3341. }
  3342. }
  3343. template <class T1>
  3344. std::vector<T1> *GetDataArray(LPCWSTR name) {
  3345. return nullptr;
  3346. }
  3347. template <>
  3348. std::vector<int> *GetDataArray(LPCWSTR name) {
  3349. for (size_t i = 0; i < m_tableSize; ++i) {
  3350. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3351. return &(m_table[i].m_int32Table);
  3352. }
  3353. }
  3354. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3355. return nullptr;
  3356. }
  3357. template <>
  3358. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  3359. for (size_t i = 0; i < m_tableSize; ++i) {
  3360. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3361. return &(m_table[i].m_int8Table);
  3362. }
  3363. }
  3364. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3365. return nullptr;
  3366. }
  3367. template <>
  3368. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  3369. for (size_t i = 0; i < m_tableSize; ++i) {
  3370. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3371. return &(m_table[i].m_int16Table);
  3372. }
  3373. }
  3374. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3375. return nullptr;
  3376. }
  3377. template <>
  3378. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  3379. for (size_t i = 0; i < m_tableSize; ++i) {
  3380. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3381. return &(m_table[i].m_uint32Table);
  3382. }
  3383. }
  3384. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3385. return nullptr;
  3386. }
  3387. template <>
  3388. std::vector<float> *GetDataArray(LPCWSTR name) {
  3389. for (size_t i = 0; i < m_tableSize; ++i) {
  3390. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3391. return &(m_table[i].m_floatTable);
  3392. }
  3393. }
  3394. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3395. return nullptr;
  3396. }
  3397. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  3398. template <>
  3399. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  3400. for (size_t i = 0; i < m_tableSize; ++i) {
  3401. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3402. return &(m_table[i].m_halfTable);
  3403. }
  3404. }
  3405. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3406. return nullptr;
  3407. }
  3408. template <>
  3409. std::vector<double> *GetDataArray(LPCWSTR name) {
  3410. for (size_t i = 0; i < m_tableSize; ++i) {
  3411. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3412. return &(m_table[i].m_doubleTable);
  3413. }
  3414. }
  3415. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3416. return nullptr;
  3417. }
  3418. template <>
  3419. std::vector<bool> *GetDataArray(LPCWSTR name) {
  3420. for (size_t i = 0; i < m_tableSize; ++i) {
  3421. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3422. return &(m_table[i].m_boolTable);
  3423. }
  3424. }
  3425. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3426. return nullptr;
  3427. }
  3428. };
  3429. static TableParameter UnaryFPOpParameters[] = {
  3430. { L"ShaderOp.Target", TableParameter::STRING, true },
  3431. { L"ShaderOp.Text", TableParameter::STRING, true },
  3432. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3433. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3434. { L"Validation.Type", TableParameter::STRING, true },
  3435. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3436. { L"Warp.Version", TableParameter::UINT, false }
  3437. };
  3438. static TableParameter BinaryFPOpParameters[] = {
  3439. { L"ShaderOp.Target", TableParameter::STRING, true },
  3440. { L"ShaderOp.Text", TableParameter::STRING, true },
  3441. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3442. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3443. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3444. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  3445. { L"Validation.Type", TableParameter::STRING, true },
  3446. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3447. };
  3448. static TableParameter TertiaryFPOpParameters[] = {
  3449. { L"ShaderOp.Target", TableParameter::STRING, true },
  3450. { L"ShaderOp.Text", TableParameter::STRING, true },
  3451. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3452. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3453. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3454. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3455. { L"Validation.Type", TableParameter::STRING, true },
  3456. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3457. };
  3458. static TableParameter UnaryHalfOpParameters[] = {
  3459. { L"ShaderOp.Target", TableParameter::STRING, true },
  3460. { L"ShaderOp.Text", TableParameter::STRING, true },
  3461. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3462. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3463. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3464. { L"Validation.Type", TableParameter::STRING, true },
  3465. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3466. { L"Warp.Version", TableParameter::UINT, false }
  3467. };
  3468. static TableParameter BinaryHalfOpParameters[] = {
  3469. { L"ShaderOp.Target", TableParameter::STRING, true },
  3470. { L"ShaderOp.Text", TableParameter::STRING, true },
  3471. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3472. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3473. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3474. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3475. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  3476. { L"Validation.Type", TableParameter::STRING, true },
  3477. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3478. };
  3479. static TableParameter TertiaryHalfOpParameters[] = {
  3480. { L"ShaderOp.Target", TableParameter::STRING, true },
  3481. { L"ShaderOp.Text", TableParameter::STRING, true },
  3482. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3483. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3484. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3485. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  3486. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3487. { L"Validation.Type", TableParameter::STRING, true },
  3488. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3489. };
  3490. static TableParameter UnaryIntOpParameters[] = {
  3491. { L"ShaderOp.Target", TableParameter::STRING, true },
  3492. { L"ShaderOp.Text", TableParameter::STRING, true },
  3493. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3494. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3495. { L"Validation.Tolerance", TableParameter::INT32, true },
  3496. };
  3497. static TableParameter UnaryUintOpParameters[] = {
  3498. { L"ShaderOp.Target", TableParameter::STRING, true },
  3499. { L"ShaderOp.Text", TableParameter::STRING, true },
  3500. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3501. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3502. { L"Validation.Tolerance", TableParameter::INT32, true },
  3503. };
  3504. static TableParameter BinaryIntOpParameters[] = {
  3505. { L"ShaderOp.Target", TableParameter::STRING, true },
  3506. { L"ShaderOp.Text", TableParameter::STRING, true },
  3507. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3508. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3509. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3510. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  3511. { L"Validation.Tolerance", TableParameter::INT32, true },
  3512. };
  3513. static TableParameter TertiaryIntOpParameters[] = {
  3514. { L"ShaderOp.Target", TableParameter::STRING, true },
  3515. { L"ShaderOp.Text", TableParameter::STRING, true },
  3516. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3517. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3518. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3519. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3520. { L"Validation.Tolerance", TableParameter::INT32, true },
  3521. };
  3522. static TableParameter BinaryUintOpParameters[] = {
  3523. { L"ShaderOp.Target", TableParameter::STRING, true },
  3524. { L"ShaderOp.Text", TableParameter::STRING, true },
  3525. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3526. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3527. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3528. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  3529. { L"Validation.Tolerance", TableParameter::INT32, true },
  3530. };
  3531. static TableParameter TertiaryUintOpParameters[] = {
  3532. { L"ShaderOp.Target", TableParameter::STRING, true },
  3533. { L"ShaderOp.Text", TableParameter::STRING, true },
  3534. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3535. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3536. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3537. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3538. { L"Validation.Tolerance", TableParameter::INT32, true },
  3539. };
  3540. static TableParameter UnaryInt16OpParameters[] = {
  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::INT16_TABLE, true },
  3545. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3546. { L"Validation.Tolerance", TableParameter::INT32, true },
  3547. };
  3548. static TableParameter UnaryUint16OpParameters[] = {
  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::UINT16_TABLE, true },
  3553. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3554. { L"Validation.Tolerance", TableParameter::INT32, true },
  3555. };
  3556. static TableParameter BinaryInt16OpParameters[] = {
  3557. { L"ShaderOp.Target", TableParameter::STRING, true },
  3558. { L"ShaderOp.Text", TableParameter::STRING, true },
  3559. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3560. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3561. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3562. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3563. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  3564. { L"Validation.Tolerance", TableParameter::INT32, true },
  3565. };
  3566. static TableParameter TertiaryInt16OpParameters[] = {
  3567. { L"ShaderOp.Target", TableParameter::STRING, true },
  3568. { L"ShaderOp.Text", TableParameter::STRING, true },
  3569. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3570. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3571. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3572. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  3573. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3574. { L"Validation.Tolerance", TableParameter::INT32, true },
  3575. };
  3576. static TableParameter BinaryUint16OpParameters[] = {
  3577. { L"ShaderOp.Target", TableParameter::STRING, true },
  3578. { L"ShaderOp.Text", TableParameter::STRING, true },
  3579. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3580. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3581. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3582. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3583. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  3584. { L"Validation.Tolerance", TableParameter::INT32, true },
  3585. };
  3586. static TableParameter TertiaryUint16OpParameters[] = {
  3587. { L"ShaderOp.Target", TableParameter::STRING, true },
  3588. { L"ShaderOp.Text", TableParameter::STRING, true },
  3589. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3590. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3591. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3592. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  3593. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3594. { L"Validation.Tolerance", TableParameter::INT32, true },
  3595. };
  3596. static TableParameter DotOpParameters[] = {
  3597. { L"ShaderOp.Target", TableParameter::STRING, true },
  3598. { L"ShaderOp.Text", TableParameter::STRING, true },
  3599. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3600. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3601. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3602. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  3603. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  3604. { L"Validation.Type", TableParameter::STRING, true },
  3605. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3606. };
  3607. static TableParameter Dot2AddHalfOpParameters[] = {
  3608. { L"ShaderOp.Target", TableParameter::STRING, true },
  3609. { L"ShaderOp.Text", TableParameter::STRING, true },
  3610. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3611. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3612. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3613. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3614. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3615. { L"Validation.Type", TableParameter::STRING, true },
  3616. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3617. };
  3618. static TableParameter Dot4AddI8PackedOpParameters[] = {
  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::INT32_TABLE, true },
  3624. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3625. };
  3626. static TableParameter Dot4AddU8PackedOpParameters[] = {
  3627. { L"ShaderOp.Target", TableParameter::STRING, true },
  3628. { L"ShaderOp.Text", TableParameter::STRING, true },
  3629. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3630. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3631. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3632. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3633. };
  3634. static TableParameter Msad4OpParameters[] = {
  3635. { L"ShaderOp.Text", TableParameter::STRING, true },
  3636. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3637. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  3638. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3639. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3640. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  3641. };
  3642. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  3643. { L"ShaderOp.Name", TableParameter::STRING, true },
  3644. { L"ShaderOp.Text", TableParameter::STRING, true },
  3645. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3646. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3647. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3648. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3649. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3650. };
  3651. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  3652. { L"ShaderOp.Name", TableParameter::STRING, true },
  3653. { L"ShaderOp.Text", TableParameter::STRING, true },
  3654. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3655. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3656. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3657. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3658. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3659. };
  3660. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  3661. { L"ShaderOp.Name", TableParameter::STRING, true },
  3662. { L"ShaderOp.Text", TableParameter::STRING, true },
  3663. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3664. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3665. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3666. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3667. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3668. };
  3669. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  3670. { L"ShaderOp.Name", TableParameter::STRING, true },
  3671. { L"ShaderOp.Text", TableParameter::STRING, true },
  3672. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3673. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3674. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3675. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3676. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3677. };
  3678. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  3679. { L"ShaderOp.Name", TableParameter::STRING, true },
  3680. { L"ShaderOp.Target", TableParameter::STRING, true },
  3681. { L"ShaderOp.Text", TableParameter::STRING, true },
  3682. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  3683. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  3684. };
  3685. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  3686. { L"ShaderOp.Name", TableParameter::STRING, true },
  3687. { L"ShaderOp.Target", TableParameter::STRING, true },
  3688. { L"ShaderOp.Text", TableParameter::STRING, true },
  3689. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  3690. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  3691. };
  3692. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  3693. { L"ShaderOp.Name", TableParameter::STRING, true },
  3694. { L"ShaderOp.Text", TableParameter::STRING, true },
  3695. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3696. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  3697. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  3698. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  3699. };
  3700. static TableParameter CBufferTestHalfParameters[] = {
  3701. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  3702. };
  3703. static TableParameter DenormBinaryFPOpParameters[] = {
  3704. { L"ShaderOp.Target", TableParameter::STRING, true },
  3705. { L"ShaderOp.Text", TableParameter::STRING, true },
  3706. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3707. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3708. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3709. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3710. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3711. { L"Validation.Type", TableParameter::STRING, true },
  3712. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3713. };
  3714. static TableParameter DenormTertiaryFPOpParameters[] = {
  3715. { L"ShaderOp.Target", TableParameter::STRING, true },
  3716. { L"ShaderOp.Text", TableParameter::STRING, true },
  3717. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3718. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3719. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3720. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3721. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3722. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3723. { L"Validation.Type", TableParameter::STRING, true },
  3724. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3725. };
  3726. static TableParameter PackUnpackOpParameters[] = {
  3727. { L"ShaderOp.Text", TableParameter::STRING, true },
  3728. { L"Validation.Type", TableParameter::STRING, true },
  3729. { L"Validation.Tolerance", TableParameter::UINT, true },
  3730. { L"Validation.Input", TableParameter::UINT32_TABLE, true },
  3731. };
  3732. static bool IsHexString(PCWSTR str, uint16_t *value) {
  3733. std::wstring wString(str);
  3734. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3735. LPCWSTR wstr = wString.c_str();
  3736. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  3737. *value = (uint16_t)wcstol(wstr, NULL, 0);
  3738. return true;
  3739. }
  3740. return false;
  3741. }
  3742. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  3743. std::wstring wString(str);
  3744. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3745. PCWSTR wstr = wString.data();
  3746. if (_wcsicmp(wstr, L"NaN") == 0) {
  3747. value = NAN;
  3748. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  3749. value = -(INFINITY);
  3750. } else if (_wcsicmp(wstr, L"inf") == 0) {
  3751. value = INFINITY;
  3752. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  3753. value = -(FLT_MIN / 2);
  3754. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  3755. value = FLT_MIN / 2;
  3756. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  3757. _wcsicmp(wstr, L"-0") == 0) {
  3758. value = -0.0f;
  3759. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  3760. _wcsicmp(wstr, L"0") == 0) {
  3761. value = 0.0f;
  3762. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  3763. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  3764. value = (float&)temp_i;
  3765. }
  3766. else {
  3767. // evaluate the expression of wstring
  3768. double val = _wtof(wstr);
  3769. if (val == 0) {
  3770. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  3771. return E_FAIL;
  3772. }
  3773. value = (float)val;
  3774. }
  3775. return S_OK;
  3776. }
  3777. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  3778. std::wstring wString(str);
  3779. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3780. PCWSTR wstr = wString.data();
  3781. // evaluate the expression of string
  3782. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  3783. value = 0;
  3784. return S_OK;
  3785. }
  3786. int val = _wtoi(wstr);
  3787. if (val == 0) {
  3788. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3789. return E_FAIL;
  3790. }
  3791. value = val;
  3792. return S_OK;
  3793. }
  3794. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3795. std::wstring wString(str);
  3796. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3797. PCWSTR wstr = wString.data();
  3798. // evaluate the expression of string
  3799. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3800. value = 0;
  3801. return S_OK;
  3802. }
  3803. wchar_t *end;
  3804. unsigned int val = std::wcstoul(wstr, &end, 0);
  3805. if (val == 0) {
  3806. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3807. return E_FAIL;
  3808. }
  3809. value = val;
  3810. return S_OK;
  3811. }
  3812. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3813. std::wstring wstr(str);
  3814. size_t curPosition = 0;
  3815. // parse a string of dot product separated by commas
  3816. for (size_t i = 0; i < count; ++i) {
  3817. size_t nextPosition = wstr.find(L",", curPosition);
  3818. if (FAILED(ParseDataToFloat(
  3819. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3820. *(ptr + i)))) {
  3821. return E_FAIL;
  3822. }
  3823. curPosition = nextPosition + 1;
  3824. }
  3825. return S_OK;
  3826. }
  3827. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3828. std::wstring wstr(str);
  3829. size_t curPosition = 0;
  3830. // parse a string of dot product separated by commas
  3831. for (size_t i = 0; i < count; ++i) {
  3832. size_t nextPosition = wstr.find(L",", curPosition);
  3833. float floatValue;
  3834. if (FAILED(ParseDataToFloat(
  3835. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3836. return E_FAIL;
  3837. }
  3838. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3839. curPosition = nextPosition + 1;
  3840. }
  3841. return S_OK;
  3842. }
  3843. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3844. std::wstring wstr(str);
  3845. size_t curPosition = 0;
  3846. // parse a string of dot product separated by commas
  3847. for (size_t i = 0; i < count; ++i) {
  3848. size_t nextPosition = wstr.find(L",", curPosition);
  3849. if (FAILED(ParseDataToUint(
  3850. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3851. *(ptr + i)))) {
  3852. return E_FAIL;
  3853. }
  3854. curPosition = nextPosition + 1;
  3855. }
  3856. return S_OK;
  3857. }
  3858. HRESULT TableParameterHandler::ParseTableRow() {
  3859. TableParameter *table = m_table;
  3860. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3861. switch (table[i].m_type) {
  3862. case TableParameter::INT8:
  3863. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3864. table[i].m_int32)) && table[i].m_required) {
  3865. // TryGetValue does not suppport reading from int16
  3866. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3867. return E_FAIL;
  3868. }
  3869. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3870. break;
  3871. case TableParameter::INT16:
  3872. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3873. table[i].m_int32)) && table[i].m_required) {
  3874. // TryGetValue does not suppport reading from int16
  3875. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3876. return E_FAIL;
  3877. }
  3878. table[i].m_int16 = (short)(table[i].m_int32);
  3879. break;
  3880. case TableParameter::INT32:
  3881. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3882. table[i].m_int32)) && table[i].m_required) {
  3883. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3884. return E_FAIL;
  3885. }
  3886. break;
  3887. case TableParameter::UINT:
  3888. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3889. table[i].m_uint)) && table[i].m_required) {
  3890. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3891. return E_FAIL;
  3892. }
  3893. break;
  3894. case TableParameter::DOUBLE:
  3895. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3896. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3897. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3898. return E_FAIL;
  3899. }
  3900. break;
  3901. case TableParameter::STRING:
  3902. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3903. table[i].m_str)) && table[i].m_required) {
  3904. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3905. return E_FAIL;
  3906. }
  3907. break;
  3908. case TableParameter::BOOL:
  3909. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3910. table[i].m_str)) && table[i].m_bool) {
  3911. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3912. return E_FAIL;
  3913. }
  3914. break;
  3915. case TableParameter::INT8_TABLE: {
  3916. WEX::TestExecution::TestDataArray<int> tempTable;
  3917. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3918. table[i].m_name, tempTable)) && table[i].m_required) {
  3919. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3920. return E_FAIL;
  3921. }
  3922. // TryGetValue does not suppport reading from int8
  3923. table[i].m_int8Table.resize(tempTable.GetSize());
  3924. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3925. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  3926. }
  3927. break;
  3928. }
  3929. case TableParameter::INT16_TABLE: {
  3930. WEX::TestExecution::TestDataArray<int> tempTable;
  3931. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3932. table[i].m_name, tempTable)) && table[i].m_required) {
  3933. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3934. return E_FAIL;
  3935. }
  3936. // TryGetValue does not suppport reading from int8
  3937. table[i].m_int16Table.resize(tempTable.GetSize());
  3938. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3939. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  3940. }
  3941. break;
  3942. }case TableParameter::INT32_TABLE: {
  3943. WEX::TestExecution::TestDataArray<int> tempTable;
  3944. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3945. table[i].m_name, tempTable)) && table[i].m_required) {
  3946. // TryGetValue does not suppport reading from int8
  3947. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3948. return E_FAIL;
  3949. }
  3950. table[i].m_int32Table.resize(tempTable.GetSize());
  3951. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3952. table[i].m_int32Table[j] = tempTable[j];
  3953. }
  3954. break;
  3955. }
  3956. case TableParameter::UINT8_TABLE: {
  3957. WEX::TestExecution::TestDataArray<int> tempTable;
  3958. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3959. table[i].m_name, tempTable)) && table[i].m_required) {
  3960. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3961. return E_FAIL;
  3962. }
  3963. // TryGetValue does not suppport reading from int8
  3964. table[i].m_int8Table.resize(tempTable.GetSize());
  3965. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3966. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  3967. }
  3968. break;
  3969. }
  3970. case TableParameter::UINT16_TABLE: {
  3971. WEX::TestExecution::TestDataArray<int> tempTable;
  3972. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3973. table[i].m_name, tempTable)) && table[i].m_required) {
  3974. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3975. return E_FAIL;
  3976. }
  3977. // TryGetValue does not suppport reading from int8
  3978. table[i].m_uint16Table.resize(tempTable.GetSize());
  3979. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3980. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  3981. }
  3982. break;
  3983. }
  3984. case TableParameter::UINT32_TABLE: {
  3985. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  3986. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3987. table[i].m_name, tempTable)) && table[i].m_required) {
  3988. // TryGetValue does not suppport reading from int8
  3989. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3990. return E_FAIL;
  3991. }
  3992. table[i].m_uint32Table.resize(tempTable.GetSize());
  3993. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3994. table[i].m_uint32Table[j] = tempTable[j];
  3995. }
  3996. break;
  3997. }
  3998. case TableParameter::FLOAT_TABLE: {
  3999. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4000. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4001. table[i].m_name, tempTable)) && table[i].m_required) {
  4002. // TryGetValue does not suppport reading from int8
  4003. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4004. return E_FAIL;
  4005. }
  4006. table[i].m_floatTable.resize(tempTable.GetSize());
  4007. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4008. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  4009. }
  4010. break;
  4011. }
  4012. case TableParameter::HALF_TABLE: {
  4013. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4014. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4015. table[i].m_name, tempTable)) && table[i].m_required) {
  4016. // TryGetValue does not suppport reading from int8
  4017. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4018. return E_FAIL;
  4019. }
  4020. table[i].m_halfTable.resize(tempTable.GetSize());
  4021. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4022. uint16_t value = 0;
  4023. if (IsHexString(tempTable[j], &value)) {
  4024. table[i].m_halfTable[j] = value;
  4025. }
  4026. else {
  4027. float val;
  4028. ParseDataToFloat(tempTable[j], val);
  4029. if (isdenorm(val))
  4030. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  4031. else
  4032. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  4033. }
  4034. }
  4035. break;
  4036. }
  4037. case TableParameter::DOUBLE_TABLE: {
  4038. WEX::TestExecution::TestDataArray<double> tempTable;
  4039. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4040. table[i].m_name, tempTable)) && table[i].m_required) {
  4041. // TryGetValue does not suppport reading from int8
  4042. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4043. return E_FAIL;
  4044. }
  4045. table[i].m_doubleTable.resize(tempTable.GetSize());
  4046. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4047. table[i].m_doubleTable[j] = tempTable[j];
  4048. }
  4049. break;
  4050. }
  4051. case TableParameter::BOOL_TABLE: {
  4052. WEX::TestExecution::TestDataArray<bool> tempTable;
  4053. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4054. table[i].m_name, tempTable)) && table[i].m_required) {
  4055. // TryGetValue does not suppport reading from int8
  4056. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4057. return E_FAIL;
  4058. }
  4059. table[i].m_boolTable.resize(tempTable.GetSize());
  4060. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4061. table[i].m_boolTable[j] = tempTable[j];
  4062. }
  4063. break;
  4064. }
  4065. case TableParameter::STRING_TABLE: {
  4066. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4067. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4068. table[i].m_name, tempTable)) && table[i].m_required) {
  4069. // TryGetValue does not suppport reading from int8
  4070. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4071. return E_FAIL;
  4072. }
  4073. table[i].m_StringTable.resize(tempTable.GetSize());
  4074. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4075. table[i].m_StringTable[j] = tempTable[j];
  4076. }
  4077. break;
  4078. }
  4079. default:
  4080. DXASSERT_NOMSG("Invalid Parameter Type");
  4081. }
  4082. if (errno == ERANGE) {
  4083. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  4084. return E_FAIL;
  4085. }
  4086. }
  4087. return S_OK;
  4088. }
  4089. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  4090. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4091. }
  4092. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  4093. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4094. }
  4095. static void VerifyOutputWithExpectedValueUInt4(XMUINT4 output, XMUINT4 ref) {
  4096. VERIFY_ARE_EQUAL(output.x, ref.x);
  4097. VERIFY_ARE_EQUAL(output.y, ref.y);
  4098. VERIFY_ARE_EQUAL(output.z, ref.z);
  4099. VERIFY_ARE_EQUAL(output.w, ref.w);
  4100. }
  4101. static void VerifyOutputWithExpectedValueFloat(
  4102. float output, float ref, LPCWSTR type, double tolerance,
  4103. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4104. if (_wcsicmp(type, L"Relative") == 0) {
  4105. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  4106. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4107. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  4108. } else if (_wcsicmp(type, L"ULP") == 0) {
  4109. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  4110. } else {
  4111. LogErrorFmt(L"Failed to read comparison type %S", type);
  4112. }
  4113. }
  4114. static bool CompareOutputWithExpectedValueFloat(
  4115. float output, float ref, LPCWSTR type, double tolerance,
  4116. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4117. if (_wcsicmp(type, L"Relative") == 0) {
  4118. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  4119. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4120. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  4121. } else if (_wcsicmp(type, L"ULP") == 0) {
  4122. return CompareFloatULP(output, ref, (int)tolerance, mode);
  4123. } else {
  4124. LogErrorFmt(L"Failed to read comparison type %S", type);
  4125. return false;
  4126. }
  4127. }
  4128. static void VerifyOutputWithExpectedValueHalf(
  4129. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  4130. if (_wcsicmp(type, L"Relative") == 0) {
  4131. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  4132. }
  4133. else if (_wcsicmp(type, L"Epsilon") == 0) {
  4134. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  4135. }
  4136. else if (_wcsicmp(type, L"ULP") == 0) {
  4137. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  4138. }
  4139. else {
  4140. LogErrorFmt(L"Failed to read comparison type %S", type);
  4141. }
  4142. }
  4143. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  4144. WEX::TestExecution::SetVerifyOutput verifySettings(
  4145. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4146. CComPtr<IStream> pStream;
  4147. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4148. CComPtr<ID3D12Device> pDevice;
  4149. if (!CreateDevice(&pDevice)) {
  4150. return;
  4151. }
  4152. // Read data from the table
  4153. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  4154. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  4155. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4156. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4157. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4158. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4159. return;
  4160. }
  4161. std::vector<float> *Validation_Input =
  4162. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4163. std::vector<float> *Validation_Expected =
  4164. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4165. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4166. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4167. size_t count = Validation_Input->size();
  4168. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4169. pDevice, m_support, pStream, "UnaryFPOp",
  4170. // this callbacked is called when the test
  4171. // is creating the resource to run the test
  4172. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4173. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4174. size_t size = sizeof(SUnaryFPOp) * count;
  4175. Data.resize(size);
  4176. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  4177. for (size_t i = 0; i < count; ++i) {
  4178. SUnaryFPOp *p = &pPrimitives[i];
  4179. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4180. }
  4181. // use shader from data table
  4182. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4183. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4184. });
  4185. MappedData data;
  4186. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4187. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  4188. WEX::TestExecution::DisableVerifyExceptions dve;
  4189. for (unsigned i = 0; i < count; ++i) {
  4190. SUnaryFPOp *p = &pPrimitives[i];
  4191. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4192. LogCommentFmt(
  4193. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  4194. p->input, p->output, val);
  4195. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  4196. }
  4197. }
  4198. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  4199. WEX::TestExecution::SetVerifyOutput verifySettings(
  4200. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4201. CComPtr<IStream> pStream;
  4202. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4203. CComPtr<ID3D12Device> pDevice;
  4204. if (!CreateDevice(&pDevice)) {
  4205. return;
  4206. }
  4207. // Read data from the table
  4208. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  4209. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  4210. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4211. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4212. std::vector<float> *Validation_Input1 =
  4213. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4214. std::vector<float> *Validation_Input2 =
  4215. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4216. std::vector<float> *Validation_Expected1 =
  4217. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4218. std::vector<float> *Validation_Expected2 =
  4219. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  4220. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4221. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4222. size_t count = Validation_Input1->size();
  4223. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4224. pDevice, m_support, pStream, "BinaryFPOp",
  4225. // this callbacked is called when the test
  4226. // is creating the resource to run the test
  4227. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4228. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4229. size_t size = sizeof(SBinaryFPOp) * count;
  4230. Data.resize(size);
  4231. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4232. for (size_t i = 0; i < count; ++i) {
  4233. SBinaryFPOp *p = &pPrimitives[i];
  4234. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4235. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4236. }
  4237. // use shader from data table
  4238. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4239. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4240. });
  4241. MappedData data;
  4242. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4243. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4244. WEX::TestExecution::DisableVerifyExceptions dve;
  4245. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4246. if (numExpected == 2) {
  4247. for (unsigned i = 0; i < count; ++i) {
  4248. SBinaryFPOp *p = &pPrimitives[i];
  4249. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4250. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4251. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4252. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  4253. i, p->input1, p->input2, p->output1, val1, p->output2,
  4254. val2);
  4255. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4256. Validation_Tolerance);
  4257. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  4258. Validation_Tolerance);
  4259. }
  4260. }
  4261. else if (numExpected == 1) {
  4262. for (unsigned i = 0; i < count; ++i) {
  4263. SBinaryFPOp *p = &pPrimitives[i];
  4264. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4265. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4266. L"%6.8f, expected1 = %6.8f",
  4267. i, p->input1, p->input2, p->output1, val1);
  4268. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4269. Validation_Tolerance);
  4270. }
  4271. }
  4272. else {
  4273. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4274. }
  4275. }
  4276. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  4277. WEX::TestExecution::SetVerifyOutput verifySettings(
  4278. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4279. CComPtr<IStream> pStream;
  4280. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4281. CComPtr<ID3D12Device> pDevice;
  4282. if (!CreateDevice(&pDevice)) {
  4283. return;
  4284. }
  4285. // Read data from the table
  4286. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  4287. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  4288. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4289. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4290. std::vector<float> *Validation_Input1 =
  4291. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4292. std::vector<float> *Validation_Input2 =
  4293. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4294. std::vector<float> *Validation_Input3 =
  4295. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  4296. std::vector<float> *Validation_Expected =
  4297. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4298. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4299. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4300. size_t count = Validation_Input1->size();
  4301. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4302. pDevice, m_support, pStream, "TertiaryFPOp",
  4303. // this callbacked is called when the test
  4304. // is creating the resource to run the test
  4305. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4306. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4307. size_t size = sizeof(STertiaryFPOp) * count;
  4308. Data.resize(size);
  4309. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  4310. for (size_t i = 0; i < count; ++i) {
  4311. STertiaryFPOp *p = &pPrimitives[i];
  4312. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4313. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4314. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4315. }
  4316. // use shader from data table
  4317. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4318. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4319. });
  4320. MappedData data;
  4321. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4322. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  4323. WEX::TestExecution::DisableVerifyExceptions dve;
  4324. for (unsigned i = 0; i < count; ++i) {
  4325. STertiaryFPOp *p = &pPrimitives[i];
  4326. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4327. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  4328. L"%6.8f, expected = %6.8f",
  4329. i, p->input1, p->input2, p->input3, p->output, val);
  4330. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  4331. Validation_Tolerance);
  4332. }
  4333. }
  4334. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  4335. WEX::TestExecution::SetVerifyOutput verifySettings(
  4336. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4337. CComPtr<IStream> pStream;
  4338. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4339. CComPtr<ID3D12Device> pDevice;
  4340. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4341. return;
  4342. }
  4343. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4344. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4345. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4346. return;
  4347. }
  4348. // Read data from the table
  4349. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  4350. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  4351. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4352. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4353. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4354. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4355. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4356. return;
  4357. }
  4358. std::vector<uint16_t> *Validation_Input =
  4359. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4360. std::vector<uint16_t> *Validation_Expected =
  4361. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4362. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4363. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4364. size_t count = Validation_Input->size();
  4365. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4366. pDevice, m_support, pStream, "UnaryFPOp",
  4367. // this callbacked is called when the test
  4368. // is creating the resource to run the test
  4369. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4370. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4371. size_t size = sizeof(SUnaryHalfOp) * count;
  4372. Data.resize(size);
  4373. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  4374. for (size_t i = 0; i < count; ++i) {
  4375. SUnaryHalfOp *p = &pPrimitives[i];
  4376. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4377. }
  4378. // use shader from data table
  4379. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4380. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4381. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4382. });
  4383. MappedData data;
  4384. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4385. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  4386. WEX::TestExecution::DisableVerifyExceptions dve;
  4387. for (unsigned i = 0; i < count; ++i) {
  4388. SUnaryHalfOp *p = &pPrimitives[i];
  4389. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  4390. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4391. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4392. i, ConvertFloat16ToFloat32(p->input), p->input,
  4393. ConvertFloat16ToFloat32(p->output), p->output,
  4394. ConvertFloat16ToFloat32(expected), expected);
  4395. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4396. }
  4397. }
  4398. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  4399. WEX::TestExecution::SetVerifyOutput verifySettings(
  4400. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4401. CComPtr<IStream> pStream;
  4402. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4403. CComPtr<ID3D12Device> pDevice;
  4404. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4405. return;
  4406. }
  4407. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4408. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4409. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4410. return;
  4411. }
  4412. // Read data from the table
  4413. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  4414. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  4415. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4416. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4417. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4418. std::vector<uint16_t> *Validation_Input1 =
  4419. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4420. std::vector<uint16_t> *Validation_Input2 =
  4421. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4422. std::vector<uint16_t> *Validation_Expected1 =
  4423. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4424. std::vector<uint16_t> *Validation_Expected2 =
  4425. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  4426. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4427. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4428. size_t count = Validation_Input1->size();
  4429. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4430. pDevice, m_support, pStream, "BinaryFPOp",
  4431. // this callbacked is called when the test
  4432. // is creating the resource to run the test
  4433. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4434. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4435. size_t size = sizeof(SBinaryHalfOp) * count;
  4436. Data.resize(size);
  4437. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  4438. for (size_t i = 0; i < count; ++i) {
  4439. SBinaryHalfOp *p = &pPrimitives[i];
  4440. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4441. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4442. }
  4443. // use shader from data table
  4444. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4445. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4446. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4447. });
  4448. MappedData data;
  4449. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4450. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  4451. WEX::TestExecution::DisableVerifyExceptions dve;
  4452. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4453. if (numExpected == 2) {
  4454. for (unsigned i = 0; i < count; ++i) {
  4455. SBinaryHalfOp *p = &pPrimitives[i];
  4456. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  4457. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  4458. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  4459. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  4460. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4461. ConvertFloat16ToFloat32(p->input2), p->input2,
  4462. ConvertFloat16ToFloat32(p->output1), p->output1,
  4463. ConvertFloat16ToFloat32(p->output2), p->output2,
  4464. ConvertFloat16ToFloat32(expected1), expected1,
  4465. ConvertFloat16ToFloat32(expected2), expected2);
  4466. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  4467. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  4468. }
  4469. }
  4470. else if (numExpected == 1) {
  4471. for (unsigned i = 0; i < count; ++i) {
  4472. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  4473. SBinaryHalfOp *p = &pPrimitives[i];
  4474. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4475. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4476. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4477. ConvertFloat16ToFloat32(p->output1), p->output1,
  4478. ConvertFloat16ToFloat32(expected), expected);
  4479. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  4480. }
  4481. }
  4482. else {
  4483. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4484. }
  4485. }
  4486. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  4487. WEX::TestExecution::SetVerifyOutput verifySettings(
  4488. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4489. CComPtr<IStream> pStream;
  4490. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4491. CComPtr<ID3D12Device> pDevice;
  4492. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4493. return;
  4494. }
  4495. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4496. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4497. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4498. return;
  4499. }
  4500. // Read data from the table
  4501. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  4502. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  4503. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4504. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4505. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4506. std::vector<uint16_t> *Validation_Input1 =
  4507. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4508. std::vector<uint16_t> *Validation_Input2 =
  4509. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4510. std::vector<uint16_t> *Validation_Input3 =
  4511. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  4512. std::vector<uint16_t> *Validation_Expected =
  4513. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4514. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4515. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4516. size_t count = Validation_Input1->size();
  4517. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4518. pDevice, m_support, pStream, "TertiaryFPOp",
  4519. // this callbacked is called when the test
  4520. // is creating the resource to run the test
  4521. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4522. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4523. size_t size = sizeof(STertiaryHalfOp) * count;
  4524. Data.resize(size);
  4525. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  4526. for (size_t i = 0; i < count; ++i) {
  4527. STertiaryHalfOp *p = &pPrimitives[i];
  4528. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4529. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4530. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4531. }
  4532. // use shader from data table
  4533. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4534. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4535. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4536. });
  4537. MappedData data;
  4538. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4539. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  4540. WEX::TestExecution::DisableVerifyExceptions dve;
  4541. for (unsigned i = 0; i < count; ++i) {
  4542. STertiaryHalfOp *p = &pPrimitives[i];
  4543. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  4544. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  4545. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4546. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4547. ConvertFloat16ToFloat32(p->input2), p->input2,
  4548. ConvertFloat16ToFloat32(p->input3), p->input3,
  4549. ConvertFloat16ToFloat32(p->output), p->output,
  4550. ConvertFloat16ToFloat32(expected), expected);
  4551. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4552. }
  4553. }
  4554. TEST_F(ExecutionTest, UnaryIntOpTest) {
  4555. WEX::TestExecution::SetVerifyOutput verifySettings(
  4556. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4557. CComPtr<IStream> pStream;
  4558. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4559. CComPtr<ID3D12Device> pDevice;
  4560. if (!CreateDevice(&pDevice)) {
  4561. return;
  4562. }
  4563. // Read data from the table
  4564. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  4565. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  4566. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4567. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4568. std::vector<int> *Validation_Input =
  4569. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4570. std::vector<int> *Validation_Expected =
  4571. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4572. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4573. size_t count = Validation_Input->size();
  4574. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4575. pDevice, m_support, pStream, "UnaryIntOp",
  4576. // this callbacked is called when the test
  4577. // is creating the resource to run the test
  4578. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4579. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4580. size_t size = sizeof(SUnaryIntOp) * count;
  4581. Data.resize(size);
  4582. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  4583. for (size_t i = 0; i < count; ++i) {
  4584. SUnaryIntOp *p = &pPrimitives[i];
  4585. int val = (*Validation_Input)[i % Validation_Input->size()];
  4586. p->input = val;
  4587. }
  4588. // use shader data table
  4589. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4590. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4591. });
  4592. MappedData data;
  4593. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4594. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  4595. WEX::TestExecution::DisableVerifyExceptions dve;
  4596. for (unsigned i = 0; i < count; ++i) {
  4597. SUnaryIntOp *p = &pPrimitives[i];
  4598. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4599. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  4600. L"expected = %11i(0x%08x)",
  4601. i, p->input, p->input, p->output, p->output, val, val);
  4602. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4603. }
  4604. }
  4605. TEST_F(ExecutionTest, UnaryUintOpTest) {
  4606. WEX::TestExecution::SetVerifyOutput verifySettings(
  4607. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4608. CComPtr<IStream> pStream;
  4609. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4610. CComPtr<ID3D12Device> pDevice;
  4611. if (!CreateDevice(&pDevice)) {
  4612. return;
  4613. }
  4614. // Read data from the table
  4615. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  4616. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  4617. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4618. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4619. std::vector<unsigned int> *Validation_Input =
  4620. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4621. std::vector<unsigned int> *Validation_Expected =
  4622. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4623. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4624. size_t count = Validation_Input->size();
  4625. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4626. pDevice, m_support, pStream, "UnaryUintOp",
  4627. // this callbacked is called when the test
  4628. // is creating the resource to run the test
  4629. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4630. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4631. size_t size = sizeof(SUnaryUintOp) * count;
  4632. Data.resize(size);
  4633. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  4634. for (size_t i = 0; i < count; ++i) {
  4635. SUnaryUintOp *p = &pPrimitives[i];
  4636. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  4637. p->input = val;
  4638. }
  4639. // use shader data table
  4640. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4641. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4642. });
  4643. MappedData data;
  4644. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4645. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  4646. WEX::TestExecution::DisableVerifyExceptions dve;
  4647. for (unsigned i = 0; i < count; ++i) {
  4648. SUnaryUintOp *p = &pPrimitives[i];
  4649. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4650. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  4651. L"expected = %11u(0x%08x)",
  4652. i, p->input, p->input, p->output, p->output, val, val);
  4653. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4654. }
  4655. }
  4656. TEST_F(ExecutionTest, BinaryIntOpTest) {
  4657. WEX::TestExecution::SetVerifyOutput verifySettings(
  4658. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4659. CComPtr<IStream> pStream;
  4660. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4661. CComPtr<ID3D12Device> pDevice;
  4662. if (!CreateDevice(&pDevice)) {
  4663. return;
  4664. }
  4665. // Read data from the table
  4666. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  4667. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  4668. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4669. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4670. std::vector<int> *Validation_Input1 =
  4671. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4672. std::vector<int> *Validation_Input2 =
  4673. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4674. std::vector<int> *Validation_Expected1 =
  4675. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4676. std::vector<int> *Validation_Expected2 =
  4677. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  4678. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4679. size_t count = Validation_Input1->size();
  4680. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4681. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4682. pDevice, m_support, pStream, "BinaryIntOp",
  4683. // this callbacked is called when the test
  4684. // is creating the resource to run the test
  4685. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4686. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4687. size_t size = sizeof(SBinaryIntOp) * count;
  4688. Data.resize(size);
  4689. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  4690. for (size_t i = 0; i < count; ++i) {
  4691. SBinaryIntOp *p = &pPrimitives[i];
  4692. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4693. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4694. p->input1 = val1;
  4695. p->input2 = val2;
  4696. }
  4697. // use shader from data table
  4698. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4699. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4700. });
  4701. MappedData data;
  4702. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4703. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  4704. WEX::TestExecution::DisableVerifyExceptions dve;
  4705. if (numExpected == 2) {
  4706. for (unsigned i = 0; i < count; ++i) {
  4707. SBinaryIntOp *p = &pPrimitives[i];
  4708. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4709. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4710. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4711. L"%11i(0x%08x), output1 = "
  4712. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  4713. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  4714. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4715. p->output1, val1, val1, p->output2, p->output2, val2,
  4716. val2);
  4717. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4718. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4719. }
  4720. }
  4721. else if (numExpected == 1) {
  4722. for (unsigned i = 0; i < count; ++i) {
  4723. SBinaryIntOp *p = &pPrimitives[i];
  4724. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4725. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4726. L"%11i(0x%08x), output = "
  4727. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  4728. p->input1, p->input1, p->input2, p->input2,
  4729. p->output1, p->output1, val1, val1);
  4730. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4731. }
  4732. }
  4733. else {
  4734. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4735. }
  4736. }
  4737. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  4738. WEX::TestExecution::SetVerifyOutput verifySettings(
  4739. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4740. CComPtr<IStream> pStream;
  4741. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4742. CComPtr<ID3D12Device> pDevice;
  4743. if (!CreateDevice(&pDevice)) {
  4744. return;
  4745. }
  4746. // Read data from the table
  4747. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  4748. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  4749. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4750. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4751. std::vector<int> *Validation_Input1 =
  4752. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4753. std::vector<int> *Validation_Input2 =
  4754. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4755. std::vector<int> *Validation_Input3 =
  4756. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4757. std::vector<int> *Validation_Expected =
  4758. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4759. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4760. size_t count = Validation_Input1->size();
  4761. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4762. pDevice, m_support, pStream, "TertiaryIntOp",
  4763. // this callbacked is called when the test
  4764. // is creating the resource to run the test
  4765. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4766. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4767. size_t size = sizeof(STertiaryIntOp) * count;
  4768. Data.resize(size);
  4769. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  4770. for (size_t i = 0; i < count; ++i) {
  4771. STertiaryIntOp *p = &pPrimitives[i];
  4772. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4773. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4774. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4775. p->input1 = val1;
  4776. p->input2 = val2;
  4777. p->input3 = val3;
  4778. }
  4779. // use shader from data table
  4780. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4781. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4782. });
  4783. MappedData data;
  4784. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4785. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  4786. WEX::TestExecution::DisableVerifyExceptions dve;
  4787. for (unsigned i = 0; i < count; ++i) {
  4788. STertiaryIntOp *p = &pPrimitives[i];
  4789. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4790. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4791. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4792. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4793. i, p->input1, p->input1, p->input2, p->input2,
  4794. p->input3, p->input3, p->output, p->output, val1,
  4795. val1);
  4796. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4797. }
  4798. }
  4799. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4800. WEX::TestExecution::SetVerifyOutput verifySettings(
  4801. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4802. CComPtr<IStream> pStream;
  4803. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4804. CComPtr<ID3D12Device> pDevice;
  4805. if (!CreateDevice(&pDevice)) {
  4806. return;
  4807. }
  4808. // Read data from the table
  4809. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4810. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4811. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4812. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4813. std::vector<unsigned int> *Validation_Input1 =
  4814. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4815. std::vector<unsigned int> *Validation_Input2 =
  4816. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4817. std::vector<unsigned int> *Validation_Expected1 =
  4818. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4819. std::vector<unsigned int> *Validation_Expected2 =
  4820. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4821. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4822. size_t count = Validation_Input1->size();
  4823. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4824. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4825. pDevice, m_support, pStream, "BinaryUintOp",
  4826. // this callbacked is called when the test
  4827. // is creating the resource to run the test
  4828. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4829. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4830. size_t size = sizeof(SBinaryUintOp) * count;
  4831. Data.resize(size);
  4832. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4833. for (size_t i = 0; i < count; ++i) {
  4834. SBinaryUintOp *p = &pPrimitives[i];
  4835. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4836. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4837. p->input1 = val1;
  4838. p->input2 = val2;
  4839. }
  4840. // use shader from data table
  4841. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4842. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4843. });
  4844. MappedData data;
  4845. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4846. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4847. WEX::TestExecution::DisableVerifyExceptions dve;
  4848. if (numExpected == 2) {
  4849. for (unsigned i = 0; i < count; ++i) {
  4850. SBinaryUintOp *p = &pPrimitives[i];
  4851. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4852. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4853. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4854. L"%11u(0x%08x), output1 = "
  4855. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4856. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4857. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4858. p->output1, val1, val1, p->output2, p->output2, val2,
  4859. val2);
  4860. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4861. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4862. }
  4863. }
  4864. else if (numExpected == 1) {
  4865. for (unsigned i = 0; i < count; ++i) {
  4866. SBinaryUintOp *p = &pPrimitives[i];
  4867. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4868. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4869. L"%11u(0x%08x), output = "
  4870. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4871. p->input1, p->input1, p->input2, p->input2,
  4872. p->output1, p->output1, val1, val1);
  4873. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4874. }
  4875. }
  4876. else {
  4877. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4878. }
  4879. }
  4880. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4881. WEX::TestExecution::SetVerifyOutput verifySettings(
  4882. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4883. CComPtr<IStream> pStream;
  4884. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4885. CComPtr<ID3D12Device> pDevice;
  4886. if (!CreateDevice(&pDevice)) {
  4887. return;
  4888. }
  4889. // Read data from the table
  4890. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4891. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4892. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4893. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4894. std::vector<unsigned int> *Validation_Input1 =
  4895. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4896. std::vector<unsigned int> *Validation_Input2 =
  4897. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4898. std::vector<unsigned int> *Validation_Input3 =
  4899. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4900. std::vector<unsigned int> *Validation_Expected =
  4901. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4902. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4903. size_t count = Validation_Input1->size();
  4904. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4905. pDevice, m_support, pStream, "TertiaryUintOp",
  4906. // this callbacked is called when the test
  4907. // is creating the resource to run the test
  4908. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4909. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4910. size_t size = sizeof(STertiaryUintOp) * count;
  4911. Data.resize(size);
  4912. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4913. for (size_t i = 0; i < count; ++i) {
  4914. STertiaryUintOp *p = &pPrimitives[i];
  4915. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4916. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4917. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4918. p->input1 = val1;
  4919. p->input2 = val2;
  4920. p->input3 = val3;
  4921. }
  4922. // use shader from data table
  4923. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4924. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4925. });
  4926. MappedData data;
  4927. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4928. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  4929. WEX::TestExecution::DisableVerifyExceptions dve;
  4930. for (unsigned i = 0; i < count; ++i) {
  4931. STertiaryUintOp *p = &pPrimitives[i];
  4932. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4933. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4934. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  4935. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4936. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4937. p->output, p->output, val1, val1);
  4938. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4939. }
  4940. }
  4941. // 16 bit integer type tests
  4942. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  4943. WEX::TestExecution::SetVerifyOutput verifySettings(
  4944. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4945. CComPtr<IStream> pStream;
  4946. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4947. CComPtr<ID3D12Device> pDevice;
  4948. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4949. return;
  4950. }
  4951. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4952. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4953. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4954. return;
  4955. }
  4956. // Read data from the table
  4957. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  4958. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  4959. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4960. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4961. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4962. std::vector<short> *Validation_Input =
  4963. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4964. std::vector<short> *Validation_Expected =
  4965. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4966. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4967. size_t count = Validation_Input->size();
  4968. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4969. pDevice, m_support, pStream, "UnaryIntOp",
  4970. // this callbacked is called when the test
  4971. // is creating the resource to run the test
  4972. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4973. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4974. size_t size = sizeof(SUnaryInt16Op) * count;
  4975. Data.resize(size);
  4976. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  4977. for (size_t i = 0; i < count; ++i) {
  4978. SUnaryInt16Op *p = &pPrimitives[i];
  4979. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4980. }
  4981. // use shader data table
  4982. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4983. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4984. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4985. });
  4986. MappedData data;
  4987. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4988. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  4989. WEX::TestExecution::DisableVerifyExceptions dve;
  4990. for (unsigned i = 0; i < count; ++i) {
  4991. SUnaryInt16Op *p = &pPrimitives[i];
  4992. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  4993. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  4994. L"expected = %5hi(0x%08x)",
  4995. i, p->input, p->input, p->output, p->output, val, val);
  4996. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4997. }
  4998. }
  4999. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  5000. WEX::TestExecution::SetVerifyOutput verifySettings(
  5001. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5002. CComPtr<IStream> pStream;
  5003. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5004. CComPtr<ID3D12Device> pDevice;
  5005. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5006. return;
  5007. }
  5008. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5009. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5010. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5011. return;
  5012. }
  5013. // Read data from the table
  5014. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  5015. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  5016. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5017. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5018. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5019. std::vector<unsigned short> *Validation_Input =
  5020. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5021. std::vector<unsigned short> *Validation_Expected =
  5022. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5023. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5024. size_t count = Validation_Input->size();
  5025. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5026. pDevice, m_support, pStream, "UnaryUintOp",
  5027. // this callbacked is called when the test
  5028. // is creating the resource to run the test
  5029. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5030. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  5031. size_t size = sizeof(SUnaryUint16Op) * count;
  5032. Data.resize(size);
  5033. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  5034. for (size_t i = 0; i < count; ++i) {
  5035. SUnaryUint16Op *p = &pPrimitives[i];
  5036. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5037. }
  5038. // use shader data table
  5039. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5040. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5041. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5042. });
  5043. MappedData data;
  5044. test->Test->GetReadBackData("SUnaryUintOp", &data);
  5045. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  5046. WEX::TestExecution::DisableVerifyExceptions dve;
  5047. for (unsigned i = 0; i < count; ++i) {
  5048. SUnaryUint16Op *p = &pPrimitives[i];
  5049. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5050. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  5051. L"expected = %5hu(0x%08x)",
  5052. i, p->input, p->input, p->output, p->output, val, val);
  5053. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5054. }
  5055. }
  5056. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  5057. WEX::TestExecution::SetVerifyOutput verifySettings(
  5058. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5059. CComPtr<IStream> pStream;
  5060. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5061. CComPtr<ID3D12Device> pDevice;
  5062. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5063. return;
  5064. }
  5065. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5066. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5067. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5068. return;
  5069. }
  5070. // Read data from the table
  5071. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  5072. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  5073. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5074. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5075. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5076. std::vector<short> *Validation_Input1 =
  5077. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5078. std::vector<short> *Validation_Input2 =
  5079. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5080. std::vector<short> *Validation_Expected1 =
  5081. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5082. std::vector<short> *Validation_Expected2 =
  5083. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  5084. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5085. size_t count = Validation_Input1->size();
  5086. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5087. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5088. pDevice, m_support, pStream, "BinaryIntOp",
  5089. // this callbacked is called when the test
  5090. // is creating the resource to run the test
  5091. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5092. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  5093. size_t size = sizeof(SBinaryInt16Op) * count;
  5094. Data.resize(size);
  5095. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  5096. for (size_t i = 0; i < count; ++i) {
  5097. SBinaryInt16Op *p = &pPrimitives[i];
  5098. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5099. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5100. }
  5101. // use shader from data table
  5102. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5103. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5104. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5105. });
  5106. MappedData data;
  5107. test->Test->GetReadBackData("SBinaryIntOp", &data);
  5108. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  5109. WEX::TestExecution::DisableVerifyExceptions dve;
  5110. if (numExpected == 2) {
  5111. for (unsigned i = 0; i < count; ++i) {
  5112. SBinaryInt16Op *p = &pPrimitives[i];
  5113. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5114. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5115. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5116. L"%5hi(0x%08x), output1 = "
  5117. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  5118. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  5119. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5120. p->output1, val1, val1, p->output2, p->output2, val2,
  5121. val2);
  5122. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5123. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5124. }
  5125. }
  5126. else if (numExpected == 1) {
  5127. for (unsigned i = 0; i < count; ++i) {
  5128. SBinaryInt16Op *p = &pPrimitives[i];
  5129. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5130. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5131. L"%5hi(0x%08x), output = "
  5132. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  5133. p->input1, p->input1, p->input2, p->input2,
  5134. p->output1, p->output1, val1, val1);
  5135. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5136. }
  5137. }
  5138. else {
  5139. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5140. }
  5141. }
  5142. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  5143. WEX::TestExecution::SetVerifyOutput verifySettings(
  5144. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5145. CComPtr<IStream> pStream;
  5146. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5147. CComPtr<ID3D12Device> pDevice;
  5148. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5149. return;
  5150. }
  5151. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5152. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5153. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5154. return;
  5155. }
  5156. // Read data from the table
  5157. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  5158. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  5159. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5160. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5161. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5162. std::vector<short> *Validation_Input1 =
  5163. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5164. std::vector<short> *Validation_Input2 =
  5165. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5166. std::vector<short> *Validation_Input3 =
  5167. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  5168. std::vector<short> *Validation_Expected =
  5169. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5170. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5171. size_t count = Validation_Input1->size();
  5172. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5173. pDevice, m_support, pStream, "TertiaryIntOp",
  5174. // this callbacked is called when the test
  5175. // is creating the resource to run the test
  5176. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5177. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  5178. size_t size = sizeof(STertiaryInt16Op) * count;
  5179. Data.resize(size);
  5180. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  5181. for (size_t i = 0; i < count; ++i) {
  5182. STertiaryInt16Op *p = &pPrimitives[i];
  5183. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5184. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5185. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5186. }
  5187. // use shader from data table
  5188. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5189. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5190. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5191. });
  5192. MappedData data;
  5193. test->Test->GetReadBackData("STertiaryIntOp", &data);
  5194. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  5195. WEX::TestExecution::DisableVerifyExceptions dve;
  5196. for (unsigned i = 0; i < count; ++i) {
  5197. STertiaryInt16Op *p = &pPrimitives[i];
  5198. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5199. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  5200. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  5201. L"%11i(0x%08x), expected = %11i(0x%08x)",
  5202. i, p->input1, p->input1, p->input2, p->input2,
  5203. p->input3, p->input3, p->output, p->output, val1,
  5204. val1);
  5205. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5206. }
  5207. }
  5208. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  5209. WEX::TestExecution::SetVerifyOutput verifySettings(
  5210. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5211. CComPtr<IStream> pStream;
  5212. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5213. CComPtr<ID3D12Device> pDevice;
  5214. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5215. return;
  5216. }
  5217. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5218. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5219. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5220. return;
  5221. }
  5222. // Read data from the table
  5223. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  5224. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  5225. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5226. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5227. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5228. std::vector<unsigned short> *Validation_Input1 =
  5229. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5230. std::vector<unsigned short> *Validation_Input2 =
  5231. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5232. std::vector<unsigned short> *Validation_Expected1 =
  5233. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5234. std::vector<unsigned short> *Validation_Expected2 =
  5235. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  5236. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5237. size_t count = Validation_Input1->size();
  5238. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5239. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5240. pDevice, m_support, pStream, "BinaryUintOp",
  5241. // this callbacked is called when the test
  5242. // is creating the resource to run the test
  5243. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5244. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  5245. size_t size = sizeof(SBinaryUint16Op) * count;
  5246. Data.resize(size);
  5247. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  5248. for (size_t i = 0; i < count; ++i) {
  5249. SBinaryUint16Op *p = &pPrimitives[i];
  5250. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5251. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5252. }
  5253. // use shader from data table
  5254. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5255. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5256. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5257. });
  5258. MappedData data;
  5259. test->Test->GetReadBackData("SBinaryUintOp", &data);
  5260. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  5261. WEX::TestExecution::DisableVerifyExceptions dve;
  5262. if (numExpected == 2) {
  5263. for (unsigned i = 0; i < count; ++i) {
  5264. SBinaryUint16Op *p = &pPrimitives[i];
  5265. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5266. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5267. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5268. L"%5hu(0x%08x), output1 = "
  5269. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  5270. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  5271. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5272. p->output1, val1, val1, p->output2, p->output2, val2,
  5273. val2);
  5274. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5275. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5276. }
  5277. }
  5278. else if (numExpected == 1) {
  5279. for (unsigned i = 0; i < count; ++i) {
  5280. SBinaryUint16Op *p = &pPrimitives[i];
  5281. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5282. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5283. L"%5hu(0x%08x), output = "
  5284. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5285. p->input1, p->input1, p->input2, p->input2,
  5286. p->output1, p->output1, val1, val1);
  5287. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5288. }
  5289. }
  5290. else {
  5291. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5292. }
  5293. }
  5294. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  5295. WEX::TestExecution::SetVerifyOutput verifySettings(
  5296. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5297. CComPtr<IStream> pStream;
  5298. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5299. CComPtr<ID3D12Device> pDevice;
  5300. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5301. return;
  5302. }
  5303. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5304. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5305. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5306. return;
  5307. }
  5308. // Read data from the table
  5309. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  5310. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  5311. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5312. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5313. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5314. std::vector<unsigned short> *Validation_Input1 =
  5315. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5316. std::vector<unsigned short> *Validation_Input2 =
  5317. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5318. std::vector<unsigned short> *Validation_Input3 =
  5319. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  5320. std::vector<unsigned short> *Validation_Expected =
  5321. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5322. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5323. size_t count = Validation_Input1->size();
  5324. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5325. pDevice, m_support, pStream, "TertiaryUintOp",
  5326. // this callbacked is called when the test
  5327. // is creating the resource to run the test
  5328. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5329. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  5330. size_t size = sizeof(STertiaryUint16Op) * count;
  5331. Data.resize(size);
  5332. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  5333. for (size_t i = 0; i < count; ++i) {
  5334. STertiaryUint16Op *p = &pPrimitives[i];
  5335. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5336. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5337. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5338. }
  5339. // use shader from data table
  5340. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5341. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5342. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5343. });
  5344. MappedData data;
  5345. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5346. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  5347. WEX::TestExecution::DisableVerifyExceptions dve;
  5348. for (unsigned i = 0; i < count; ++i) {
  5349. STertiaryUint16Op *p = &pPrimitives[i];
  5350. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5351. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5352. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  5353. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5354. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5355. p->output, p->output, val1, val1);
  5356. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5357. }
  5358. }
  5359. TEST_F(ExecutionTest, DotTest) {
  5360. WEX::TestExecution::SetVerifyOutput verifySettings(
  5361. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5362. CComPtr<IStream> pStream;
  5363. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5364. CComPtr<ID3D12Device> pDevice;
  5365. if (!CreateDevice(&pDevice)) {
  5366. return;
  5367. }
  5368. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  5369. TableParameterHandler handler(DotOpParameters, tableSize);
  5370. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5371. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5372. std::vector<WEX::Common::String> *Validation_Input1 =
  5373. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5374. std::vector<WEX::Common::String> *Validation_Input2 =
  5375. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5376. std::vector<WEX::Common::String> *Validation_dot2 =
  5377. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5378. std::vector<WEX::Common::String> *Validation_dot3 =
  5379. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  5380. std::vector<WEX::Common::String> *Validation_dot4 =
  5381. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  5382. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5383. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5384. size_t count = Validation_Input1->size();
  5385. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5386. pDevice, m_support, pStream, "DotOp",
  5387. // this callbacked is called when the test
  5388. // is creating the resource to run the test
  5389. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5390. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  5391. size_t size = sizeof(SDotOp) * count;
  5392. Data.resize(size);
  5393. SDotOp *pPrimitives = (SDotOp*)Data.data();
  5394. for (size_t i = 0; i < count; ++i) {
  5395. SDotOp *p = &pPrimitives[i];
  5396. XMFLOAT4 val1,val2;
  5397. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  5398. (float *)&val1, 4));
  5399. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  5400. (float *)&val2, 4));
  5401. p->input1 = val1;
  5402. p->input2 = val2;
  5403. }
  5404. // use shader from data table
  5405. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5406. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5407. });
  5408. MappedData data;
  5409. test->Test->GetReadBackData("SDotOp", &data);
  5410. SDotOp *pPrimitives = (SDotOp*)data.data();
  5411. WEX::TestExecution::DisableVerifyExceptions dve;
  5412. for (size_t i = 0; i < count; ++i) {
  5413. SDotOp *p = &pPrimitives[i];
  5414. float dot2, dot3, dot4;
  5415. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  5416. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  5417. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  5418. LogCommentFmt(
  5419. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  5420. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  5421. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  5422. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  5423. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  5424. p->o_dot4, dot4);
  5425. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  5426. tolerance);
  5427. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  5428. tolerance);
  5429. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  5430. tolerance);
  5431. }
  5432. }
  5433. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  5434. WEX::TestExecution::SetVerifyOutput verifySettings(
  5435. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5436. CComPtr<IStream> pStream;
  5437. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5438. CComPtr<ID3D12Device> pDevice;
  5439. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5440. return;
  5441. }
  5442. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5443. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5444. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5445. return;
  5446. }
  5447. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  5448. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  5449. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5450. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5451. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5452. std::vector<WEX::Common::String> *validation_input1 =
  5453. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5454. std::vector<WEX::Common::String> *validation_input2 =
  5455. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5456. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  5457. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  5458. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5459. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5460. size_t count = validation_input1->size();
  5461. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5462. pDevice, m_support, pStream, "Dot2AddHalfOp",
  5463. // this callback is called when the test
  5464. // is creating the resource to run the test
  5465. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5466. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  5467. size_t size = sizeof(SDot2AddHalfOp) * count;
  5468. Data.resize(size);
  5469. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  5470. for (size_t i = 0; i < count; ++i) {
  5471. SDot2AddHalfOp *p = &pPrimitives[i];
  5472. Half2 val1,val2;
  5473. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  5474. (uint16_t *)&val1, 2));
  5475. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  5476. (uint16_t *)&val2, 2));
  5477. p->input1 = val1;
  5478. p->input2 = val2;
  5479. p->acc = (*validation_acc)[i];
  5480. }
  5481. // use shader from data table
  5482. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5483. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5484. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5485. });
  5486. MappedData data;
  5487. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  5488. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  5489. WEX::TestExecution::DisableVerifyExceptions dve;
  5490. for (size_t i = 0; i < count; ++i) {
  5491. SDot2AddHalfOp *p = &pPrimitives[i];
  5492. float expectedResult = (*validation_result)[i];
  5493. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  5494. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  5495. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  5496. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  5497. LogCommentFmt(
  5498. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  5499. L"result = %f, result_expected = %f",
  5500. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  5501. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  5502. }
  5503. }
  5504. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  5505. WEX::TestExecution::SetVerifyOutput verifySettings(
  5506. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5507. CComPtr<IStream> pStream;
  5508. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5509. CComPtr<ID3D12Device> pDevice;
  5510. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5511. return;
  5512. }
  5513. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  5514. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  5515. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5516. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5517. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5518. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5519. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  5520. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  5521. size_t count = validation_input1->size();
  5522. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5523. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  5524. // this callback is called when the test
  5525. // is creating the resource to run the test
  5526. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5527. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  5528. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  5529. Data.resize(size);
  5530. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  5531. for (size_t i = 0; i < count; ++i) {
  5532. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5533. p->input1 = (*validation_input1)[i];
  5534. p->input2 = (*validation_input2)[i];
  5535. p->acc = (*validation_acc)[i];
  5536. }
  5537. // use shader from data table
  5538. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5539. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5540. });
  5541. MappedData data;
  5542. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  5543. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  5544. WEX::TestExecution::DisableVerifyExceptions dve;
  5545. for (size_t i = 0; i < count; ++i) {
  5546. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5547. int32_t expectedResult = (*validation_result)[i];
  5548. LogCommentFmt(
  5549. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  5550. L"result = %d, result_expected = %d",
  5551. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5552. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  5553. }
  5554. }
  5555. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  5556. WEX::TestExecution::SetVerifyOutput verifySettings(
  5557. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5558. CComPtr<IStream> pStream;
  5559. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5560. CComPtr<ID3D12Device> pDevice;
  5561. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5562. return;
  5563. }
  5564. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  5565. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  5566. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5567. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5568. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5569. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5570. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  5571. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  5572. size_t count = validation_input1->size();
  5573. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5574. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  5575. // this callback is called when the test
  5576. // is creating the resource to run the test
  5577. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5578. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  5579. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  5580. Data.resize(size);
  5581. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  5582. for (size_t i = 0; i < count; ++i) {
  5583. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5584. p->input1 = (*validation_input1)[i];
  5585. p->input2 = (*validation_input2)[i];
  5586. p->acc = (*validation_acc)[i];
  5587. }
  5588. // use shader from data table
  5589. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5590. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5591. });
  5592. MappedData data;
  5593. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  5594. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  5595. WEX::TestExecution::DisableVerifyExceptions dve;
  5596. for (size_t i = 0; i < count; ++i) {
  5597. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5598. uint32_t expectedResult = (*validation_result)[i];
  5599. LogCommentFmt(
  5600. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  5601. L"result = %u, result_expected = %u, ",
  5602. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5603. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  5604. }
  5605. }
  5606. TEST_F(ExecutionTest, Msad4Test) {
  5607. WEX::TestExecution::SetVerifyOutput verifySettings(
  5608. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5609. CComPtr<IStream> pStream;
  5610. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5611. CComPtr<ID3D12Device> pDevice;
  5612. if (!CreateDevice(&pDevice)) {
  5613. return;
  5614. }
  5615. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  5616. TableParameterHandler handler(Msad4OpParameters, tableSize);
  5617. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5618. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5619. std::vector<unsigned int> *Validation_Reference =
  5620. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5621. std::vector<WEX::Common::String> *Validation_Source =
  5622. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5623. std::vector<WEX::Common::String> *Validation_Accum =
  5624. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  5625. std::vector<WEX::Common::String> *Validation_Expected =
  5626. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5627. size_t count = Validation_Expected->size();
  5628. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5629. pDevice, m_support, pStream, "Msad4",
  5630. // this callbacked is called when the test
  5631. // is creating the resource to run the test
  5632. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5633. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  5634. size_t size = sizeof(SMsad4) * count;
  5635. Data.resize(size);
  5636. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  5637. for (size_t i = 0; i < count; ++i) {
  5638. SMsad4 *p = &pPrimitives[i];
  5639. XMUINT2 src;
  5640. XMUINT4 accum;
  5641. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  5642. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  5643. p->ref = (*Validation_Reference)[i];
  5644. p->src = src;
  5645. p->accum = accum;
  5646. }
  5647. // use shader from data table
  5648. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5649. });
  5650. MappedData data;
  5651. test->Test->GetReadBackData("SMsad4", &data);
  5652. SMsad4 *pPrimitives = (SMsad4*)data.data();
  5653. WEX::TestExecution::DisableVerifyExceptions dve;
  5654. for (size_t i = 0; i < count; ++i) {
  5655. SMsad4 *p = &pPrimitives[i];
  5656. XMUINT4 result;
  5657. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  5658. (unsigned int *)&result, 4));
  5659. LogCommentFmt(
  5660. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  5661. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5662. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5663. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  5664. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  5665. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  5666. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  5667. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  5668. result.x, result.x, result.y, result.y, result.z, result.z,
  5669. result.w, result.w);
  5670. int toleranceInt = (int)tolerance;
  5671. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  5672. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  5673. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  5674. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  5675. }
  5676. }
  5677. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  5678. WEX::TestExecution::SetVerifyOutput verifySettings(
  5679. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5680. CComPtr<IStream> pStream;
  5681. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5682. CComPtr<ID3D12Device> pDevice;
  5683. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5684. return;
  5685. }
  5686. // Read data from the table
  5687. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  5688. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  5689. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5690. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5691. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5692. std::vector<WEX::Common::String> *Validation_Input1 =
  5693. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5694. std::vector<WEX::Common::String> *Validation_Input2 =
  5695. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5696. std::vector<WEX::Common::String> *Validation_Expected1 =
  5697. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5698. // two expected outputs for any mode
  5699. std::vector<WEX::Common::String> *Validation_Expected2 =
  5700. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5701. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5702. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5703. size_t count = Validation_Input1->size();
  5704. using namespace hlsl::DXIL;
  5705. Float32DenormMode mode = Float32DenormMode::Any;
  5706. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5707. mode = Float32DenormMode::Preserve;
  5708. }
  5709. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5710. mode = Float32DenormMode::FTZ;
  5711. }
  5712. if (mode == Float32DenormMode::Any) {
  5713. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5714. "must have same number of expected values");
  5715. }
  5716. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5717. pDevice, m_support, pStream, "BinaryFPOp",
  5718. // this callbacked is called when the test
  5719. // is creating the resource to run the test
  5720. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5721. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  5722. size_t size = sizeof(SBinaryFPOp) * count;
  5723. Data.resize(size);
  5724. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  5725. for (size_t i = 0; i < count; ++i) {
  5726. SBinaryFPOp *p = &pPrimitives[i];
  5727. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5728. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5729. float val1, val2;
  5730. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5731. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5732. p->input1 = val1;
  5733. p->input2 = val2;
  5734. }
  5735. // use shader from data table
  5736. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5737. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5738. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5739. });
  5740. MappedData data;
  5741. test->Test->GetReadBackData("SBinaryFPOp", &data);
  5742. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  5743. WEX::TestExecution::DisableVerifyExceptions dve;
  5744. for (unsigned i = 0; i < count; ++i) {
  5745. SBinaryFPOp *p = &pPrimitives[i];
  5746. if (mode == Float32DenormMode::Any) {
  5747. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5748. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5749. float val1;
  5750. float val2;
  5751. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5752. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5753. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5754. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5755. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  5756. VERIFY_IS_TRUE(
  5757. CompareOutputWithExpectedValueFloat(
  5758. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  5759. CompareOutputWithExpectedValueFloat(
  5760. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  5761. }
  5762. else {
  5763. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5764. float val1;
  5765. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5766. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5767. L"%6.8f, expected = %6.8f(%a)",
  5768. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  5769. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  5770. Validation_Tolerance, mode);
  5771. }
  5772. }
  5773. }
  5774. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  5775. WEX::TestExecution::SetVerifyOutput verifySettings(
  5776. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5777. CComPtr<IStream> pStream;
  5778. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5779. CComPtr<ID3D12Device> pDevice;
  5780. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5781. return;
  5782. }
  5783. // Read data from the table
  5784. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  5785. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  5786. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5787. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5788. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5789. std::vector<WEX::Common::String> *Validation_Input1 =
  5790. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5791. std::vector<WEX::Common::String> *Validation_Input2 =
  5792. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5793. std::vector<WEX::Common::String> *Validation_Input3 =
  5794. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5795. std::vector<WEX::Common::String> *Validation_Expected1 =
  5796. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5797. // two expected outputs for any mode
  5798. std::vector<WEX::Common::String> *Validation_Expected2 =
  5799. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5800. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5801. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5802. size_t count = Validation_Input1->size();
  5803. using namespace hlsl::DXIL;
  5804. Float32DenormMode mode = Float32DenormMode::Any;
  5805. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5806. mode = Float32DenormMode::Preserve;
  5807. }
  5808. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5809. mode = Float32DenormMode::FTZ;
  5810. }
  5811. if (mode == Float32DenormMode::Any) {
  5812. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5813. "must have same number of expected values");
  5814. }
  5815. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5816. pDevice, m_support, pStream, "TertiaryFPOp",
  5817. // this callbacked is called when the test
  5818. // is creating the resource to run the test
  5819. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5820. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5821. size_t size = sizeof(STertiaryFPOp) * count;
  5822. Data.resize(size);
  5823. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5824. for (size_t i = 0; i < count; ++i) {
  5825. STertiaryFPOp *p = &pPrimitives[i];
  5826. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5827. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5828. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5829. float val1, val2, val3;
  5830. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5831. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5832. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5833. p->input1 = val1;
  5834. p->input2 = val2;
  5835. p->input3 = val3;
  5836. }
  5837. // use shader from data table
  5838. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5839. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5840. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5841. });
  5842. MappedData data;
  5843. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5844. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5845. WEX::TestExecution::DisableVerifyExceptions dve;
  5846. for (unsigned i = 0; i < count; ++i) {
  5847. STertiaryFPOp *p = &pPrimitives[i];
  5848. if (mode == Float32DenormMode::Any) {
  5849. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5850. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5851. float val1;
  5852. float val2;
  5853. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5854. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5855. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5856. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5857. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5858. VERIFY_IS_TRUE(
  5859. CompareOutputWithExpectedValueFloat(
  5860. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5861. CompareOutputWithExpectedValueFloat(
  5862. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5863. }
  5864. else {
  5865. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5866. float val1;
  5867. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5868. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5869. L"%6.8f, expected = %6.8f(%a)",
  5870. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5871. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5872. Validation_Tolerance, mode);
  5873. }
  5874. }
  5875. }
  5876. // Setup for wave intrinsics tests
  5877. enum class ShaderOpKind {
  5878. WaveSum,
  5879. WaveProduct,
  5880. WaveActiveMax,
  5881. WaveActiveMin,
  5882. WaveCountBits,
  5883. WaveActiveAllEqual,
  5884. WaveActiveAnyTrue,
  5885. WaveActiveAllTrue,
  5886. WaveActiveBitOr,
  5887. WaveActiveBitAnd,
  5888. WaveActiveBitXor,
  5889. ShaderOpInvalid
  5890. };
  5891. struct ShaderOpKindPair {
  5892. LPCWSTR name;
  5893. ShaderOpKind kind;
  5894. };
  5895. static ShaderOpKindPair ShaderOpKindTable[] = {
  5896. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5897. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5898. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5899. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5900. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5901. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5902. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5903. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5904. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5905. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5906. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5907. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5908. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5909. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5910. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5911. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5912. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5913. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  5914. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  5915. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  5916. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  5917. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  5918. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  5919. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  5920. };
  5921. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  5922. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  5923. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  5924. return ShaderOpKindTable[i].kind;
  5925. }
  5926. }
  5927. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  5928. return ShaderOpKind::ShaderOpInvalid;
  5929. }
  5930. template <typename InType, typename OutType, ShaderOpKind kind>
  5931. struct computeExpected {
  5932. OutType operator()(const std::vector<InType> &inputs,
  5933. const std::vector<int> &masks, int maskValue,
  5934. unsigned int index) {
  5935. return 0;
  5936. }
  5937. };
  5938. template <typename InType, typename OutType>
  5939. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  5940. OutType operator()(const std::vector<InType> &inputs,
  5941. const std::vector<int> &masks, int maskValue,
  5942. unsigned int index) {
  5943. OutType sum = 0;
  5944. for (size_t i = 0; i < index; ++i) {
  5945. if (masks.at(i) == maskValue) {
  5946. sum += inputs.at(i);
  5947. }
  5948. }
  5949. return sum;
  5950. }
  5951. };
  5952. template <typename InType, typename OutType>
  5953. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  5954. OutType operator()(const std::vector<InType> &inputs,
  5955. const std::vector<int> &masks, int maskValue,
  5956. unsigned int index) {
  5957. OutType prod = 1;
  5958. for (size_t i = 0; i < index; ++i) {
  5959. if (masks.at(i) == maskValue) {
  5960. prod *= inputs.at(i);
  5961. }
  5962. }
  5963. return prod;
  5964. }
  5965. };
  5966. template <typename InType, typename OutType>
  5967. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  5968. OutType operator()(const std::vector<InType> &inputs,
  5969. const std::vector<int> &masks, int maskValue,
  5970. unsigned int index) {
  5971. OutType maximum = std::numeric_limits<OutType>::min();
  5972. for (size_t i = 0; i < index; ++i) {
  5973. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  5974. maximum = inputs.at(i);
  5975. }
  5976. return maximum;
  5977. }
  5978. };
  5979. template <typename InType, typename OutType>
  5980. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  5981. OutType operator()(const std::vector<InType> &inputs,
  5982. const std::vector<int> &masks, int maskValue,
  5983. unsigned int index) {
  5984. OutType minimum = std::numeric_limits<OutType>::max();
  5985. for (size_t i = 0; i < index; ++i) {
  5986. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  5987. minimum = inputs.at(i);
  5988. }
  5989. return minimum;
  5990. }
  5991. };
  5992. template <typename InType, typename OutType>
  5993. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  5994. OutType operator()(const std::vector<InType> &inputs,
  5995. const std::vector<int> &masks, int maskValue,
  5996. unsigned int index) {
  5997. OutType count = 0;
  5998. for (size_t i = 0; i < index; ++i) {
  5999. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  6000. count++;
  6001. }
  6002. }
  6003. return count;
  6004. }
  6005. };
  6006. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  6007. // So we cannot use c++ bool type to represent bool in HLSL
  6008. // HLSL returns 0 for false and 1 for true
  6009. template <typename InType, typename OutType>
  6010. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  6011. OutType operator()(const std::vector<InType> &inputs,
  6012. const std::vector<int> &masks, int maskValue,
  6013. unsigned int index) {
  6014. for (size_t i = 0; i < index; ++i) {
  6015. if (masks.at(i) == maskValue && inputs.at(i) != 0) {
  6016. return 1;
  6017. }
  6018. }
  6019. return 0;
  6020. }
  6021. };
  6022. template <typename InType, typename OutType>
  6023. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  6024. OutType operator()(const std::vector<InType> &inputs,
  6025. const std::vector<int> &masks, int maskValue,
  6026. unsigned int index) {
  6027. for (size_t i = 0; i < index; ++i) {
  6028. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  6029. return 0;
  6030. }
  6031. }
  6032. return 1;
  6033. }
  6034. };
  6035. template <typename InType, typename OutType>
  6036. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  6037. OutType operator()(const std::vector<InType> &inputs,
  6038. const std::vector<int> &masks, int maskValue,
  6039. unsigned int index) {
  6040. const InType *val = nullptr;
  6041. for (size_t i = 0; i < index; ++i) {
  6042. if (masks.at(i) == maskValue) {
  6043. if (val && *val != inputs.at(i)) {
  6044. return 0;
  6045. }
  6046. val = &inputs.at(i);
  6047. }
  6048. }
  6049. return 1;
  6050. }
  6051. };
  6052. template <typename InType, typename OutType>
  6053. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  6054. OutType operator()(const std::vector<InType> &inputs,
  6055. const std::vector<int> &masks, int maskValue,
  6056. unsigned int index) {
  6057. OutType bits = 0x00000000;
  6058. for (size_t i = 0; i < index; ++i) {
  6059. if (masks.at(i) == maskValue) {
  6060. bits |= inputs.at(i);
  6061. }
  6062. }
  6063. return bits;
  6064. }
  6065. };
  6066. template <typename InType, typename OutType>
  6067. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  6068. OutType operator()(const std::vector<InType> &inputs,
  6069. const std::vector<int> &masks, int maskValue,
  6070. unsigned int index) {
  6071. OutType bits = 0xffffffff;
  6072. for (size_t i = 0; i < index; ++i) {
  6073. if (masks.at(i) == maskValue) {
  6074. bits &= inputs.at(i);
  6075. }
  6076. }
  6077. return bits;
  6078. }
  6079. };
  6080. template <typename InType, typename OutType>
  6081. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  6082. OutType operator()(const std::vector<InType> &inputs,
  6083. const std::vector<int> &masks, int maskValue,
  6084. unsigned int index) {
  6085. OutType bits = 0x00000000;
  6086. for (size_t i = 0; i < index; ++i) {
  6087. if (masks.at(i) == maskValue) {
  6088. bits ^= inputs.at(i);
  6089. }
  6090. }
  6091. return bits;
  6092. }
  6093. };
  6094. // Mask functions used to control active lanes
  6095. static int MaskAll(int i) {
  6096. UNREFERENCED_PARAMETER(i);
  6097. return 1;
  6098. }
  6099. static int MaskEveryOther(int i) {
  6100. return i % 2 == 0 ? 1 : 0;
  6101. }
  6102. static int MaskEveryThird(int i) {
  6103. return i % 3 == 0 ? 1 : 0;
  6104. }
  6105. typedef int(*MaskFunction)(int);
  6106. static MaskFunction MaskFunctionTable[] = {
  6107. MaskAll, MaskEveryOther, MaskEveryThird
  6108. };
  6109. template <typename InType, typename OutType>
  6110. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  6111. const std::vector<int> &masks,
  6112. int maskValue, unsigned int index,
  6113. LPCWSTR str) {
  6114. ShaderOpKind kind = GetShaderOpKind(str);
  6115. switch (kind) {
  6116. case ShaderOpKind::WaveSum:
  6117. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  6118. case ShaderOpKind::WaveProduct:
  6119. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  6120. case ShaderOpKind::WaveActiveMax:
  6121. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  6122. case ShaderOpKind::WaveActiveMin:
  6123. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  6124. case ShaderOpKind::WaveCountBits:
  6125. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  6126. case ShaderOpKind::WaveActiveBitOr:
  6127. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  6128. case ShaderOpKind::WaveActiveBitAnd:
  6129. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  6130. case ShaderOpKind::WaveActiveBitXor:
  6131. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  6132. case ShaderOpKind::WaveActiveAnyTrue:
  6133. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  6134. case ShaderOpKind::WaveActiveAllTrue:
  6135. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  6136. case ShaderOpKind::WaveActiveAllEqual:
  6137. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  6138. default:
  6139. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  6140. return (OutType) 0;
  6141. }
  6142. };
  6143. // A framework for testing individual wave intrinsics tests.
  6144. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  6145. template <class T1, class T2>
  6146. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  6147. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  6148. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6149. // Resource representation for compute shader
  6150. // firstLaneId is used to group different waves
  6151. // laneIndex is used to identify lane within the wave.
  6152. // Lane ids are not necessarily in same order as thread ids.
  6153. struct PerThreadData {
  6154. unsigned firstLaneId;
  6155. unsigned laneIndex;
  6156. int mask;
  6157. T1 input;
  6158. T2 output;
  6159. };
  6160. unsigned int NumThreadsX = 8;
  6161. unsigned int NumThreadsY = 12;
  6162. unsigned int NumThreadsZ = 1;
  6163. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6164. static const unsigned int DispatchGroupCount = 1;
  6165. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  6166. CComPtr<IStream> pStream;
  6167. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6168. CComPtr<ID3D12Device> pDevice;
  6169. if (!CreateDevice(&pDevice)) {
  6170. return;
  6171. }
  6172. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6173. // Optional feature, so it's correct to not support it if declared as such.
  6174. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6175. return;
  6176. }
  6177. TableParameterHandler handler(pParameterList, numParameter);
  6178. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  6179. // Obtain the list of input lists
  6180. std::vector<std::vector<T1>*> InputDataList;
  6181. for (unsigned int i = 0;
  6182. i < numInputSet; ++i) {
  6183. std::wstring inputName = L"Validation.InputSet";
  6184. inputName.append(std::to_wstring(i + 1));
  6185. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  6186. }
  6187. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  6188. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6189. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6190. // Running compute shader for each input set with different masks
  6191. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  6192. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  6193. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  6194. pDevice, m_support, "WaveIntrinsicsOp",
  6195. // this callbacked is called when the test
  6196. // is creating the resource to run the test
  6197. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6198. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  6199. size_t size = sizeof(PerThreadData) * ThreadCount;
  6200. Data.resize(size);
  6201. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  6202. // 4 different inputs for each operation test
  6203. size_t index = 0;
  6204. std::vector<T1> *IntList = InputDataList[setIndex];
  6205. while (index < ThreadCount) {
  6206. PerThreadData *p = &pPrimitives[index];
  6207. p->firstLaneId = 0xFFFFBFFF;
  6208. p->laneIndex = 0xFFFFBFFF;
  6209. p->mask = MaskFunctionTable[maskIndex]((int)index);
  6210. p->input = (*IntList)[index % IntList->size()];
  6211. p->output = 0xFFFFBFFF;
  6212. index++;
  6213. }
  6214. // use shader from data table
  6215. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6216. }, ShaderOpSet);
  6217. // Check the value
  6218. MappedData data;
  6219. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  6220. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  6221. WEX::TestExecution::DisableVerifyExceptions dve;
  6222. // Grouping data by waves
  6223. std::vector<int> firstLaneIds;
  6224. for (size_t i = 0; i < ThreadCount; ++i) {
  6225. PerThreadData *p = &pPrimitives[i];
  6226. int firstLaneId = p->firstLaneId;
  6227. if (!contains(firstLaneIds, firstLaneId)) {
  6228. firstLaneIds.push_back(firstLaneId);
  6229. }
  6230. }
  6231. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  6232. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6233. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  6234. }
  6235. for (size_t i = 0; i < ThreadCount; ++i) {
  6236. PerThreadData *p = &pPrimitives[i];
  6237. waves[p->firstLaneId].get()->push_back(p);
  6238. }
  6239. // validate for each wave
  6240. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6241. // collect inputs and masks for a given wave
  6242. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  6243. std::vector<T1> inputList(waveData->size());
  6244. std::vector<int> maskList(waveData->size(), -1);
  6245. std::vector<T2> outputList(waveData->size());
  6246. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  6247. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6248. unsigned laneID = waveData->at(j)->laneIndex;
  6249. // ensure that each lane ID is unique and within the range
  6250. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  6251. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  6252. maskList.at(laneID) = waveData->at(j)->mask;
  6253. inputList.at(laneID) = waveData->at(j)->input;
  6254. outputList.at(laneID) = waveData->at(j)->output;
  6255. }
  6256. std::wstring inputStr = L"Wave Inputs: ";
  6257. std::wstring maskStr = L"Wave Masks: ";
  6258. std::wstring outputStr = L"Wave Outputs: ";
  6259. // append input string and mask string in lane id order
  6260. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6261. maskStr.append(std::to_wstring(maskList.at(j)));
  6262. maskStr.append(L" ");
  6263. inputStr.append(std::to_wstring(inputList.at(j)));
  6264. inputStr.append(L" ");
  6265. outputStr.append(std::to_wstring(outputList.at(j)));
  6266. outputStr.append(L" ");
  6267. }
  6268. LogCommentFmt(inputStr.data());
  6269. LogCommentFmt(maskStr.data());
  6270. LogCommentFmt(outputStr.data());
  6271. LogCommentFmt(L"\n");
  6272. // Compute expected output for a given inputs, masks, and index
  6273. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  6274. T2 expected;
  6275. // WaveActive is equivalent to WavePrefix lane # lane count
  6276. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  6277. if (maskList.at(laneIndex) == 1) {
  6278. expected = computeExpectedWithShaderOp<T1, T2>(
  6279. inputList, maskList, 1, index,
  6280. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6281. }
  6282. else {
  6283. expected = computeExpectedWithShaderOp<T1, T2>(
  6284. inputList, maskList, 0, index,
  6285. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6286. }
  6287. // TODO: use different comparison for floating point inputs
  6288. bool equal = outputList.at(laneIndex) == expected;
  6289. if (!equal) {
  6290. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  6291. }
  6292. VERIFY_IS_TRUE(equal);
  6293. }
  6294. }
  6295. }
  6296. }
  6297. }
  6298. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  6299. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  6300. if (GetTestParamUseWARP(true) &&
  6301. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6302. return;
  6303. }
  6304. WaveIntrinsicsActivePrefixTest<int, int>(
  6305. WaveIntrinsicsActiveIntParameters,
  6306. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  6307. /*isPrefix*/ false);
  6308. }
  6309. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  6310. if (GetTestParamUseWARP(true) &&
  6311. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6312. return;
  6313. }
  6314. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6315. WaveIntrinsicsActiveUintParameters,
  6316. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  6317. /*isPrefix*/ false);
  6318. }
  6319. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  6320. if (GetTestParamUseWARP(true) &&
  6321. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6322. return;
  6323. }
  6324. WaveIntrinsicsActivePrefixTest<int, int>(
  6325. WaveIntrinsicsPrefixIntParameters,
  6326. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  6327. /*isPrefix*/ true);
  6328. }
  6329. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  6330. if (GetTestParamUseWARP(true) &&
  6331. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6332. return;
  6333. }
  6334. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6335. WaveIntrinsicsPrefixUintParameters,
  6336. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  6337. /*isPrefix*/ true);
  6338. }
  6339. template <typename T>
  6340. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  6341. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6342. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6343. return static_cast<T>(1);
  6344. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6345. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  6346. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6347. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  6348. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6349. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  6350. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6351. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6352. return static_cast<T>(0);
  6353. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6354. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6355. return static_cast<T>(-1);
  6356. } else {
  6357. return static_cast<T>(0);
  6358. }
  6359. }
  6360. template <typename T>
  6361. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  6362. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6363. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6364. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  6365. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6366. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  6367. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  6368. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6369. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6370. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  6371. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6372. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  6373. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  6374. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6375. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  6376. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  6377. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6378. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6379. // For CountBits, each lane contributes a boolean value. The test input is
  6380. // a zero or non-zero integer. If the input is a non-zero value then the
  6381. // condition is true, thus we contribute one to the bit count.
  6382. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  6383. } else {
  6384. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  6385. }
  6386. }
  6387. template <class T>
  6388. void
  6389. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  6390. size_t numParameters) {
  6391. WEX::TestExecution::SetVerifyOutput
  6392. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6393. struct PerThreadData {
  6394. uint32_t key;
  6395. uint32_t firstLaneId;
  6396. uint32_t laneId;
  6397. uint32_t mask;
  6398. T value;
  6399. T result;
  6400. };
  6401. constexpr size_t NumThreadsX = 8;
  6402. constexpr size_t NumThreadsY = 12;
  6403. constexpr size_t NumThreadsZ = 1;
  6404. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6405. constexpr size_t DispatchGroupSize = 1;
  6406. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  6407. CComPtr<IStream> pStream;
  6408. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6409. CComPtr<ID3D12Device> pDevice;
  6410. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  6411. return;
  6412. }
  6413. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6414. // Optional feature, so it's correct to not support it if declared as such.
  6415. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6416. return;
  6417. }
  6418. std::shared_ptr<st::ShaderOpSet>
  6419. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6420. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6421. TableParameterHandler handler(pParameterList, numParameters);
  6422. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6423. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  6424. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  6425. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  6426. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  6427. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  6428. std::shared_ptr<ShaderOpTestResult> test =
  6429. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  6430. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  6431. UNREFERENCED_PARAMETER(name);
  6432. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  6433. data.resize(dataSize);
  6434. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  6435. for (size_t i = 0; i != ThreadCount; ++i) {
  6436. pThreadData[i].key = keys->at(i % keys->size());
  6437. pThreadData[i].value = values->at(i % values->size());
  6438. pThreadData[i].firstLaneId = 0xdeadbeef;
  6439. pThreadData[i].laneId = 0xdeadbeef;
  6440. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  6441. pThreadData[i].result = 0xdeadbeef;
  6442. }
  6443. pShaderOp->Shaders.at(0).Text = shaderSource;
  6444. pShaderOp->Shaders.at(0).Target = shaderProfile;
  6445. }, ShaderOpSet);
  6446. MappedData mappedData;
  6447. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  6448. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  6449. // Partition our data into waves
  6450. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  6451. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  6452. PerThreadData *elt = &resultData[i];
  6453. // Basic sanity checks
  6454. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  6455. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  6456. waves[elt->firstLaneId].push_back(elt);
  6457. }
  6458. // Verify each wave
  6459. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  6460. for (auto &w : waves) {
  6461. std::vector<PerThreadData *> &waveData = w.second;
  6462. struct {
  6463. bool operator()(PerThreadData *a, PerThreadData *b) const {
  6464. return (a->laneId < b->laneId);
  6465. }
  6466. } compare;
  6467. // Need to sort based on the lane id
  6468. std::sort(waveData.begin(), waveData.end(), compare);
  6469. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  6470. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  6471. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  6472. PerThreadData *data = waveData[i];
  6473. // Compute prefix operation over each previous lane element that has the
  6474. // same key value, and is part of the same active thread group
  6475. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  6476. for (unsigned j = 0; j < i; ++j) {
  6477. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  6478. accum = refFn(accum, waveData[j]->value);
  6479. }
  6480. }
  6481. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  6482. VERIFY_IS_TRUE(accum == data->result);
  6483. }
  6484. LogCommentFmt(L"\n");
  6485. }
  6486. }
  6487. }
  6488. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  6489. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  6490. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  6491. }
  6492. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  6493. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  6494. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  6495. }
  6496. TEST_F(ExecutionTest, CBufferTestHalf) {
  6497. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6498. CComPtr<IStream> pStream;
  6499. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6500. // Single operation test at the moment.
  6501. CComPtr<ID3D12Device> pDevice;
  6502. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  6503. return;
  6504. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6505. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6506. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6507. return;
  6508. }
  6509. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  6510. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  6511. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6512. UNREFERENCED_PARAMETER(pShaderOp);
  6513. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  6514. // use shader from data table.
  6515. Data.resize(sizeof(InputData));
  6516. uint16_t *pData = (uint16_t *)Data.data();
  6517. for (size_t i = 0; i < 4; ++i, ++pData) {
  6518. *pData = InputData[i];
  6519. }
  6520. });
  6521. {
  6522. MappedData data;
  6523. test->Test->GetReadBackData("RTarget", &data);
  6524. const uint16_t *pPixels = (uint16_t *)data.data();
  6525. for (int i = 0; i < 4; ++i) {
  6526. uint16_t output = *(pPixels + i);
  6527. float outputFloat = ConvertFloat16ToFloat32(output);
  6528. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  6529. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  6530. i, inputFloat, InputData[i], outputFloat, output);
  6531. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  6532. }
  6533. }
  6534. }
  6535. TEST_F(ExecutionTest, BarycentricsTest) {
  6536. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6537. CComPtr<IStream> pStream;
  6538. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6539. CComPtr<ID3D12Device> pDevice;
  6540. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  6541. return;
  6542. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  6543. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  6544. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6545. return;
  6546. }
  6547. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  6548. MappedData data;
  6549. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  6550. UINT width = (UINT)D.Width;
  6551. UINT height = D.Height;
  6552. UINT pixelSize = GetByteSizeForFormat(D.Format);
  6553. test->Test->GetReadBackData("RTarget", &data);
  6554. //const uint8_t *pPixels = (uint8_t *)data.data();
  6555. const float *pPixels = (float *)data.data();
  6556. // Get the vertex of barycentric coordinate using VBuffer
  6557. MappedData triangleData;
  6558. test->Test->GetReadBackData("VBuffer", &triangleData);
  6559. const float *pTriangleData = (float*)triangleData.data();
  6560. // get the size of the input data
  6561. unsigned triangleVertexSizeInFloat = 0;
  6562. for (auto element : test->ShaderOp->InputElements)
  6563. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  6564. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  6565. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  6566. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  6567. XMFLOAT3 barycentricWeights[4] = {
  6568. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  6569. XMFLOAT3(0.5f, 0.25f, 0.25f),
  6570. XMFLOAT3(0.25f, 0.5f, 0.25f),
  6571. XMFLOAT3(0.25f, 0.25f, 0.50f)
  6572. };
  6573. float tolerance = 0.001f;
  6574. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  6575. float w0 = barycentricWeights[i].x;
  6576. float w1 = barycentricWeights[i].y;
  6577. float w2 = barycentricWeights[i].z;
  6578. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  6579. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  6580. // map from x1 y1 to rtv pixels
  6581. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  6582. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  6583. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  6584. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  6585. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  6586. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  6587. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  6588. }
  6589. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  6590. }
  6591. static const char RawBufferTestShaderDeclarations[] =
  6592. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  6593. "typedef COMPONENT_TYPE scalar; \r\n"
  6594. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  6595. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  6596. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  6597. "\r\n"
  6598. "struct TestData { \r\n"
  6599. " scalar v1; \r\n"
  6600. " vector2 v2; \r\n"
  6601. " vector3 v3; \r\n"
  6602. " vector4 v4; \r\n"
  6603. "}; \r\n"
  6604. "\r\n"
  6605. "struct UavData {\r\n"
  6606. " TestData input; \r\n"
  6607. " TestData output; \r\n"
  6608. " TestData srvOut; \r\n"
  6609. "}; \r\n"
  6610. "\r\n"
  6611. "ByteAddressBuffer srv0 : register(t0); \r\n"
  6612. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  6613. "ByteAddressBuffer srv2 : register(t2); \r\n"
  6614. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  6615. "\r\n"
  6616. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  6617. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  6618. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  6619. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  6620. static const char RawBufferTestShaderBody[] =
  6621. " // offset of 'out' in 'UavData'\r\n"
  6622. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  6623. "\r\n"
  6624. " // offset of 'srv_out' in 'UavData'\r\n"
  6625. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  6626. "\r\n"
  6627. " // offsets within the 'Data' struct\r\n"
  6628. " const int v1_offset = 0; \r\n"
  6629. " const int v2_offset = COMPONENT_SIZE; \r\n"
  6630. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  6631. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  6632. "\r\n"
  6633. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  6634. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  6635. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  6636. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  6637. "\r\n"
  6638. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  6639. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  6640. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  6641. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  6642. "\r\n"
  6643. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  6644. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  6645. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  6646. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  6647. "\r\n"
  6648. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  6649. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  6650. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  6651. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  6652. "\r\n"
  6653. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  6654. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  6655. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  6656. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  6657. "\r\n"
  6658. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  6659. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  6660. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  6661. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  6662. "\r\n"
  6663. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  6664. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  6665. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  6666. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  6667. "\r\n"
  6668. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  6669. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  6670. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  6671. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  6672. static const char RawBufferTestComputeShaderTemplate[] =
  6673. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6674. "[numthreads(1, 1, 1)]\r\n"
  6675. "void main(uint GI : SV_GroupIndex) {\r\n"
  6676. "%s\r\n" // <- RawBufferTestShaderBody
  6677. "};";
  6678. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  6679. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6680. "struct PSInput { \r\n"
  6681. " float4 pos : SV_POSITION; \r\n"
  6682. "}; \r\n"
  6683. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  6684. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  6685. "%s\r\n" // <- RawBufferTestShaderBody
  6686. " } \r\n"
  6687. " return uint4(1, 2, 3, 4); \r\n"
  6688. "};";
  6689. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  6690. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6691. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  6692. }
  6693. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  6694. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6695. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  6696. }
  6697. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  6698. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6699. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6700. }
  6701. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  6702. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6703. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6704. }
  6705. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  6706. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6707. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  6708. }
  6709. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  6710. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6711. RawBufferLdStTestData<uint16_t> halfData;
  6712. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  6713. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6714. }
  6715. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  6716. }
  6717. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  6718. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6719. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  6720. }
  6721. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  6722. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6723. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  6724. }
  6725. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  6726. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6727. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  6728. }
  6729. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  6730. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6731. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  6732. }
  6733. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  6734. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6735. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  6736. }
  6737. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  6738. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6739. RawBufferLdStTestData<uint16_t> halfData;
  6740. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  6741. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6742. }
  6743. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  6744. }
  6745. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6746. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  6747. char *&sTy, char *&additionalOptions) {
  6748. if (!CreateDevice(&pDevice, shaderModel)) {
  6749. return false;
  6750. }
  6751. additionalOptions = "";
  6752. switch (dataType) {
  6753. case RawBufferLdStType::I64:
  6754. if (!DoesDeviceSupportInt64(pDevice)) {
  6755. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  6756. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6757. return false;
  6758. }
  6759. sTy = "int64_t";
  6760. break;
  6761. case RawBufferLdStType::Double:
  6762. if (!DoesDeviceSupportDouble(pDevice)) {
  6763. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  6764. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6765. return false;
  6766. }
  6767. sTy = "double";
  6768. break;
  6769. case RawBufferLdStType::I16:
  6770. case RawBufferLdStType::Half:
  6771. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6772. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6773. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6774. return false;
  6775. }
  6776. additionalOptions = "-enable-16bit-types";
  6777. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  6778. break;
  6779. case RawBufferLdStType::I32:
  6780. sTy = "int32_t";
  6781. break;
  6782. case RawBufferLdStType::Float:
  6783. sTy = "float";
  6784. break;
  6785. default:
  6786. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  6787. }
  6788. // read shader config
  6789. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6790. return true;
  6791. }
  6792. template <class Ty>
  6793. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6794. // read buffers back & verify expected values
  6795. static const int UavBufferCount = 4;
  6796. char bufferName[11] = "UAVBufferX";
  6797. for (unsigned i = 0; i < UavBufferCount; i++) {
  6798. MappedData dataUav;
  6799. RawBufferLdStUavData<Ty> *pOutData;
  6800. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6801. test->GetReadBackData(bufferName, &dataUav);
  6802. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6803. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6804. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6805. // scalar
  6806. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6807. // vector 2
  6808. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6809. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6810. // vector 3
  6811. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6812. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6813. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6814. // vector 4
  6815. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6816. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6817. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6818. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6819. // verify SRV Store
  6820. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6821. // scalar
  6822. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6823. // vector 2
  6824. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6825. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6826. // vector 3
  6827. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6828. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6829. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6830. // vector 4
  6831. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6832. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6833. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6834. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6835. }
  6836. }
  6837. template <class Ty>
  6838. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6839. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6840. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6841. CComPtr<ID3D12Device> pDevice;
  6842. CComPtr<IStream> pStream;
  6843. char *sTy, *additionalOptions;
  6844. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6845. return;
  6846. }
  6847. // format shader source
  6848. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6849. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6850. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6851. // format compiler args
  6852. char compilerOptions[256];
  6853. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6854. // run the shader
  6855. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6856. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6857. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6858. (Name[9] >= '0' && Name[9] <= '3'));
  6859. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6860. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6861. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6862. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6863. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6864. });
  6865. // verify expected values
  6866. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6867. }
  6868. template <class Ty>
  6869. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6870. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6871. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6872. CComPtr<ID3D12Device> pDevice;
  6873. CComPtr<IStream> pStream;
  6874. char *sTy, *additionalOptions;
  6875. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6876. return;
  6877. }
  6878. // format shader source
  6879. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6880. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6881. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6882. // format compiler args
  6883. char compilerOptions[256];
  6884. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6885. // run the shader
  6886. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6887. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6888. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6889. (Name[9] >= '0' && Name[9] <= '3'));
  6890. // pixel shader is at index 1, vertex shader at index 0
  6891. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6892. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6893. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6894. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6895. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6896. });
  6897. // verify expected values
  6898. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6899. }
  6900. template<typename T>
  6901. uint32_t pack(std::array<T, 4> unpackedVals)
  6902. {
  6903. uint32_t dst = 0;
  6904. constexpr uint32_t bitMask = 0xFF;
  6905. for (uint32_t i = 0U; i < 4U; ++i)
  6906. {
  6907. dst |= (unpackedVals[i] & bitMask) << (i * 8);
  6908. }
  6909. return dst;
  6910. }
  6911. template <typename T>
  6912. uint32_t pack_clamp_u8(std::array<T, 4> unpackedVals)
  6913. {
  6914. int32_t clamp_min = std::numeric_limits<uint8_t>::min();
  6915. int32_t clamp_max = std::numeric_limits<uint8_t>::max();
  6916. uint32_t dst = 0;
  6917. for (uint32_t i = 0U; i < 4U; ++i)
  6918. {
  6919. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6920. dst |= ((uint8_t)clamped) << (i * 8);
  6921. }
  6922. return dst;
  6923. }
  6924. template <typename T>
  6925. uint32_t pack_clamp_s8(std::array<T, 4> unpackedVals)
  6926. {
  6927. int32_t clamp_min = std::numeric_limits<int8_t>::min();
  6928. int32_t clamp_max = std::numeric_limits<int8_t>::max();
  6929. uint32_t dst = 0;
  6930. for (uint32_t i = 0U; i < 4U; ++i)
  6931. {
  6932. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6933. dst |= ((uint8_t)clamped) << (i * 8);
  6934. }
  6935. return dst;
  6936. }
  6937. template<typename T>
  6938. std::array<T, 4> unpack_u(uint32_t packedVal)
  6939. {
  6940. std::array<T, 4> ret;
  6941. ret[0] = (uint8_t)((packedVal & 0x000000FF) >> 0 );
  6942. ret[1] = (uint8_t)((packedVal & 0x0000FF00) >> 8 );
  6943. ret[2] = (uint8_t)((packedVal & 0x00FF0000) >> 16);
  6944. ret[3] = (uint8_t)((packedVal & 0xFF000000) >> 24);
  6945. return ret;
  6946. }
  6947. template<typename T>
  6948. std::array<T, 4> unpack_s(uint32_t packedVal)
  6949. {
  6950. std::array<T, 4> ret;
  6951. ret[0] = (int8_t)((packedVal & 0x000000FF) >> 0 );
  6952. ret[1] = (int8_t)((packedVal & 0x0000FF00) >> 8 );
  6953. ret[2] = (int8_t)((packedVal & 0x00FF0000) >> 16);
  6954. ret[3] = (int8_t)((packedVal & 0xFF000000) >> 24);
  6955. return ret;
  6956. }
  6957. TEST_F(ExecutionTest, PackUnpackTest) {
  6958. WEX::TestExecution::SetVerifyOutput verifySettings(
  6959. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6960. CComPtr<IStream> pStream;
  6961. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6962. CComPtr<ID3D12Device> pDevice;
  6963. #ifdef PACKUNPACK_PLACEHOLDER
  6964. string args = "-enable-16bit-types -DPACKUNPACK_PLACEHOLDER";
  6965. string target = "cs_6_2";
  6966. if (!CreateDevice(&pDevice)) {
  6967. return;
  6968. }
  6969. #else
  6970. string args = "-enable-16bit-types";
  6971. string target = "cs_6_6";
  6972. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  6973. return;
  6974. }
  6975. #endif
  6976. int tableSize = sizeof(PackUnpackOpParameters) / sizeof(TableParameter);
  6977. TableParameterHandler handler(PackUnpackOpParameters, tableSize);
  6978. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6979. std::vector<uint32_t> *validation_input = &handler.GetTableParamByName(L"Validation.Input")->m_uint32Table;
  6980. uint32_t validation_tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_uint;
  6981. size_t count = validation_input->size();
  6982. std::vector<SPackUnpackOpOutPacked> expectedPacked(count / 4);
  6983. std::vector<SPackUnpackOpOutUnpacked> expectedUnpacked(count / 4);
  6984. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  6985. pDevice, m_support, pStream, "PackUnpackOp",
  6986. // this callback is called when the test
  6987. // is creating the resource to run the test
  6988. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6989. if (0 == _stricmp(Name, "g_bufIn"))
  6990. {
  6991. size_t size = sizeof(uint32_t) * 4 * count;
  6992. Data.resize(size);
  6993. uint32_t *pPrimitives = (uint32_t*)Data.data();
  6994. for (size_t i = 0; i < count / 4; ++i) {
  6995. uint32_t *p = &pPrimitives[i * 4];
  6996. uint32_t x = (*validation_input)[i * 4 + 0];
  6997. uint32_t y = (*validation_input)[i * 4 + 1];
  6998. uint32_t z = (*validation_input)[i * 4 + 2];
  6999. uint32_t w = (*validation_input)[i * 4 + 3];
  7000. p[0] = x;
  7001. p[1] = y;
  7002. p[2] = z;
  7003. p[3] = w;
  7004. std::array<uint32_t, 4> inputUint32 = { x, y, z, w };
  7005. std::array<int32_t, 4> inputInt32 = { (int32_t)x, (int32_t)y, (int32_t)z, (int32_t)w };
  7006. std::array<uint16_t, 4> inputUint16 = { (uint16_t)x, (uint16_t)y, (uint16_t)z, (uint16_t)w };
  7007. std::array<int16_t, 4> inputInt16 = { (int16_t)x, (int16_t)y, (int16_t)z, (int16_t)w };
  7008. // Pack unclamped
  7009. expectedPacked[i].packedUint32 = pack(inputUint32);
  7010. expectedPacked[i].packedInt32 = pack(inputInt32);
  7011. expectedPacked[i].packedUint16 = pack(inputUint16);
  7012. expectedPacked[i].packedInt16 = pack(inputInt16);
  7013. // pack clamped
  7014. expectedPacked[i].packedClampedUint32 = pack_clamp_u8(inputInt32);
  7015. expectedPacked[i].packedClampedInt32 = pack_clamp_s8(inputInt32);
  7016. expectedPacked[i].packedClampedUint16 = pack_clamp_u8(inputInt16);
  7017. expectedPacked[i].packedClampedInt16 = pack_clamp_s8(inputInt16);
  7018. // unpack
  7019. expectedUnpacked[i].outputUint32 = unpack_u<uint32_t>(expectedPacked[i].packedUint32);
  7020. expectedUnpacked[i].outputInt32 = unpack_s<int32_t >(expectedPacked[i].packedInt32 );
  7021. expectedUnpacked[i].outputUint16 = unpack_u<uint16_t>(expectedPacked[i].packedUint16);
  7022. expectedUnpacked[i].outputInt16 = unpack_s<int16_t >(expectedPacked[i].packedInt16 );
  7023. expectedUnpacked[i].outputClampedUint32 = unpack_u<uint32_t>(expectedPacked[i].packedClampedUint32);
  7024. expectedUnpacked[i].outputClampedInt32 = unpack_s<int32_t >(expectedPacked[i].packedClampedInt32 );
  7025. expectedUnpacked[i].outputClampedUint16 = unpack_u<uint16_t>(expectedPacked[i].packedClampedUint16);
  7026. expectedUnpacked[i].outputClampedInt16 = unpack_s<int16_t >(expectedPacked[i].packedClampedInt16 );
  7027. }
  7028. }
  7029. else
  7030. {
  7031. std::fill(Data.begin(), Data.end(), 0);
  7032. }
  7033. // use shader from data table
  7034. pShaderOp->Shaders.at(0).Target = target.c_str();
  7035. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  7036. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7037. });
  7038. MappedData packedData;
  7039. test->Test->GetReadBackData("g_bufOutPacked", &packedData);
  7040. SPackUnpackOpOutPacked *readBackPacked = (SPackUnpackOpOutPacked *)packedData.data();
  7041. MappedData unpackedData;
  7042. test->Test->GetReadBackData("g_bufOutPackedUnpacked", &unpackedData);
  7043. SPackUnpackOpOutUnpacked *readBackUnpacked = (SPackUnpackOpOutUnpacked *)unpackedData.data();
  7044. for (size_t i = 0; i < count / 4; ++i)
  7045. {
  7046. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint32, expectedPacked[i].packedUint32, validation_tolerance);
  7047. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt32 , expectedPacked[i].packedInt32 , validation_tolerance);
  7048. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint16, expectedPacked[i].packedUint16, validation_tolerance);
  7049. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt16 , expectedPacked[i].packedInt16 , validation_tolerance);
  7050. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint32, expectedPacked[i].packedClampedUint32, validation_tolerance);
  7051. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt32 , expectedPacked[i].packedClampedInt32 , validation_tolerance);
  7052. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint16, expectedPacked[i].packedClampedUint16, validation_tolerance);
  7053. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt16 , expectedPacked[i].packedClampedInt16 , validation_tolerance);
  7054. for (uint32_t j = 0; j < 4; ++j)
  7055. {
  7056. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint32[j], expectedUnpacked[i].outputUint32[j], validation_tolerance);
  7057. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt32 [j], expectedUnpacked[i].outputInt32 [j], validation_tolerance);
  7058. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint16[j], expectedUnpacked[i].outputUint16[j], validation_tolerance);
  7059. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt16 [j], expectedUnpacked[i].outputInt16 [j], validation_tolerance);
  7060. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint32[j], expectedUnpacked[i].outputClampedUint32[j], validation_tolerance);
  7061. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt32 [j], expectedUnpacked[i].outputClampedInt32 [j], validation_tolerance);
  7062. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint16[j], expectedUnpacked[i].outputClampedUint16[j], validation_tolerance);
  7063. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt16 [j], expectedUnpacked[i].outputClampedInt16 [j], validation_tolerance);
  7064. }
  7065. }
  7066. }
  7067. // This test expects a <pShader> that retrieves a signal value from each of a few
  7068. // resources that are initialized here. <isDynamic> determines if it uses the
  7069. // 6.6 Dynamic Resources feature.
  7070. // Values are read back from the result UAV and compared to the expected signals
  7071. void ExecutionTest::RunResourceTest(ID3D12Device *pDevice, const char *pShader,
  7072. const wchar_t *sm, bool isDynamic) {
  7073. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7074. const int NumSRVs = 3;
  7075. const int NumUAVs = 4;
  7076. const int NumResources = NumSRVs + NumUAVs;
  7077. const int NumSamplers = 2;
  7078. const int valueSize = 16;
  7079. static const int DispatchGroupX = 1;
  7080. static const int DispatchGroupY = 1;
  7081. static const int DispatchGroupZ = 1;
  7082. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  7083. CComPtr<ID3D12CommandQueue> pCommandQueue;
  7084. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  7085. FenceObj FO;
  7086. size_t valueSizeInBytes = valueSize * sizeof(float);
  7087. CreateComputeCommandQueue(pDevice, L"DynamicResourcesTest Command Queue", &pCommandQueue);
  7088. InitFenceObj(pDevice, &FO);
  7089. // Create root signature.
  7090. CComPtr<ID3D12RootSignature> pRootSignature;
  7091. if (!isDynamic) {
  7092. // Not dynamic, create a range for each resource and from them, the root signature
  7093. CD3DX12_DESCRIPTOR_RANGE ranges[NumResources];
  7094. CD3DX12_DESCRIPTOR_RANGE srange[NumSamplers];
  7095. for (int i = 0; i < NumSRVs; i++)
  7096. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, i, 0);
  7097. for (int i = NumSRVs; i < NumResources; i++)
  7098. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, i - NumSRVs, 0);
  7099. for (int i = 0; i < NumSamplers; i++)
  7100. srange[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, i, 0);
  7101. CreateRootSignatureFromRanges(pDevice, &pRootSignature, ranges, NumResources, srange, NumSamplers);
  7102. } else {
  7103. // Dynamic just requires the flags indicating that the builtin arrays should be accessible
  7104. #if !defined(D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)
  7105. #define D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x400
  7106. #define D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x800
  7107. #endif
  7108. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  7109. rootSignatureDesc.Init(0, nullptr, 0, nullptr,
  7110. D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
  7111. D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
  7112. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  7113. }
  7114. // Create pipeline state object.
  7115. CComPtr<ID3D12PipelineState> pComputeState;
  7116. CreateComputePSO(pDevice, pRootSignature, pShader, sm, &pComputeState);
  7117. // Create a command allocator and list for compute.
  7118. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  7119. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  7120. // Set up SRV resources
  7121. CComPtr<ID3D12Resource> pSRVResources[NumSRVs];
  7122. CComPtr<ID3D12Resource> pUAVResources[NumUAVs];
  7123. CComPtr<ID3D12Resource> pUploadResources[NumResources];
  7124. {
  7125. D3D12_RESOURCE_DESC bufDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  7126. float values[valueSize];
  7127. for (int i = 0; i < NumSRVs - 1; i++) {
  7128. for (int j = 0; j < valueSize; j++)
  7129. values[j] = 10.0 + i;
  7130. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufDesc,
  7131. &pSRVResources[i], &pUploadResources[i]);
  7132. }
  7133. D3D12_RESOURCE_DESC tex2dDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 4, 4);
  7134. for (int j = 0; j < valueSize; j++)
  7135. values[j] = 10.0 + (NumSRVs - 1);
  7136. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex2dDesc,
  7137. &pSRVResources[NumSRVs - 1], &pUploadResources[NumSRVs - 1]);
  7138. }
  7139. // Set up UAV resources
  7140. CComPtr<ID3D12Resource> pReadBuffer;
  7141. float values[valueSize];
  7142. for (int i = 0; i < NumUAVs - 2; i++) {
  7143. for (int j = 0; j < valueSize; j++)
  7144. values[j] = 20.0 + i;
  7145. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7146. &pUAVResources[i], &pUploadResources[NumSRVs + i]);
  7147. }
  7148. for (int j = 0; j < valueSize; j++)
  7149. values[j] = 20.0 + (NumUAVs - 1);
  7150. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7151. &pUAVResources[NumUAVs - 2], &pUploadResources[NumResources - 2], &pReadBuffer);
  7152. for (int j = 0; j < valueSize; j++)
  7153. values[j] = 20.0 + (NumUAVs - 2);
  7154. D3D12_RESOURCE_DESC tex1dDesc = CD3DX12_RESOURCE_DESC::Tex1D(DXGI_FORMAT_R32_FLOAT, valueSize, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  7155. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex1dDesc,
  7156. &pUAVResources[NumUAVs - 1], &pUploadResources[NumResources - 1]);
  7157. // Close the command list and execute it to perform the GPU setup.
  7158. pCommandList->Close();
  7159. ExecuteCommandList(pCommandQueue, pCommandList);
  7160. WaitForSignal(pCommandQueue, FO);
  7161. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  7162. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  7163. CComPtr<ID3D12DescriptorHeap> pResHeap;
  7164. CComPtr<ID3D12DescriptorHeap> pSampHeap;
  7165. CreateDefaultDescHeaps(pDevice, NumSRVs + NumUAVs, NumSamplers, &pResHeap, &pSampHeap);
  7166. // Create Rootsignature and descriptor tables
  7167. {
  7168. ID3D12DescriptorHeap *descHeaps[2] = {pResHeap, pSampHeap};
  7169. pCommandList->SetDescriptorHeaps(2, descHeaps);
  7170. pCommandList->SetComputeRootSignature(pRootSignature);
  7171. if (!isDynamic) {
  7172. // Only non-dynamic resources require descriptortables
  7173. pCommandList->SetComputeRootDescriptorTable(0, pResHeap->GetGPUDescriptorHandleForHeapStart());
  7174. pCommandList->SetComputeRootDescriptorTable(1, pSampHeap->GetGPUDescriptorHandleForHeapStart());
  7175. }
  7176. }
  7177. CD3DX12_CPU_DESCRIPTOR_HANDLE baseHandle(pResHeap->GetCPUDescriptorHandleForHeapStart());
  7178. // Create SRVs
  7179. CreateRawSRV(pDevice, baseHandle, valueSize, pSRVResources[0]);
  7180. CreateStructSRV(pDevice, baseHandle, valueSize, sizeof(float), pSRVResources[1]);
  7181. CreateTex2DSRV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pSRVResources[2]);
  7182. // Create UAVs
  7183. CreateRawUAV(pDevice, baseHandle, valueSize, pUAVResources[0]);
  7184. CreateStructUAV(pDevice, baseHandle, valueSize, sizeof(float), pUAVResources[1]);
  7185. CreateTypedUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[2]);
  7186. CreateTex1DUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[3]);
  7187. D3D12_FILTER filters[] = {D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT};
  7188. float borderColors[] = {30.0, 31.0};
  7189. CreateDefaultSamplers(pDevice, pSampHeap->GetCPUDescriptorHandleForHeapStart(),
  7190. filters, borderColors, NumSamplers);
  7191. // Run the compute shader and copy the results back to readable memory.
  7192. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  7193. RecordTransitionBarrier(pCommandList, pUAVResources[NumUAVs - 2], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  7194. pCommandList->CopyResource(pReadBuffer, pUAVResources[NumUAVs - 2]);
  7195. pCommandList->Close();
  7196. ExecuteCommandList(pCommandQueue, pCommandList);
  7197. WaitForSignal(pCommandQueue, FO);
  7198. MappedData data(pReadBuffer, valueSize*sizeof(float));
  7199. const float *pData = (float*)data.data();
  7200. LogCommentFmt(L"Verify bound resources are properly selected");
  7201. VERIFY_ARE_EQUAL(pData[0], 10);
  7202. VERIFY_ARE_EQUAL(pData[1], 11);
  7203. VERIFY_ARE_EQUAL(pData[2], 12);
  7204. VERIFY_ARE_EQUAL(pData[3], 20);
  7205. VERIFY_ARE_EQUAL(pData[4], 21);
  7206. VERIFY_ARE_EQUAL(pData[5], 22);
  7207. VERIFY_ARE_EQUAL(pData[6], 30);
  7208. VERIFY_ARE_EQUAL(pData[7], 1); // samplecmp 1 means it matched 31
  7209. }
  7210. TEST_F(ExecutionTest, SignatureResourcesTest) {
  7211. std::string pShader =
  7212. "ByteAddressBuffer g_rawBuf : register(t0);\n"
  7213. "StructuredBuffer<float> g_structBuf : register(t1);\n"
  7214. "Texture2D<float> g_tex : register(t2);\n"
  7215. "RWByteAddressBuffer g_rwRawBuf : register(u0);\n"
  7216. "RWStructuredBuffer<float> g_rwStructBuf : register(u1);\n"
  7217. "RWBuffer<float> g_result : register(u2);\n"
  7218. "RWTexture1D<float> g_rwTex : register(u3);\n"
  7219. "SamplerState g_samp : register(s0);\n"
  7220. "SamplerComparisonState g_sampCmp : register(s1);\n"
  7221. "[NumThreads(1, 1, 1)]\n"
  7222. "void main(uint ix : SV_GroupIndex) {\n"
  7223. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7224. " g_result[1] = g_structBuf.Load(0);\n"
  7225. " g_result[2] = g_tex.Load(0);\n"
  7226. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7227. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7228. " g_result[5] = g_rwTex.Load(0);\n"
  7229. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7230. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7231. "}\n";
  7232. CComPtr<ID3D12Device> pDevice;
  7233. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7234. return;
  7235. RunResourceTest(pDevice, pShader.c_str(), L"cs_6_6", /*isDynamic*/false);
  7236. }
  7237. TEST_F(ExecutionTest, DynamicResourcesTest) {
  7238. static const char pShader[] =
  7239. "static ByteAddressBuffer g_rawBuf = ResourceDescriptorHeap[0];\n"
  7240. "static StructuredBuffer<float> g_structBuf = ResourceDescriptorHeap[1];\n"
  7241. "static Texture2D<float> g_tex = ResourceDescriptorHeap[2];\n"
  7242. "static RWByteAddressBuffer g_rwRawBuf = ResourceDescriptorHeap[3];\n"
  7243. "static RWStructuredBuffer<float> g_rwStructBuf = ResourceDescriptorHeap[4];\n"
  7244. "static RWBuffer<float> g_result = ResourceDescriptorHeap[5];\n"
  7245. "static RWTexture1D<float> g_rwTex = ResourceDescriptorHeap[6];\n"
  7246. "static SamplerState g_samp = SamplerDescriptorHeap[0];\n"
  7247. "static SamplerComparisonState g_sampCmp = SamplerDescriptorHeap[1];\n"
  7248. "[NumThreads(1, 1, 1)]\n"
  7249. "void main(uint ix : SV_GroupIndex) {\n"
  7250. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7251. " g_result[1] = g_structBuf.Load(0);\n"
  7252. " g_result[2] = g_tex.Load(0);\n"
  7253. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7254. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7255. " g_result[5] = g_rwTex.Load(0);\n"
  7256. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7257. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7258. "}\n";
  7259. CComPtr<ID3D12Device> pDevice;
  7260. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7261. return;
  7262. RunResourceTest(pDevice, pShader, L"cs_6_6", /*isDynamic*/true);
  7263. }
  7264. #define MAX_WAVESIZE 128
  7265. #define strinfigy2(arg) #arg
  7266. #define strinfigy(arg) strinfigy2(arg)
  7267. void ExecutionTest::WaveSizeTest() {
  7268. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7269. CComPtr<ID3D12Device> pDevice;
  7270. CComPtr<IStream> pStream;
  7271. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7272. return;
  7273. }
  7274. // Check Wave support
  7275. if (!DoesDeviceSupportWaveOps(pDevice)) {
  7276. // Optional feature, so it's correct to not support it if declared as such.
  7277. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  7278. return;
  7279. }
  7280. // read shader config
  7281. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7282. // Get supported wave sizes
  7283. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waveOpts;
  7284. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &waveOpts, sizeof(waveOpts)));
  7285. UINT minWaveSize = waveOpts.WaveLaneCountMin;
  7286. UINT maxWaveSize = waveOpts.WaveLaneCountMax;
  7287. DXASSERT_NOMSG(minWaveSize <= maxWaveSize);
  7288. DXASSERT((minWaveSize & (minWaveSize - 1)) == 0, "must be a power of 2");
  7289. DXASSERT((maxWaveSize & (maxWaveSize - 1)) == 0, "must be a power of 2");
  7290. // format shader source
  7291. const char waveSizeTestShader[] =
  7292. "struct TestData { \r\n"
  7293. " uint count; \r\n"
  7294. "}; \r\n"
  7295. "RWStructuredBuffer<TestData> data : register(u0); \r\n"
  7296. "\r\n"
  7297. "// Note: WAVESIZE will be defined via compiler option -D\r\n"
  7298. "[wavesize(WAVESIZE)]\r\n"
  7299. "[numthreads(" strinfigy(MAX_WAVESIZE) "*2,1,1)]\r\n"
  7300. "void main(uint3 tid : SV_DispatchThreadID ) { \r\n"
  7301. " data[tid.x].count = WaveActiveSum(1); \r\n"
  7302. "}\r\n";
  7303. struct WaveSizeTestData {
  7304. uint32_t count;
  7305. };
  7306. for (UINT waveSize = minWaveSize; waveSize <= maxWaveSize; waveSize *= 2) {
  7307. // format compiler args
  7308. char compilerOptions[32];
  7309. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D WAVESIZE=%d", waveSize) != -1);
  7310. // run the shader
  7311. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "WaveSizeTest",
  7312. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7313. VERIFY_IS_TRUE((0 == strncmp(Name, "UAVBuffer0", 10)));
  7314. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  7315. pShaderOp->Shaders.at(0).Text = waveSizeTestShader;
  7316. VERIFY_IS_TRUE(sizeof(WaveSizeTestData)*MAX_WAVESIZE <= Data.size());
  7317. WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
  7318. memset(&pInData, sizeof(WaveSizeTestData)*MAX_WAVESIZE, 0);
  7319. });
  7320. // verify expected values
  7321. MappedData dataUav;
  7322. WaveSizeTestData *pOutData;
  7323. test->Test->GetReadBackData("UAVBuffer0", &dataUav);
  7324. VERIFY_ARE_EQUAL(sizeof(WaveSizeTestData)*MAX_WAVESIZE, dataUav.size());
  7325. pOutData = (WaveSizeTestData*)dataUav.data();
  7326. LogCommentFmt(L"Verifying test result for wave size %d", waveSize);
  7327. for (unsigned i = 0; i < MAX_WAVESIZE; i++) {
  7328. if (!VERIFY_ARE_EQUAL(pOutData[i].count, waveSize))
  7329. break;
  7330. }
  7331. }
  7332. }
  7333. // Atomic operation testing
  7334. // Atomic tests take a single integer index as input and contort it into some
  7335. // kind of interesting contributor to the operation in question.
  7336. // So each vertex, pixel, thread, or other will have a unique index that produces
  7337. // a contributing value to the calculation which is stored in a small resource
  7338. // For arithmetic or bitwise operations, each contributor accumulates to the same
  7339. // location in the resource indexed by the operation type. Addition is in index 0
  7340. // umin/umax are in 1 and 2 and so on.
  7341. // To make sure that the most significant bits are involved in the calculation,
  7342. // particularly in the case of 64-bit values, each contributing value is duplicated
  7343. // to the lower and upper halves of the value. There is an exception to this when
  7344. // addition exceeds the available size and also for compare and exchange explained below.
  7345. // For compare and exchange operations, 64 output locations are shared by the various lanes.
  7346. // Each lane attempts to write to a location that is shared with several others.
  7347. // The first one to write to it determines its contents, which will be the lane index <ix>
  7348. // in the upper bits and the output location index in the lower bits.
  7349. // This ensures that the compare operations consider the upper bits in the comparison.
  7350. // The initial compare store is followed by a compare exchange that compares for the
  7351. // value the current lane would have assigned there. Finally, the output of the cmpxchg
  7352. // is used to determine if the current lane should perform the final unconditional exchange.
  7353. // The values are verified by checking the lower bits for the matching location index
  7354. // and ensuring that the upper bits undergoing the same transformation result in the location index.
  7355. // For lane index <ix> the location is calculated and final result assigned as if by this code:
  7356. // g_outputBuf[(ix/3)%64] = (ix << shBits) | ((ix/3)%64);
  7357. bool AtomicResultMatches(const BYTE *uResults, uint64_t gold, size_t size) {
  7358. if (memcmp(uResults, &gold, size)) {
  7359. if (size == 4)
  7360. LogCommentFmt(L" value %d is not %d", ((uint32_t*)uResults)[0], (uint32_t)gold);
  7361. else
  7362. LogCommentFmt(L" value %lld is not %lld", ((uint64_t*)uResults)[0], gold);
  7363. return false;
  7364. }
  7365. return true;
  7366. }
  7367. // Used to duplicate the lower half bits into the upper half bits of an integer
  7368. // To verify that the full value is being considered, many tests duplicate the results into the upper half
  7369. #define SHIFT(val, bits) (((val)&((1ULL<<(bits))-1ULL)) | ((val) << (bits)))
  7370. // Symbolic constants for the results
  7371. #define ADD_IDX 0
  7372. #define UMIN_IDX 1
  7373. #define UMAX_IDX 2
  7374. #define AND_IDX 3
  7375. #define OR_IDX 4
  7376. #define XOR_IDX 5
  7377. #define SMIN_IDX 0
  7378. #define SMAX_IDX 1
  7379. // Verify results for atomic operations. <uResults> and <sResults> are pointers to
  7380. // the readback resource sections containing unsigned and signed integers respectively.
  7381. // <pXchg> is a poiner to the readback resource containing the results of the compare
  7382. // and exchange operations tests. <stride> is the number of bytes between results for
  7383. // all of the results pointers. <maxIdx> is the number of indices that went into the results
  7384. // which is used to determine what the results should be. <bitSize> is the size in bits of
  7385. // the produced results, either 32 or 64.
  7386. void VerifyAtomicResults(const BYTE *uResults, const BYTE *sResults,
  7387. const BYTE *pXchg, size_t stride, size_t maxIdx, size_t bitSize) {
  7388. // Each atomic test performs the test on the value in the lower half
  7389. // and also duplicated in the upper half of the value. The SHIFT macros account for this.
  7390. // This is to verify that the upper bits are considered
  7391. size_t shBits = bitSize/2;
  7392. size_t byteSize = bitSize/8;
  7393. // Test ADD Operation
  7394. // ADD just sums all the indices. The result should the sum of the highest and lowest indices
  7395. // multiplied by half the number of sums.
  7396. size_t addResult = (maxIdx)*(maxIdx-1)/2;
  7397. LogCommentFmt(L"Verifying %d-bit integer atomic add", bitSize);
  7398. // For 32-bit values, the sum exceeds the 16 bit limit, so we can't duplicate
  7399. // That's fine, the duplication is really for 64-bit values.
  7400. if (bitSize < 64)
  7401. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, addResult, byteSize));
  7402. else
  7403. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, SHIFT(addResult, shBits), byteSize));
  7404. // Test MIN and MAX Operations
  7405. // The result of a simple min and max of any sequence of indices would be fairly uninteresting
  7406. // and certain erroneous behavior might mistakenly produce the correct results.
  7407. // To make it interesting, the contributing values will change depending on the evenness of the index.
  7408. // On an even index, min and max operate on the bitflipped index. For signed compares, this is
  7409. // interpretted as a negative value and for unsigned, a very high value.
  7410. // For unsigned min/max, index 0 will be bitflipped to ~0, which is interpretted as the maximum
  7411. // Because zero is manipulated, this leaves 1 as the lowest value.
  7412. LogCommentFmt(L"Verifying %d-bit integer atomic umin", bitSize);
  7413. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMIN_IDX, SHIFT(1ULL, shBits), byteSize)); // UMin
  7414. LogCommentFmt(L"Verifying %d-bit integer atomic umax", bitSize);
  7415. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMAX_IDX, ~0ULL, byteSize)); // UMax
  7416. // For signed min/max, the index just before the last will be bitflipped (maxIndex is always even).
  7417. // This is interpretted as -maxIndex and will be the lowest
  7418. // The maxIndex will be unaltered and interpretted as the highest.
  7419. LogCommentFmt(L"Verifying %d-bit integer atomic smin", bitSize);
  7420. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMIN_IDX, SHIFT(-(maxIdx-1), shBits), byteSize)); // SMin
  7421. LogCommentFmt(L"Verifying %d-bit integer atomic smax", bitSize);
  7422. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMAX_IDX, SHIFT(maxIdx-1, shBits), byteSize)); // SMax
  7423. // Test AND and OR operations.
  7424. // For AND operations, all indices are bitflipped and ANDed to the previous result.
  7425. // This means that the highest bits, which are never set by the contributing indices will be set
  7426. // for all the indices, so they will be set in the final result.
  7427. // For OR operations, the indices are ORed to the previous result unaltered
  7428. // This means that any bit that is set in any index will be set in the final OR result.
  7429. // In practice, this means that the cumulative result of the AND and OR operations
  7430. // are bitflipped versions of each other.
  7431. // Finding the most significant set bit by the max index or next power of two (pot)
  7432. // gives us the pivot point for these results
  7433. size_t nextPot = 1ULL << (bitSize - 1);
  7434. for (;nextPot && !((maxIdx-1) & (nextPot)); nextPot >>= 1) {}
  7435. nextPot <<= 1;
  7436. LogCommentFmt(L"Verifying %d-bit integer atomic and", bitSize);
  7437. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*AND_IDX, ~SHIFT(nextPot-1, shBits), byteSize)); // And
  7438. LogCommentFmt(L"Verifying %d-bit integer atomic or", bitSize);
  7439. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*OR_IDX, SHIFT(nextPot-1, shBits), byteSize)); // Or
  7440. // Test XOR operation
  7441. // For XOR operations, a 1 is shifted by the number of spaces equal to the index and XORed
  7442. // to the previous result. Because this would rapidely shift off the end of the value,
  7443. // giving undefined and uninteresting results, the index is moduloed to a value that will
  7444. // fit within the type size.
  7445. // Because many of the tests use total numbers of lanes that can be evenly divisible by 32 or 64,
  7446. // these values aren't used for the modulo since the expected result might be zero,
  7447. // which could be encountered through erroneous behavior.
  7448. // Instead, one less than the type size in bits is used for the modulo.
  7449. // Even though we don't know the actual order these operations are performed,
  7450. // indices that make up a contiguous sequence of 31 or 63 values can be thought of as one of a series of "passes".
  7451. // Each "pass" sets or clears the bits depending on what's already there.
  7452. // if the number of the pass is odd, the bits are being unset and all above the mod position should be set.
  7453. // If even, the bits are in the process of being set and bits below the mod position should be set.
  7454. size_t xorResult = ((1ULL<<((maxIdx)%(bitSize-1))) -1);
  7455. if (((maxIdx/(bitSize-1))&1)) {
  7456. xorResult ^= ~0ULL;
  7457. // The XOR above may set uninvolved upper bits, messing up the compare. So AND off the uninvolved bits.
  7458. xorResult &= ((1ULL<<(bitSize-1)) - 1);
  7459. }
  7460. LogCommentFmt(L"Verifying %d-bit integer atomic xor", bitSize);
  7461. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*XOR_IDX, xorResult, byteSize));
  7462. // Test CMP/XCHG Operations
  7463. // This tests CompareStore, CompareExchange, and Exchange operations.
  7464. // Unlike above, every lane isn't contributing to the same resource location
  7465. // Instead, every lane competes with a few others to update the same resource location.
  7466. // The first lane to find the contents of their location uninitialized will
  7467. // update it. To verify that upper bits are considered in the comparison and
  7468. // in the assignment, the value stored in the lowest bits is the location index.
  7469. // This ensures that part will be the same for each of the competing lanes.
  7470. // The uppermost bits are updated with the index of the lane that got there first.
  7471. // Subsequent calls to CompareExchange will verify this value matches and alter
  7472. // the content slightly. Finally, a simple check of the output value to what
  7473. // the current lane would expect and a call to exchange will update the value once more
  7474. // To verify this has gone through properly, the upper portion is converted as
  7475. // if to calculate the location index and compared with the location index.
  7476. // It could be the index of any of several lanes that assign to that location,
  7477. // but this ensures that it is not any lane outside of that group.
  7478. // The lower bits are compared to the location index as well.
  7479. LogCommentFmt(L"Verifying %d-bit integer atomic cmp/xchg results", bitSize);
  7480. for (size_t i = 0; i < 64; i++) {
  7481. uint64_t val = *((uint64_t*)(pXchg + i*stride));
  7482. // Verify lower bits match location index exactly
  7483. VERIFY_ARE_EQUAL(i, val & ((1ULL << shBits) - 1ULL));
  7484. // Verify that upper bits contain original index that transforms to location index
  7485. VERIFY_ARE_EQUAL(((val >> shBits)/3)%64, i);
  7486. }
  7487. }
  7488. void VerifyAtomicsRawTest(std::shared_ptr<ShaderOpTestResult> test,
  7489. size_t maxIdx, size_t bitSize) {
  7490. size_t stride = 8;
  7491. // struct mirroring that in the shader
  7492. struct AtomicStuff {
  7493. float prepad[2][3];
  7494. UINT uintEl[4];
  7495. int sintEl[4];
  7496. struct useless {
  7497. uint32_t unused[3];
  7498. } postpad;
  7499. float last;
  7500. };
  7501. MappedData uintData, xchgData;
  7502. test->Test->GetReadBackData("U0", &uintData);
  7503. test->Test->GetReadBackData("U1", &xchgData);
  7504. const AtomicStuff *pStruct = (AtomicStuff *)uintData.data();
  7505. const AtomicStuff *pStrXchg = (AtomicStuff *)xchgData.data();
  7506. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWStructuredBuffer resource", bitSize);
  7507. VerifyAtomicResults((const BYTE*)&(pStruct[0].uintEl[2]), (const BYTE*)&(pStruct[1].sintEl[2]),
  7508. (const BYTE*)&(pStrXchg[0].uintEl[2]), sizeof(AtomicStuff), maxIdx, bitSize);
  7509. const BYTE *pUint = nullptr;
  7510. const BYTE *pXchg = nullptr;
  7511. test->Test->GetReadBackData("U2", &uintData);
  7512. test->Test->GetReadBackData("U3", &xchgData);
  7513. pUint = (BYTE *)uintData.data();
  7514. pXchg = (BYTE *)xchgData.data();
  7515. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWByteAddressBuffer resource", bitSize);
  7516. VerifyAtomicResults(pUint, pUint + stride*6,
  7517. pXchg, stride, maxIdx, bitSize);
  7518. }
  7519. void VerifyAtomicsTypedTest(std::shared_ptr<ShaderOpTestResult> test,
  7520. size_t maxIdx, size_t bitSize) {
  7521. size_t stride = 8;
  7522. MappedData uintData, sintData, xchgData;
  7523. const BYTE *pUint = nullptr;
  7524. const BYTE *pSint = nullptr;
  7525. const BYTE *pXchg = nullptr;
  7526. // Typed resources can't share between 32 and 64 bits
  7527. if (bitSize == 32) {
  7528. test->Test->GetReadBackData("U4", &uintData);
  7529. test->Test->GetReadBackData("U5", &sintData);
  7530. test->Test->GetReadBackData("U6", &xchgData);
  7531. } else {
  7532. test->Test->GetReadBackData("U12", &uintData);
  7533. test->Test->GetReadBackData("U13", &sintData);
  7534. test->Test->GetReadBackData("U14", &xchgData);
  7535. }
  7536. pUint = (BYTE *)uintData.data();
  7537. pSint = (BYTE *)sintData.data();
  7538. pXchg = (BYTE *)xchgData.data();
  7539. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWBuffer resource", bitSize);
  7540. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7541. // Typed resources can't share between 32 and 64 bits
  7542. if (bitSize == 32) {
  7543. test->Test->GetReadBackData("U7", &uintData);
  7544. test->Test->GetReadBackData("U8", &sintData);
  7545. test->Test->GetReadBackData("U9", &xchgData);
  7546. } else {
  7547. test->Test->GetReadBackData("U15", &uintData);
  7548. test->Test->GetReadBackData("U16", &sintData);
  7549. test->Test->GetReadBackData("U17", &xchgData);
  7550. }
  7551. pUint = (BYTE *)uintData.data();
  7552. pSint = (BYTE *)sintData.data();
  7553. pXchg = (BYTE *)xchgData.data();
  7554. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWTexture resource", bitSize);
  7555. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7556. }
  7557. void VerifyAtomicsSharedTest(std::shared_ptr<ShaderOpTestResult> test,
  7558. size_t maxIdx, size_t bitSize) {
  7559. size_t stride = 8;
  7560. MappedData uintData, xchgData;
  7561. const BYTE *pUint = nullptr;
  7562. const BYTE *pXchg = nullptr;
  7563. test->Test->GetReadBackData("U10", &uintData);
  7564. test->Test->GetReadBackData("U11", &xchgData);
  7565. pUint = (BYTE *)uintData.data();
  7566. pXchg = (BYTE *)xchgData.data();
  7567. LogCommentFmt(L"Verifying %d-bit integer atomic operations on groupshared variables", bitSize);
  7568. VerifyAtomicResults(pUint, pUint + stride*6,
  7569. pXchg, stride, maxIdx, bitSize);
  7570. }
  7571. void VerifyAtomicsTest(std::shared_ptr<ShaderOpTestResult> test,
  7572. size_t maxIdx, size_t bitSize) {
  7573. VerifyAtomicsRawTest(test, maxIdx, bitSize);
  7574. VerifyAtomicsTypedTest(test, maxIdx, bitSize);
  7575. }
  7576. TEST_F(ExecutionTest, AtomicsTest) {
  7577. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7578. CComPtr<IStream> pStream;
  7579. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7580. CComPtr<ID3D12Device> pDevice;
  7581. if (!CreateDevice(&pDevice))
  7582. return;
  7583. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7584. std::make_shared<st::ShaderOpSet>();
  7585. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7586. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7587. // Test compute shader
  7588. LogCommentFmt(L"Verifying 32-bit integer atomic operations in compute shader");
  7589. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7590. VerifyAtomicsTest(test, 32*32, 32);
  7591. VerifyAtomicsSharedTest(test, 32*32, 32);
  7592. // Test mesh shader if available
  7593. pShaderOp->CS = nullptr;
  7594. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7595. LogCommentFmt(L"Verifying 32-bit integer atomic operations in amp/mesh/pixel shaders");
  7596. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7597. VerifyAtomicsTest(test, 8*8*2 + 8*8*2 + 64*64, 32);
  7598. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 32);
  7599. }
  7600. // Test Vertex + Pixel shader
  7601. pShaderOp->MS = nullptr;
  7602. LogCommentFmt(L"Verifying 32-bit integer atomic operations in vert/pixel shaders");
  7603. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7604. VerifyAtomicsTest(test, 64*64+6, 32);
  7605. }
  7606. TEST_F(ExecutionTest, Atomics64Test) {
  7607. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7608. CComPtr<IStream> pStream;
  7609. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7610. CComPtr<ID3D12Device> pDevice;
  7611. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7612. return;
  7613. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7614. std::make_shared<st::ShaderOpSet>();
  7615. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7616. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7617. // Reassign shader stages to 64-bit versions
  7618. // Collect 64-bit shaders
  7619. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7620. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7621. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7622. if (!strcmp(S.Name, "CS64")) CS64 = S.Name;
  7623. if (!strcmp(S.Name, "VS64")) VS64 = S.Name;
  7624. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7625. if (!strcmp(S.Name, "AS64")) AS64 = S.Name;
  7626. if (!strcmp(S.Name, "MS64")) MS64 = S.Name;
  7627. }
  7628. pShaderOp->CS = CS64;
  7629. pShaderOp->VS = VS64;
  7630. pShaderOp->PS = PS64;
  7631. pShaderOp->AS = AS64;
  7632. pShaderOp->MS = MS64;
  7633. // Test compute shader
  7634. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in compute shader");
  7635. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7636. VerifyAtomicsRawTest(test, 32*32, 64);
  7637. // Test mesh shader if available
  7638. pShaderOp->CS = nullptr;
  7639. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7640. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in amp/mesh/pixel shader");
  7641. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7642. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7643. }
  7644. // Test Vertex + Pixel shader
  7645. pShaderOp->MS = nullptr;
  7646. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in vert/pixel shader");
  7647. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7648. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7649. }
  7650. TEST_F(ExecutionTest, AtomicsTyped64Test) {
  7651. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7652. CComPtr<IStream> pStream;
  7653. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7654. CComPtr<ID3D12Device> pDevice;
  7655. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7656. return;
  7657. if (!DoesDeviceSupportInt64(pDevice)) {
  7658. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7659. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7660. return;
  7661. }
  7662. if (!DoesDeviceSupportTyped64Atomics(pDevice)) {
  7663. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on typed resources.");
  7664. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7665. return;
  7666. }
  7667. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7668. std::make_shared<st::ShaderOpSet>();
  7669. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7670. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7671. // Reassign shader stages to 64-bit versions
  7672. // Collect 64-bit shaders
  7673. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7674. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7675. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7676. if (!strcmp(S.Name, "CSTY64")) CS64 = S.Name;
  7677. if (!strcmp(S.Name, "VSTY64")) VS64 = S.Name;
  7678. if (!strcmp(S.Name, "PSTY64")) PS64 = S.Name;
  7679. if (!strcmp(S.Name, "ASTY64")) AS64 = S.Name;
  7680. if (!strcmp(S.Name, "MSTY64")) MS64 = S.Name;
  7681. }
  7682. pShaderOp->CS = CS64;
  7683. pShaderOp->VS = VS64;
  7684. pShaderOp->PS = PS64;
  7685. pShaderOp->AS = AS64;
  7686. pShaderOp->MS = MS64;
  7687. // Test compute shader
  7688. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in compute shader");
  7689. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7690. VerifyAtomicsTypedTest(test, 32*32, 64);
  7691. // Test mesh shader if available
  7692. pShaderOp->CS = nullptr;
  7693. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7694. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in amp/mesh/pixel shader");
  7695. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7696. VerifyAtomicsTypedTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7697. }
  7698. // Test Vertex + Pixel shader
  7699. pShaderOp->MS = nullptr;
  7700. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in vert/pixel shader");
  7701. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7702. VerifyAtomicsTypedTest(test, 64*64+6, 64);
  7703. }
  7704. TEST_F(ExecutionTest, AtomicsShared64Test) {
  7705. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7706. CComPtr<IStream> pStream;
  7707. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7708. CComPtr<ID3D12Device> pDevice;
  7709. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7710. return;
  7711. if (!DoesDeviceSupportInt64(pDevice)) {
  7712. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7713. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7714. return;
  7715. }
  7716. if (!DoesDeviceSupportShared64Atomics(pDevice)) {
  7717. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on groupshared variables.");
  7718. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7719. return;
  7720. }
  7721. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7722. std::make_shared<st::ShaderOpSet>();
  7723. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7724. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7725. // Reassign shader stages to 64-bit versions
  7726. // Collect 64-bit shaders
  7727. LPCSTR CS64 = nullptr, PS64 = nullptr;
  7728. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7729. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7730. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7731. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7732. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7733. if (!strcmp(S.Name, "ASSH64")) AS64 = S.Name;
  7734. if (!strcmp(S.Name, "MSSH64")) MS64 = S.Name;
  7735. }
  7736. pShaderOp->CS = CS64;
  7737. pShaderOp->PS = PS64;
  7738. pShaderOp->AS = AS64;
  7739. pShaderOp->MS = MS64;
  7740. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in compute shader");
  7741. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7742. VerifyAtomicsSharedTest(test, 32*32, 64);
  7743. // Test mesh shader if available
  7744. pShaderOp->CS = nullptr;
  7745. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7746. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in amp/mesh/pixel shader");
  7747. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7748. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 64);
  7749. }
  7750. }
  7751. // Float Atomics
  7752. // These operations are almost the same as for the 32-bit and 64-bit integer tests
  7753. // The difference is that there is no need to verify the upper bits.
  7754. // So there is no storing of different parts in upper and lower halves.
  7755. // Additionally, the only operations that are supported on floats
  7756. // are compare and exchange operations. So that's all that is tested here.
  7757. // Just as above, a number of lanes are assigned the same output value.
  7758. // Unlike above, one location is needed for the result of the special NaN test
  7759. // For this reason, the conversion is reduced by one and shifted by one to leave
  7760. // the zero-indexed location available.
  7761. // Verify results for a particular set of atomics results
  7762. void VerifyAtomicFloatResults(const float *results, size_t maxIdx) {
  7763. // The first entry is for NaN to ensure that compares between NaNs succeed
  7764. // The sentinal value is 0.123, for which this compare is sufficient.
  7765. VERIFY_IS_TRUE(results[0] >= 0.120 && results[0] < 0.125);
  7766. // Start at 1 because 0 is just for NaN tests
  7767. for (size_t i = 1; i < 64; i++) {
  7768. VERIFY_ARE_EQUAL((int(results[i])/3)%63 + 1, i);
  7769. }
  7770. }
  7771. void VerifyAtomicsFloatSharedTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7772. MappedData Data;
  7773. const float *pData = nullptr;
  7774. test->Test->GetReadBackData("U4", &Data);
  7775. pData = (float *)Data.data();
  7776. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on groupshared variables");
  7777. VerifyAtomicFloatResults(pData, maxIdx);
  7778. }
  7779. void VerifyAtomicsFloatTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7780. // struct mirroring that in the shader
  7781. struct AtomicStuff {
  7782. float prepad[2][3];
  7783. float fltEl[2];
  7784. struct useless {
  7785. uint32_t unused[3];
  7786. } postpad;
  7787. };
  7788. // Test Compute Shader
  7789. MappedData Data;
  7790. const float *pData = nullptr;
  7791. test->Test->GetReadBackData("U0", &Data);
  7792. const AtomicStuff *pStructData = (AtomicStuff *)Data.data();
  7793. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWStructuredBuffer resources");
  7794. VERIFY_IS_TRUE(pStructData[0].fltEl[1] >= 0.120 && pStructData[0].fltEl[1] < 0.125);
  7795. for (size_t i = 1; i < 64; i++) {
  7796. VERIFY_ARE_EQUAL((int(pStructData[i].fltEl[1])/3)%63 + 1, i);
  7797. }
  7798. test->Test->GetReadBackData("U1", &Data);
  7799. pData = (float *)Data.data();
  7800. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWByteAddressBuffer resources");
  7801. VerifyAtomicFloatResults(pData, maxIdx);
  7802. test->Test->GetReadBackData("U2", &Data);
  7803. pData = (float *)Data.data();
  7804. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWBuffer resources");
  7805. VerifyAtomicFloatResults(pData, maxIdx);
  7806. test->Test->GetReadBackData("U3", &Data);
  7807. pData = (float *)Data.data();
  7808. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWTexture resources");
  7809. VerifyAtomicFloatResults(pData, maxIdx);
  7810. }
  7811. TEST_F(ExecutionTest, AtomicsFloatTest) {
  7812. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7813. CComPtr<IStream> pStream;
  7814. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7815. CComPtr<ID3D12Device> pDevice;
  7816. if (!CreateDevice(&pDevice))
  7817. return;
  7818. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7819. std::make_shared<st::ShaderOpSet>();
  7820. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7821. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("FloatAtomics");
  7822. // Test compute shader
  7823. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in compute shader");
  7824. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7825. VerifyAtomicsFloatTest(test, 32*32);
  7826. VerifyAtomicsFloatSharedTest(test, 32*32);
  7827. // Test mesh shader if available
  7828. pShaderOp->CS = nullptr;
  7829. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7830. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in amp/mesh/pixel shaders");
  7831. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7832. VerifyAtomicsFloatTest(test, 8*8*2 + 8*8*2 + 64*64);
  7833. VerifyAtomicsFloatSharedTest(test, 8*8*2 + 8*8*2);
  7834. }
  7835. // Test Vertex + Pixel shader
  7836. pShaderOp->MS = nullptr;
  7837. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in vert/pixel shaders");
  7838. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7839. VerifyAtomicsFloatTest(test, 64*64+6);
  7840. }
  7841. // The IsHelperLane test renders 3-pixel triangle into 16x16 render target restricted
  7842. // to 2x2 viewport alligned at (0,0) which guarantees it will run in a single quad.
  7843. //
  7844. // Pixels to be rendered*
  7845. // (0,0)* (0,1)*
  7846. // (1,0) (1,1)*
  7847. //
  7848. // Pixel (1,0) is not rendered and is in helper lane.
  7849. //
  7850. // Each thread will use ddx_fine and ddy_fine to read the IsHelperLane() values from other threads.
  7851. // The bottom right pixel will write the results into the UAV buffer.
  7852. //
  7853. // Then the top level pixel (0,0) is discarded and the process above is repeated.
  7854. //
  7855. // Runs with shader models 6.0 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  7856. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6).
  7857. //
  7858. TEST_F(ExecutionTest, HelperLaneTest) {
  7859. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7860. CComPtr<IStream> pStream;
  7861. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7862. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  7863. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7864. #ifdef ISHELPERLANE_PLACEHOLDER
  7865. string args = "-DISHELPERLANE_PLACEHOLDER";
  7866. #else
  7867. string args = "";
  7868. #endif
  7869. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_6 };
  7870. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  7871. D3D_SHADER_MODEL sm = TestShaderModels[i];
  7872. LogCommentFmt(L"Verifying IsHelperLane in shader model 6.%1u", ((UINT)sm & 0x0f));
  7873. CComPtr<ID3D12Device> pDevice;
  7874. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */))
  7875. continue;
  7876. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestNoWave",
  7877. // this callbacked is called when the test is creating the resource to run the test
  7878. [&](LPCSTR Name, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  7879. VERIFY_IS_TRUE(0 == _stricmp(Name, "UAVBuffer0"));
  7880. std::fill(Data.begin(), Data.end(), 0xCC);
  7881. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7882. pShaderOp->Shaders.at(1).Arguments = args.c_str();
  7883. }, ShaderOpSet);
  7884. struct HelperLaneTestResult {
  7885. int32_t is_helper_00;
  7886. int32_t is_helper_10;
  7887. int32_t is_helper_01;
  7888. int32_t is_helper_11;
  7889. };
  7890. MappedData uavData;
  7891. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  7892. HelperLaneTestResult* pTestResults = (HelperLaneTestResult*)uavData.data();
  7893. MappedData renderData;
  7894. test->Test->GetReadBackData("RTarget", &renderData);
  7895. const uint32_t* pPixels = (uint32_t*)renderData.data();
  7896. // before discard
  7897. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_00, 0);
  7898. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_10, 0);
  7899. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_01, 1);
  7900. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_11, 0);
  7901. // after discard
  7902. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_00, 1);
  7903. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_10, 0);
  7904. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_01, 1);
  7905. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_11, 0);
  7906. UNREFERENCED_PARAMETER(pPixels);
  7907. }
  7908. }
  7909. struct HelperLaneWaveTestResult60 {
  7910. // 6.0 wave ops
  7911. int32_t anyTrue;
  7912. int32_t allTrue;
  7913. XMUINT4 ballot;
  7914. int32_t waterfallLoopCount;
  7915. int32_t allEqual;
  7916. int32_t countBits;
  7917. int32_t sum;
  7918. int32_t product;
  7919. int32_t bitAnd;
  7920. int32_t bitOr;
  7921. int32_t bitXor;
  7922. int32_t min;
  7923. int32_t max;
  7924. int32_t prefixCountBits;
  7925. int32_t prefixProduct;
  7926. int32_t prefixSum;
  7927. };
  7928. struct HelperLaneQuadTestResult {
  7929. int32_t is_helper_this;
  7930. int32_t is_helper_across_X;
  7931. int32_t is_helper_across_Y;
  7932. int32_t is_helper_across_Diag;
  7933. };
  7934. struct HelperLaneWaveTestResult65 {
  7935. // 6.5 wave ops
  7936. XMUINT4 match;
  7937. int32_t mpCountBits;
  7938. int32_t mpSum;
  7939. int32_t mpProduct;
  7940. int32_t mpBitAnd;
  7941. int32_t mpBitOr;
  7942. int32_t mpBitXor;
  7943. };
  7944. struct HelperLaneWaveTestResult {
  7945. HelperLaneWaveTestResult60 sm60;
  7946. HelperLaneQuadTestResult sm60_quad;
  7947. HelperLaneWaveTestResult65 sm65;
  7948. };
  7949. struct foo { int32_t a; int32_t b; int32_t c; };
  7950. struct bar { foo f; int32_t d; XMUINT4 g; };
  7951. foo f = {1, 2, 3};
  7952. bar b = { { 1, 2, 3 }, 0, { 1, 2, 3, 4 } };
  7953. HelperLaneWaveTestResult HelperLane_CS_ExpectedResults = {
  7954. // HelperLaneWaveTestResult60
  7955. { 0, 1, { 0x7, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  7956. // HelperLaneQuadTestResult
  7957. { 0, 0, 0, 0 },
  7958. // HelperLaneWaveTestResult65
  7959. { {0x7, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  7960. };
  7961. HelperLaneWaveTestResult HelperLane_VS_ExpectedResults = HelperLane_CS_ExpectedResults;
  7962. HelperLaneWaveTestResult HelperLane_PS_ExpectedResults = {
  7963. // HelperLaneWaveTestResult60
  7964. { 0, 1, { 0xB, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  7965. // HelperLaneQuadTestResult
  7966. { 0, 1, 0, 0 },
  7967. // HelperLaneWaveTestResult65
  7968. { {0xB, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  7969. };
  7970. HelperLaneWaveTestResult HelperLane_PSAfterDiscard_ExpectedResults = {
  7971. // HelperLaneWaveTestResult60
  7972. { 0, 1, { 0xA, 0, 0, 0 }, 2, 1, 2, 8, 16, 1, 0, 0, 10, 1, 1, 4, 2 },
  7973. // HelperLaneQuadTestResult
  7974. { 0, 1, 0, 1 },
  7975. // HelperLaneWaveTestResult65
  7976. { {0xA, 0, 0, 0}, 1, 2, 4, 1, 0, 0 }
  7977. };
  7978. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, uint32_t expectedValue, uint32_t actualValue) {
  7979. bool matches = (expectedValue == actualValue);
  7980. LogCommentFmt(L"%s%s, expected = %u, actual = %u", matches ? L" - " : L"FAILED: ", testDesc, expectedValue, actualValue);
  7981. return matches;
  7982. }
  7983. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, XMUINT4 expectedValue, XMUINT4 actualValue) {
  7984. bool matches = (expectedValue.x == actualValue.x && expectedValue.y == actualValue.y &&
  7985. expectedValue.z == actualValue.z && expectedValue.w == actualValue.w);
  7986. 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,
  7987. expectedValue.x, expectedValue.y, expectedValue.z, expectedValue.w, actualValue.x, actualValue.y, actualValue.z, actualValue.w);
  7988. return matches;
  7989. }
  7990. bool VerifyHelperLaneWaveResults(ExecutionTest::D3D_SHADER_MODEL sm, HelperLaneWaveTestResult& testResults, HelperLaneWaveTestResult& expectedResults, bool verifyQuads) {
  7991. bool passed = true;
  7992. {
  7993. HelperLaneWaveTestResult60& tr60 = testResults.sm60;
  7994. HelperLaneWaveTestResult60& tr60exp = expectedResults.sm60;
  7995. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAnyTrue(IsHelperLane())", tr60exp.anyTrue, tr60.anyTrue);
  7996. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllTrue(!IsHelperLane())", tr60exp.allTrue, tr60.allTrue);
  7997. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBallot(true) has exactly 3 bits set", tr60exp.ballot, tr60.ballot);
  7998. passed &= HelperLaneResultLogAndVerify(L"!WaveReadLaneFirst(IsHelperLane()) && WaveIsFirstLane() in a waterfall loop", tr60exp.waterfallLoopCount, tr60.waterfallLoopCount);
  7999. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllEqual(IsHelperLane())", tr60exp.allEqual, tr60.allEqual);
  8000. passed &= HelperLaneResultLogAndVerify(L"WaveActiveCountBits(true)", tr60exp.countBits, tr60.countBits);
  8001. passed &= HelperLaneResultLogAndVerify(L"WaveActiveSum(4)", tr60exp.sum, tr60.sum);
  8002. passed &= HelperLaneResultLogAndVerify(L"WaveActiveProduct(4)", tr60exp.product, tr60.product);
  8003. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitAnd(!IsHelperLane())", tr60exp.bitAnd, tr60.bitAnd);
  8004. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitOr(IsHelperLane())", tr60exp.bitOr, tr60.bitOr);
  8005. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitXor(IsHelperLane())", tr60exp.bitXor, tr60.bitXor);
  8006. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMin(IsHelperLane() ? 1 : 10)", tr60exp.min, tr60.min);
  8007. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMax(IsHelperLane() ? 10 : 1)", tr60exp.max, tr60.max);
  8008. passed &= HelperLaneResultLogAndVerify(L"WavePrefixCountBits(1)", tr60exp.prefixCountBits, tr60.prefixCountBits);
  8009. passed &= HelperLaneResultLogAndVerify(L"WavePrefixProduct(4)", tr60exp.prefixProduct, tr60.prefixProduct);
  8010. passed &= HelperLaneResultLogAndVerify(L"WavePrefixSum(2)", tr60exp.prefixSum, tr60.prefixSum);
  8011. }
  8012. if (verifyQuads) {
  8013. HelperLaneQuadTestResult& quad_tr = testResults.sm60_quad;
  8014. HelperLaneQuadTestResult& quad_tr_exp = expectedResults.sm60_quad;
  8015. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 3 / pixel (1,1) - IsHelperLane()", quad_tr_exp.is_helper_this, quad_tr.is_helper_this);
  8016. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 2 / pixel (0,1) - IsHelperLane()", quad_tr_exp.is_helper_across_X, quad_tr.is_helper_across_X);
  8017. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 1 / pixel (1,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Y, quad_tr.is_helper_across_Y);
  8018. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 0 / pixel (0,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Diag, quad_tr.is_helper_across_Diag);
  8019. }
  8020. if (sm >= D3D_SHADER_MODEL_6_5) {
  8021. HelperLaneWaveTestResult65& tr65 = testResults.sm65;
  8022. HelperLaneWaveTestResult65& tr65exp = expectedResults.sm65;
  8023. passed &= HelperLaneResultLogAndVerify(L"WaveMatch(true) has exactly 3 bits set", tr65exp.match, tr65.match);
  8024. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixCountBits(1, no_masked_bits)", tr65exp.mpCountBits, tr65.mpCountBits);
  8025. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixSum(2, no_masked_bits)", tr65exp.mpSum, tr65.mpSum);
  8026. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixProduct(4, no_masked_bits)", tr65exp.mpProduct, tr65.mpProduct);
  8027. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixAnd(IsHelperLane() ? 0 : 1, no_masked_bits)", tr65exp.mpBitAnd, tr65.mpBitAnd);
  8028. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixOr(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitOr, tr65.mpBitOr);
  8029. passed &= HelperLaneResultLogAndVerify(L"verify WaveMultiPrefixXor(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitXor, tr65.mpBitXor);
  8030. }
  8031. return passed;
  8032. }
  8033. void CleanUAVBuffer0Buffer(LPCSTR BufferName, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  8034. VERIFY_IS_TRUE(0 == _stricmp(BufferName, "UAVBuffer0"));
  8035. std::fill(Data.begin(), Data.end(), 0xCC);
  8036. }
  8037. //
  8038. // The IsHelperLane test that use Wave intrinsics to verify IsHelperLane() and Wave operations on active lanes.
  8039. //
  8040. // Runs with shader models 6.0, 6.5 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  8041. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6) and the shader model 6.5 wave intrinsics (sm >= 6.5).
  8042. //
  8043. // For compute and vertex shaders IsHelperLane() always returns false and might be optimized away in the front end.
  8044. // However it can be exposed to the driver in CS/VS through an exported function in a library so drivers need
  8045. // to be prepared to handle it. For this reason the test is compiled with disabled optimizations (/Od).
  8046. // The tests are also validating that wave intrinsics operate correctly with 3 threads in a CS or 3 vertices
  8047. // in a VS where the rest of the lanes in the wave are not active (dead lanes).
  8048. //
  8049. TEST_F(ExecutionTest, HelperLaneTestWave) {
  8050. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  8051. CComPtr<IStream> pStream;
  8052. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  8053. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  8054. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8055. st::ShaderOp* pShaderOp = ShaderOpSet->GetShaderOp("HelperLaneTestWave");
  8056. #ifdef ISHELPERLANE_PLACEHOLDER
  8057. LPCSTR args = "/Od -DISHELPERLANE_PLACEHOLDER";
  8058. #else
  8059. LPCSTR args = "/Od";
  8060. #endif
  8061. if (args[0]) {
  8062. for (st::ShaderOpShader& S : pShaderOp->Shaders)
  8063. S.Arguments = args;
  8064. }
  8065. bool testPassed = true;
  8066. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_5, D3D_SHADER_MODEL_6_6 };
  8067. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  8068. D3D_SHADER_MODEL sm = TestShaderModels[i];
  8069. LogCommentFmt(L"\r\nVerifying IsHelperLane using Wave intrinsics in shader model 6.%1u", ((UINT)sm & 0x0f));
  8070. bool smPassed = true;
  8071. CComPtr<ID3D12Device> pDevice;
  8072. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */)) {
  8073. continue;
  8074. }
  8075. if (!DoesDeviceSupportWaveOps(pDevice)) {
  8076. LogCommentFmt(L"Device does not support wave operations in shader model 6.%1u", ((UINT)sm & 0x0f));
  8077. continue;
  8078. }
  8079. if (sm >= D3D_SHADER_MODEL_6_5) {
  8080. // Reassign shader stages to 6.5 versions
  8081. LPCSTR CS65 = nullptr, VS65 = nullptr, PS65 = nullptr;
  8082. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8083. if (!strcmp(S.Name, "CS65")) CS65 = S.Name;
  8084. if (!strcmp(S.Name, "VS65")) VS65 = S.Name;
  8085. if (!strcmp(S.Name, "PS65")) PS65 = S.Name;
  8086. }
  8087. pShaderOp->CS = CS65;
  8088. pShaderOp->VS = VS65;
  8089. pShaderOp->PS = PS65;
  8090. }
  8091. const unsigned CS_INDEX = 0, VS_INDEX = 0, PS_INDEX = 1, PS_INDEX_AFTER_DISCARD = 2;
  8092. // Test Compute shader
  8093. {
  8094. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave",
  8095. CleanUAVBuffer0Buffer, ShaderOpSet);
  8096. MappedData uavData;
  8097. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8098. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8099. LogCommentFmt(L"\r\nCompute shader");
  8100. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[CS_INDEX], HelperLane_CS_ExpectedResults, true);
  8101. }
  8102. // Test Vertex + Pixel shader
  8103. {
  8104. pShaderOp->CS = nullptr;
  8105. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave", CleanUAVBuffer0Buffer, ShaderOpSet);
  8106. MappedData uavData;
  8107. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8108. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8109. LogCommentFmt(L"\r\nVertex shader");
  8110. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[VS_INDEX], HelperLane_VS_ExpectedResults, false);
  8111. LogCommentFmt(L"\r\nPixel shader");
  8112. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX], HelperLane_PS_ExpectedResults, true);
  8113. LogCommentFmt(L"\r\nPixel shader with discarded pixel");
  8114. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX_AFTER_DISCARD], HelperLane_PSAfterDiscard_ExpectedResults, true);
  8115. MappedData renderData;
  8116. test->Test->GetReadBackData("RTarget", &renderData);
  8117. const uint32_t* pPixels = (uint32_t*)renderData.data();
  8118. UNREFERENCED_PARAMETER(pPixels);
  8119. }
  8120. testPassed &= smPassed;
  8121. }
  8122. VERIFY_ARE_EQUAL(testPassed, true);
  8123. }
  8124. #ifndef _HLK_CONF
  8125. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  8126. char **pReadBackDump) {
  8127. std::stringstream str;
  8128. unsigned count = 0;
  8129. for (auto &R : pShaderOp->Resources) {
  8130. if (!R.ReadBack)
  8131. continue;
  8132. ++count;
  8133. str << "Resource: " << R.Name << "\r\n";
  8134. // Find a descriptor that can tell us how to dump this resource.
  8135. bool found = false;
  8136. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  8137. for (auto &D : Heaps.Descriptors) {
  8138. if (_stricmp(D.ResName, R.Name) != 0) {
  8139. continue;
  8140. }
  8141. found = true;
  8142. if (_stricmp(D.Kind, "UAV") != 0) {
  8143. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  8144. break;
  8145. }
  8146. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  8147. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  8148. break;
  8149. }
  8150. // We can map back to the structure if a structured buffer via the shader, but
  8151. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  8152. MappedData data;
  8153. pTest->GetReadBackData(R.Name, &data);
  8154. uint32_t *pData = (uint32_t *)data.data();
  8155. size_t u32_count = R.Desc.Width / sizeof(uint32_t);
  8156. for (size_t i = 0; i < u32_count; ++i) {
  8157. float f = *(float *)pData;
  8158. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  8159. << std::dec << " " << f << "\r\n";
  8160. ++pData;
  8161. }
  8162. break;
  8163. }
  8164. if (found) break;
  8165. }
  8166. if (!found) {
  8167. str << "Unable to find a view for the resource.\r\n";
  8168. }
  8169. }
  8170. str << "Resources read back: " << count << "\r\n";
  8171. std::string s(str.str());
  8172. CComHeapPtr<char> pDump;
  8173. if (!pDump.Allocate(s.size() + 1))
  8174. throw std::bad_alloc();
  8175. memcpy(pDump.m_pData, s.data(), s.size());
  8176. pDump.m_pData[s.size()] = '\0';
  8177. *pReadBackDump = pDump.Detach();
  8178. }
  8179. // This is the exported interface by use from HLSLHost.exe.
  8180. // It's exclusive with the use of the DLL as a TAEF target.
  8181. extern "C" {
  8182. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  8183. HRESULT hr = EnableExperimentalShaderModels();
  8184. if (FAILED(hr)) {
  8185. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  8186. }
  8187. return S_OK;
  8188. }
  8189. __declspec(dllexport) HRESULT WINAPI
  8190. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  8191. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  8192. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  8193. HRESULT hr;
  8194. if (pReadBackDump) *pReadBackDump = nullptr;
  8195. st::SetOutputFn(pStrCtx, pOutputStrFn);
  8196. CComPtr<ID3D12InfoQueue> pInfoQueue;
  8197. CComHeapPtr<char> pDump;
  8198. bool FilterCreation = false;
  8199. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  8200. // Creation is largely driven by inputs, so don't log create/destroy messages.
  8201. pInfoQueue->PushEmptyStorageFilter();
  8202. pInfoQueue->PushEmptyRetrievalFilter();
  8203. if (FilterCreation) {
  8204. D3D12_INFO_QUEUE_FILTER filter;
  8205. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  8206. ZeroMemory(&filter, sizeof(filter));
  8207. filter.DenyList.NumCategories = _countof(denyCategories);
  8208. filter.DenyList.pCategoryList = denyCategories;
  8209. pInfoQueue->PushStorageFilter(&filter);
  8210. }
  8211. }
  8212. else {
  8213. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  8214. }
  8215. try {
  8216. dxc::DxcDllSupport m_support;
  8217. m_support.Initialize();
  8218. const char *pName = nullptr;
  8219. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, strlen(pText));
  8220. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  8221. std::make_shared<st::ShaderOpSet>();
  8222. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8223. st::ShaderOp *pShaderOp;
  8224. if (pName == nullptr) {
  8225. if (ShaderOpSet->ShaderOps.size() != 1) {
  8226. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  8227. return E_FAIL;
  8228. }
  8229. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  8230. }
  8231. else {
  8232. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  8233. }
  8234. if (pShaderOp == nullptr) {
  8235. std::string msg = "Unable to find shader op ";
  8236. msg += pName;
  8237. msg += "; available ops";
  8238. const char sep = ':';
  8239. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  8240. msg += sep;
  8241. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  8242. }
  8243. CA2W msgWide(msg.c_str());
  8244. pOutputStrFn(pStrCtx, msgWide);
  8245. return E_FAIL;
  8246. }
  8247. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  8248. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  8249. test->SetDxcSupport(&m_support);
  8250. test->RunShaderOp(pShaderOp);
  8251. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  8252. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  8253. if (!pShaderOp->IsCompute()) {
  8254. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  8255. test->GetPipelineStats(&stats);
  8256. wchar_t statsText[400];
  8257. StringCchPrintfW(statsText, _countof(statsText),
  8258. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  8259. L"Vertex shader invocations: %I64u\r\n"
  8260. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  8261. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  8262. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  8263. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  8264. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  8265. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  8266. stats.DSInvocations, stats.CSInvocations);
  8267. pOutputStrFn(pStrCtx, statsText);
  8268. }
  8269. if (pReadBackDump) {
  8270. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  8271. }
  8272. hr = S_OK;
  8273. }
  8274. catch (const CAtlException &E)
  8275. {
  8276. hr = E.m_hr;
  8277. }
  8278. catch (const std::bad_alloc &)
  8279. {
  8280. hr = E_OUTOFMEMORY;
  8281. }
  8282. catch (const std::exception &)
  8283. {
  8284. hr = E_FAIL;
  8285. }
  8286. // Drain the device message queue if available.
  8287. if (pInfoQueue != nullptr) {
  8288. wchar_t buf[200];
  8289. StringCchPrintfW(buf, _countof(buf),
  8290. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  8291. L"allowed/denied by storage filter=%u/%u "
  8292. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  8293. (unsigned)pInfoQueue->GetNumStoredMessages(),
  8294. (unsigned)pInfoQueue->GetMessageCountLimit(),
  8295. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  8296. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  8297. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  8298. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  8299. pOutputStrFn(pStrCtx, buf);
  8300. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  8301. pInfoQueue->ClearStoredMessages();
  8302. pInfoQueue->PopRetrievalFilter();
  8303. pInfoQueue->PopStorageFilter();
  8304. if (FilterCreation) {
  8305. pInfoQueue->PopStorageFilter();
  8306. }
  8307. }
  8308. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  8309. return hr;
  8310. }
  8311. }
  8312. #endif
  8313. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  8314. // Do not remove the line above - it is used by TranslateExecutionTest.py