ExecutionTest.cpp 369 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // ExecutionTest.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // These tests run by executing compiled programs, and thus involve more //
  9. // moving parts, like the runtime and drivers. //
  10. // //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include <algorithm>
  13. #include <memory>
  14. #include <array>
  15. #include <vector>
  16. #include <string>
  17. #include <map>
  18. #include <unordered_set>
  19. #include <strstream>
  20. #include <iomanip>
  21. #include "dxc/Test/CompilationResult.h"
  22. #include "dxc/Test/HLSLTestData.h"
  23. #include <Shlwapi.h>
  24. #include <atlcoll.h>
  25. #include <locale>
  26. #include <algorithm>
  27. #undef _read
  28. #include "WexTestClass.h"
  29. #include "dxc/Test/HlslTestUtils.h"
  30. #include "dxc/Test/DxcTestUtils.h"
  31. #include "dxc/Support/Global.h"
  32. #include "dxc/Support/WinIncludes.h"
  33. #include "dxc/Support/FileIOHelper.h"
  34. #include "dxc/Support/Unicode.h"
  35. //
  36. // d3d12.h and dxgi1_4.h are included in the Windows 10 SDK
  37. // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899120(v=vs.85).aspx
  38. // https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
  39. //
  40. #include <d3d12.h>
  41. #include <dxgi1_4.h>
  42. #include <DXGIDebug.h>
  43. #include "dxc/Support/d3dx12.h"
  44. #include <DirectXMath.h>
  45. #include <strsafe.h>
  46. #include <d3dcompiler.h>
  47. #include <wincodec.h>
  48. #include "ShaderOpTest.h"
  49. #pragma comment(lib, "d3dcompiler.lib")
  50. #pragma comment(lib, "windowscodecs.lib")
  51. #pragma comment(lib, "dxguid.lib")
  52. #pragma comment(lib, "version.lib")
  53. // A more recent Windows SDK than currently required is needed for these.
  54. typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)(
  55. UINT NumFeatures,
  56. __in_ecount(NumFeatures) const IID* pIIDs,
  57. __in_ecount_opt(NumFeatures) void* pConfigurationStructs,
  58. __in_ecount_opt(NumFeatures) UINT* pConfigurationStructSizes);
  59. static const GUID D3D12ExperimentalShaderModelsID = { /* 76f5573e-f13a-40f5-b297-81ce9e18933f */
  60. 0x76f5573e,
  61. 0xf13a,
  62. 0x40f5,
  63. { 0xb2, 0x97, 0x81, 0xce, 0x9e, 0x18, 0x93, 0x3f }
  64. };
  65. using namespace DirectX;
  66. using namespace hlsl_test;
  67. template <typename TSequence, typename T>
  68. static bool contains(TSequence s, const T &val) {
  69. return std::cend(s) != std::find(std::cbegin(s), std::cend(s), val);
  70. }
  71. template <typename InputIterator, typename T>
  72. static bool contains(InputIterator b, InputIterator e, const T &val) {
  73. return e != std::find(b, e, val);
  74. }
  75. static HRESULT EnableExperimentalShaderModels() {
  76. HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
  77. if (hRuntime == NULL) {
  78. return HRESULT_FROM_WIN32(GetLastError());
  79. }
  80. D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
  81. (D3D12EnableExperimentalFeaturesFn)GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures");
  82. if (pD3D12EnableExperimentalFeatures == nullptr) {
  83. FreeLibrary(hRuntime);
  84. return HRESULT_FROM_WIN32(GetLastError());
  85. }
  86. HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
  87. FreeLibrary(hRuntime);
  88. return hr;
  89. }
  90. static HRESULT ReportLiveObjects() {
  91. CComPtr<IDXGIDebug1> pDebug;
  92. IFR(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)));
  93. IFR(pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL));
  94. return S_OK;
  95. }
  96. static void WriteInfoQueueMessages(void *pStrCtx, st::OutputStringFn pOutputStrFn, ID3D12InfoQueue *pInfoQueue) {
  97. bool allMessagesOK = true;
  98. UINT64 count = pInfoQueue->GetNumStoredMessages();
  99. CAtlArray<BYTE> message;
  100. for (UINT64 i = 0; i < count; ++i) {
  101. // 'GetMessageA' rather than 'GetMessage' is an artifact of user32 headers.
  102. SIZE_T msgLen = 0;
  103. if (FAILED(pInfoQueue->GetMessageA(i, nullptr, &msgLen))) {
  104. allMessagesOK = false;
  105. continue;
  106. }
  107. if (message.GetCount() < msgLen) {
  108. if (!message.SetCount(msgLen)) {
  109. allMessagesOK = false;
  110. continue;
  111. }
  112. }
  113. D3D12_MESSAGE *pMessage = (D3D12_MESSAGE *)message.GetData();
  114. if (FAILED(pInfoQueue->GetMessageA(i, pMessage, &msgLen))) {
  115. allMessagesOK = false;
  116. continue;
  117. }
  118. CA2W msgW(pMessage->pDescription, CP_ACP);
  119. pOutputStrFn(pStrCtx, msgW.m_psz);
  120. pOutputStrFn(pStrCtx, L"\r\n");
  121. }
  122. if (!allMessagesOK) {
  123. pOutputStrFn(pStrCtx, L"Failed to retrieve some messages.\r\n");
  124. }
  125. }
  126. class CComContext {
  127. private:
  128. bool m_init;
  129. public:
  130. CComContext() : m_init(false) {}
  131. ~CComContext() { Dispose(); }
  132. void Dispose() { if (!m_init) return; m_init = false; CoUninitialize(); }
  133. HRESULT Init() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { m_init = true; } return hr; }
  134. };
  135. static void SavePixelsToFile(LPCVOID pPixels, DXGI_FORMAT format, UINT32 m_width, UINT32 m_height, LPCWSTR pFileName) {
  136. CComContext ctx;
  137. CComPtr<IWICImagingFactory> pFactory;
  138. CComPtr<IWICBitmap> pBitmap;
  139. CComPtr<IWICBitmapEncoder> pEncoder;
  140. CComPtr<IWICBitmapFrameEncode> pFrameEncode;
  141. CComPtr<hlsl::AbstractMemoryStream> pStream;
  142. CComPtr<IMalloc> pMalloc;
  143. struct PF {
  144. DXGI_FORMAT Format;
  145. GUID PixelFormat;
  146. UINT32 PixelSize;
  147. bool operator==(DXGI_FORMAT F) const {
  148. return F == Format;
  149. }
  150. } Vals[] = {
  151. // Add more pixel format mappings as needed.
  152. { DXGI_FORMAT_R8G8B8A8_UNORM, GUID_WICPixelFormat32bppRGBA, 4 }
  153. };
  154. PF *pFormat = std::find(Vals, Vals + _countof(Vals), format);
  155. VERIFY_SUCCEEDED(ctx.Init());
  156. VERIFY_SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory));
  157. VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
  158. VERIFY_SUCCEEDED(hlsl::CreateMemoryStream(pMalloc, &pStream));
  159. VERIFY_ARE_NOT_EQUAL(pFormat, Vals + _countof(Vals));
  160. VERIFY_SUCCEEDED(pFactory->CreateBitmapFromMemory(m_width, m_height, pFormat->PixelFormat, m_width * pFormat->PixelSize, m_width * m_height * pFormat->PixelSize, (BYTE *)pPixels, &pBitmap));
  161. VERIFY_SUCCEEDED(pFactory->CreateEncoder(GUID_ContainerFormatBmp, nullptr, &pEncoder));
  162. VERIFY_SUCCEEDED(pEncoder->Initialize(pStream, WICBitmapEncoderNoCache));
  163. VERIFY_SUCCEEDED(pEncoder->CreateNewFrame(&pFrameEncode, nullptr));
  164. VERIFY_SUCCEEDED(pFrameEncode->Initialize(nullptr));
  165. VERIFY_SUCCEEDED(pFrameEncode->WriteSource(pBitmap, nullptr));
  166. VERIFY_SUCCEEDED(pFrameEncode->Commit());
  167. VERIFY_SUCCEEDED(pEncoder->Commit());
  168. hlsl::WriteBinaryFile(pFileName, pStream->GetPtr(), pStream->GetPtrSize());
  169. }
  170. // Checks if the given warp version supports the given operation.
  171. bool IsValidWarpDllVersion(unsigned int minBuildNumber) {
  172. HMODULE pLibrary = LoadLibrary("D3D10Warp.dll");
  173. if (pLibrary) {
  174. char path[MAX_PATH];
  175. DWORD length = GetModuleFileName(pLibrary, path, MAX_PATH);
  176. if (length) {
  177. DWORD dwVerHnd = 0;
  178. DWORD dwVersionInfoSize = GetFileVersionInfoSize(path, &dwVerHnd);
  179. std::unique_ptr<int[]> VffInfo(new int[dwVersionInfoSize]);
  180. if (GetFileVersionInfo(path, NULL, dwVersionInfoSize, VffInfo.get())) {
  181. LPVOID versionInfo;
  182. UINT size;
  183. if (VerQueryValue(VffInfo.get(), "\\", &versionInfo, &size)) {
  184. if (size) {
  185. VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)versionInfo;
  186. unsigned int warpBuildNumber = verInfo->dwFileVersionLS >> 16 & 0xffff;
  187. if (verInfo->dwSignature == 0xFEEF04BD && warpBuildNumber >= minBuildNumber) {
  188. return true;
  189. }
  190. }
  191. }
  192. }
  193. }
  194. FreeLibrary(pLibrary);
  195. }
  196. return false;
  197. }
  198. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS2
  199. #define D3D12_FEATURE_D3D12_OPTIONS3 ((D3D12_FEATURE)21)
  200. #define NTDDI_WIN10_RS3 0x0A000004 /* ABRACADABRA_WIN10_RS2 */
  201. typedef
  202. enum D3D12_COMMAND_LIST_SUPPORT_FLAGS
  203. {
  204. D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0,
  205. D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT = (1 << D3D12_COMMAND_LIST_TYPE_DIRECT),
  206. D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE = (1 << D3D12_COMMAND_LIST_TYPE_BUNDLE),
  207. D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE = (1 << D3D12_COMMAND_LIST_TYPE_COMPUTE),
  208. D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY = (1 << D3D12_COMMAND_LIST_TYPE_COPY),
  209. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE = (1 << 4),
  210. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS = (1 << 5)
  211. } D3D12_COMMAND_LIST_SUPPORT_FLAGS;
  212. typedef
  213. enum D3D12_VIEW_INSTANCING_TIER
  214. {
  215. D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0,
  216. D3D12_VIEW_INSTANCING_TIER_1 = 1,
  217. D3D12_VIEW_INSTANCING_TIER_2 = 2,
  218. D3D12_VIEW_INSTANCING_TIER_3 = 3
  219. } D3D12_VIEW_INSTANCING_TIER;
  220. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS3
  221. {
  222. _Out_ BOOL CopyQueueTimestampQueriesSupported;
  223. _Out_ BOOL CastingFullyTypedFormatSupported;
  224. _Out_ DWORD WriteBufferImmediateSupportFlags;
  225. _Out_ D3D12_VIEW_INSTANCING_TIER ViewInstancingTier;
  226. _Out_ BOOL BarycentricsSupported;
  227. } D3D12_FEATURE_DATA_D3D12_OPTIONS3;
  228. #endif
  229. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS3
  230. #define D3D12_FEATURE_D3D12_OPTIONS4 ((D3D12_FEATURE)23)
  231. typedef enum D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER
  232. {
  233. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_0,
  234. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1,
  235. } D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER;
  236. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS4
  237. {
  238. _Out_ BOOL ReservedBufferPlacementSupported;
  239. _Out_ D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER SharedResourceCompatibilityTier;
  240. _Out_ BOOL Native16BitShaderOpsSupported;
  241. } D3D12_FEATURE_DATA_D3D12_OPTIONS4;
  242. #endif
  243. // Virtual class to compute the expected result given a set of inputs
  244. struct TableParameter;
  245. class ExecutionTest {
  246. public:
  247. // By default, ignore these tests, which require a recent build to run properly.
  248. BEGIN_TEST_CLASS(ExecutionTest)
  249. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  250. TEST_CLASS_PROPERTY(L"Ignore", L"true")
  251. TEST_METHOD_PROPERTY(L"Priority", L"0")
  252. END_TEST_CLASS()
  253. TEST_CLASS_SETUP(ExecutionTestClassSetup)
  254. TEST_METHOD(BasicComputeTest);
  255. TEST_METHOD(BasicTriangleTest);
  256. TEST_METHOD(BasicTriangleOpTest);
  257. BEGIN_TEST_METHOD(BasicTriangleOpTestHalf)
  258. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  259. END_TEST_METHOD()
  260. TEST_METHOD(OutOfBoundsTest);
  261. TEST_METHOD(SaturateTest);
  262. TEST_METHOD(SignTest);
  263. TEST_METHOD(Int64Test);
  264. TEST_METHOD(LifetimeIntrinsicTest)
  265. TEST_METHOD(WaveIntrinsicsTest);
  266. TEST_METHOD(WaveIntrinsicsDDITest);
  267. TEST_METHOD(WaveIntrinsicsInPSTest);
  268. TEST_METHOD(WaveSizeTest);
  269. TEST_METHOD(PartialDerivTest);
  270. TEST_METHOD(DerivativesTest);
  271. TEST_METHOD(ComputeSampleTest);
  272. TEST_METHOD(AtomicsTest);
  273. TEST_METHOD(Atomics64Test);
  274. TEST_METHOD(AtomicsTyped64Test);
  275. TEST_METHOD(AtomicsShared64Test);
  276. TEST_METHOD(AtomicsFloatTest);
  277. TEST_METHOD(SignatureResourcesTest)
  278. TEST_METHOD(DynamicResourcesTest)
  279. TEST_METHOD(QuadReadTest)
  280. BEGIN_TEST_METHOD(CBufferTestHalf)
  281. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  282. END_TEST_METHOD()
  283. TEST_METHOD(BasicShaderModel61);
  284. BEGIN_TEST_METHOD(BasicShaderModel63)
  285. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  286. END_TEST_METHOD()
  287. BEGIN_TEST_METHOD(WaveIntrinsicsActiveIntTest)
  288. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveIntTable")
  289. END_TEST_METHOD()
  290. BEGIN_TEST_METHOD(WaveIntrinsicsActiveUintTest)
  291. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveUintTable")
  292. END_TEST_METHOD()
  293. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixIntTest)
  294. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixIntTable")
  295. END_TEST_METHOD()
  296. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixUintTest)
  297. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixUintTable")
  298. END_TEST_METHOD()
  299. BEGIN_TEST_METHOD(WaveIntrinsicsSM65IntTest)
  300. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixIntTable")
  301. END_TEST_METHOD()
  302. BEGIN_TEST_METHOD(WaveIntrinsicsSM65UintTest)
  303. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixUintTable")
  304. END_TEST_METHOD()
  305. // TAEF data-driven tests.
  306. BEGIN_TEST_METHOD(UnaryFloatOpTest)
  307. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
  308. END_TEST_METHOD()
  309. BEGIN_TEST_METHOD(BinaryFloatOpTest)
  310. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
  311. END_TEST_METHOD()
  312. BEGIN_TEST_METHOD(TertiaryFloatOpTest)
  313. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
  314. END_TEST_METHOD()
  315. BEGIN_TEST_METHOD(UnaryHalfOpTest)
  316. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
  317. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  318. END_TEST_METHOD()
  319. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  320. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  321. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  322. END_TEST_METHOD()
  323. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  324. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  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(UnaryIntOpTest)
  328. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  329. END_TEST_METHOD()
  330. BEGIN_TEST_METHOD(BinaryIntOpTest)
  331. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  332. END_TEST_METHOD()
  333. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  334. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  335. END_TEST_METHOD()
  336. BEGIN_TEST_METHOD(UnaryUintOpTest)
  337. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  338. END_TEST_METHOD()
  339. BEGIN_TEST_METHOD(BinaryUintOpTest)
  340. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  341. END_TEST_METHOD()
  342. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  343. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  344. END_TEST_METHOD()
  345. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  346. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  347. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  348. END_TEST_METHOD()
  349. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  350. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  351. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  352. END_TEST_METHOD()
  353. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  354. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  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(UnaryUint16OpTest)
  358. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  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(BinaryUint16OpTest)
  362. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  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(TertiaryUint16OpTest)
  366. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  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(DotTest)
  370. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  371. END_TEST_METHOD()
  372. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  373. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  374. END_TEST_METHOD()
  375. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  376. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  377. END_TEST_METHOD()
  378. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  379. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  380. END_TEST_METHOD()
  381. BEGIN_TEST_METHOD(Msad4Test)
  382. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  383. END_TEST_METHOD()
  384. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  385. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  386. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  387. END_TEST_METHOD()
  388. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  389. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  390. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  391. END_TEST_METHOD()
  392. TEST_METHOD(BarycentricsTest);
  393. TEST_METHOD(ComputeRawBufferLdStI32);
  394. TEST_METHOD(ComputeRawBufferLdStFloat);
  395. BEGIN_TEST_METHOD(ComputeRawBufferLdStI64)
  396. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  397. END_TEST_METHOD()
  398. BEGIN_TEST_METHOD(ComputeRawBufferLdStDouble)
  399. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  400. END_TEST_METHOD()
  401. BEGIN_TEST_METHOD(ComputeRawBufferLdStI16)
  402. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  403. END_TEST_METHOD()
  404. BEGIN_TEST_METHOD(ComputeRawBufferLdStHalf)
  405. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  406. END_TEST_METHOD()
  407. TEST_METHOD(GraphicsRawBufferLdStI32);
  408. TEST_METHOD(GraphicsRawBufferLdStFloat);
  409. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI64)
  410. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  411. END_TEST_METHOD()
  412. BEGIN_TEST_METHOD(GraphicsRawBufferLdStDouble)
  413. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  414. END_TEST_METHOD()
  415. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI16)
  416. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  417. END_TEST_METHOD()
  418. BEGIN_TEST_METHOD(GraphicsRawBufferLdStHalf)
  419. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  420. END_TEST_METHOD()
  421. BEGIN_TEST_METHOD(PackUnpackTest)
  422. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#PackUnpackOpTable")
  423. END_TEST_METHOD()
  424. dxc::DxcDllSupport m_support;
  425. VersionSupportInfo m_ver;
  426. bool m_ExperimentalModeEnabled = false;
  427. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  428. // Do not remove the following line - it is used by TranslateExecutionTest.py
  429. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  430. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  431. // require the Windows 10 SDK.
  432. typedef enum D3D_SHADER_MODEL {
  433. D3D_SHADER_MODEL_5_1 = 0x51,
  434. D3D_SHADER_MODEL_6_0 = 0x60,
  435. D3D_SHADER_MODEL_6_1 = 0x61,
  436. D3D_SHADER_MODEL_6_2 = 0x62,
  437. D3D_SHADER_MODEL_6_3 = 0x63,
  438. D3D_SHADER_MODEL_6_4 = 0x64,
  439. D3D_SHADER_MODEL_6_5 = 0x65,
  440. D3D_SHADER_MODEL_6_6 = 0x66,
  441. } D3D_SHADER_MODEL;
  442. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  443. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  444. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  445. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  446. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  447. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  448. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  449. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  450. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  451. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  452. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  453. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  454. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  455. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  456. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  457. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  458. #else
  459. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  460. #endif
  461. bool UseDxbc() {
  462. #ifdef _HLK_CONF
  463. return false;
  464. #else
  465. return GetTestParamBool(L"DXBC");
  466. #endif
  467. }
  468. bool UseWarpByDefault() {
  469. #ifdef _HLK_CONF
  470. return false;
  471. #else
  472. return true;
  473. #endif
  474. }
  475. bool UseDebugIfaces() {
  476. return true;
  477. }
  478. bool SaveImages() {
  479. return GetTestParamBool(L"SaveImages");
  480. }
  481. void RunResourceTest(ID3D12Device *pDevice, const char *pShader, const wchar_t *sm, bool isDynamic);
  482. template <class T1, class T2>
  483. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  484. size_t numParameter, bool isPrefix);
  485. template <typename T>
  486. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  487. size_t numParameters);
  488. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  489. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  490. enum class RawBufferLdStType {
  491. I32,
  492. Float,
  493. I64,
  494. Double,
  495. I16,
  496. Half
  497. };
  498. template <class Ty>
  499. struct RawBufferLdStTestData {
  500. Ty v1, v2[2], v3[3], v4[4];
  501. };
  502. template <class Ty>
  503. struct RawBufferLdStUavData {
  504. RawBufferLdStTestData<Ty> input, output, srvOut;
  505. };
  506. template <class Ty>
  507. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  508. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  509. template <class Ty>
  510. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  511. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  512. template <class Ty>
  513. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  514. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  515. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  516. template <class Ty>
  517. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  518. template <class Ty>
  519. const wchar_t* BasicShaderModelTest_GetFormatString();
  520. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  521. VERIFY_SUCCEEDED(m_support.Initialize());
  522. CComPtr<IDxcCompiler> pCompiler;
  523. CComPtr<IDxcLibrary> pLibrary;
  524. CComPtr<IDxcBlobEncoding> pTextBlob;
  525. CComPtr<IDxcOperationResult> pResult;
  526. HRESULT resultCode;
  527. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  528. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  529. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  530. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, pOptions, numOptions, nullptr, 0, nullptr, &pResult));
  531. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  532. if (FAILED(resultCode)) {
  533. CComPtr<IDxcBlobEncoding> errors;
  534. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  535. #ifndef _HLK_CONF
  536. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  537. #endif
  538. }
  539. VERIFY_SUCCEEDED(resultCode);
  540. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  541. }
  542. void CreateCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue, D3D12_COMMAND_LIST_TYPE type) {
  543. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  544. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  545. queueDesc.Type = type;
  546. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  547. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  548. }
  549. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  550. CreateCommandQueue(pDevice, pName, ppCommandQueue, D3D12_COMMAND_LIST_TYPE_COMPUTE);
  551. }
  552. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, LPCWSTR pTargetProfile, ID3D12PipelineState **ppComputeState, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  553. CComPtr<ID3DBlob> pComputeShader;
  554. // Load and compile shaders.
  555. if (UseDxbc()) {
  556. #ifndef _HLK_CONF
  557. DXBCFromText(pShader, L"main", pTargetProfile, &pComputeShader);
  558. #endif
  559. }
  560. else {
  561. CompileFromText(pShader, L"main", pTargetProfile, &pComputeShader, pOptions, numOptions);
  562. }
  563. // Describe and create the compute pipeline state object (PSO).
  564. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  565. computePsoDesc.pRootSignature = pRootSignature;
  566. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  567. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  568. }
  569. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  570. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true,
  571. bool enableRayTracing = false) {
  572. if (testModel > HIGHEST_SHADER_MODEL) {
  573. UINT minor = (UINT)testModel & 0x0f;
  574. LogCommentFmt(L"Installed SDK does not support "
  575. L"shader model 6.%1u", minor);
  576. if (skipUnsupported) {
  577. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  578. }
  579. return false;
  580. }
  581. const D3D_FEATURE_LEVEL FeatureLevelRequired = enableRayTracing ? D3D_FEATURE_LEVEL_12_0 : D3D_FEATURE_LEVEL_11_0;
  582. CComPtr<IDXGIFactory4> factory;
  583. CComPtr<ID3D12Device> pDevice;
  584. *ppDevice = nullptr;
  585. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  586. if (GetTestParamUseWARP(UseWarpByDefault())) {
  587. CComPtr<IDXGIAdapter> warpAdapter;
  588. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  589. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  590. IID_PPV_ARGS(&pDevice));
  591. if (FAILED(createHR)) {
  592. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  593. if (skipUnsupported) {
  594. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  595. }
  596. return false;
  597. }
  598. } else {
  599. CComPtr<IDXGIAdapter1> hardwareAdapter;
  600. WEX::Common::String AdapterValue;
  601. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  602. AdapterValue);
  603. if (SUCCEEDED(hr)) {
  604. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  605. } else {
  606. WEX::Logging::Log::Comment(
  607. L"Using default hardware adapter with D3D12 support.");
  608. }
  609. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  610. IID_PPV_ARGS(&pDevice)));
  611. }
  612. // retrieve adapter information
  613. LUID adapterID = pDevice->GetAdapterLuid();
  614. CComPtr<IDXGIAdapter> adapter;
  615. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  616. DXGI_ADAPTER_DESC AdapterDesc;
  617. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  618. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  619. if (pDevice == nullptr)
  620. return false;
  621. if (!UseDxbc()) {
  622. // Check for DXIL support.
  623. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  624. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  625. } D3D12_FEATURE_DATA_SHADER_MODEL;
  626. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  627. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  628. SMData.HighestShaderModel = testModel;
  629. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
  630. (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
  631. if (SMData.HighestShaderModel < testModel) {
  632. UINT minor = (UINT)testModel & 0x0f;
  633. LogCommentFmt(L"The selected device does not support "
  634. L"shader model 6.%1u", minor);
  635. if (skipUnsupported) {
  636. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  637. }
  638. return false;
  639. }
  640. }
  641. if (UseDebugIfaces()) {
  642. CComPtr<ID3D12InfoQueue> pInfoQueue;
  643. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  644. pInfoQueue->SetMuteDebugOutput(FALSE);
  645. }
  646. }
  647. *ppDevice = pDevice.Detach();
  648. return true;
  649. }
  650. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  651. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  652. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  653. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  654. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  655. }
  656. void CreateGraphicsCommandQueueAndList(
  657. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  658. ID3D12CommandAllocator **ppAllocator,
  659. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  660. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  661. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  662. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  663. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  664. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  665. IID_PPV_ARGS(ppCommandList)));
  666. }
  667. void CreateGraphicsPSO(ID3D12Device *pDevice,
  668. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  669. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  670. ID3D12PipelineState **ppPSO) {
  671. CComPtr<ID3DBlob> vertexShader;
  672. CComPtr<ID3DBlob> pixelShader;
  673. if (UseDxbc()) {
  674. #ifndef _HLK_CONF
  675. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  676. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  677. #endif
  678. } else {
  679. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  680. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  681. }
  682. // Describe and create the graphics pipeline state object (PSO).
  683. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  684. psoDesc.InputLayout = *pInputLayout;
  685. psoDesc.pRootSignature = pRootSignature;
  686. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  687. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  688. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  689. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  690. psoDesc.DepthStencilState.DepthEnable = FALSE;
  691. psoDesc.DepthStencilState.StencilEnable = FALSE;
  692. psoDesc.SampleMask = UINT_MAX;
  693. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  694. psoDesc.NumRenderTargets = 1;
  695. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  696. psoDesc.SampleDesc.Count = 1;
  697. VERIFY_SUCCEEDED(
  698. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  699. }
  700. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  701. ID3D12DescriptorHeap *pHeap, UINT width,
  702. UINT height,
  703. ID3D12Resource **ppRenderTarget,
  704. ID3D12Resource **ppBuffer) {
  705. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  706. const size_t formatElementSize = 4;
  707. CComPtr<ID3D12Resource> pRenderTarget;
  708. CComPtr<ID3D12Resource> pBuffer;
  709. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  710. pHeap->GetCPUDescriptorHandleForHeapStart());
  711. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  712. CD3DX12_RESOURCE_DESC rtDesc(
  713. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  714. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  715. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  716. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  717. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  718. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  719. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  720. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  721. // resource.
  722. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  723. CD3DX12_RESOURCE_DESC readDesc(
  724. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  725. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  726. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  727. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  728. *ppRenderTarget = pRenderTarget.Detach();
  729. *ppBuffer = pBuffer.Detach();
  730. }
  731. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  732. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  733. ID3D12RootSignature **pRootSig) {
  734. CComPtr<ID3DBlob> signature;
  735. CComPtr<ID3DBlob> error;
  736. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  737. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  738. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  739. IID_PPV_ARGS(pRootSig)));
  740. }
  741. void CreateRootSignatureFromRanges(ID3D12Device *pDevice, ID3D12RootSignature **pRootSig,
  742. CD3DX12_DESCRIPTOR_RANGE *resRanges, UINT resCt,
  743. CD3DX12_DESCRIPTOR_RANGE *sampRanges = nullptr, UINT sampCt = 0,
  744. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
  745. CD3DX12_ROOT_PARAMETER rootParameters[2];
  746. rootParameters[0].InitAsDescriptorTable(resCt, resRanges, D3D12_SHADER_VISIBILITY_ALL);
  747. rootParameters[1].InitAsDescriptorTable(sampCt, sampRanges, D3D12_SHADER_VISIBILITY_ALL);
  748. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  749. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, flags);
  750. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, pRootSig);
  751. }
  752. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  753. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  754. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  755. rtvHeapDesc.NumDescriptors = numDescriptors;
  756. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  757. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  758. VERIFY_SUCCEEDED(
  759. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  760. if (rtvDescriptorSize != nullptr) {
  761. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  762. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  763. }
  764. }
  765. void CreateTestResources(ID3D12Device *pDevice,
  766. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  767. UINT32 valueSizeInBytes, D3D12_RESOURCE_DESC resDesc,
  768. ID3D12Resource **ppResource,
  769. ID3D12Resource **ppUploadResource,
  770. ID3D12Resource **ppReadBuffer = nullptr) {
  771. CComPtr<ID3D12Resource> pResource;
  772. CComPtr<ID3D12Resource> pReadBuffer;
  773. CComPtr<ID3D12Resource> pUploadResource;
  774. D3D12_SUBRESOURCE_DATA transferData;
  775. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  776. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  777. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  778. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  779. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  780. pDevice->GetCopyableFootprints(&resDesc, 0, 1/*mipleveles*/, 0, nullptr, nullptr, nullptr, &uploadBufferDesc.Width);
  781. uploadBufferDesc.Height = 1;
  782. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  783. &defaultHeapProperties,
  784. D3D12_HEAP_FLAG_NONE,
  785. &resDesc,
  786. D3D12_RESOURCE_STATE_COPY_DEST,
  787. nullptr,
  788. IID_PPV_ARGS(&pResource)));
  789. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  790. &uploadHeapProperties,
  791. D3D12_HEAP_FLAG_NONE,
  792. &uploadBufferDesc,
  793. D3D12_RESOURCE_STATE_GENERIC_READ,
  794. nullptr,
  795. IID_PPV_ARGS(&pUploadResource)));
  796. if (ppReadBuffer)
  797. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  798. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  799. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  800. transferData.pData = values;
  801. transferData.RowPitch = valueSizeInBytes/resDesc.Height;
  802. transferData.SlicePitch = valueSizeInBytes;
  803. UpdateSubresources<1>(pCommandList, pResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  804. if (resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
  805. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  806. else
  807. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
  808. *ppResource = pResource.Detach();
  809. *ppUploadResource = pUploadResource.Detach();
  810. if (ppReadBuffer)
  811. *ppReadBuffer = pReadBuffer.Detach();
  812. }
  813. void CreateTestUavs(ID3D12Device *pDevice,
  814. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  815. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  816. ID3D12Resource **ppUploadResource = nullptr,
  817. ID3D12Resource **ppReadBuffer = nullptr) {
  818. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  819. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufferDesc,
  820. ppUavResource, ppUploadResource, ppReadBuffer);
  821. }
  822. // Create and return descriptor heaps for the given device
  823. // with the given number of resources and samples.
  824. // using some reasonable defaults
  825. void CreateDefaultDescHeaps(ID3D12Device *pDevice,
  826. int NumResources, int NumSamplers,
  827. ID3D12DescriptorHeap **ppResHeap, ID3D12DescriptorHeap **ppSampHeap) {
  828. // Describe and create descriptor heaps.
  829. ID3D12DescriptorHeap *pResHeap, *pSampHeap;
  830. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  831. heapDesc.NumDescriptors = NumResources;
  832. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  833. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  834. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pResHeap)));
  835. heapDesc.NumDescriptors = NumSamplers;
  836. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
  837. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pSampHeap)));
  838. *ppResHeap = pResHeap;
  839. *ppSampHeap = pSampHeap;
  840. }
  841. // Create Resource views for <pDevice> given the SRV and UAV information provided
  842. // using some reasonable defaults
  843. void CreateDefaultResourceViews(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  844. int numElements,
  845. const CComPtr<ID3D12Resource> pSRVResources[], int NumSRVs,
  846. const CComPtr<ID3D12Resource> pUAVResources[], int NumUAVs) {
  847. CD3DX12_CPU_DESCRIPTOR_HANDLE baseHandle(heapStart);
  848. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  849. // Create SRVs
  850. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  851. srvDesc.Format = DXGI_FORMAT_UNKNOWN;
  852. srvDesc.ViewDimension = D3D12_SRV_DIMENSION_BUFFER;
  853. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  854. srvDesc.Buffer.FirstElement = 0;
  855. srvDesc.Buffer.NumElements = numElements;
  856. srvDesc.Buffer.StructureByteStride = sizeof(float);
  857. for (int i = 0; i < NumSRVs - 1; i++) {
  858. pDevice->CreateShaderResourceView(pSRVResources[i], &srvDesc, baseHandle);
  859. baseHandle = baseHandle.Offset(descriptorSize);
  860. }
  861. srvDesc.Format = DXGI_FORMAT_R32_FLOAT;
  862. srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
  863. srvDesc.Texture2D.MostDetailedMip = 0;
  864. srvDesc.Texture2D.MipLevels = 1;
  865. srvDesc.Texture2D.PlaneSlice = 0;
  866. srvDesc.Texture2D.ResourceMinLODClamp = 0;
  867. pDevice->CreateShaderResourceView(pSRVResources[NumSRVs - 1], &srvDesc, baseHandle);
  868. baseHandle = baseHandle.Offset(descriptorSize);
  869. // Create UAVs
  870. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  871. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  872. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  873. uavDesc.Buffer.FirstElement = 0;
  874. uavDesc.Buffer.NumElements = numElements;
  875. uavDesc.Buffer.StructureByteStride = sizeof(float);
  876. uavDesc.Buffer.CounterOffsetInBytes = 0;
  877. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  878. for (int i = 0; i < NumUAVs - 1; i++) {
  879. pDevice->CreateUnorderedAccessView(pUAVResources[i], nullptr, &uavDesc, baseHandle);
  880. baseHandle = baseHandle.Offset(descriptorSize);
  881. }
  882. uavDesc.Format = DXGI_FORMAT_R32_FLOAT;
  883. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1D;
  884. uavDesc.Texture1D.MipSlice = 0;
  885. pDevice->CreateUnorderedAccessView(pUAVResources[NumUAVs - 1], nullptr, &uavDesc, baseHandle);
  886. }
  887. // Create Samplers for <pDevice> given the filter and border color information provided
  888. // using some reasonable defaults
  889. void CreateDefaultSamplers(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  890. D3D12_FILTER filters[], float BorderColors[], int NumSamplers) {
  891. CD3DX12_CPU_DESCRIPTOR_HANDLE sampHandle(heapStart);
  892. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
  893. D3D12_SAMPLER_DESC sampDesc = {};
  894. sampDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  895. sampDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  896. sampDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  897. sampDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  898. sampDesc.MipLODBias = 0;
  899. sampDesc.MaxAnisotropy = 1;
  900. sampDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_EQUAL;
  901. sampDesc.MinLOD = 0;
  902. sampDesc.MaxLOD = 0;
  903. for (int i = 0; i < NumSamplers; i++) {
  904. sampDesc.Filter = filters[i];
  905. for (int j = 0; j < 4; j++)
  906. sampDesc.BorderColor[j] = BorderColors[i];
  907. pDevice->CreateSampler(&sampDesc, sampHandle);
  908. sampHandle = sampHandle.Offset(descriptorSize);
  909. }
  910. }
  911. template <typename TVertex, int len>
  912. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  913. ID3D12Resource **ppVertexBuffer,
  914. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  915. size_t vertexBufferSize = sizeof(vertices);
  916. CComPtr<ID3D12Resource> pVertexBuffer;
  917. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  918. CD3DX12_RESOURCE_DESC bufferDesc(
  919. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  920. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  921. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  922. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  923. IID_PPV_ARGS(&pVertexBuffer)));
  924. UINT8 *pVertexDataBegin;
  925. CD3DX12_RANGE readRange(0, 0);
  926. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  927. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  928. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  929. pVertexBuffer->Unmap(0, nullptr);
  930. // Initialize the vertex buffer view.
  931. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  932. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  933. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  934. *ppVertexBuffer = pVertexBuffer.Detach();
  935. }
  936. // Requires Anniversary Edition headers, so simplifying things for current setup.
  937. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  938. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  939. BOOL WaveOps;
  940. UINT WaveLaneCountMin;
  941. UINT WaveLaneCountMax;
  942. UINT TotalLaneCount;
  943. BOOL ExpandedComputeResourceStates;
  944. BOOL Int64ShaderOps;
  945. };
  946. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  947. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  948. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  949. return false;
  950. return O.Int64ShaderOps != FALSE;
  951. }
  952. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  953. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  954. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  955. return false;
  956. return O.DoublePrecisionFloatShaderOps != FALSE;
  957. }
  958. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  959. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  960. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  961. return false;
  962. return O.WaveOps != FALSE;
  963. }
  964. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  965. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  966. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  967. return false;
  968. return O.BarycentricsSupported != FALSE;
  969. }
  970. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  971. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  972. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  973. return false;
  974. return O.Native16BitShaderOpsSupported != FALSE;
  975. }
  976. bool DoesDeviceSupportMeshShaders(ID3D12Device *pDevice) {
  977. #if defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB
  978. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  979. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))))
  980. return false;
  981. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
  982. #else
  983. return false;
  984. #endif
  985. }
  986. bool DoesDeviceSupportMeshAmpDerivatives(ID3D12Device *pDevice) {
  987. #if 0
  988. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  989. D3D12_FEATURE_DATA_D3D12_OPTIONS8 O8;
  990. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))) ||
  991. FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS8, &O8, sizeof(O8))))
  992. return false;
  993. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED &&
  994. O8.DerivativesInMeshAndAmplificationShadersSupported != FALSE;
  995. #else
  996. return false;
  997. #endif
  998. }
  999. bool DoesDeviceSupportTyped64Atomics(ID3D12Device *pDevice) {
  1000. #if 0
  1001. D3D12_FEATURE_DATA_D3D12_OPTIONS8 O8;
  1002. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS8, &O8, sizeof(O8))))
  1003. return false;
  1004. return O8.AtomicInt64OnTypedResourceSupported != FALSE;
  1005. #else
  1006. return false;
  1007. #endif
  1008. }
  1009. bool DoesDeviceSupportShared64Atomics(ID3D12Device *pDevice) {
  1010. #if 0
  1011. D3D12_FEATURE_DATA_D3D12_OPTIONS8 O8;
  1012. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS8, &O8, sizeof(O8))))
  1013. return false;
  1014. return O8.AtomicInt64OnGroupSharedSupported != FALSE;
  1015. #else
  1016. return false;
  1017. #endif
  1018. }
  1019. #ifndef _HLK_CONF
  1020. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  1021. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  1022. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  1023. CComPtr<ID3DBlob> pErrors;
  1024. D3D_SHADER_MACRO d3dMacro[2];
  1025. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  1026. d3dMacro[0].Definition = "1";
  1027. d3dMacro[0].Name = "USING_DXBC";
  1028. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  1029. if (pErrors != nullptr) {
  1030. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  1031. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  1032. }
  1033. VERIFY_SUCCEEDED(hr);
  1034. }
  1035. #endif
  1036. HRESULT EnableDebugLayer() {
  1037. // The debug layer does net yet validate DXIL programs that require rewriting,
  1038. // but basic logging should work properly.
  1039. HRESULT hr = S_FALSE;
  1040. if (UseDebugIfaces()) {
  1041. CComPtr<ID3D12Debug> debugController;
  1042. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  1043. if (SUCCEEDED(hr)) {
  1044. debugController->EnableDebugLayer();
  1045. hr = S_OK;
  1046. }
  1047. }
  1048. return hr;
  1049. }
  1050. #ifndef _HLK_CONF
  1051. HRESULT EnableExperimentalMode() {
  1052. if (m_ExperimentalModeEnabled) {
  1053. return S_OK;
  1054. }
  1055. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1056. return S_FALSE;
  1057. }
  1058. HRESULT hr = EnableExperimentalShaderModels();
  1059. if (SUCCEEDED(hr)) {
  1060. m_ExperimentalModeEnabled = true;
  1061. }
  1062. return hr;
  1063. }
  1064. #endif
  1065. struct FenceObj {
  1066. HANDLE m_fenceEvent = NULL;
  1067. CComPtr<ID3D12Fence> m_fence;
  1068. UINT64 m_fenceValue;
  1069. ~FenceObj() {
  1070. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  1071. }
  1072. };
  1073. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  1074. pObj->m_fenceValue = 1;
  1075. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  1076. IID_PPV_ARGS(&pObj->m_fence)));
  1077. // Create an event handle to use for frame synchronization.
  1078. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  1079. if (pObj->m_fenceEvent == nullptr) {
  1080. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  1081. }
  1082. }
  1083. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  1084. VERIFY_SUCCEEDED(m_support.Initialize());
  1085. CComPtr<IDxcLibrary> pLibrary;
  1086. CComPtr<IDxcBlobEncoding> pBlob;
  1087. CComPtr<IStream> pStream;
  1088. std::wstring path = GetPathToHlslDataFile(relativePath);
  1089. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  1090. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  1091. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  1092. *ppStream = pStream.Detach();
  1093. }
  1094. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  1095. ID3D12DescriptorHeap *pRtvHeap,
  1096. UINT rtvDescriptorSize,
  1097. UINT instanceCount,
  1098. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  1099. ID3D12RootSignature *pRootSig,
  1100. ID3D12Resource *pRenderTarget,
  1101. ID3D12Resource *pReadBuffer) {
  1102. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  1103. D3D12_VIEWPORT viewport;
  1104. D3D12_RECT scissorRect;
  1105. memset(&viewport, 0, sizeof(viewport));
  1106. viewport.Height = (float)rtDesc.Height;
  1107. viewport.Width = (float)rtDesc.Width;
  1108. viewport.MaxDepth = 1.0f;
  1109. memset(&scissorRect, 0, sizeof(scissorRect));
  1110. scissorRect.right = (long)rtDesc.Width;
  1111. scissorRect.bottom = rtDesc.Height;
  1112. if (pRootSig != nullptr) {
  1113. pList->SetGraphicsRootSignature(pRootSig);
  1114. }
  1115. pList->RSSetViewports(1, &viewport);
  1116. pList->RSSetScissorRects(1, &scissorRect);
  1117. // Indicate that the buffer will be used as a render target.
  1118. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  1119. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  1120. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  1121. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  1122. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  1123. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  1124. pList->DrawInstanced(3, instanceCount, 0, 0);
  1125. // Transition to copy source and copy into read-back buffer.
  1126. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1127. // Copy into read-back buffer.
  1128. UINT64 rowPitch = rtDesc.Width * 4;
  1129. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  1130. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  1131. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  1132. Footprint.Offset = 0;
  1133. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  1134. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  1135. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  1136. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  1137. }
  1138. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  1139. void RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR shader, D3D_SHADER_MODEL shaderModel, bool useLibTarget, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1140. void RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1141. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1142. void RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1143. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions);
  1144. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  1145. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  1146. pCommandList->SetDescriptorHeaps(1, pHeaps);
  1147. }
  1148. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  1149. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  1150. }
  1151. };
  1152. #define WAVE_INTRINSIC_DXBC_GUARD \
  1153. "#ifdef USING_DXBC\r\n" \
  1154. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  1155. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  1156. "bool WaveIsFirstLane() { return true; }\r\n" \
  1157. "uint WaveGetLaneCount() { return 1; }\r\n" \
  1158. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  1159. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  1160. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  1161. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  1162. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  1163. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  1164. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  1165. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  1166. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  1167. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  1168. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  1169. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  1170. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  1171. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  1172. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  1173. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  1174. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  1175. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  1176. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  1177. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  1178. "#endif\r\n"
  1179. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  1180. size_t count) {
  1181. values.resize(count); // one element per dispatch group, in bytes
  1182. for (size_t i = 0; i < count; ++i) {
  1183. values[i] = (uint32_t)i;
  1184. }
  1185. }
  1186. bool ExecutionTest::ExecutionTestClassSetup() {
  1187. #ifdef _HLK_CONF
  1188. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1189. VERIFY_SUCCEEDED(m_support.Initialize());
  1190. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1191. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1192. if (m_EnableDebugLayer) {
  1193. EnableDebugLayer();
  1194. }
  1195. return true;
  1196. #else
  1197. HRESULT hr = EnableExperimentalMode();
  1198. if (FAILED(hr)) {
  1199. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1200. }
  1201. else if (hr == S_FALSE) {
  1202. LogCommentFmt(L"Experimental mode not enabled.");
  1203. }
  1204. else {
  1205. LogCommentFmt(L"Experimental mode enabled.");
  1206. }
  1207. hr = EnableDebugLayer();
  1208. if (FAILED(hr)) {
  1209. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1210. }
  1211. else {
  1212. LogCommentFmt(L"Debug layer enabled.");
  1213. }
  1214. return true;
  1215. #endif
  1216. }
  1217. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1218. static const int DispatchGroupX = 1;
  1219. static const int DispatchGroupY = 1;
  1220. static const int DispatchGroupZ = 1;
  1221. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1222. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1223. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1224. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1225. UINT uavDescriptorSize;
  1226. FenceObj FO;
  1227. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1228. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1229. InitFenceObj(pDevice, &FO);
  1230. // Describe and create a UAV descriptor heap.
  1231. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1232. heapDesc.NumDescriptors = 1;
  1233. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1234. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1235. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1236. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1237. // Create root signature.
  1238. CComPtr<ID3D12RootSignature> pRootSignature;
  1239. {
  1240. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1241. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1242. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1243. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1244. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1245. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1246. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1247. }
  1248. // Create pipeline state object.
  1249. CComPtr<ID3D12PipelineState> pComputeState;
  1250. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1251. // Create a command allocator and list for compute.
  1252. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1253. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1254. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1255. // Set up UAV resource.
  1256. CComPtr<ID3D12Resource> pUavResource;
  1257. CComPtr<ID3D12Resource> pReadBuffer;
  1258. CComPtr<ID3D12Resource> pUploadResource;
  1259. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1260. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1261. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1262. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1263. // Close the command list and execute it to perform the GPU setup.
  1264. pCommandList->Close();
  1265. ExecuteCommandList(pCommandQueue, pCommandList);
  1266. WaitForSignal(pCommandQueue, FO);
  1267. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1268. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1269. // Run the compute shader and copy the results back to readable memory.
  1270. {
  1271. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1272. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1273. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1274. uavDesc.Buffer.FirstElement = 0;
  1275. uavDesc.Buffer.NumElements = (UINT)values.size();
  1276. uavDesc.Buffer.StructureByteStride = 0;
  1277. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1278. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1279. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1280. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1281. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1282. SetDescriptorHeap(pCommandList, pUavHeap);
  1283. pCommandList->SetComputeRootSignature(pRootSignature);
  1284. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1285. }
  1286. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1287. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1288. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1289. pCommandList->Close();
  1290. ExecuteCommandList(pCommandQueue, pCommandList);
  1291. WaitForSignal(pCommandQueue, FO);
  1292. {
  1293. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1294. uint32_t *pData = (uint32_t *)mappedData.data();
  1295. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1296. }
  1297. WaitForSignal(pCommandQueue, FO);
  1298. }
  1299. void ExecutionTest::RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1300. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1301. // Create command queue.
  1302. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1303. CreateComputeCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue);
  1304. FenceObj FO;
  1305. InitFenceObj(pDevice, &FO);
  1306. // Compile shader "main" and create pipeline state object.
  1307. CComPtr<ID3D12PipelineState> pComputeState;
  1308. CreateComputePSO(pDevice, pRootSignature, pShader, pTargetProfile, &pComputeState, pOptions, numOptions);
  1309. // Create a command allocator and list for compute.
  1310. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1311. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1312. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1313. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1314. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1315. // Set up UAV resource.
  1316. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1317. CComPtr<ID3D12Resource> pUavResource;
  1318. CComPtr<ID3D12Resource> pReadBuffer;
  1319. CComPtr<ID3D12Resource> pUploadResource;
  1320. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pReadBuffer, &pUploadResource);
  1321. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunLifetimeIntrinsicTest UAV"));
  1322. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunLifetimeIntrinsicTest UAV Read Buffer"));
  1323. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunLifetimeIntrinsicTest UAV Upload Buffer"));
  1324. // Close the command list and execute it to perform the GPU setup.
  1325. pCommandList->Close();
  1326. ExecuteCommandList(pCommandQueue, pCommandList);
  1327. WaitForSignal(pCommandQueue, FO);
  1328. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1329. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1330. // Run the compute shader and copy the results back to readable memory.
  1331. {
  1332. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1333. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1334. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1335. uavDesc.Buffer.FirstElement = 0;
  1336. uavDesc.Buffer.NumElements = (UINT)values.size();
  1337. uavDesc.Buffer.StructureByteStride = 0;
  1338. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1339. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1340. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1341. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1342. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1343. SetDescriptorHeap(pCommandList, pUavHeap);
  1344. pCommandList->SetComputeRootSignature(pRootSignature);
  1345. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1346. }
  1347. static const int DispatchGroupX = 1;
  1348. static const int DispatchGroupY = 1;
  1349. static const int DispatchGroupZ = 1;
  1350. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1351. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1352. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1353. pCommandList->Close();
  1354. ExecuteCommandList(pCommandQueue, pCommandList);
  1355. WaitForSignal(pCommandQueue, FO);
  1356. {
  1357. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1358. uint32_t *pData = (uint32_t *)mappedData.data();
  1359. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1360. }
  1361. WaitForSignal(pCommandQueue, FO);
  1362. }
  1363. void ExecutionTest::RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1364. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions) {
  1365. // Create command queue.
  1366. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1367. CreateCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue, D3D12_COMMAND_LIST_TYPE_DIRECT);
  1368. FenceObj FO;
  1369. InitFenceObj(pDevice, &FO);
  1370. // Compile raygen shader.
  1371. CComPtr<ID3DBlob> pShaderLib;
  1372. CompileFromText(pShader, L"RayGen", pTargetProfile, &pShaderLib, pOptions, numOptions);
  1373. // Describe and create the RT pipeline state object (RTPSO).
  1374. CD3DX12_STATE_OBJECT_DESC stateObjectDesc(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
  1375. auto lib = stateObjectDesc.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
  1376. CD3DX12_SHADER_BYTECODE byteCode(pShaderLib);
  1377. lib->SetDXILLibrary(&byteCode);
  1378. lib->DefineExport(L"RayGen");
  1379. const int payloadCount = 4;
  1380. const int attributeCount = 2;
  1381. const int maxRecursion = 2;
  1382. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT>()->Config(payloadCount * sizeof(float), attributeCount * sizeof(float));
  1383. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT>()->Config(maxRecursion);
  1384. // Create (local!) root sig subobject and associate with shader.
  1385. auto localRootSigSubObj = stateObjectDesc.CreateSubobject<CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT>();
  1386. localRootSigSubObj->SetRootSignature(pRootSignature);
  1387. auto x = stateObjectDesc.CreateSubobject<CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT>();
  1388. x->SetSubobjectToAssociate(*localRootSigSubObj);
  1389. x->AddExport(L"RayGen");
  1390. CComPtr<ID3D12StateObject> pStateObject;
  1391. VERIFY_SUCCEEDED(pDevice->CreateStateObject(stateObjectDesc, IID_PPV_ARGS(&pStateObject)));
  1392. // Create a command allocator and list.
  1393. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1394. CComPtr<ID3D12GraphicsCommandList4> pCommandList;
  1395. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator)));
  1396. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, nullptr, IID_PPV_ARGS(&pCommandList)));
  1397. pCommandList->SetPipelineState1(pStateObject);
  1398. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1399. // Close the command list and execute it to kick-off compilation in the driver.
  1400. // NOTE: We don't care about anything else, so we're not setting up any resources and don't actually execute the shader.
  1401. pCommandList->Close();
  1402. ExecuteCommandList(pCommandQueue, pCommandList);
  1403. WaitForSignal(pCommandQueue, FO);
  1404. }
  1405. void ExecutionTest::RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR pShader, D3D_SHADER_MODEL shaderModel, bool useLibTarget,
  1406. LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1407. LPCWSTR pTargetProfile;
  1408. switch (shaderModel) {
  1409. default: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_0"; break; // Default to 6.3 for lib, 6.0 otherwise.
  1410. case D3D_SHADER_MODEL_6_0: pTargetProfile = useLibTarget ? L"lib_6_0" : L"cs_6_0"; break;
  1411. case D3D_SHADER_MODEL_6_3: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_3"; break;
  1412. case D3D_SHADER_MODEL_6_5: pTargetProfile = useLibTarget ? L"lib_6_5" : L"cs_6_5"; break;
  1413. case D3D_SHADER_MODEL_6_6: pTargetProfile = useLibTarget ? L"lib_6_6" : L"cs_6_6"; break;
  1414. }
  1415. // Describe a UAV descriptor heap.
  1416. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1417. heapDesc.NumDescriptors = 1;
  1418. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1419. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1420. // Create the UAV descriptor heap.
  1421. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1422. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1423. // Create root signature.
  1424. CComPtr<ID3D12RootSignature> pRootSignature;
  1425. {
  1426. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1427. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1428. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1429. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1430. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1431. D3D12_ROOT_SIGNATURE_FLAGS rootSigFlag = useLibTarget ? D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE : D3D12_ROOT_SIGNATURE_FLAG_NONE;
  1432. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSigFlag);
  1433. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1434. }
  1435. if (useLibTarget)
  1436. RunLifetimeIntrinsicLibTest(reinterpret_cast<ID3D12Device5*>(pDevice), pShader, pRootSignature, pTargetProfile, pOptions, numOptions);
  1437. else
  1438. RunLifetimeIntrinsicComputeTest(pDevice, pShader, pUavHeap, pRootSignature, pTargetProfile, pOptions, numOptions, values);
  1439. }
  1440. TEST_F(ExecutionTest, LifetimeIntrinsicTest) {
  1441. // The only thing we test here is that existence of lifetime intrinsics or
  1442. // their fallback replacement (store undef or store zeroinitializer) do not
  1443. // cause any issues in the runtime and driver stack.
  1444. // The easiest way to force placement of intrinsics is to create an array in
  1445. // a local scope that is dynamically indexed. It must not be optimized away,
  1446. // so we do some bogus initialization that prevents this. Since all the code
  1447. // is guarded by a conditional that is dynamically always false, the actual
  1448. // effect of the shader is that the same value that was read is written back.
  1449. static const char* pShader = R"(
  1450. RWByteAddressBuffer g_bab : register(u0);
  1451. void fn(uint GI) {
  1452. const uint addr = GI * 4;
  1453. const int val = g_bab.Load(addr);
  1454. int res = val;
  1455. if (val < 0) { // Never true.
  1456. int arr[200];
  1457. for (int i = 0; i < 200; ++i) {
  1458. arr[i] = arr[val - i];
  1459. }
  1460. res += arr[val];
  1461. }
  1462. g_bab.Store(addr, (uint)res);
  1463. }
  1464. [numthreads(8,8,1)]
  1465. void main(uint GI : SV_GroupIndex) {
  1466. fn(GI);
  1467. }
  1468. [shader("raygeneration")]
  1469. void RayGen() {
  1470. const uint d = DispatchRaysIndex().x;
  1471. const uint g = g > 64 ? 63 : g;
  1472. fn(g);
  1473. }
  1474. )";
  1475. static const int NumThreadsX = 8;
  1476. static const int NumThreadsY = 8;
  1477. static const int NumThreadsZ = 1;
  1478. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1479. static const int DispatchGroupCount = 1;
  1480. // TODO: There's probably a lot of things in the rest of this test that could be stripped away.
  1481. CComPtr<ID3D12Device5> pDevice;
  1482. if (!CreateDevice(reinterpret_cast<ID3D12Device**>(&pDevice), D3D_SHADER_MODEL_6_6, true, true)) {
  1483. WEX::Logging::Log::Comment(L"Lifetime test not run pre 6.6");
  1484. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  1485. return;
  1486. }
  1487. std::vector<uint32_t> values;
  1488. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1489. // Run a number of tests for different configurations that will cause
  1490. // lifetime intrinsics to be placed directly, be replaced by a zeroinitializer
  1491. // store, or be replaced by an undef store.
  1492. LPCWSTR pOptions15[] = {L"/validator-version 1.5"};
  1493. LPCWSTR pOptions16[] = {L"/validator-version 1.6", L"/Vd"};
  1494. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1495. // Test regular shader with zeroinitializer store.
  1496. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions15, _countof(pOptions15), values);
  1497. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1498. // Test library with zeroinitializer store.
  1499. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions15, _countof(pOptions15), values);
  1500. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1501. // Testing SM 6.6 and validator version 1.6 requires experimental shaders
  1502. // being turned on.
  1503. if (!m_ExperimentalModeEnabled)
  1504. return;
  1505. // Test regular shader with undef store.
  1506. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions16, _countof(pOptions16), values);
  1507. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1508. // Test library with undef store.
  1509. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions16, _countof(pOptions16), values);
  1510. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1511. // Test regular shader with lifetime intrinsics.
  1512. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, false, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1513. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1514. // Test library with lifetime intrinsics.
  1515. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, true, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1516. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1517. }
  1518. TEST_F(ExecutionTest, BasicComputeTest) {
  1519. #ifndef _HLK_CONF
  1520. //
  1521. // BasicComputeTest is a simple compute shader that can be used as the basis
  1522. // for more interesting compute execution tests.
  1523. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1524. // rendering code paths for comparison.
  1525. //
  1526. static const char pShader[] =
  1527. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1528. "[numthreads(8,8,1)]\r\n"
  1529. "void main(uint GI : SV_GroupIndex) {"
  1530. " uint addr = GI * 4;\r\n"
  1531. " uint val = g_bab.Load(addr);\r\n"
  1532. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1533. " g_bab.Store(addr, val + 1);\r\n"
  1534. "}";
  1535. static const int NumThreadsX = 8;
  1536. static const int NumThreadsY = 8;
  1537. static const int NumThreadsZ = 1;
  1538. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1539. static const int DispatchGroupCount = 1;
  1540. CComPtr<ID3D12Device> pDevice;
  1541. if (!CreateDevice(&pDevice))
  1542. return;
  1543. std::vector<uint32_t> values;
  1544. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1545. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1546. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1547. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1548. #endif
  1549. }
  1550. TEST_F(ExecutionTest, BasicTriangleTest) {
  1551. #ifndef _HLK_CONF
  1552. static const UINT FrameCount = 2;
  1553. static const UINT m_width = 320;
  1554. static const UINT m_height = 200;
  1555. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1556. struct Vertex {
  1557. XMFLOAT3 position;
  1558. XMFLOAT4 color;
  1559. };
  1560. // Pipeline objects.
  1561. CComPtr<ID3D12Device> pDevice;
  1562. CComPtr<ID3D12Resource> pRenderTarget;
  1563. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1564. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1565. CComPtr<ID3D12RootSignature> pRootSig;
  1566. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1567. CComPtr<ID3D12PipelineState> pPipelineState;
  1568. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1569. CComPtr<ID3D12Resource> pReadBuffer;
  1570. UINT rtvDescriptorSize;
  1571. CComPtr<ID3D12Resource> pVertexBuffer;
  1572. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1573. // Synchronization objects.
  1574. FenceObj FO;
  1575. // Shaders.
  1576. static const char pShaders[] =
  1577. "struct PSInput {\r\n"
  1578. " float4 position : SV_POSITION;\r\n"
  1579. " float4 color : COLOR;\r\n"
  1580. "};\r\n\r\n"
  1581. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1582. " PSInput result;\r\n"
  1583. "\r\n"
  1584. " result.position = position;\r\n"
  1585. " result.color = color;\r\n"
  1586. " return result;\r\n"
  1587. "}\r\n\r\n"
  1588. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1589. " return 1; //input.color;\r\n"
  1590. "};\r\n";
  1591. if (!CreateDevice(&pDevice))
  1592. return;
  1593. struct BasicTestChecker {
  1594. CComPtr<ID3D12Device> m_pDevice;
  1595. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1596. bool m_OK = false;
  1597. void SetOK(bool value) { m_OK = value; }
  1598. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1599. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1600. return;
  1601. m_pInfoQueue->PushEmptyStorageFilter();
  1602. m_pInfoQueue->PushEmptyRetrievalFilter();
  1603. }
  1604. ~BasicTestChecker() {
  1605. if (!m_OK && m_pInfoQueue != nullptr) {
  1606. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1607. bool invalidBytecodeFound = false;
  1608. CAtlArray<BYTE> m_pBytes;
  1609. for (UINT64 i = 0; i < count; ++i) {
  1610. SIZE_T len = 0;
  1611. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1612. continue;
  1613. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1614. continue;
  1615. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1616. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1617. continue;
  1618. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1619. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1620. invalidBytecodeFound = true;
  1621. break;
  1622. }
  1623. }
  1624. if (invalidBytecodeFound) {
  1625. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1626. L"typically indicates that experimental mode "
  1627. L"is not set up properly.");
  1628. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1629. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1630. }
  1631. }
  1632. else {
  1633. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1634. L"queue - dumping complete queue.");
  1635. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1636. }
  1637. }
  1638. }
  1639. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1640. LogCommentFmt(L"%s", pMsg);
  1641. }
  1642. };
  1643. BasicTestChecker BTC(pDevice);
  1644. {
  1645. InitFenceObj(pDevice, &FO);
  1646. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1647. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1648. // Create an empty root signature.
  1649. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1650. rootSignatureDesc.Init(
  1651. 0, nullptr, 0, nullptr,
  1652. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1653. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1654. // Create the pipeline state, which includes compiling and loading shaders.
  1655. // Define the vertex input layout.
  1656. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1657. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1658. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1659. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1660. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1661. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1662. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1663. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1664. &pCommandAllocator, &pCommandList,
  1665. pPipelineState);
  1666. // Define the geometry for a triangle.
  1667. Vertex triangleVertices[] = {
  1668. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1669. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1670. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1671. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1672. WaitForSignal(pCommandQueue, FO);
  1673. }
  1674. // Render and execute the command list.
  1675. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1676. &vertexBufferView, pRootSig, pRenderTarget,
  1677. pReadBuffer);
  1678. VERIFY_SUCCEEDED(pCommandList->Close());
  1679. ExecuteCommandList(pCommandQueue, pCommandList);
  1680. // Wait for previous frame.
  1681. WaitForSignal(pCommandQueue, FO);
  1682. // At this point, we've verified that execution succeeded with DXIL.
  1683. BTC.SetOK(true);
  1684. // Read back to CPU and examine contents.
  1685. {
  1686. MappedData data(pReadBuffer, m_width * m_height * 4);
  1687. const uint32_t *pPixels = (uint32_t *)data.data();
  1688. if (SaveImages()) {
  1689. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1690. }
  1691. uint32_t top = pPixels[m_width / 2]; // Top center.
  1692. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1693. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1694. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1695. }
  1696. #endif
  1697. }
  1698. TEST_F(ExecutionTest, Int64Test) {
  1699. static const char pShader[] =
  1700. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1701. "[numthreads(8,8,1)]\r\n"
  1702. "void main(uint GI : SV_GroupIndex) {"
  1703. " uint addr = GI * 4;\r\n"
  1704. " uint val = g_bab.Load(addr);\r\n"
  1705. " uint64_t u64 = val;\r\n"
  1706. " u64 *= val;\r\n"
  1707. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1708. "}";
  1709. static const int NumThreadsX = 8;
  1710. static const int NumThreadsY = 8;
  1711. static const int NumThreadsZ = 1;
  1712. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1713. static const int DispatchGroupCount = 1;
  1714. CComPtr<ID3D12Device> pDevice;
  1715. if (!CreateDevice(&pDevice))
  1716. return;
  1717. if (!DoesDeviceSupportInt64(pDevice)) {
  1718. // Optional feature, so it's correct to not support it if declared as such.
  1719. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1720. return;
  1721. }
  1722. std::vector<uint32_t> values;
  1723. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1724. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1725. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1726. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1727. }
  1728. TEST_F(ExecutionTest, SignTest) {
  1729. static const char pShader[] =
  1730. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1731. "[numthreads(8,1,1)]\r\n"
  1732. "void main(uint GI : SV_GroupIndex) {"
  1733. " uint addr = GI * 4;\r\n"
  1734. " int val = g_bab.Load(addr);\r\n"
  1735. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1736. "}";
  1737. static const int NumThreadsX = 8;
  1738. static const int NumThreadsY = 1;
  1739. static const int NumThreadsZ = 1;
  1740. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1741. static const int DispatchGroupCount = 1;
  1742. CComPtr<ID3D12Device> pDevice;
  1743. if (!CreateDevice(&pDevice))
  1744. return;
  1745. const uint32_t neg1 = (uint32_t)-1;
  1746. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1747. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1748. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1749. VERIFY_ARE_EQUAL(values[0], neg1);
  1750. VERIFY_ARE_EQUAL(values[1], neg1);
  1751. VERIFY_ARE_EQUAL(values[2], neg1);
  1752. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1753. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1754. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1755. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1756. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1757. }
  1758. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1759. #ifndef _HLK_CONF
  1760. CComPtr<ID3D12Device> pDevice;
  1761. if (!CreateDevice(&pDevice))
  1762. return;
  1763. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1764. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1765. return;
  1766. bool waveSupported = O.WaveOps;
  1767. UINT laneCountMin = O.WaveLaneCountMin;
  1768. UINT laneCountMax = O.WaveLaneCountMax;
  1769. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1770. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1771. if (waveSupported) {
  1772. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1773. }
  1774. else {
  1775. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1776. }
  1777. #endif
  1778. }
  1779. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1780. #ifndef _HLK_CONF
  1781. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1782. struct PerThreadData {
  1783. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1784. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1785. uint32_t pfBC, pfSum, pfProd;
  1786. uint32_t ballot[4];
  1787. uint32_t diver; // divergent value, used in calculation
  1788. int32_t i_diver; // divergent value, used in calculation
  1789. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1790. int32_t i_pfSum, i_pfProd;
  1791. };
  1792. static const char pShader[] =
  1793. WAVE_INTRINSIC_DXBC_GUARD
  1794. "struct PerThreadData {\r\n"
  1795. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1796. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1797. " uint pfBC, pfSum, pfProd;\r\n"
  1798. " uint4 ballot;\r\n"
  1799. " uint diver;\r\n"
  1800. " int i_diver;\r\n"
  1801. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1802. " int i_pfSum, i_pfProd;\r\n"
  1803. "};\r\n"
  1804. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1805. "[numthreads(8,8,1)]\r\n"
  1806. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1807. " PerThreadData pts = g_sb[GI];\r\n"
  1808. " uint diver = GTID.x + 2;\r\n"
  1809. " pts.diver = diver;\r\n"
  1810. " pts.flags = 0;\r\n"
  1811. " pts.preds = 0;\r\n"
  1812. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1813. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1814. " pts.laneCount = WaveGetLaneCount();\r\n"
  1815. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1816. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1817. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1818. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1819. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1820. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1821. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1822. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1823. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1824. "\r\n"
  1825. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1826. " pts.allSum = WaveActiveSum(diver);\r\n"
  1827. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1828. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1829. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1830. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1831. " pts.allMin = WaveActiveMin(diver);\r\n"
  1832. " pts.allMax = WaveActiveMax(diver);\r\n"
  1833. "\r\n"
  1834. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1835. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1836. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1837. "\r\n"
  1838. " int i_diver = pts.i_diver;\r\n"
  1839. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1840. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1841. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1842. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1843. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1844. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1845. "\r\n"
  1846. " g_sb[GI] = pts;\r\n"
  1847. "}";
  1848. static const int NumtheadsX = 8;
  1849. static const int NumtheadsY = 8;
  1850. static const int NumtheadsZ = 1;
  1851. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1852. static const int DispatchGroupCount = 1;
  1853. CComPtr<ID3D12Device> pDevice;
  1854. if (!CreateDevice(&pDevice))
  1855. return;
  1856. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1857. // Optional feature, so it's correct to not support it if declared as such.
  1858. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1859. return;
  1860. }
  1861. std::vector<PerThreadData> values;
  1862. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1863. for (size_t i = 0; i < values.size(); ++i) {
  1864. memset(&values[i], 0, sizeof(PerThreadData));
  1865. values[i].id = i;
  1866. values[i].i_diver = (int)i;
  1867. values[i].i_diver *= (i % 2) ? 1 : -1;
  1868. }
  1869. static const int DispatchGroupX = 1;
  1870. static const int DispatchGroupY = 1;
  1871. static const int DispatchGroupZ = 1;
  1872. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1873. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1874. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1875. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1876. UINT uavDescriptorSize;
  1877. FenceObj FO;
  1878. bool dxbc = UseDxbc();
  1879. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1880. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1881. InitFenceObj(pDevice, &FO);
  1882. // Describe and create a UAV descriptor heap.
  1883. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1884. heapDesc.NumDescriptors = 1;
  1885. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1886. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1887. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1888. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1889. // Create root signature.
  1890. CComPtr<ID3D12RootSignature> pRootSignature;
  1891. {
  1892. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1893. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1894. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1895. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1896. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1897. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1898. CComPtr<ID3DBlob> signature;
  1899. CComPtr<ID3DBlob> error;
  1900. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  1901. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  1902. }
  1903. // Create pipeline state object.
  1904. CComPtr<ID3D12PipelineState> pComputeState;
  1905. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1906. // Create a command allocator and list for compute.
  1907. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1908. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1909. // Set up UAV resource.
  1910. CComPtr<ID3D12Resource> pUavResource;
  1911. CComPtr<ID3D12Resource> pReadBuffer;
  1912. CComPtr<ID3D12Resource> pUploadResource;
  1913. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1914. // Close the command list and execute it to perform the GPU setup.
  1915. pCommandList->Close();
  1916. ExecuteCommandList(pCommandQueue, pCommandList);
  1917. WaitForSignal(pCommandQueue, FO);
  1918. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1919. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1920. // Run the compute shader and copy the results back to readable memory.
  1921. {
  1922. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1923. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  1924. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1925. uavDesc.Buffer.FirstElement = 0;
  1926. uavDesc.Buffer.NumElements = values.size();
  1927. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  1928. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1929. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  1930. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1931. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1932. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1933. SetDescriptorHeap(pCommandList, pUavHeap);
  1934. pCommandList->SetComputeRootSignature(pRootSignature);
  1935. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1936. }
  1937. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1938. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1939. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1940. pCommandList->Close();
  1941. ExecuteCommandList(pCommandQueue, pCommandList);
  1942. WaitForSignal(pCommandQueue, FO);
  1943. {
  1944. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1945. PerThreadData *pData = (PerThreadData *)mappedData.data();
  1946. memcpy(values.data(), pData, valueSizeInBytes);
  1947. // Gather some general data.
  1948. // The 'firstLaneId' captures a unique number per first-lane per wave.
  1949. // Counting the number distinct firstLaneIds gives us the number of waves.
  1950. std::vector<uint32_t> firstLaneIds;
  1951. for (size_t i = 0; i < values.size(); ++i) {
  1952. PerThreadData &pts = values[i];
  1953. uint32_t firstLaneId = pts.firstLaneId;
  1954. if (!contains(firstLaneIds, firstLaneId)) {
  1955. firstLaneIds.push_back(firstLaneId);
  1956. }
  1957. }
  1958. // Waves should cover 4 threads or more.
  1959. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  1960. if (!dxbc) {
  1961. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  1962. }
  1963. // Now, group threads into waves.
  1964. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  1965. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  1966. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  1967. }
  1968. for (size_t i = 0; i < values.size(); ++i) {
  1969. PerThreadData &pts = values[i];
  1970. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  1971. wave->push_back(&pts);
  1972. }
  1973. // Verify that all the wave values are coherent across the wave.
  1974. for (size_t i = 0; i < values.size(); ++i) {
  1975. PerThreadData &pts = values[i];
  1976. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  1977. // Sort the lanes by increasing lane ID.
  1978. struct LaneIdOrderPred {
  1979. bool operator()(PerThreadData *a, PerThreadData *b) {
  1980. return a->laneIndex < b->laneIndex;
  1981. }
  1982. };
  1983. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  1984. // Verify some interesting properties of the first lane.
  1985. uint32_t pfBC, pfSum, pfProd;
  1986. int32_t i_pfSum, i_pfProd;
  1987. int32_t i_allMax, i_allMin;
  1988. {
  1989. PerThreadData *ptdFirst = wave->front();
  1990. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  1991. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  1992. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  1993. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  1994. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  1995. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  1996. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  1997. pfSum = ptdFirst->diver;
  1998. pfProd = ptdFirst->diver;
  1999. i_pfSum = ptdFirst->i_diver;
  2000. i_pfProd = ptdFirst->i_diver;
  2001. i_allMax = i_allMin = ptdFirst->i_diver;
  2002. }
  2003. // Calculate values which take into consideration all lanes.
  2004. uint32_t preds = 0;
  2005. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  2006. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  2007. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  2008. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  2009. uint32_t ballot[4] = { 0, 0, 0, 0 };
  2010. int32_t i_allSum = 0, i_allProd = 1;
  2011. for (size_t n = 0; n < wave->size(); ++n) {
  2012. std::vector<PerThreadData *> &lanes = *wave.get();
  2013. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  2014. if (lanes[n]->diver == 1) preds |= (1 << 0);
  2015. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  2016. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  2017. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  2018. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  2019. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  2020. if (lanes[n]->diver > 3) {
  2021. // This is the uint4 result layout:
  2022. // .x -> bits 0 .. 31
  2023. // .y -> bits 32 .. 63
  2024. // .z -> bits 64 .. 95
  2025. // .w -> bits 96 ..127
  2026. uint32_t component = lanes[n]->laneIndex / 32;
  2027. uint32_t bit = lanes[n]->laneIndex % 32;
  2028. ballot[component] |= 1 << bit;
  2029. }
  2030. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  2031. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  2032. i_allProd *= lanes[n]->i_diver;
  2033. i_allSum += lanes[n]->i_diver;
  2034. }
  2035. for (size_t n = 1; n < wave->size(); ++n) {
  2036. // 'All' operations are uniform across the wave.
  2037. std::vector<PerThreadData *> &lanes = *wave.get();
  2038. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  2039. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  2040. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  2041. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  2042. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  2043. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  2044. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  2045. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  2046. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  2047. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  2048. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  2049. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  2050. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  2051. // first-lane reads and uniform reads are uniform across the wave.
  2052. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  2053. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  2054. // the lane count is uniform across the wave.
  2055. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  2056. // The predicates are uniform across the wave.
  2057. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  2058. // the lane index is distinct per thread.
  2059. for (size_t prior = 0; prior < n; ++prior) {
  2060. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  2061. }
  2062. // Ballot results are uniform across the wave.
  2063. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  2064. // Keep running total of prefix calculation. Prefix values are exclusive to
  2065. // the executing lane.
  2066. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  2067. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  2068. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  2069. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  2070. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  2071. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  2072. pfSum += lanes[n]->diver;
  2073. pfProd *= lanes[n]->diver;
  2074. i_pfSum += lanes[n]->i_diver;
  2075. i_pfProd *= lanes[n]->i_diver;
  2076. }
  2077. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  2078. }
  2079. // Compare each value of each per-thread element.
  2080. for (size_t i = 0; i < values.size(); ++i) {
  2081. PerThreadData &pts = values[i];
  2082. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  2083. }
  2084. }
  2085. #endif
  2086. }
  2087. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  2088. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  2089. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2090. struct Vertex {
  2091. XMFLOAT3 position;
  2092. };
  2093. struct PerPixelData {
  2094. XMFLOAT4 position;
  2095. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  2096. uint32_t id0, id1, id2, id3;
  2097. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  2098. };
  2099. const UINT RTWidth = 128;
  2100. const UINT RTHeight = 128;
  2101. // Shaders.
  2102. static const char pShaders[] =
  2103. WAVE_INTRINSIC_DXBC_GUARD
  2104. "struct PSInput {\r\n"
  2105. " float4 position : SV_POSITION;\r\n"
  2106. "};\r\n\r\n"
  2107. "PSInput VSMain(float4 position : POSITION) {\r\n"
  2108. " PSInput result;\r\n"
  2109. "\r\n"
  2110. " result.position = position;\r\n"
  2111. " return result;\r\n"
  2112. "}\r\n\r\n"
  2113. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  2114. "struct PerPixelData {\r\n"
  2115. " float4 position;\r\n"
  2116. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  2117. " uint id0, id1, id2, id3;\r\n"
  2118. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  2119. "};\r\n"
  2120. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  2121. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  2122. " uint one = 1;\r\n"
  2123. " PerPixelData d;\r\n"
  2124. " d.position = input.position;\r\n"
  2125. " d.id = pos_to_id(input.position);\r\n"
  2126. " d.flags = 0;\r\n"
  2127. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  2128. " d.laneIndex = WaveGetLaneIndex();\r\n"
  2129. " d.laneCount = WaveGetLaneCount();\r\n"
  2130. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  2131. " d.sum1 = WaveActiveSum(one);\r\n"
  2132. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  2133. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  2134. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  2135. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  2136. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  2137. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  2138. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  2139. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  2140. " g_sb.Append(d);\r\n"
  2141. " return 1;\r\n"
  2142. "};\r\n";
  2143. CComPtr<ID3D12Device> pDevice;
  2144. CComPtr<ID3D12CommandQueue> pCommandQueue;
  2145. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  2146. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  2147. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  2148. CComPtr<ID3D12PipelineState> pPSO;
  2149. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  2150. UINT uavDescriptorSize, rtvDescriptorSize;
  2151. CComPtr<ID3D12Resource> pVertexBuffer;
  2152. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  2153. if (!CreateDevice(&pDevice))
  2154. return;
  2155. if (!DoesDeviceSupportWaveOps(pDevice)) {
  2156. // Optional feature, so it's correct to not support it if declared as such.
  2157. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  2158. return;
  2159. }
  2160. FenceObj FO;
  2161. InitFenceObj(pDevice, &FO);
  2162. // Describe and create a UAV descriptor heap.
  2163. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  2164. heapDesc.NumDescriptors = 1;
  2165. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  2166. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  2167. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  2168. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2169. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  2170. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  2171. // Create root signature: one UAV.
  2172. CComPtr<ID3D12RootSignature> pRootSignature;
  2173. {
  2174. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2175. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  2176. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2177. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2178. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2179. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  2180. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  2181. }
  2182. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  2183. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  2184. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  2185. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  2186. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  2187. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  2188. &pCommandList, pPSO);
  2189. // Single triangle covering half the target.
  2190. Vertex vertices[] = {
  2191. { { -1.0f, 1.0f, 0.0f } },
  2192. { { 1.0f, 1.0f, 0.0f } },
  2193. { { -1.0f, -1.0f, 0.0f } } };
  2194. const UINT TriangleCount = _countof(vertices) / 3;
  2195. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  2196. bool dxbc = UseDxbc();
  2197. // Set up UAV resource.
  2198. std::vector<PerPixelData> values;
  2199. values.resize(RTWidth * RTHeight * 2);
  2200. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  2201. memset(values.data(), 0, valueSizeInBytes);
  2202. CComPtr<ID3D12Resource> pUavResource;
  2203. CComPtr<ID3D12Resource> pUavReadBuffer;
  2204. CComPtr<ID3D12Resource> pUploadResource;
  2205. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pUavReadBuffer);
  2206. // Set up the append counter resource.
  2207. CComPtr<ID3D12Resource> pUavCounterResource;
  2208. CComPtr<ID3D12Resource> pReadCounterBuffer;
  2209. CComPtr<ID3D12Resource> pUploadCounterResource;
  2210. BYTE zero[sizeof(UINT)] = { 0 };
  2211. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pUploadCounterResource, &pReadCounterBuffer);
  2212. // Close the command list and execute it to perform the GPU setup.
  2213. pCommandList->Close();
  2214. ExecuteCommandList(pCommandQueue, pCommandList);
  2215. WaitForSignal(pCommandQueue, FO);
  2216. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2217. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  2218. pCommandList->SetGraphicsRootSignature(pRootSignature);
  2219. SetDescriptorHeap(pCommandList, pUavHeap);
  2220. {
  2221. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2222. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2223. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2224. uavDesc.Buffer.FirstElement = 0;
  2225. uavDesc.Buffer.NumElements = (UINT)values.size();
  2226. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  2227. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2228. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2229. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2230. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2231. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  2232. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  2233. }
  2234. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  2235. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2236. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2237. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  2238. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  2239. VERIFY_SUCCEEDED(pCommandList->Close());
  2240. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  2241. ExecuteCommandList(pCommandQueue, pCommandList);
  2242. WaitForSignal(pCommandQueue, FO);
  2243. {
  2244. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  2245. const uint32_t *pPixels = (uint32_t *)data.data();
  2246. if (SaveImages()) {
  2247. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  2248. }
  2249. }
  2250. uint32_t appendCount;
  2251. {
  2252. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  2253. appendCount = *((uint32_t *)mappedData.data());
  2254. LogCommentFmt(L"%u elements in append buffer", appendCount);
  2255. }
  2256. {
  2257. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  2258. PerPixelData *pData = (PerPixelData *)mappedData.data();
  2259. memcpy(values.data(), pData, valueSizeInBytes);
  2260. // DXBC is handy to test pipeline setup, but interesting functions are
  2261. // stubbed out, so there is no point in further validation.
  2262. if (dxbc)
  2263. return;
  2264. uint32_t maxActiveLaneCount = 0;
  2265. uint32_t maxLaneCount = 0;
  2266. for (uint32_t i = 0; i < appendCount; ++i) {
  2267. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  2268. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  2269. }
  2270. uint32_t peerOfHelperLanes = 0;
  2271. for (uint32_t i = 0; i < appendCount; ++i) {
  2272. if (values[i].sum1 != maxActiveLaneCount) {
  2273. ++peerOfHelperLanes;
  2274. }
  2275. }
  2276. LogCommentFmt(
  2277. L"Found: %u threads. Waves reported up to %u total lanes, up "
  2278. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  2279. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  2280. // Group threads into quad invocations.
  2281. uint32_t singlePixelCount = 0;
  2282. uint32_t multiPixelCount = 0;
  2283. std::unordered_set<uint32_t> ids;
  2284. std::multimap<uint32_t, PerPixelData *> idGroups;
  2285. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  2286. for (uint32_t i = 0; i < appendCount; ++i) {
  2287. ids.insert(values[i].id);
  2288. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  2289. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  2290. }
  2291. for (uint32_t id : ids) {
  2292. if (idGroups.count(id) == 1)
  2293. ++singlePixelCount;
  2294. else
  2295. ++multiPixelCount;
  2296. }
  2297. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  2298. singlePixelCount, multiPixelCount);
  2299. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  2300. // Where every pixel is distinct, it's very straightforward to validate.
  2301. {
  2302. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  2303. while (cur != end) {
  2304. bool simpleWave = true;
  2305. uint32_t firstId = (*cur).first;
  2306. auto groupEnd = cur;
  2307. while (groupEnd != end && (*groupEnd).first == firstId) {
  2308. if (idGroups.count((*groupEnd).second->id) > 1)
  2309. simpleWave = false;
  2310. ++groupEnd;
  2311. }
  2312. if (simpleWave) {
  2313. // Break the wave into quads.
  2314. struct QuadData {
  2315. unsigned count;
  2316. PerPixelData *data[4];
  2317. };
  2318. std::map<uint32_t, QuadData> quads;
  2319. for (auto i = cur; i != groupEnd; ++i) {
  2320. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  2321. uint32_t laneId = (*i).second->id;
  2322. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  2323. (*i).second->id2, (*i).second->id3};
  2324. // Since this is a simple wave, each lane has an unique id and
  2325. // therefore should not have any ids in there.
  2326. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  2327. // check if QuadReadLaneAt is returning same values in a single quad.
  2328. bool newQuad = true;
  2329. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  2330. auto match = quads.find(laneIds[quadIndex]);
  2331. if (match != quads.end()) {
  2332. (*match).second.data[(*match).second.count++] = (*i).second;
  2333. newQuad = false;
  2334. break;
  2335. }
  2336. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  2337. if (quadMemberData != idGroups.end()) {
  2338. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  2339. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  2340. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  2341. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  2342. }
  2343. }
  2344. if (newQuad) {
  2345. QuadData qdata;
  2346. qdata.count = 1;
  2347. qdata.data[0] = (*i).second;
  2348. quads.insert(std::make_pair(laneId, qdata));
  2349. }
  2350. }
  2351. for (auto quadPair : quads) {
  2352. unsigned count = quadPair.second.count;
  2353. // There could be only one pixel data on the edge of the triangle
  2354. if (count < 2) continue;
  2355. PerPixelData **data = quadPair.second.data;
  2356. bool isTop[4];
  2357. bool isLeft[4];
  2358. PerPixelData helperData;
  2359. memset(&helperData, sizeof(helperData), 0);
  2360. PerPixelData *layout[4]; // tl,tr,bl,br
  2361. memset(layout, sizeof(layout), 0);
  2362. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  2363. int idx = top ? 0 : 2;
  2364. idx += left ? 0 : 1;
  2365. return &layout[idx];
  2366. };
  2367. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  2368. PerPixelData **pResult = fnToLayout(top, left);
  2369. if (*pResult == nullptr) return &helperData;
  2370. return *pResult;
  2371. };
  2372. VERIFY_IS_TRUE(count <= 4);
  2373. if (count == 2) {
  2374. isTop[0] = data[0]->position.y < data[1]->position.y;
  2375. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  2376. isLeft[0] = data[0]->position.x < data[1]->position.x;
  2377. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  2378. }
  2379. else {
  2380. // with at least three samples, we have distinct x and y coordinates.
  2381. float left = std::min(data[0]->position.x, data[1]->position.x);
  2382. left = std::min(data[2]->position.x, left);
  2383. float top = std::min(data[0]->position.y, data[1]->position.y);
  2384. top = std::min(data[2]->position.y, top);
  2385. for (unsigned i = 0; i < count; ++i) {
  2386. isTop[i] = data[i]->position.y == top;
  2387. isLeft[i] = data[i]->position.x == left;
  2388. }
  2389. }
  2390. for (unsigned i = 0; i < count; ++i) {
  2391. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  2392. }
  2393. // Finally, we have a proper quad reconstructed. Validate.
  2394. for (unsigned i = 0; i < count; ++i) {
  2395. PerPixelData *d = data[i];
  2396. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  2397. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  2398. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  2399. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  2400. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  2401. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  2402. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  2403. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2404. }
  2405. }
  2406. }
  2407. cur = groupEnd;
  2408. }
  2409. }
  2410. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2411. //
  2412. // Consider: for pixels that were shaded multiple times, check whether
  2413. // some grouping of threads into quads satisfies all value requirements.
  2414. }
  2415. }
  2416. struct ShaderOpTestResult {
  2417. st::ShaderOp *ShaderOp;
  2418. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2419. std::shared_ptr<st::ShaderOpTest> Test;
  2420. };
  2421. struct SPrimitives {
  2422. float f_float;
  2423. float f_float2;
  2424. float f_float_o;
  2425. float f_float2_o;
  2426. };
  2427. std::shared_ptr<ShaderOpTestResult>
  2428. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2429. LPCSTR pName,
  2430. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2431. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2432. st::ShaderOp *pShaderOp;
  2433. if (pName == nullptr) {
  2434. if (ShaderOpSet->ShaderOps.size() != 1) {
  2435. VERIFY_FAIL(L"Expected a single shader operation.");
  2436. }
  2437. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2438. }
  2439. else {
  2440. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2441. }
  2442. if (pShaderOp == nullptr) {
  2443. std::string msg = "Unable to find shader op ";
  2444. msg += pName;
  2445. msg += "; available ops";
  2446. const char sep = ':';
  2447. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2448. msg += sep;
  2449. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2450. }
  2451. CA2W msgWide(msg.c_str());
  2452. VERIFY_FAIL(msgWide.m_psz);
  2453. }
  2454. // This won't actually be used since we're supplying the device,
  2455. // but let's make it consistent.
  2456. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2457. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2458. test->SetDxcSupport(&support);
  2459. test->SetInitCallback(pInitCallback);
  2460. test->SetDevice(pDevice);
  2461. test->RunShaderOp(pShaderOp);
  2462. std::shared_ptr<ShaderOpTestResult> result =
  2463. std::make_shared<ShaderOpTestResult>();
  2464. result->ShaderOpSet = ShaderOpSet;
  2465. result->Test = test;
  2466. result->ShaderOp = pShaderOp;
  2467. return result;
  2468. }
  2469. std::shared_ptr<ShaderOpTestResult>
  2470. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2471. IStream *pStream, LPCSTR pName,
  2472. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2473. DXASSERT_NOMSG(pStream != nullptr);
  2474. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2475. std::make_shared<st::ShaderOpSet>();
  2476. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2477. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2478. }
  2479. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2480. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2481. CComPtr<IStream> pStream;
  2482. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2483. // Single operation test at the moment.
  2484. CComPtr<ID3D12Device> pDevice;
  2485. if (!CreateDevice(&pDevice))
  2486. return;
  2487. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2488. MappedData data;
  2489. // Read back to CPU and examine contents - should get pure red.
  2490. {
  2491. MappedData data;
  2492. test->Test->GetReadBackData("RTarget", &data);
  2493. const uint32_t *pPixels = (uint32_t *)data.data();
  2494. uint32_t first = *pPixels;
  2495. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2496. }
  2497. }
  2498. TEST_F(ExecutionTest, SaturateTest) {
  2499. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2500. CComPtr<IStream> pStream;
  2501. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2502. // Single operation test at the moment.
  2503. CComPtr<ID3D12Device> pDevice;
  2504. if (!CreateDevice(&pDevice))
  2505. return;
  2506. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2507. MappedData data;
  2508. test->Test->GetReadBackData("U0", &data);
  2509. const float *pValues = (float *)data.data();
  2510. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2511. const float ExpectedCases[9] = {
  2512. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2513. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2514. 0.0f // nan
  2515. };
  2516. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2517. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2518. ++pValues;
  2519. }
  2520. }
  2521. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2522. #ifdef _HLK_CONF
  2523. UNREFERENCED_PARAMETER(ShaderOpName);
  2524. UNREFERENCED_PARAMETER(FileName);
  2525. UNREFERENCED_PARAMETER(testModel);
  2526. #else
  2527. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2528. CComPtr<IStream> pStream;
  2529. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2530. // Single operation test at the moment.
  2531. CComPtr<ID3D12Device> pDevice;
  2532. if (!CreateDevice(&pDevice, testModel))
  2533. return;
  2534. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2535. MappedData data;
  2536. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2537. UINT width = (UINT64)D.Width;
  2538. UINT height = (UINT64)D.Height;
  2539. test->Test->GetReadBackData("RTarget", &data);
  2540. const uint32_t *pPixels = (uint32_t *)data.data();
  2541. if (SaveImages()) {
  2542. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2543. }
  2544. uint32_t top = pPixels[width / 2]; // Top center.
  2545. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2546. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2547. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2548. // This is the basic validation test for shader operations, so it's good to
  2549. // check this here at least for this one test case.
  2550. data.reset();
  2551. test.reset();
  2552. ReportLiveObjects();
  2553. #endif
  2554. }
  2555. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2556. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2557. }
  2558. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2559. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2560. }
  2561. void VerifyDerivResults(const float *pPixels, UINT offsetCenter) {
  2562. // pixel at the center
  2563. float CenterDDXFine = pPixels[offsetCenter];
  2564. float CenterDDYFine = pPixels[offsetCenter + 1];
  2565. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2566. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2567. LogCommentFmt(
  2568. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2569. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2570. // The texture for the 9 pixels in the center should look like the following
  2571. // 256 32 64
  2572. // 2048 256 512
  2573. // 1 .125 .25
  2574. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2575. // So for fine derivatives there can be up to two possible results for the center pixel,
  2576. // while for coarse derivatives there can be up to six possible results.
  2577. int ulpTolerance = 1;
  2578. // 512 - 256 or 2048 - 256
  2579. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2580. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2581. // 256 - 32 or 256 - .125
  2582. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2583. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2584. if (top && left) {
  2585. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2586. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2587. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2588. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2589. }
  2590. else if (top) { // top right quad
  2591. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2592. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2593. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2594. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2595. }
  2596. else if (left) { // bottom left quad
  2597. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2598. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2599. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2600. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2601. }
  2602. else { // bottom right
  2603. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2604. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2605. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2606. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2607. }
  2608. }
  2609. // Rendering two right triangles forming a square and assigning a texture value
  2610. // for each pixel to calculate derivates.
  2611. TEST_F(ExecutionTest, PartialDerivTest) {
  2612. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2613. CComPtr<IStream> pStream;
  2614. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2615. CComPtr<ID3D12Device> pDevice;
  2616. if (!CreateDevice(&pDevice))
  2617. return;
  2618. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2619. MappedData data;
  2620. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2621. UINT width = (UINT)D.Width;
  2622. UINT height = D.Height;
  2623. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2624. test->Test->GetReadBackData("RTarget", &data);
  2625. const float *pPixels = (float *)data.data();
  2626. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2627. UINT offsetCenter = centerIndex * pixelSize;
  2628. VerifyDerivResults(pPixels, offsetCenter);
  2629. }
  2630. TEST_F(ExecutionTest, DerivativesTest) {
  2631. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2632. CComPtr<IStream> pStream;
  2633. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2634. CComPtr<ID3D12Device> pDevice;
  2635. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2636. return;
  2637. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2638. std::make_shared<st::ShaderOpSet>();
  2639. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2640. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Derivatives");
  2641. LPCSTR CS = pShaderOp->CS;
  2642. struct Dispatch {
  2643. int x, y, z;
  2644. int mx, my, mz;
  2645. };
  2646. std::vector<Dispatch> dispatches =
  2647. {
  2648. {32, 32, 1, 8, 8, 1},
  2649. {64, 4, 1, 64, 2, 1},
  2650. {1, 4, 64, 1, 4, 32},
  2651. {64, 1, 1, 64, 1, 1},
  2652. {1, 64, 1, 1, 64, 1},
  2653. {1, 1, 64, 1, 1, 64},
  2654. {16, 16, 3, 4, 4, 3},
  2655. {32, 3, 8, 8, 3, 2},
  2656. {3, 1, 64, 3, 1, 32}
  2657. };
  2658. char compilerOptions[256];
  2659. for (Dispatch &D : dispatches) {
  2660. UINT width = D.x;
  2661. UINT height = D.y;
  2662. UINT depth = D.z;
  2663. UINT mwidth = D.mx;
  2664. UINT mheight = D.my;
  2665. UINT mdepth = D.mz;
  2666. UINT pixelSize = 4; // always float4
  2667. // format compiler args
  2668. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2669. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2670. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2671. width, height, depth, mwidth, mheight, mdepth));
  2672. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2673. S.Arguments = compilerOptions;
  2674. pShaderOp->DispatchX = width;
  2675. pShaderOp->DispatchY = height;
  2676. pShaderOp->DispatchZ = depth;
  2677. // Test Compute Shader
  2678. pShaderOp->CS = CS;
  2679. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2680. MappedData data;
  2681. test->Test->GetReadBackData("U0", &data);
  2682. const float *pPixels = (float *)data.data();
  2683. // To find roughly the center for compute, divide the pixel count in half,
  2684. // truncate to next lowest power of 16 (4x4), which is the repeating period
  2685. // and then add 10 to reach the point the test expects
  2686. UINT centerIndex = (((UINT64)(width * height * depth)/2) & ~0xF) + 10;
  2687. UINT offsetCenter = centerIndex * pixelSize;
  2688. LogCommentFmt(L"Verifying derivatives in compute shader results");
  2689. VerifyDerivResults(pPixels, offsetCenter);
  2690. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2691. // Disable CS so mesh goes forward
  2692. pShaderOp->CS = nullptr;
  2693. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2694. test->Test->GetReadBackData("U1", &data);
  2695. pPixels = (float *)data.data();
  2696. centerIndex = (((UINT64)(mwidth * mheight * mdepth)/2) & ~0xF) + 10;
  2697. offsetCenter = centerIndex * pixelSize;
  2698. LogCommentFmt(L"Verifying derivatives in mesh shader results");
  2699. VerifyDerivResults(pPixels, offsetCenter);
  2700. test->Test->GetReadBackData("U2", &data);
  2701. pPixels = (float *)data.data();
  2702. LogCommentFmt(L"Verifying derivatives in amplification shader results");
  2703. VerifyDerivResults(pPixels, offsetCenter);
  2704. }
  2705. }
  2706. // Final test with not divisible by 4 dispatch size just to make sure it runs
  2707. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2708. S.Arguments = "-D DISPATCHX=3 -D DISPATCHY=3 -D DISPATCHZ=3 "
  2709. "-D MESHDISPATCHX=3 -D MESHDISPATCHY=3 -D MESHDISPATCHZ=3";
  2710. pShaderOp->DispatchX = 3;
  2711. pShaderOp->DispatchY = 3;
  2712. pShaderOp->DispatchZ = 3;
  2713. // Test Compute Shader
  2714. pShaderOp->CS = CS;
  2715. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2716. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2717. pShaderOp->CS = nullptr;
  2718. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2719. }
  2720. }
  2721. // Verify the results for the quad starting with the given index
  2722. void VerifyQuadReadResults(const UINT *pPixels, UINT quadIndex) {
  2723. for (UINT i = 0; i < 4; i++) {
  2724. UINT ix = quadIndex + i;
  2725. VERIFY_ARE_EQUAL(pPixels[4*ix + 0], ix); // ReadLaneAt own quad index
  2726. VERIFY_ARE_EQUAL(pPixels[4*ix + 1], (ix^1));// ReadAcrossX
  2727. VERIFY_ARE_EQUAL(pPixels[4*ix + 2], (ix^2));// ReadAcrossY
  2728. VERIFY_ARE_EQUAL(pPixels[4*ix + 3], (ix^3));// ReadAcrossDiagonal
  2729. }
  2730. }
  2731. TEST_F(ExecutionTest, QuadReadTest) {
  2732. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2733. CComPtr<IStream> pStream;
  2734. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2735. CComPtr<ID3D12Device> pDevice;
  2736. if (!CreateDevice(&pDevice))
  2737. return;
  2738. if (GetTestParamUseWARP(UseWarpByDefault())) {
  2739. WEX::Logging::Log::Comment(L"WARP does not support QuadRead in compute shaders.");
  2740. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2741. return;
  2742. }
  2743. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2744. std::make_shared<st::ShaderOpSet>();
  2745. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2746. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("QuadRead");
  2747. LPCSTR CS = pShaderOp->CS;
  2748. struct Dispatch {
  2749. int x, y, z;
  2750. int mx, my, mz;
  2751. };
  2752. //std::vector<std::tuple<int, int, int, int, int>> dispatches =
  2753. std::vector<Dispatch> dispatches =
  2754. {
  2755. {32, 32, 1, 8, 8, 1},
  2756. {64, 4, 1, 64, 2, 1},
  2757. {1, 4, 64, 1, 4, 32},
  2758. {64, 1, 1, 64, 1, 1},
  2759. {1, 64, 1, 1, 64, 1},
  2760. {1, 1, 64, 1, 1, 64},
  2761. {16, 16, 3, 4, 4, 3},
  2762. {32, 3, 8, 8, 3, 2},
  2763. {3, 1, 64, 3, 1, 32}
  2764. };
  2765. for (Dispatch &D : dispatches) {
  2766. UINT width = D.x;
  2767. UINT height = D.y;
  2768. UINT depth = D.z;
  2769. UINT mwidth = D.mx;
  2770. UINT mheight = D.my;
  2771. UINT mdepth = D.mz;
  2772. // format compiler args
  2773. char compilerOptions[256];
  2774. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2775. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2776. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2777. width, height, depth, mwidth, mheight, mdepth));
  2778. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2779. S.Arguments = compilerOptions;
  2780. pShaderOp->DispatchX = width;
  2781. pShaderOp->DispatchY = height;
  2782. pShaderOp->DispatchZ = depth;
  2783. // Test Compute Shader
  2784. pShaderOp->CS = CS;
  2785. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2786. MappedData data;
  2787. test->Test->GetReadBackData("U0", &data);
  2788. const UINT *pPixels = (UINT *)data.data();
  2789. // To find roughly the center for compute, divide the pixel count in half
  2790. // and truncate to next lowest power of 4 to start at a quad
  2791. UINT offsetCenter = ((UINT64)(width * height * depth)/2) & ~0x3;
  2792. // Test first, second and center quads
  2793. LogCommentFmt(L"Verifying QuadRead* in compute shader results");
  2794. VerifyQuadReadResults(pPixels, 0);
  2795. VerifyQuadReadResults(pPixels, 4);
  2796. VerifyQuadReadResults(pPixels, offsetCenter);
  2797. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2798. offsetCenter = ((UINT64)(mwidth * mheight * mdepth)/2) & ~0x3;
  2799. // Disable CS so mesh goes forward
  2800. pShaderOp->CS = nullptr;
  2801. test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2802. test->Test->GetReadBackData("U1", &data);
  2803. pPixels = (UINT *)data.data();
  2804. // Test first, second and center quads
  2805. LogCommentFmt(L"Verifying QuadRead* in mesh shader results");
  2806. VerifyQuadReadResults(pPixels, 0);
  2807. VerifyQuadReadResults(pPixels, 4);
  2808. VerifyQuadReadResults(pPixels, offsetCenter);
  2809. test->Test->GetReadBackData("U2", &data);
  2810. pPixels = (UINT *)data.data();
  2811. // Test first, second and center quads
  2812. LogCommentFmt(L"Verifying QuadRead* in amplification shader results");
  2813. VerifyQuadReadResults(pPixels, 0);
  2814. VerifyQuadReadResults(pPixels, 4);
  2815. VerifyQuadReadResults(pPixels, offsetCenter);
  2816. }
  2817. }
  2818. }
  2819. void VerifySampleResults(const UINT *pPixels) {
  2820. UINT xlod = 0;
  2821. UINT ylod = 0;
  2822. // Each pixel contains 4 samples and 4 LOD calculations.
  2823. // 2 of these (called 'left' and 'right') have X values that vary and a constant Y
  2824. // 2 others (called 'top' and 'bot') have Y values that vary and a constant X
  2825. // Only of the X variant sample results and one of the Y variant results
  2826. // are actually reported for the pixel.
  2827. // The other 2 serve as "helpers" to the other pixels in the quad.
  2828. // On the left side of the quad, the 'left' samples are reported.
  2829. // Op the top of the quad, the 'top' samples are reported and so on.
  2830. // The varying coordinate values alternate between zero and a
  2831. // value whose magnitude increases with the index.
  2832. // As a result, the LOD level should steadily increas.
  2833. // Due to vagaries of implementation, the same derivatives
  2834. // in both directions might result in different levels for different locations
  2835. // in the quad. So only comparisons between sample results and LOD calculations
  2836. // and ensuring that the LOD increased and reaches the max can be tested reliably.
  2837. for (unsigned i = 0; i < 64; i++) {
  2838. // CalculateLOD and Sample from texture with mip levels containing LOD index should match
  2839. VERIFY_ARE_EQUAL(pPixels[4*i + 0], pPixels[4*i + 1]);
  2840. VERIFY_ARE_EQUAL(pPixels[4*i + 2], pPixels[4*i + 3]);
  2841. // Make sure LODs are ever climbing as magnitudes increase
  2842. VERIFY_IS_TRUE(pPixels[4*i] >= xlod);
  2843. xlod = pPixels[4*i];
  2844. VERIFY_IS_TRUE(pPixels[4*i + 2] >= ylod);
  2845. ylod = pPixels[4*i + 2];
  2846. }
  2847. // Make sure we reached the max lod level for both tracks
  2848. VERIFY_ARE_EQUAL(xlod, 6);
  2849. VERIFY_ARE_EQUAL(ylod, 6);
  2850. }
  2851. TEST_F(ExecutionTest, ComputeSampleTest) {
  2852. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2853. CComPtr<IStream> pStream;
  2854. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2855. CComPtr<ID3D12Device> pDevice;
  2856. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2857. return;
  2858. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2859. std::make_shared<st::ShaderOpSet>();
  2860. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2861. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("ComputeSample");
  2862. D3D12_RESOURCE_DESC &texDesc = pShaderOp->GetResourceByName("T0")->Desc;
  2863. UINT texWidth = (UINT)texDesc.Width;
  2864. UINT texHeight = (UINT)texDesc.Height;
  2865. // Initialize texture with the LOD number in each corresponding mip level
  2866. auto SampleInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2867. VERIFY_ARE_EQUAL(0, _stricmp(Name, "T0"));
  2868. size_t size = sizeof(float) * texWidth * texHeight * 2;
  2869. Data.resize(size);
  2870. float *pPrimitives = (float *)Data.data();
  2871. float lod = 0.0;
  2872. int ix = 0;
  2873. while (texHeight > 0 && texWidth > 0) {
  2874. if(!texHeight) texHeight = 1;
  2875. if(!texWidth) texWidth = 1;
  2876. for (size_t j = 0; j < texHeight; ++j) {
  2877. for (size_t i = 0; i < texWidth; ++i) {
  2878. pPrimitives[ix++] = lod;
  2879. }
  2880. }
  2881. lod += 1.0;
  2882. texHeight >>= 1;
  2883. texWidth >>= 1;
  2884. }
  2885. };
  2886. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2887. MappedData data;
  2888. test->Test->GetReadBackData("U0", &data);
  2889. const UINT *pPixels = (UINT *)data.data();
  2890. VerifySampleResults(pPixels);
  2891. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2892. // Disable CS so mesh goes forward
  2893. pShaderOp->CS = nullptr;
  2894. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2895. }
  2896. }
  2897. // Executing a simple binop to verify shadel model 6.1 support; runs with
  2898. // ShaderModel61.CoreRequirement
  2899. TEST_F(ExecutionTest, BasicShaderModel61) {
  2900. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  2901. }
  2902. // Executing a simple binop to verify shadel model 6.3 support; runs with
  2903. // ShaderModel63.CoreRequirement
  2904. TEST_F(ExecutionTest, BasicShaderModel63) {
  2905. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  2906. }
  2907. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  2908. WEX::TestExecution::SetVerifyOutput verifySettings(
  2909. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2910. CComPtr<ID3D12Device> pDevice;
  2911. if (!CreateDevice(&pDevice, shaderModel)) {
  2912. return;
  2913. }
  2914. char *pShaderModelStr;
  2915. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  2916. pShaderModelStr = "cs_6_1";
  2917. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  2918. pShaderModelStr = "cs_6_3";
  2919. } else {
  2920. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  2921. pShaderModelStr = nullptr;
  2922. }
  2923. const char shaderTemplate[] =
  2924. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  2925. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  2926. "[numthreads(8,8,1)]"
  2927. "void main(uint GI : SV_GroupIndex) {"
  2928. " SBinaryOp l = g_buf[GI];"
  2929. " l.output = l.input1 + l.input2;"
  2930. " g_buf[GI] = l;"
  2931. "}";
  2932. char shader[sizeof(shaderTemplate) + 50];
  2933. // Run simple shader with float data types
  2934. char* sTy = "float";
  2935. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  2936. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  2937. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  2938. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  2939. // Run simple shader with double data types
  2940. if (DoesDeviceSupportDouble(pDevice)) {
  2941. sTy = "double";
  2942. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  2943. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  2944. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  2945. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  2946. }
  2947. else {
  2948. // Optional feature, so it's correct to not support it if declared as such.
  2949. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  2950. }
  2951. // Run simple shader with int64 types
  2952. if (DoesDeviceSupportInt64(pDevice)) {
  2953. sTy = "int64_t";
  2954. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  2955. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  2956. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  2957. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  2958. }
  2959. else {
  2960. // Optional feature, so it's correct to not support it if declared as such.
  2961. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  2962. }
  2963. }
  2964. template <class Ty>
  2965. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  2966. DXASSERT_NOMSG("Unsupported type");
  2967. return "";
  2968. }
  2969. template <>
  2970. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  2971. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  2972. }
  2973. template <>
  2974. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  2975. return BasicShaderModelTest_GetFormatString<float>();
  2976. }
  2977. template <>
  2978. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  2979. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  2980. }
  2981. template <class Ty>
  2982. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  2983. Ty *pInputDataPairs, unsigned inputDataCount) {
  2984. struct SBinaryOp {
  2985. Ty input1;
  2986. Ty input2;
  2987. Ty output;
  2988. };
  2989. CComPtr<IStream> pStream;
  2990. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2991. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  2992. pDevice, m_support, pStream, "BinaryFPOp",
  2993. // this callbacked is called when the test is creating the resource to run the test
  2994. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2995. UNREFERENCED_PARAMETER(Name);
  2996. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  2997. pShaderOp->Shaders.at(0).Text = pShader;
  2998. size_t size = sizeof(SBinaryOp) * inputDataCount;
  2999. Data.resize(size);
  3000. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  3001. Ty *pIn = pInputDataPairs;
  3002. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  3003. SBinaryOp *p = &pPrimitives[i];
  3004. p->input1 = pIn[0];
  3005. p->input2 = pIn[1];
  3006. }
  3007. });
  3008. VERIFY_SUCCEEDED(S_OK);
  3009. MappedData data;
  3010. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3011. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  3012. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  3013. Ty *pIn = pInputDataPairs;
  3014. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  3015. Ty expValue = pIn[0] + pIn[1];
  3016. SBinaryOp *p = &pPrimitives[i];
  3017. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  3018. VERIFY_ARE_EQUAL(p->output, expValue);
  3019. }
  3020. }
  3021. // Resource structure for data-driven tests.
  3022. struct SUnaryFPOp {
  3023. float input;
  3024. float output;
  3025. };
  3026. struct SBinaryFPOp {
  3027. float input1;
  3028. float input2;
  3029. float output1;
  3030. float output2;
  3031. };
  3032. struct STertiaryFPOp {
  3033. float input1;
  3034. float input2;
  3035. float input3;
  3036. float output;
  3037. };
  3038. struct SUnaryHalfOp {
  3039. uint16_t input;
  3040. uint16_t output;
  3041. };
  3042. struct SBinaryHalfOp {
  3043. uint16_t input1;
  3044. uint16_t input2;
  3045. uint16_t output1;
  3046. uint16_t output2;
  3047. };
  3048. struct STertiaryHalfOp {
  3049. uint16_t input1;
  3050. uint16_t input2;
  3051. uint16_t input3;
  3052. uint16_t output;
  3053. };
  3054. struct SUnaryIntOp {
  3055. int input;
  3056. int output;
  3057. };
  3058. struct SUnaryUintOp {
  3059. unsigned int input;
  3060. unsigned int output;
  3061. };
  3062. struct SBinaryIntOp {
  3063. int input1;
  3064. int input2;
  3065. int output1;
  3066. int output2;
  3067. };
  3068. struct STertiaryIntOp {
  3069. int input1;
  3070. int input2;
  3071. int input3;
  3072. int output;
  3073. };
  3074. struct SBinaryUintOp {
  3075. unsigned int input1;
  3076. unsigned int input2;
  3077. unsigned int output1;
  3078. unsigned int output2;
  3079. };
  3080. struct STertiaryUintOp {
  3081. unsigned int input1;
  3082. unsigned int input2;
  3083. unsigned int input3;
  3084. unsigned int output;
  3085. };
  3086. struct SUnaryInt16Op {
  3087. short input;
  3088. short output;
  3089. };
  3090. struct SUnaryUint16Op {
  3091. unsigned short input;
  3092. unsigned short output;
  3093. };
  3094. struct SBinaryInt16Op {
  3095. short input1;
  3096. short input2;
  3097. short output1;
  3098. short output2;
  3099. };
  3100. struct STertiaryInt16Op {
  3101. short input1;
  3102. short input2;
  3103. short input3;
  3104. short output;
  3105. };
  3106. struct SBinaryUint16Op {
  3107. unsigned short input1;
  3108. unsigned short input2;
  3109. unsigned short output1;
  3110. unsigned short output2;
  3111. };
  3112. struct STertiaryUint16Op {
  3113. unsigned short input1;
  3114. unsigned short input2;
  3115. unsigned short input3;
  3116. unsigned short output;
  3117. };
  3118. // representation for HLSL float vectors
  3119. struct SDotOp {
  3120. XMFLOAT4 input1;
  3121. XMFLOAT4 input2;
  3122. float o_dot2;
  3123. float o_dot3;
  3124. float o_dot4;
  3125. };
  3126. struct Half2
  3127. {
  3128. uint16_t x;
  3129. uint16_t y;
  3130. Half2() = default;
  3131. Half2(const Half2&) = default;
  3132. Half2& operator=(const Half2&) = default;
  3133. Half2(Half2&&) = default;
  3134. Half2& operator=(Half2&&) = default;
  3135. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  3136. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  3137. };
  3138. struct SDot2AddHalfOp {
  3139. Half2 input1;
  3140. Half2 input2;
  3141. float acc;
  3142. float result;
  3143. };
  3144. struct SDot4AddI8PackedOp {
  3145. uint32_t input1;
  3146. uint32_t input2;
  3147. int32_t acc;
  3148. int32_t result;
  3149. };
  3150. struct SDot4AddU8PackedOp {
  3151. uint32_t input1;
  3152. uint32_t input2;
  3153. uint32_t acc;
  3154. uint32_t result;
  3155. };
  3156. struct SMsad4 {
  3157. unsigned int ref;
  3158. XMUINT2 src;
  3159. XMUINT4 accum;
  3160. XMUINT4 result;
  3161. };
  3162. struct SPackUnpackOpOutPacked
  3163. {
  3164. uint32_t packedUint32;
  3165. uint32_t packedInt32;
  3166. uint32_t packedUint16;
  3167. uint32_t packedInt16;
  3168. uint32_t packedClampedUint32;
  3169. uint32_t packedClampedInt32;
  3170. uint32_t packedClampedUint16;
  3171. uint32_t packedClampedInt16;
  3172. };
  3173. struct SPackUnpackOpOutUnpacked {
  3174. std::array<uint32_t, 4> outputUint32;
  3175. std::array<int32_t, 4> outputInt32;
  3176. std::array<uint16_t, 4> outputUint16;
  3177. std::array<int16_t, 4> outputInt16;
  3178. std::array<uint32_t, 4> outputClampedUint32;
  3179. std::array<int32_t, 4> outputClampedInt32;
  3180. std::array<uint16_t, 4> outputClampedUint16;
  3181. std::array<int16_t, 4> outputClampedInt16;
  3182. };
  3183. // Parameter representation for taef data-driven tests
  3184. struct TableParameter {
  3185. LPCWSTR m_name;
  3186. enum TableParameterType {
  3187. INT8,
  3188. INT16,
  3189. INT32,
  3190. UINT,
  3191. FLOAT,
  3192. HALF,
  3193. DOUBLE,
  3194. STRING,
  3195. BOOL,
  3196. INT8_TABLE,
  3197. INT16_TABLE,
  3198. INT32_TABLE,
  3199. FLOAT_TABLE,
  3200. HALF_TABLE,
  3201. DOUBLE_TABLE,
  3202. STRING_TABLE,
  3203. UINT8_TABLE,
  3204. UINT16_TABLE,
  3205. UINT32_TABLE,
  3206. BOOL_TABLE
  3207. };
  3208. TableParameterType m_type;
  3209. bool m_required; // required parameter
  3210. int8_t m_int8;
  3211. int16_t m_int16;
  3212. int m_int32;
  3213. unsigned int m_uint;
  3214. float m_float;
  3215. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  3216. double m_double;
  3217. bool m_bool;
  3218. WEX::Common::String m_str;
  3219. std::vector<int8_t> m_int8Table;
  3220. std::vector<int16_t> m_int16Table;
  3221. std::vector<int> m_int32Table;
  3222. std::vector<uint8_t> m_uint8Table;
  3223. std::vector<uint16_t> m_uint16Table;
  3224. std::vector<unsigned int> m_uint32Table;
  3225. std::vector<float> m_floatTable;
  3226. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  3227. std::vector<double> m_doubleTable;
  3228. std::vector<bool> m_boolTable;
  3229. std::vector<WEX::Common::String> m_StringTable;
  3230. };
  3231. class TableParameterHandler {
  3232. private:
  3233. HRESULT ParseTableRow();
  3234. public:
  3235. TableParameter* m_table;
  3236. size_t m_tableSize;
  3237. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  3238. clearTableParameter();
  3239. VERIFY_SUCCEEDED(ParseTableRow());
  3240. }
  3241. TableParameter* GetTableParamByName(LPCWSTR name) {
  3242. for (size_t i = 0; i < m_tableSize; ++i) {
  3243. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3244. return &m_table[i];
  3245. }
  3246. }
  3247. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3248. return nullptr;
  3249. }
  3250. void clearTableParameter() {
  3251. for (size_t i = 0; i < m_tableSize; ++i) {
  3252. m_table[i].m_int32 = 0;
  3253. m_table[i].m_uint = 0;
  3254. m_table[i].m_double = 0;
  3255. m_table[i].m_bool = false;
  3256. m_table[i].m_str = WEX::Common::String();
  3257. }
  3258. }
  3259. template <class T1>
  3260. std::vector<T1> *GetDataArray(LPCWSTR name) {
  3261. return nullptr;
  3262. }
  3263. template <>
  3264. std::vector<int> *GetDataArray(LPCWSTR name) {
  3265. for (size_t i = 0; i < m_tableSize; ++i) {
  3266. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3267. return &(m_table[i].m_int32Table);
  3268. }
  3269. }
  3270. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3271. return nullptr;
  3272. }
  3273. template <>
  3274. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  3275. for (size_t i = 0; i < m_tableSize; ++i) {
  3276. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3277. return &(m_table[i].m_int8Table);
  3278. }
  3279. }
  3280. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3281. return nullptr;
  3282. }
  3283. template <>
  3284. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  3285. for (size_t i = 0; i < m_tableSize; ++i) {
  3286. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3287. return &(m_table[i].m_int16Table);
  3288. }
  3289. }
  3290. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3291. return nullptr;
  3292. }
  3293. template <>
  3294. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  3295. for (size_t i = 0; i < m_tableSize; ++i) {
  3296. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3297. return &(m_table[i].m_uint32Table);
  3298. }
  3299. }
  3300. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3301. return nullptr;
  3302. }
  3303. template <>
  3304. std::vector<float> *GetDataArray(LPCWSTR name) {
  3305. for (size_t i = 0; i < m_tableSize; ++i) {
  3306. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3307. return &(m_table[i].m_floatTable);
  3308. }
  3309. }
  3310. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3311. return nullptr;
  3312. }
  3313. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  3314. template <>
  3315. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  3316. for (size_t i = 0; i < m_tableSize; ++i) {
  3317. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3318. return &(m_table[i].m_halfTable);
  3319. }
  3320. }
  3321. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3322. return nullptr;
  3323. }
  3324. template <>
  3325. std::vector<double> *GetDataArray(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].m_doubleTable);
  3329. }
  3330. }
  3331. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3332. return nullptr;
  3333. }
  3334. template <>
  3335. std::vector<bool> *GetDataArray(LPCWSTR name) {
  3336. for (size_t i = 0; i < m_tableSize; ++i) {
  3337. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3338. return &(m_table[i].m_boolTable);
  3339. }
  3340. }
  3341. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3342. return nullptr;
  3343. }
  3344. };
  3345. static TableParameter UnaryFPOpParameters[] = {
  3346. { L"ShaderOp.Target", TableParameter::STRING, true },
  3347. { L"ShaderOp.Text", TableParameter::STRING, true },
  3348. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3349. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3350. { L"Validation.Type", TableParameter::STRING, true },
  3351. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3352. { L"Warp.Version", TableParameter::UINT, false }
  3353. };
  3354. static TableParameter BinaryFPOpParameters[] = {
  3355. { L"ShaderOp.Target", TableParameter::STRING, true },
  3356. { L"ShaderOp.Text", TableParameter::STRING, true },
  3357. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3358. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3359. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3360. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  3361. { L"Validation.Type", TableParameter::STRING, true },
  3362. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3363. };
  3364. static TableParameter TertiaryFPOpParameters[] = {
  3365. { L"ShaderOp.Target", TableParameter::STRING, true },
  3366. { L"ShaderOp.Text", TableParameter::STRING, true },
  3367. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3368. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3369. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3370. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3371. { L"Validation.Type", TableParameter::STRING, true },
  3372. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3373. };
  3374. static TableParameter UnaryHalfOpParameters[] = {
  3375. { L"ShaderOp.Target", TableParameter::STRING, true },
  3376. { L"ShaderOp.Text", TableParameter::STRING, true },
  3377. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3378. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3379. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3380. { L"Validation.Type", TableParameter::STRING, true },
  3381. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3382. { L"Warp.Version", TableParameter::UINT, false }
  3383. };
  3384. static TableParameter BinaryHalfOpParameters[] = {
  3385. { L"ShaderOp.Target", TableParameter::STRING, true },
  3386. { L"ShaderOp.Text", TableParameter::STRING, true },
  3387. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3388. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3389. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3390. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3391. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  3392. { L"Validation.Type", TableParameter::STRING, true },
  3393. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3394. };
  3395. static TableParameter TertiaryHalfOpParameters[] = {
  3396. { L"ShaderOp.Target", TableParameter::STRING, true },
  3397. { L"ShaderOp.Text", TableParameter::STRING, true },
  3398. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3399. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3400. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3401. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  3402. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3403. { L"Validation.Type", TableParameter::STRING, true },
  3404. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3405. };
  3406. static TableParameter UnaryIntOpParameters[] = {
  3407. { L"ShaderOp.Target", TableParameter::STRING, true },
  3408. { L"ShaderOp.Text", TableParameter::STRING, true },
  3409. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3410. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3411. { L"Validation.Tolerance", TableParameter::INT32, true },
  3412. };
  3413. static TableParameter UnaryUintOpParameters[] = {
  3414. { L"ShaderOp.Target", TableParameter::STRING, true },
  3415. { L"ShaderOp.Text", TableParameter::STRING, true },
  3416. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3417. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3418. { L"Validation.Tolerance", TableParameter::INT32, true },
  3419. };
  3420. static TableParameter BinaryIntOpParameters[] = {
  3421. { L"ShaderOp.Target", TableParameter::STRING, true },
  3422. { L"ShaderOp.Text", TableParameter::STRING, true },
  3423. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3424. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3425. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3426. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  3427. { L"Validation.Tolerance", TableParameter::INT32, true },
  3428. };
  3429. static TableParameter TertiaryIntOpParameters[] = {
  3430. { L"ShaderOp.Target", TableParameter::STRING, true },
  3431. { L"ShaderOp.Text", TableParameter::STRING, true },
  3432. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3433. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3434. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3435. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3436. { L"Validation.Tolerance", TableParameter::INT32, true },
  3437. };
  3438. static TableParameter BinaryUintOpParameters[] = {
  3439. { L"ShaderOp.Target", TableParameter::STRING, true },
  3440. { L"ShaderOp.Text", TableParameter::STRING, true },
  3441. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3442. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3443. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3444. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  3445. { L"Validation.Tolerance", TableParameter::INT32, true },
  3446. };
  3447. static TableParameter TertiaryUintOpParameters[] = {
  3448. { L"ShaderOp.Target", TableParameter::STRING, true },
  3449. { L"ShaderOp.Text", TableParameter::STRING, true },
  3450. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3451. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3452. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3453. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3454. { L"Validation.Tolerance", TableParameter::INT32, true },
  3455. };
  3456. static TableParameter UnaryInt16OpParameters[] = {
  3457. { L"ShaderOp.Target", TableParameter::STRING, true },
  3458. { L"ShaderOp.Text", TableParameter::STRING, true },
  3459. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3460. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3461. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3462. { L"Validation.Tolerance", TableParameter::INT32, true },
  3463. };
  3464. static TableParameter UnaryUint16OpParameters[] = {
  3465. { L"ShaderOp.Target", TableParameter::STRING, true },
  3466. { L"ShaderOp.Text", TableParameter::STRING, true },
  3467. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3468. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3469. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3470. { L"Validation.Tolerance", TableParameter::INT32, true },
  3471. };
  3472. static TableParameter BinaryInt16OpParameters[] = {
  3473. { L"ShaderOp.Target", TableParameter::STRING, true },
  3474. { L"ShaderOp.Text", TableParameter::STRING, true },
  3475. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3476. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3477. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3478. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3479. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  3480. { L"Validation.Tolerance", TableParameter::INT32, true },
  3481. };
  3482. static TableParameter TertiaryInt16OpParameters[] = {
  3483. { L"ShaderOp.Target", TableParameter::STRING, true },
  3484. { L"ShaderOp.Text", TableParameter::STRING, true },
  3485. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3486. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3487. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3488. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  3489. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3490. { L"Validation.Tolerance", TableParameter::INT32, true },
  3491. };
  3492. static TableParameter BinaryUint16OpParameters[] = {
  3493. { L"ShaderOp.Target", TableParameter::STRING, true },
  3494. { L"ShaderOp.Text", TableParameter::STRING, true },
  3495. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3496. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3497. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3498. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3499. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  3500. { L"Validation.Tolerance", TableParameter::INT32, true },
  3501. };
  3502. static TableParameter TertiaryUint16OpParameters[] = {
  3503. { L"ShaderOp.Target", TableParameter::STRING, true },
  3504. { L"ShaderOp.Text", TableParameter::STRING, true },
  3505. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3506. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3507. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3508. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  3509. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3510. { L"Validation.Tolerance", TableParameter::INT32, true },
  3511. };
  3512. static TableParameter DotOpParameters[] = {
  3513. { L"ShaderOp.Target", TableParameter::STRING, true },
  3514. { L"ShaderOp.Text", TableParameter::STRING, true },
  3515. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3516. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3517. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3518. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  3519. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  3520. { L"Validation.Type", TableParameter::STRING, true },
  3521. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3522. };
  3523. static TableParameter Dot2AddHalfOpParameters[] = {
  3524. { L"ShaderOp.Target", TableParameter::STRING, true },
  3525. { L"ShaderOp.Text", TableParameter::STRING, true },
  3526. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3527. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3528. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3529. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3530. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3531. { L"Validation.Type", TableParameter::STRING, true },
  3532. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3533. };
  3534. static TableParameter Dot4AddI8PackedOpParameters[] = {
  3535. { L"ShaderOp.Target", TableParameter::STRING, true },
  3536. { L"ShaderOp.Text", TableParameter::STRING, true },
  3537. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3538. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3539. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3540. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3541. };
  3542. static TableParameter Dot4AddU8PackedOpParameters[] = {
  3543. { L"ShaderOp.Target", TableParameter::STRING, true },
  3544. { L"ShaderOp.Text", TableParameter::STRING, true },
  3545. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3546. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3547. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3548. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3549. };
  3550. static TableParameter Msad4OpParameters[] = {
  3551. { L"ShaderOp.Text", TableParameter::STRING, true },
  3552. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3553. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  3554. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3555. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3556. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  3557. };
  3558. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  3559. { L"ShaderOp.Name", TableParameter::STRING, true },
  3560. { L"ShaderOp.Text", TableParameter::STRING, true },
  3561. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3562. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3563. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3564. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3565. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3566. };
  3567. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  3568. { L"ShaderOp.Name", TableParameter::STRING, true },
  3569. { L"ShaderOp.Text", TableParameter::STRING, true },
  3570. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3571. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3572. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3573. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3574. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3575. };
  3576. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  3577. { L"ShaderOp.Name", TableParameter::STRING, true },
  3578. { L"ShaderOp.Text", TableParameter::STRING, true },
  3579. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3580. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3581. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3582. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3583. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3584. };
  3585. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  3586. { L"ShaderOp.Name", TableParameter::STRING, true },
  3587. { L"ShaderOp.Text", TableParameter::STRING, true },
  3588. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3589. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3590. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3591. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3592. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3593. };
  3594. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  3595. { L"ShaderOp.Name", TableParameter::STRING, true },
  3596. { L"ShaderOp.Target", TableParameter::STRING, true },
  3597. { L"ShaderOp.Text", TableParameter::STRING, true },
  3598. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  3599. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  3600. };
  3601. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  3602. { L"ShaderOp.Name", TableParameter::STRING, true },
  3603. { L"ShaderOp.Target", TableParameter::STRING, true },
  3604. { L"ShaderOp.Text", TableParameter::STRING, true },
  3605. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  3606. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  3607. };
  3608. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  3609. { L"ShaderOp.Name", TableParameter::STRING, true },
  3610. { L"ShaderOp.Text", TableParameter::STRING, true },
  3611. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3612. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  3613. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  3614. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  3615. };
  3616. static TableParameter CBufferTestHalfParameters[] = {
  3617. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  3618. };
  3619. static TableParameter DenormBinaryFPOpParameters[] = {
  3620. { L"ShaderOp.Target", TableParameter::STRING, true },
  3621. { L"ShaderOp.Text", TableParameter::STRING, true },
  3622. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3623. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3624. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3625. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3626. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3627. { L"Validation.Type", TableParameter::STRING, true },
  3628. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3629. };
  3630. static TableParameter DenormTertiaryFPOpParameters[] = {
  3631. { L"ShaderOp.Target", TableParameter::STRING, true },
  3632. { L"ShaderOp.Text", TableParameter::STRING, true },
  3633. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3634. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3635. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3636. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3637. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3638. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3639. { L"Validation.Type", TableParameter::STRING, true },
  3640. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3641. };
  3642. static TableParameter PackUnpackOpParameters[] = {
  3643. { L"ShaderOp.Text", TableParameter::STRING, true },
  3644. { L"Validation.Type", TableParameter::STRING, true },
  3645. { L"Validation.Tolerance", TableParameter::UINT, true },
  3646. { L"Validation.Input", TableParameter::UINT32_TABLE, true },
  3647. };
  3648. static bool IsHexString(PCWSTR str, uint16_t *value) {
  3649. std::wstring wString(str);
  3650. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3651. LPCWSTR wstr = wString.c_str();
  3652. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  3653. *value = (uint16_t)wcstol(wstr, NULL, 0);
  3654. return true;
  3655. }
  3656. return false;
  3657. }
  3658. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  3659. std::wstring wString(str);
  3660. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3661. PCWSTR wstr = wString.data();
  3662. if (_wcsicmp(wstr, L"NaN") == 0) {
  3663. value = NAN;
  3664. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  3665. value = -(INFINITY);
  3666. } else if (_wcsicmp(wstr, L"inf") == 0) {
  3667. value = INFINITY;
  3668. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  3669. value = -(FLT_MIN / 2);
  3670. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  3671. value = FLT_MIN / 2;
  3672. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  3673. _wcsicmp(wstr, L"-0") == 0) {
  3674. value = -0.0f;
  3675. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  3676. _wcsicmp(wstr, L"0") == 0) {
  3677. value = 0.0f;
  3678. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  3679. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  3680. value = (float&)temp_i;
  3681. }
  3682. else {
  3683. // evaluate the expression of wstring
  3684. double val = _wtof(wstr);
  3685. if (val == 0) {
  3686. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  3687. return E_FAIL;
  3688. }
  3689. value = (float)val;
  3690. }
  3691. return S_OK;
  3692. }
  3693. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  3694. std::wstring wString(str);
  3695. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3696. PCWSTR wstr = wString.data();
  3697. // evaluate the expression of string
  3698. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  3699. value = 0;
  3700. return S_OK;
  3701. }
  3702. int val = _wtoi(wstr);
  3703. if (val == 0) {
  3704. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3705. return E_FAIL;
  3706. }
  3707. value = val;
  3708. return S_OK;
  3709. }
  3710. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3711. std::wstring wString(str);
  3712. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3713. PCWSTR wstr = wString.data();
  3714. // evaluate the expression of string
  3715. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3716. value = 0;
  3717. return S_OK;
  3718. }
  3719. wchar_t *end;
  3720. unsigned int val = std::wcstoul(wstr, &end, 0);
  3721. if (val == 0) {
  3722. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3723. return E_FAIL;
  3724. }
  3725. value = val;
  3726. return S_OK;
  3727. }
  3728. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3729. std::wstring wstr(str);
  3730. size_t curPosition = 0;
  3731. // parse a string of dot product separated by commas
  3732. for (size_t i = 0; i < count; ++i) {
  3733. size_t nextPosition = wstr.find(L",", curPosition);
  3734. if (FAILED(ParseDataToFloat(
  3735. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3736. *(ptr + i)))) {
  3737. return E_FAIL;
  3738. }
  3739. curPosition = nextPosition + 1;
  3740. }
  3741. return S_OK;
  3742. }
  3743. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3744. std::wstring wstr(str);
  3745. size_t curPosition = 0;
  3746. // parse a string of dot product separated by commas
  3747. for (size_t i = 0; i < count; ++i) {
  3748. size_t nextPosition = wstr.find(L",", curPosition);
  3749. float floatValue;
  3750. if (FAILED(ParseDataToFloat(
  3751. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3752. return E_FAIL;
  3753. }
  3754. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3755. curPosition = nextPosition + 1;
  3756. }
  3757. return S_OK;
  3758. }
  3759. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3760. std::wstring wstr(str);
  3761. size_t curPosition = 0;
  3762. // parse a string of dot product separated by commas
  3763. for (size_t i = 0; i < count; ++i) {
  3764. size_t nextPosition = wstr.find(L",", curPosition);
  3765. if (FAILED(ParseDataToUint(
  3766. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3767. *(ptr + i)))) {
  3768. return E_FAIL;
  3769. }
  3770. curPosition = nextPosition + 1;
  3771. }
  3772. return S_OK;
  3773. }
  3774. HRESULT TableParameterHandler::ParseTableRow() {
  3775. TableParameter *table = m_table;
  3776. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3777. switch (table[i].m_type) {
  3778. case TableParameter::INT8:
  3779. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3780. table[i].m_int32)) && table[i].m_required) {
  3781. // TryGetValue does not suppport reading from int16
  3782. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3783. return E_FAIL;
  3784. }
  3785. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3786. break;
  3787. case TableParameter::INT16:
  3788. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3789. table[i].m_int32)) && table[i].m_required) {
  3790. // TryGetValue does not suppport reading from int16
  3791. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3792. return E_FAIL;
  3793. }
  3794. table[i].m_int16 = (short)(table[i].m_int32);
  3795. break;
  3796. case TableParameter::INT32:
  3797. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3798. table[i].m_int32)) && table[i].m_required) {
  3799. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3800. return E_FAIL;
  3801. }
  3802. break;
  3803. case TableParameter::UINT:
  3804. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3805. table[i].m_uint)) && table[i].m_required) {
  3806. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3807. return E_FAIL;
  3808. }
  3809. break;
  3810. case TableParameter::DOUBLE:
  3811. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3812. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3813. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3814. return E_FAIL;
  3815. }
  3816. break;
  3817. case TableParameter::STRING:
  3818. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3819. table[i].m_str)) && table[i].m_required) {
  3820. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3821. return E_FAIL;
  3822. }
  3823. break;
  3824. case TableParameter::BOOL:
  3825. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3826. table[i].m_str)) && table[i].m_bool) {
  3827. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3828. return E_FAIL;
  3829. }
  3830. break;
  3831. case TableParameter::INT8_TABLE: {
  3832. WEX::TestExecution::TestDataArray<int> tempTable;
  3833. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3834. table[i].m_name, tempTable)) && table[i].m_required) {
  3835. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3836. return E_FAIL;
  3837. }
  3838. // TryGetValue does not suppport reading from int8
  3839. table[i].m_int8Table.resize(tempTable.GetSize());
  3840. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3841. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  3842. }
  3843. break;
  3844. }
  3845. case TableParameter::INT16_TABLE: {
  3846. WEX::TestExecution::TestDataArray<int> tempTable;
  3847. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3848. table[i].m_name, tempTable)) && table[i].m_required) {
  3849. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3850. return E_FAIL;
  3851. }
  3852. // TryGetValue does not suppport reading from int8
  3853. table[i].m_int16Table.resize(tempTable.GetSize());
  3854. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3855. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  3856. }
  3857. break;
  3858. }case TableParameter::INT32_TABLE: {
  3859. WEX::TestExecution::TestDataArray<int> tempTable;
  3860. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3861. table[i].m_name, tempTable)) && table[i].m_required) {
  3862. // TryGetValue does not suppport reading from int8
  3863. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3864. return E_FAIL;
  3865. }
  3866. table[i].m_int32Table.resize(tempTable.GetSize());
  3867. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3868. table[i].m_int32Table[j] = tempTable[j];
  3869. }
  3870. break;
  3871. }
  3872. case TableParameter::UINT8_TABLE: {
  3873. WEX::TestExecution::TestDataArray<int> tempTable;
  3874. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3875. table[i].m_name, tempTable)) && table[i].m_required) {
  3876. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3877. return E_FAIL;
  3878. }
  3879. // TryGetValue does not suppport reading from int8
  3880. table[i].m_int8Table.resize(tempTable.GetSize());
  3881. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3882. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  3883. }
  3884. break;
  3885. }
  3886. case TableParameter::UINT16_TABLE: {
  3887. WEX::TestExecution::TestDataArray<int> tempTable;
  3888. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3889. table[i].m_name, tempTable)) && table[i].m_required) {
  3890. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3891. return E_FAIL;
  3892. }
  3893. // TryGetValue does not suppport reading from int8
  3894. table[i].m_uint16Table.resize(tempTable.GetSize());
  3895. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3896. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  3897. }
  3898. break;
  3899. }
  3900. case TableParameter::UINT32_TABLE: {
  3901. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  3902. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3903. table[i].m_name, tempTable)) && table[i].m_required) {
  3904. // TryGetValue does not suppport reading from int8
  3905. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3906. return E_FAIL;
  3907. }
  3908. table[i].m_uint32Table.resize(tempTable.GetSize());
  3909. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3910. table[i].m_uint32Table[j] = tempTable[j];
  3911. }
  3912. break;
  3913. }
  3914. case TableParameter::FLOAT_TABLE: {
  3915. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3916. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3917. table[i].m_name, tempTable)) && table[i].m_required) {
  3918. // TryGetValue does not suppport reading from int8
  3919. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3920. return E_FAIL;
  3921. }
  3922. table[i].m_floatTable.resize(tempTable.GetSize());
  3923. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3924. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  3925. }
  3926. break;
  3927. }
  3928. case TableParameter::HALF_TABLE: {
  3929. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3930. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3931. table[i].m_name, tempTable)) && table[i].m_required) {
  3932. // TryGetValue does not suppport reading from int8
  3933. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3934. return E_FAIL;
  3935. }
  3936. table[i].m_halfTable.resize(tempTable.GetSize());
  3937. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3938. uint16_t value = 0;
  3939. if (IsHexString(tempTable[j], &value)) {
  3940. table[i].m_halfTable[j] = value;
  3941. }
  3942. else {
  3943. float val;
  3944. ParseDataToFloat(tempTable[j], val);
  3945. if (isdenorm(val))
  3946. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  3947. else
  3948. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  3949. }
  3950. }
  3951. break;
  3952. }
  3953. case TableParameter::DOUBLE_TABLE: {
  3954. WEX::TestExecution::TestDataArray<double> tempTable;
  3955. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3956. table[i].m_name, tempTable)) && table[i].m_required) {
  3957. // TryGetValue does not suppport reading from int8
  3958. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3959. return E_FAIL;
  3960. }
  3961. table[i].m_doubleTable.resize(tempTable.GetSize());
  3962. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3963. table[i].m_doubleTable[j] = tempTable[j];
  3964. }
  3965. break;
  3966. }
  3967. case TableParameter::BOOL_TABLE: {
  3968. WEX::TestExecution::TestDataArray<bool> tempTable;
  3969. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3970. table[i].m_name, tempTable)) && table[i].m_required) {
  3971. // TryGetValue does not suppport reading from int8
  3972. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3973. return E_FAIL;
  3974. }
  3975. table[i].m_boolTable.resize(tempTable.GetSize());
  3976. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3977. table[i].m_boolTable[j] = tempTable[j];
  3978. }
  3979. break;
  3980. }
  3981. case TableParameter::STRING_TABLE: {
  3982. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3983. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3984. table[i].m_name, tempTable)) && table[i].m_required) {
  3985. // TryGetValue does not suppport reading from int8
  3986. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3987. return E_FAIL;
  3988. }
  3989. table[i].m_StringTable.resize(tempTable.GetSize());
  3990. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3991. table[i].m_StringTable[j] = tempTable[j];
  3992. }
  3993. break;
  3994. }
  3995. default:
  3996. DXASSERT_NOMSG("Invalid Parameter Type");
  3997. }
  3998. if (errno == ERANGE) {
  3999. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  4000. return E_FAIL;
  4001. }
  4002. }
  4003. return S_OK;
  4004. }
  4005. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  4006. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4007. }
  4008. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  4009. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4010. }
  4011. static void VerifyOutputWithExpectedValueFloat(
  4012. float output, float ref, LPCWSTR type, double tolerance,
  4013. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4014. if (_wcsicmp(type, L"Relative") == 0) {
  4015. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  4016. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4017. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  4018. } else if (_wcsicmp(type, L"ULP") == 0) {
  4019. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  4020. } else {
  4021. LogErrorFmt(L"Failed to read comparison type %S", type);
  4022. }
  4023. }
  4024. static bool CompareOutputWithExpectedValueFloat(
  4025. float output, float ref, LPCWSTR type, double tolerance,
  4026. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4027. if (_wcsicmp(type, L"Relative") == 0) {
  4028. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  4029. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4030. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  4031. } else if (_wcsicmp(type, L"ULP") == 0) {
  4032. return CompareFloatULP(output, ref, (int)tolerance, mode);
  4033. } else {
  4034. LogErrorFmt(L"Failed to read comparison type %S", type);
  4035. return false;
  4036. }
  4037. }
  4038. static void VerifyOutputWithExpectedValueHalf(
  4039. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  4040. if (_wcsicmp(type, L"Relative") == 0) {
  4041. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  4042. }
  4043. else if (_wcsicmp(type, L"Epsilon") == 0) {
  4044. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  4045. }
  4046. else if (_wcsicmp(type, L"ULP") == 0) {
  4047. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  4048. }
  4049. else {
  4050. LogErrorFmt(L"Failed to read comparison type %S", type);
  4051. }
  4052. }
  4053. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  4054. WEX::TestExecution::SetVerifyOutput verifySettings(
  4055. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4056. CComPtr<IStream> pStream;
  4057. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4058. CComPtr<ID3D12Device> pDevice;
  4059. if (!CreateDevice(&pDevice)) {
  4060. return;
  4061. }
  4062. // Read data from the table
  4063. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  4064. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  4065. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4066. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4067. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4068. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4069. return;
  4070. }
  4071. std::vector<float> *Validation_Input =
  4072. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4073. std::vector<float> *Validation_Expected =
  4074. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4075. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4076. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4077. size_t count = Validation_Input->size();
  4078. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4079. pDevice, m_support, pStream, "UnaryFPOp",
  4080. // this callbacked is called when the test
  4081. // is creating the resource to run the test
  4082. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4083. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4084. size_t size = sizeof(SUnaryFPOp) * count;
  4085. Data.resize(size);
  4086. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  4087. for (size_t i = 0; i < count; ++i) {
  4088. SUnaryFPOp *p = &pPrimitives[i];
  4089. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4090. }
  4091. // use shader from data table
  4092. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4093. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4094. });
  4095. MappedData data;
  4096. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4097. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  4098. WEX::TestExecution::DisableVerifyExceptions dve;
  4099. for (unsigned i = 0; i < count; ++i) {
  4100. SUnaryFPOp *p = &pPrimitives[i];
  4101. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4102. LogCommentFmt(
  4103. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  4104. p->input, p->output, val);
  4105. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  4106. }
  4107. }
  4108. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  4109. WEX::TestExecution::SetVerifyOutput verifySettings(
  4110. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4111. CComPtr<IStream> pStream;
  4112. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4113. CComPtr<ID3D12Device> pDevice;
  4114. if (!CreateDevice(&pDevice)) {
  4115. return;
  4116. }
  4117. // Read data from the table
  4118. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  4119. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  4120. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4121. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4122. std::vector<float> *Validation_Input1 =
  4123. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4124. std::vector<float> *Validation_Input2 =
  4125. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4126. std::vector<float> *Validation_Expected1 =
  4127. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4128. std::vector<float> *Validation_Expected2 =
  4129. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  4130. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4131. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4132. size_t count = Validation_Input1->size();
  4133. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4134. pDevice, m_support, pStream, "BinaryFPOp",
  4135. // this callbacked is called when the test
  4136. // is creating the resource to run the test
  4137. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4138. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4139. size_t size = sizeof(SBinaryFPOp) * count;
  4140. Data.resize(size);
  4141. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4142. for (size_t i = 0; i < count; ++i) {
  4143. SBinaryFPOp *p = &pPrimitives[i];
  4144. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4145. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4146. }
  4147. // use shader from data table
  4148. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4149. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4150. });
  4151. MappedData data;
  4152. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4153. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4154. WEX::TestExecution::DisableVerifyExceptions dve;
  4155. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4156. if (numExpected == 2) {
  4157. for (unsigned i = 0; i < count; ++i) {
  4158. SBinaryFPOp *p = &pPrimitives[i];
  4159. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4160. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4161. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4162. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  4163. i, p->input1, p->input2, p->output1, val1, p->output2,
  4164. val2);
  4165. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4166. Validation_Tolerance);
  4167. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  4168. Validation_Tolerance);
  4169. }
  4170. }
  4171. else if (numExpected == 1) {
  4172. for (unsigned i = 0; i < count; ++i) {
  4173. SBinaryFPOp *p = &pPrimitives[i];
  4174. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4175. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4176. L"%6.8f, expected1 = %6.8f",
  4177. i, p->input1, p->input2, p->output1, val1);
  4178. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4179. Validation_Tolerance);
  4180. }
  4181. }
  4182. else {
  4183. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4184. }
  4185. }
  4186. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  4187. WEX::TestExecution::SetVerifyOutput verifySettings(
  4188. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4189. CComPtr<IStream> pStream;
  4190. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4191. CComPtr<ID3D12Device> pDevice;
  4192. if (!CreateDevice(&pDevice)) {
  4193. return;
  4194. }
  4195. // Read data from the table
  4196. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  4197. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  4198. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4199. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4200. std::vector<float> *Validation_Input1 =
  4201. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4202. std::vector<float> *Validation_Input2 =
  4203. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4204. std::vector<float> *Validation_Input3 =
  4205. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  4206. std::vector<float> *Validation_Expected =
  4207. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4208. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4209. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4210. size_t count = Validation_Input1->size();
  4211. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4212. pDevice, m_support, pStream, "TertiaryFPOp",
  4213. // this callbacked is called when the test
  4214. // is creating the resource to run the test
  4215. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4216. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4217. size_t size = sizeof(STertiaryFPOp) * count;
  4218. Data.resize(size);
  4219. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  4220. for (size_t i = 0; i < count; ++i) {
  4221. STertiaryFPOp *p = &pPrimitives[i];
  4222. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4223. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4224. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4225. }
  4226. // use shader from data table
  4227. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4228. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4229. });
  4230. MappedData data;
  4231. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4232. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  4233. WEX::TestExecution::DisableVerifyExceptions dve;
  4234. for (unsigned i = 0; i < count; ++i) {
  4235. STertiaryFPOp *p = &pPrimitives[i];
  4236. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4237. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  4238. L"%6.8f, expected = %6.8f",
  4239. i, p->input1, p->input2, p->input3, p->output, val);
  4240. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  4241. Validation_Tolerance);
  4242. }
  4243. }
  4244. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  4245. WEX::TestExecution::SetVerifyOutput verifySettings(
  4246. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4247. CComPtr<IStream> pStream;
  4248. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4249. CComPtr<ID3D12Device> pDevice;
  4250. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4251. return;
  4252. }
  4253. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4254. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4255. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4256. return;
  4257. }
  4258. // Read data from the table
  4259. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  4260. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  4261. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4262. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4263. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4264. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4265. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4266. return;
  4267. }
  4268. std::vector<uint16_t> *Validation_Input =
  4269. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4270. std::vector<uint16_t> *Validation_Expected =
  4271. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4272. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4273. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4274. size_t count = Validation_Input->size();
  4275. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4276. pDevice, m_support, pStream, "UnaryFPOp",
  4277. // this callbacked is called when the test
  4278. // is creating the resource to run the test
  4279. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4280. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4281. size_t size = sizeof(SUnaryHalfOp) * count;
  4282. Data.resize(size);
  4283. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  4284. for (size_t i = 0; i < count; ++i) {
  4285. SUnaryHalfOp *p = &pPrimitives[i];
  4286. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4287. }
  4288. // use shader from data table
  4289. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4290. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4291. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4292. });
  4293. MappedData data;
  4294. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4295. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  4296. WEX::TestExecution::DisableVerifyExceptions dve;
  4297. for (unsigned i = 0; i < count; ++i) {
  4298. SUnaryHalfOp *p = &pPrimitives[i];
  4299. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  4300. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4301. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4302. i, ConvertFloat16ToFloat32(p->input), p->input,
  4303. ConvertFloat16ToFloat32(p->output), p->output,
  4304. ConvertFloat16ToFloat32(expected), expected);
  4305. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4306. }
  4307. }
  4308. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  4309. WEX::TestExecution::SetVerifyOutput verifySettings(
  4310. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4311. CComPtr<IStream> pStream;
  4312. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4313. CComPtr<ID3D12Device> pDevice;
  4314. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4315. return;
  4316. }
  4317. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4318. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4319. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4320. return;
  4321. }
  4322. // Read data from the table
  4323. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  4324. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  4325. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4326. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4327. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4328. std::vector<uint16_t> *Validation_Input1 =
  4329. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4330. std::vector<uint16_t> *Validation_Input2 =
  4331. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4332. std::vector<uint16_t> *Validation_Expected1 =
  4333. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4334. std::vector<uint16_t> *Validation_Expected2 =
  4335. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  4336. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4337. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4338. size_t count = Validation_Input1->size();
  4339. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4340. pDevice, m_support, pStream, "BinaryFPOp",
  4341. // this callbacked is called when the test
  4342. // is creating the resource to run the test
  4343. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4344. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4345. size_t size = sizeof(SBinaryHalfOp) * count;
  4346. Data.resize(size);
  4347. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  4348. for (size_t i = 0; i < count; ++i) {
  4349. SBinaryHalfOp *p = &pPrimitives[i];
  4350. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4351. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4352. }
  4353. // use shader from data table
  4354. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4355. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4356. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4357. });
  4358. MappedData data;
  4359. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4360. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  4361. WEX::TestExecution::DisableVerifyExceptions dve;
  4362. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4363. if (numExpected == 2) {
  4364. for (unsigned i = 0; i < count; ++i) {
  4365. SBinaryHalfOp *p = &pPrimitives[i];
  4366. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  4367. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  4368. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  4369. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  4370. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4371. ConvertFloat16ToFloat32(p->input2), p->input2,
  4372. ConvertFloat16ToFloat32(p->output1), p->output1,
  4373. ConvertFloat16ToFloat32(p->output2), p->output2,
  4374. ConvertFloat16ToFloat32(expected1), expected1,
  4375. ConvertFloat16ToFloat32(expected2), expected2);
  4376. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  4377. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  4378. }
  4379. }
  4380. else if (numExpected == 1) {
  4381. for (unsigned i = 0; i < count; ++i) {
  4382. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  4383. SBinaryHalfOp *p = &pPrimitives[i];
  4384. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4385. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4386. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4387. ConvertFloat16ToFloat32(p->output1), p->output1,
  4388. ConvertFloat16ToFloat32(expected), expected);
  4389. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  4390. }
  4391. }
  4392. else {
  4393. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4394. }
  4395. }
  4396. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  4397. WEX::TestExecution::SetVerifyOutput verifySettings(
  4398. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4399. CComPtr<IStream> pStream;
  4400. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4401. CComPtr<ID3D12Device> pDevice;
  4402. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4403. return;
  4404. }
  4405. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4406. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4407. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4408. return;
  4409. }
  4410. // Read data from the table
  4411. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  4412. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  4413. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4414. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4415. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4416. std::vector<uint16_t> *Validation_Input1 =
  4417. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4418. std::vector<uint16_t> *Validation_Input2 =
  4419. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4420. std::vector<uint16_t> *Validation_Input3 =
  4421. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  4422. std::vector<uint16_t> *Validation_Expected =
  4423. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4424. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4425. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4426. size_t count = Validation_Input1->size();
  4427. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4428. pDevice, m_support, pStream, "TertiaryFPOp",
  4429. // this callbacked is called when the test
  4430. // is creating the resource to run the test
  4431. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4432. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4433. size_t size = sizeof(STertiaryHalfOp) * count;
  4434. Data.resize(size);
  4435. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  4436. for (size_t i = 0; i < count; ++i) {
  4437. STertiaryHalfOp *p = &pPrimitives[i];
  4438. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4439. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4440. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4441. }
  4442. // use shader from data table
  4443. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4444. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4445. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4446. });
  4447. MappedData data;
  4448. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4449. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  4450. WEX::TestExecution::DisableVerifyExceptions dve;
  4451. for (unsigned i = 0; i < count; ++i) {
  4452. STertiaryHalfOp *p = &pPrimitives[i];
  4453. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  4454. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  4455. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4456. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4457. ConvertFloat16ToFloat32(p->input2), p->input2,
  4458. ConvertFloat16ToFloat32(p->input3), p->input3,
  4459. ConvertFloat16ToFloat32(p->output), p->output,
  4460. ConvertFloat16ToFloat32(expected), expected);
  4461. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4462. }
  4463. }
  4464. TEST_F(ExecutionTest, UnaryIntOpTest) {
  4465. WEX::TestExecution::SetVerifyOutput verifySettings(
  4466. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4467. CComPtr<IStream> pStream;
  4468. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4469. CComPtr<ID3D12Device> pDevice;
  4470. if (!CreateDevice(&pDevice)) {
  4471. return;
  4472. }
  4473. // Read data from the table
  4474. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  4475. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  4476. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4477. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4478. std::vector<int> *Validation_Input =
  4479. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4480. std::vector<int> *Validation_Expected =
  4481. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4482. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4483. size_t count = Validation_Input->size();
  4484. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4485. pDevice, m_support, pStream, "UnaryIntOp",
  4486. // this callbacked is called when the test
  4487. // is creating the resource to run the test
  4488. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4489. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4490. size_t size = sizeof(SUnaryIntOp) * count;
  4491. Data.resize(size);
  4492. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  4493. for (size_t i = 0; i < count; ++i) {
  4494. SUnaryIntOp *p = &pPrimitives[i];
  4495. int val = (*Validation_Input)[i % Validation_Input->size()];
  4496. p->input = val;
  4497. }
  4498. // use shader data table
  4499. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4500. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4501. });
  4502. MappedData data;
  4503. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4504. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  4505. WEX::TestExecution::DisableVerifyExceptions dve;
  4506. for (unsigned i = 0; i < count; ++i) {
  4507. SUnaryIntOp *p = &pPrimitives[i];
  4508. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4509. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  4510. L"expected = %11i(0x%08x)",
  4511. i, p->input, p->input, p->output, p->output, val, val);
  4512. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4513. }
  4514. }
  4515. TEST_F(ExecutionTest, UnaryUintOpTest) {
  4516. WEX::TestExecution::SetVerifyOutput verifySettings(
  4517. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4518. CComPtr<IStream> pStream;
  4519. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4520. CComPtr<ID3D12Device> pDevice;
  4521. if (!CreateDevice(&pDevice)) {
  4522. return;
  4523. }
  4524. // Read data from the table
  4525. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  4526. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  4527. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4528. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4529. std::vector<unsigned int> *Validation_Input =
  4530. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4531. std::vector<unsigned int> *Validation_Expected =
  4532. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4533. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4534. size_t count = Validation_Input->size();
  4535. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4536. pDevice, m_support, pStream, "UnaryUintOp",
  4537. // this callbacked is called when the test
  4538. // is creating the resource to run the test
  4539. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4540. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4541. size_t size = sizeof(SUnaryUintOp) * count;
  4542. Data.resize(size);
  4543. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  4544. for (size_t i = 0; i < count; ++i) {
  4545. SUnaryUintOp *p = &pPrimitives[i];
  4546. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  4547. p->input = val;
  4548. }
  4549. // use shader data table
  4550. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4551. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4552. });
  4553. MappedData data;
  4554. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4555. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  4556. WEX::TestExecution::DisableVerifyExceptions dve;
  4557. for (unsigned i = 0; i < count; ++i) {
  4558. SUnaryUintOp *p = &pPrimitives[i];
  4559. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4560. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  4561. L"expected = %11u(0x%08x)",
  4562. i, p->input, p->input, p->output, p->output, val, val);
  4563. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4564. }
  4565. }
  4566. TEST_F(ExecutionTest, BinaryIntOpTest) {
  4567. WEX::TestExecution::SetVerifyOutput verifySettings(
  4568. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4569. CComPtr<IStream> pStream;
  4570. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4571. CComPtr<ID3D12Device> pDevice;
  4572. if (!CreateDevice(&pDevice)) {
  4573. return;
  4574. }
  4575. // Read data from the table
  4576. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  4577. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  4578. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4579. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4580. std::vector<int> *Validation_Input1 =
  4581. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4582. std::vector<int> *Validation_Input2 =
  4583. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4584. std::vector<int> *Validation_Expected1 =
  4585. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4586. std::vector<int> *Validation_Expected2 =
  4587. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  4588. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4589. size_t count = Validation_Input1->size();
  4590. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4591. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4592. pDevice, m_support, pStream, "BinaryIntOp",
  4593. // this callbacked is called when the test
  4594. // is creating the resource to run the test
  4595. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4596. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4597. size_t size = sizeof(SBinaryIntOp) * count;
  4598. Data.resize(size);
  4599. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  4600. for (size_t i = 0; i < count; ++i) {
  4601. SBinaryIntOp *p = &pPrimitives[i];
  4602. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4603. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4604. p->input1 = val1;
  4605. p->input2 = val2;
  4606. }
  4607. // use shader from data table
  4608. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4609. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4610. });
  4611. MappedData data;
  4612. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4613. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  4614. WEX::TestExecution::DisableVerifyExceptions dve;
  4615. if (numExpected == 2) {
  4616. for (unsigned i = 0; i < count; ++i) {
  4617. SBinaryIntOp *p = &pPrimitives[i];
  4618. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4619. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4620. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4621. L"%11i(0x%08x), output1 = "
  4622. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  4623. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  4624. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4625. p->output1, val1, val1, p->output2, p->output2, val2,
  4626. val2);
  4627. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4628. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4629. }
  4630. }
  4631. else if (numExpected == 1) {
  4632. for (unsigned i = 0; i < count; ++i) {
  4633. SBinaryIntOp *p = &pPrimitives[i];
  4634. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4635. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4636. L"%11i(0x%08x), output = "
  4637. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  4638. p->input1, p->input1, p->input2, p->input2,
  4639. p->output1, p->output1, val1, val1);
  4640. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4641. }
  4642. }
  4643. else {
  4644. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4645. }
  4646. }
  4647. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  4648. WEX::TestExecution::SetVerifyOutput verifySettings(
  4649. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4650. CComPtr<IStream> pStream;
  4651. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4652. CComPtr<ID3D12Device> pDevice;
  4653. if (!CreateDevice(&pDevice)) {
  4654. return;
  4655. }
  4656. // Read data from the table
  4657. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  4658. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  4659. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4660. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4661. std::vector<int> *Validation_Input1 =
  4662. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4663. std::vector<int> *Validation_Input2 =
  4664. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4665. std::vector<int> *Validation_Input3 =
  4666. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4667. std::vector<int> *Validation_Expected =
  4668. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4669. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4670. size_t count = Validation_Input1->size();
  4671. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4672. pDevice, m_support, pStream, "TertiaryIntOp",
  4673. // this callbacked is called when the test
  4674. // is creating the resource to run the test
  4675. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4676. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4677. size_t size = sizeof(STertiaryIntOp) * count;
  4678. Data.resize(size);
  4679. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  4680. for (size_t i = 0; i < count; ++i) {
  4681. STertiaryIntOp *p = &pPrimitives[i];
  4682. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4683. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4684. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4685. p->input1 = val1;
  4686. p->input2 = val2;
  4687. p->input3 = val3;
  4688. }
  4689. // use shader from data table
  4690. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4691. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4692. });
  4693. MappedData data;
  4694. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4695. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  4696. WEX::TestExecution::DisableVerifyExceptions dve;
  4697. for (unsigned i = 0; i < count; ++i) {
  4698. STertiaryIntOp *p = &pPrimitives[i];
  4699. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4700. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4701. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4702. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4703. i, p->input1, p->input1, p->input2, p->input2,
  4704. p->input3, p->input3, p->output, p->output, val1,
  4705. val1);
  4706. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4707. }
  4708. }
  4709. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4710. WEX::TestExecution::SetVerifyOutput verifySettings(
  4711. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4712. CComPtr<IStream> pStream;
  4713. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4714. CComPtr<ID3D12Device> pDevice;
  4715. if (!CreateDevice(&pDevice)) {
  4716. return;
  4717. }
  4718. // Read data from the table
  4719. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4720. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4721. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4722. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4723. std::vector<unsigned int> *Validation_Input1 =
  4724. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4725. std::vector<unsigned int> *Validation_Input2 =
  4726. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4727. std::vector<unsigned int> *Validation_Expected1 =
  4728. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4729. std::vector<unsigned int> *Validation_Expected2 =
  4730. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4731. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4732. size_t count = Validation_Input1->size();
  4733. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4734. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4735. pDevice, m_support, pStream, "BinaryUintOp",
  4736. // this callbacked is called when the test
  4737. // is creating the resource to run the test
  4738. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4739. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4740. size_t size = sizeof(SBinaryUintOp) * count;
  4741. Data.resize(size);
  4742. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4743. for (size_t i = 0; i < count; ++i) {
  4744. SBinaryUintOp *p = &pPrimitives[i];
  4745. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4746. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4747. p->input1 = val1;
  4748. p->input2 = val2;
  4749. }
  4750. // use shader from data table
  4751. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4752. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4753. });
  4754. MappedData data;
  4755. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4756. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4757. WEX::TestExecution::DisableVerifyExceptions dve;
  4758. if (numExpected == 2) {
  4759. for (unsigned i = 0; i < count; ++i) {
  4760. SBinaryUintOp *p = &pPrimitives[i];
  4761. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4762. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4763. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4764. L"%11u(0x%08x), output1 = "
  4765. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4766. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4767. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4768. p->output1, val1, val1, p->output2, p->output2, val2,
  4769. val2);
  4770. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4771. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4772. }
  4773. }
  4774. else if (numExpected == 1) {
  4775. for (unsigned i = 0; i < count; ++i) {
  4776. SBinaryUintOp *p = &pPrimitives[i];
  4777. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4778. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4779. L"%11u(0x%08x), output = "
  4780. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4781. p->input1, p->input1, p->input2, p->input2,
  4782. p->output1, p->output1, val1, val1);
  4783. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4784. }
  4785. }
  4786. else {
  4787. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4788. }
  4789. }
  4790. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4791. WEX::TestExecution::SetVerifyOutput verifySettings(
  4792. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4793. CComPtr<IStream> pStream;
  4794. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4795. CComPtr<ID3D12Device> pDevice;
  4796. if (!CreateDevice(&pDevice)) {
  4797. return;
  4798. }
  4799. // Read data from the table
  4800. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4801. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4802. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4803. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4804. std::vector<unsigned int> *Validation_Input1 =
  4805. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4806. std::vector<unsigned int> *Validation_Input2 =
  4807. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4808. std::vector<unsigned int> *Validation_Input3 =
  4809. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4810. std::vector<unsigned int> *Validation_Expected =
  4811. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4812. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4813. size_t count = Validation_Input1->size();
  4814. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4815. pDevice, m_support, pStream, "TertiaryUintOp",
  4816. // this callbacked is called when the test
  4817. // is creating the resource to run the test
  4818. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4819. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4820. size_t size = sizeof(STertiaryUintOp) * count;
  4821. Data.resize(size);
  4822. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4823. for (size_t i = 0; i < count; ++i) {
  4824. STertiaryUintOp *p = &pPrimitives[i];
  4825. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4826. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4827. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4828. p->input1 = val1;
  4829. p->input2 = val2;
  4830. p->input3 = val3;
  4831. }
  4832. // use shader from data table
  4833. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4834. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4835. });
  4836. MappedData data;
  4837. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4838. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  4839. WEX::TestExecution::DisableVerifyExceptions dve;
  4840. for (unsigned i = 0; i < count; ++i) {
  4841. STertiaryUintOp *p = &pPrimitives[i];
  4842. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4843. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4844. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  4845. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4846. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4847. p->output, p->output, val1, val1);
  4848. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4849. }
  4850. }
  4851. // 16 bit integer type tests
  4852. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  4853. WEX::TestExecution::SetVerifyOutput verifySettings(
  4854. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4855. CComPtr<IStream> pStream;
  4856. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4857. CComPtr<ID3D12Device> pDevice;
  4858. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4859. return;
  4860. }
  4861. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4862. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4863. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4864. return;
  4865. }
  4866. // Read data from the table
  4867. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  4868. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  4869. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4870. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4871. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4872. std::vector<short> *Validation_Input =
  4873. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4874. std::vector<short> *Validation_Expected =
  4875. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4876. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4877. size_t count = Validation_Input->size();
  4878. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4879. pDevice, m_support, pStream, "UnaryIntOp",
  4880. // this callbacked is called when the test
  4881. // is creating the resource to run the test
  4882. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4883. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4884. size_t size = sizeof(SUnaryInt16Op) * count;
  4885. Data.resize(size);
  4886. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  4887. for (size_t i = 0; i < count; ++i) {
  4888. SUnaryInt16Op *p = &pPrimitives[i];
  4889. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4890. }
  4891. // use shader data table
  4892. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4893. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4894. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4895. });
  4896. MappedData data;
  4897. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4898. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  4899. WEX::TestExecution::DisableVerifyExceptions dve;
  4900. for (unsigned i = 0; i < count; ++i) {
  4901. SUnaryInt16Op *p = &pPrimitives[i];
  4902. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  4903. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  4904. L"expected = %5hi(0x%08x)",
  4905. i, p->input, p->input, p->output, p->output, val, val);
  4906. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4907. }
  4908. }
  4909. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  4910. WEX::TestExecution::SetVerifyOutput verifySettings(
  4911. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4912. CComPtr<IStream> pStream;
  4913. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4914. CComPtr<ID3D12Device> pDevice;
  4915. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4916. return;
  4917. }
  4918. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4919. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4920. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4921. return;
  4922. }
  4923. // Read data from the table
  4924. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  4925. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  4926. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4927. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4928. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4929. std::vector<unsigned short> *Validation_Input =
  4930. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  4931. std::vector<unsigned short> *Validation_Expected =
  4932. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  4933. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4934. size_t count = Validation_Input->size();
  4935. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4936. pDevice, m_support, pStream, "UnaryUintOp",
  4937. // this callbacked is called when the test
  4938. // is creating the resource to run the test
  4939. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4940. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4941. size_t size = sizeof(SUnaryUint16Op) * count;
  4942. Data.resize(size);
  4943. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  4944. for (size_t i = 0; i < count; ++i) {
  4945. SUnaryUint16Op *p = &pPrimitives[i];
  4946. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4947. }
  4948. // use shader data table
  4949. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4950. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4951. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4952. });
  4953. MappedData data;
  4954. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4955. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  4956. WEX::TestExecution::DisableVerifyExceptions dve;
  4957. for (unsigned i = 0; i < count; ++i) {
  4958. SUnaryUint16Op *p = &pPrimitives[i];
  4959. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  4960. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  4961. L"expected = %5hu(0x%08x)",
  4962. i, p->input, p->input, p->output, p->output, val, val);
  4963. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4964. }
  4965. }
  4966. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  4967. WEX::TestExecution::SetVerifyOutput verifySettings(
  4968. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4969. CComPtr<IStream> pStream;
  4970. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4971. CComPtr<ID3D12Device> pDevice;
  4972. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4973. return;
  4974. }
  4975. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4976. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4977. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4978. return;
  4979. }
  4980. // Read data from the table
  4981. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  4982. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  4983. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4984. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4985. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4986. std::vector<short> *Validation_Input1 =
  4987. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4988. std::vector<short> *Validation_Input2 =
  4989. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  4990. std::vector<short> *Validation_Expected1 =
  4991. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4992. std::vector<short> *Validation_Expected2 =
  4993. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  4994. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4995. size_t count = Validation_Input1->size();
  4996. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4997. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4998. pDevice, m_support, pStream, "BinaryIntOp",
  4999. // this callbacked is called when the test
  5000. // is creating the resource to run the test
  5001. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5002. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  5003. size_t size = sizeof(SBinaryInt16Op) * count;
  5004. Data.resize(size);
  5005. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  5006. for (size_t i = 0; i < count; ++i) {
  5007. SBinaryInt16Op *p = &pPrimitives[i];
  5008. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5009. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5010. }
  5011. // use shader from data table
  5012. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5013. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5014. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5015. });
  5016. MappedData data;
  5017. test->Test->GetReadBackData("SBinaryIntOp", &data);
  5018. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  5019. WEX::TestExecution::DisableVerifyExceptions dve;
  5020. if (numExpected == 2) {
  5021. for (unsigned i = 0; i < count; ++i) {
  5022. SBinaryInt16Op *p = &pPrimitives[i];
  5023. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5024. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5025. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5026. L"%5hi(0x%08x), output1 = "
  5027. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  5028. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  5029. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5030. p->output1, val1, val1, p->output2, p->output2, val2,
  5031. val2);
  5032. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5033. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5034. }
  5035. }
  5036. else if (numExpected == 1) {
  5037. for (unsigned i = 0; i < count; ++i) {
  5038. SBinaryInt16Op *p = &pPrimitives[i];
  5039. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5040. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5041. L"%5hi(0x%08x), output = "
  5042. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  5043. p->input1, p->input1, p->input2, p->input2,
  5044. p->output1, p->output1, val1, val1);
  5045. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5046. }
  5047. }
  5048. else {
  5049. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5050. }
  5051. }
  5052. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  5053. WEX::TestExecution::SetVerifyOutput verifySettings(
  5054. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5055. CComPtr<IStream> pStream;
  5056. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5057. CComPtr<ID3D12Device> pDevice;
  5058. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5059. return;
  5060. }
  5061. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5062. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5063. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5064. return;
  5065. }
  5066. // Read data from the table
  5067. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  5068. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  5069. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5070. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5071. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5072. std::vector<short> *Validation_Input1 =
  5073. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5074. std::vector<short> *Validation_Input2 =
  5075. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5076. std::vector<short> *Validation_Input3 =
  5077. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  5078. std::vector<short> *Validation_Expected =
  5079. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5080. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5081. size_t count = Validation_Input1->size();
  5082. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5083. pDevice, m_support, pStream, "TertiaryIntOp",
  5084. // this callbacked is called when the test
  5085. // is creating the resource to run the test
  5086. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5087. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  5088. size_t size = sizeof(STertiaryInt16Op) * count;
  5089. Data.resize(size);
  5090. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  5091. for (size_t i = 0; i < count; ++i) {
  5092. STertiaryInt16Op *p = &pPrimitives[i];
  5093. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5094. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5095. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5096. }
  5097. // use shader from data table
  5098. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5099. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5100. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5101. });
  5102. MappedData data;
  5103. test->Test->GetReadBackData("STertiaryIntOp", &data);
  5104. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  5105. WEX::TestExecution::DisableVerifyExceptions dve;
  5106. for (unsigned i = 0; i < count; ++i) {
  5107. STertiaryInt16Op *p = &pPrimitives[i];
  5108. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5109. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  5110. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  5111. L"%11i(0x%08x), expected = %11i(0x%08x)",
  5112. i, p->input1, p->input1, p->input2, p->input2,
  5113. p->input3, p->input3, p->output, p->output, val1,
  5114. val1);
  5115. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5116. }
  5117. }
  5118. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  5119. WEX::TestExecution::SetVerifyOutput verifySettings(
  5120. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5121. CComPtr<IStream> pStream;
  5122. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5123. CComPtr<ID3D12Device> pDevice;
  5124. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5125. return;
  5126. }
  5127. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5128. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5129. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5130. return;
  5131. }
  5132. // Read data from the table
  5133. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  5134. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  5135. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5136. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5137. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5138. std::vector<unsigned short> *Validation_Input1 =
  5139. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5140. std::vector<unsigned short> *Validation_Input2 =
  5141. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5142. std::vector<unsigned short> *Validation_Expected1 =
  5143. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5144. std::vector<unsigned short> *Validation_Expected2 =
  5145. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  5146. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5147. size_t count = Validation_Input1->size();
  5148. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5149. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5150. pDevice, m_support, pStream, "BinaryUintOp",
  5151. // this callbacked is called when the test
  5152. // is creating the resource to run the test
  5153. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5154. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  5155. size_t size = sizeof(SBinaryUint16Op) * count;
  5156. Data.resize(size);
  5157. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  5158. for (size_t i = 0; i < count; ++i) {
  5159. SBinaryUint16Op *p = &pPrimitives[i];
  5160. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5161. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5162. }
  5163. // use shader from data table
  5164. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5165. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5166. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5167. });
  5168. MappedData data;
  5169. test->Test->GetReadBackData("SBinaryUintOp", &data);
  5170. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  5171. WEX::TestExecution::DisableVerifyExceptions dve;
  5172. if (numExpected == 2) {
  5173. for (unsigned i = 0; i < count; ++i) {
  5174. SBinaryUint16Op *p = &pPrimitives[i];
  5175. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5176. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5177. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5178. L"%5hu(0x%08x), output1 = "
  5179. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  5180. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  5181. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5182. p->output1, val1, val1, p->output2, p->output2, val2,
  5183. val2);
  5184. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5185. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5186. }
  5187. }
  5188. else if (numExpected == 1) {
  5189. for (unsigned i = 0; i < count; ++i) {
  5190. SBinaryUint16Op *p = &pPrimitives[i];
  5191. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5192. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5193. L"%5hu(0x%08x), output = "
  5194. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5195. p->input1, p->input1, p->input2, p->input2,
  5196. p->output1, p->output1, val1, val1);
  5197. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5198. }
  5199. }
  5200. else {
  5201. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5202. }
  5203. }
  5204. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  5205. WEX::TestExecution::SetVerifyOutput verifySettings(
  5206. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5207. CComPtr<IStream> pStream;
  5208. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5209. CComPtr<ID3D12Device> pDevice;
  5210. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5211. return;
  5212. }
  5213. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5214. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5215. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5216. return;
  5217. }
  5218. // Read data from the table
  5219. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  5220. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  5221. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5222. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5223. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5224. std::vector<unsigned short> *Validation_Input1 =
  5225. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5226. std::vector<unsigned short> *Validation_Input2 =
  5227. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5228. std::vector<unsigned short> *Validation_Input3 =
  5229. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  5230. std::vector<unsigned short> *Validation_Expected =
  5231. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5232. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5233. size_t count = Validation_Input1->size();
  5234. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5235. pDevice, m_support, pStream, "TertiaryUintOp",
  5236. // this callbacked is called when the test
  5237. // is creating the resource to run the test
  5238. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5239. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  5240. size_t size = sizeof(STertiaryUint16Op) * count;
  5241. Data.resize(size);
  5242. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  5243. for (size_t i = 0; i < count; ++i) {
  5244. STertiaryUint16Op *p = &pPrimitives[i];
  5245. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5246. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5247. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5248. }
  5249. // use shader from data table
  5250. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5251. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5252. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5253. });
  5254. MappedData data;
  5255. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5256. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  5257. WEX::TestExecution::DisableVerifyExceptions dve;
  5258. for (unsigned i = 0; i < count; ++i) {
  5259. STertiaryUint16Op *p = &pPrimitives[i];
  5260. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5261. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5262. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  5263. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5264. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5265. p->output, p->output, val1, val1);
  5266. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5267. }
  5268. }
  5269. TEST_F(ExecutionTest, DotTest) {
  5270. WEX::TestExecution::SetVerifyOutput verifySettings(
  5271. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5272. CComPtr<IStream> pStream;
  5273. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5274. CComPtr<ID3D12Device> pDevice;
  5275. if (!CreateDevice(&pDevice)) {
  5276. return;
  5277. }
  5278. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  5279. TableParameterHandler handler(DotOpParameters, tableSize);
  5280. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5281. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5282. std::vector<WEX::Common::String> *Validation_Input1 =
  5283. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5284. std::vector<WEX::Common::String> *Validation_Input2 =
  5285. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5286. std::vector<WEX::Common::String> *Validation_dot2 =
  5287. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5288. std::vector<WEX::Common::String> *Validation_dot3 =
  5289. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  5290. std::vector<WEX::Common::String> *Validation_dot4 =
  5291. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  5292. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5293. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5294. size_t count = Validation_Input1->size();
  5295. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5296. pDevice, m_support, pStream, "DotOp",
  5297. // this callbacked is called when the test
  5298. // is creating the resource to run the test
  5299. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5300. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  5301. size_t size = sizeof(SDotOp) * count;
  5302. Data.resize(size);
  5303. SDotOp *pPrimitives = (SDotOp*)Data.data();
  5304. for (size_t i = 0; i < count; ++i) {
  5305. SDotOp *p = &pPrimitives[i];
  5306. XMFLOAT4 val1,val2;
  5307. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  5308. (float *)&val1, 4));
  5309. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  5310. (float *)&val2, 4));
  5311. p->input1 = val1;
  5312. p->input2 = val2;
  5313. }
  5314. // use shader from data table
  5315. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5316. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5317. });
  5318. MappedData data;
  5319. test->Test->GetReadBackData("SDotOp", &data);
  5320. SDotOp *pPrimitives = (SDotOp*)data.data();
  5321. WEX::TestExecution::DisableVerifyExceptions dve;
  5322. for (size_t i = 0; i < count; ++i) {
  5323. SDotOp *p = &pPrimitives[i];
  5324. float dot2, dot3, dot4;
  5325. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  5326. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  5327. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  5328. LogCommentFmt(
  5329. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  5330. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  5331. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  5332. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  5333. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  5334. p->o_dot4, dot4);
  5335. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  5336. tolerance);
  5337. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  5338. tolerance);
  5339. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  5340. tolerance);
  5341. }
  5342. }
  5343. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  5344. WEX::TestExecution::SetVerifyOutput verifySettings(
  5345. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5346. CComPtr<IStream> pStream;
  5347. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5348. CComPtr<ID3D12Device> pDevice;
  5349. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5350. return;
  5351. }
  5352. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5353. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5354. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5355. return;
  5356. }
  5357. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  5358. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  5359. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5360. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5361. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5362. std::vector<WEX::Common::String> *validation_input1 =
  5363. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5364. std::vector<WEX::Common::String> *validation_input2 =
  5365. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5366. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  5367. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  5368. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5369. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5370. size_t count = validation_input1->size();
  5371. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5372. pDevice, m_support, pStream, "Dot2AddHalfOp",
  5373. // this callback is called when the test
  5374. // is creating the resource to run the test
  5375. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5376. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  5377. size_t size = sizeof(SDot2AddHalfOp) * count;
  5378. Data.resize(size);
  5379. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  5380. for (size_t i = 0; i < count; ++i) {
  5381. SDot2AddHalfOp *p = &pPrimitives[i];
  5382. Half2 val1,val2;
  5383. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  5384. (uint16_t *)&val1, 2));
  5385. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  5386. (uint16_t *)&val2, 2));
  5387. p->input1 = val1;
  5388. p->input2 = val2;
  5389. p->acc = (*validation_acc)[i];
  5390. }
  5391. // use shader from data table
  5392. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5393. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5394. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5395. });
  5396. MappedData data;
  5397. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  5398. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  5399. WEX::TestExecution::DisableVerifyExceptions dve;
  5400. for (size_t i = 0; i < count; ++i) {
  5401. SDot2AddHalfOp *p = &pPrimitives[i];
  5402. float expectedResult = (*validation_result)[i];
  5403. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  5404. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  5405. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  5406. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  5407. LogCommentFmt(
  5408. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  5409. L"result = %f, result_expected = %f",
  5410. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  5411. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  5412. }
  5413. }
  5414. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  5415. WEX::TestExecution::SetVerifyOutput verifySettings(
  5416. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5417. CComPtr<IStream> pStream;
  5418. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5419. CComPtr<ID3D12Device> pDevice;
  5420. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5421. return;
  5422. }
  5423. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  5424. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  5425. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5426. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5427. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5428. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5429. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  5430. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  5431. size_t count = validation_input1->size();
  5432. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5433. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  5434. // this callback is called when the test
  5435. // is creating the resource to run the test
  5436. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5437. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  5438. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  5439. Data.resize(size);
  5440. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  5441. for (size_t i = 0; i < count; ++i) {
  5442. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5443. p->input1 = (*validation_input1)[i];
  5444. p->input2 = (*validation_input2)[i];
  5445. p->acc = (*validation_acc)[i];
  5446. }
  5447. // use shader from data table
  5448. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5449. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5450. });
  5451. MappedData data;
  5452. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  5453. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  5454. WEX::TestExecution::DisableVerifyExceptions dve;
  5455. for (size_t i = 0; i < count; ++i) {
  5456. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5457. int32_t expectedResult = (*validation_result)[i];
  5458. LogCommentFmt(
  5459. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  5460. L"result = %d, result_expected = %d",
  5461. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5462. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  5463. }
  5464. }
  5465. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  5466. WEX::TestExecution::SetVerifyOutput verifySettings(
  5467. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5468. CComPtr<IStream> pStream;
  5469. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5470. CComPtr<ID3D12Device> pDevice;
  5471. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5472. return;
  5473. }
  5474. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  5475. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  5476. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5477. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5478. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5479. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5480. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  5481. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  5482. size_t count = validation_input1->size();
  5483. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5484. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  5485. // this callback is called when the test
  5486. // is creating the resource to run the test
  5487. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5488. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  5489. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  5490. Data.resize(size);
  5491. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  5492. for (size_t i = 0; i < count; ++i) {
  5493. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5494. p->input1 = (*validation_input1)[i];
  5495. p->input2 = (*validation_input2)[i];
  5496. p->acc = (*validation_acc)[i];
  5497. }
  5498. // use shader from data table
  5499. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5500. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5501. });
  5502. MappedData data;
  5503. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  5504. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  5505. WEX::TestExecution::DisableVerifyExceptions dve;
  5506. for (size_t i = 0; i < count; ++i) {
  5507. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5508. uint32_t expectedResult = (*validation_result)[i];
  5509. LogCommentFmt(
  5510. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  5511. L"result = %u, result_expected = %u, ",
  5512. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5513. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  5514. }
  5515. }
  5516. TEST_F(ExecutionTest, Msad4Test) {
  5517. WEX::TestExecution::SetVerifyOutput verifySettings(
  5518. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5519. CComPtr<IStream> pStream;
  5520. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5521. CComPtr<ID3D12Device> pDevice;
  5522. if (!CreateDevice(&pDevice)) {
  5523. return;
  5524. }
  5525. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  5526. TableParameterHandler handler(Msad4OpParameters, tableSize);
  5527. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5528. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5529. std::vector<unsigned int> *Validation_Reference =
  5530. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5531. std::vector<WEX::Common::String> *Validation_Source =
  5532. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5533. std::vector<WEX::Common::String> *Validation_Accum =
  5534. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  5535. std::vector<WEX::Common::String> *Validation_Expected =
  5536. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5537. size_t count = Validation_Expected->size();
  5538. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5539. pDevice, m_support, pStream, "Msad4",
  5540. // this callbacked is called when the test
  5541. // is creating the resource to run the test
  5542. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5543. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  5544. size_t size = sizeof(SMsad4) * count;
  5545. Data.resize(size);
  5546. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  5547. for (size_t i = 0; i < count; ++i) {
  5548. SMsad4 *p = &pPrimitives[i];
  5549. XMUINT2 src;
  5550. XMUINT4 accum;
  5551. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  5552. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  5553. p->ref = (*Validation_Reference)[i];
  5554. p->src = src;
  5555. p->accum = accum;
  5556. }
  5557. // use shader from data table
  5558. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5559. });
  5560. MappedData data;
  5561. test->Test->GetReadBackData("SMsad4", &data);
  5562. SMsad4 *pPrimitives = (SMsad4*)data.data();
  5563. WEX::TestExecution::DisableVerifyExceptions dve;
  5564. for (size_t i = 0; i < count; ++i) {
  5565. SMsad4 *p = &pPrimitives[i];
  5566. XMUINT4 result;
  5567. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  5568. (unsigned int *)&result, 4));
  5569. LogCommentFmt(
  5570. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  5571. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5572. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5573. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  5574. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  5575. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  5576. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  5577. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  5578. result.x, result.x, result.y, result.y, result.z, result.z,
  5579. result.w, result.w);
  5580. int toleranceInt = (int)tolerance;
  5581. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  5582. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  5583. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  5584. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  5585. }
  5586. }
  5587. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  5588. WEX::TestExecution::SetVerifyOutput verifySettings(
  5589. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5590. CComPtr<IStream> pStream;
  5591. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5592. CComPtr<ID3D12Device> pDevice;
  5593. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5594. return;
  5595. }
  5596. // Read data from the table
  5597. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  5598. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  5599. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5600. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5601. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5602. std::vector<WEX::Common::String> *Validation_Input1 =
  5603. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5604. std::vector<WEX::Common::String> *Validation_Input2 =
  5605. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5606. std::vector<WEX::Common::String> *Validation_Expected1 =
  5607. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5608. // two expected outputs for any mode
  5609. std::vector<WEX::Common::String> *Validation_Expected2 =
  5610. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5611. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5612. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5613. size_t count = Validation_Input1->size();
  5614. using namespace hlsl::DXIL;
  5615. Float32DenormMode mode = Float32DenormMode::Any;
  5616. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5617. mode = Float32DenormMode::Preserve;
  5618. }
  5619. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5620. mode = Float32DenormMode::FTZ;
  5621. }
  5622. if (mode == Float32DenormMode::Any) {
  5623. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5624. "must have same number of expected values");
  5625. }
  5626. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5627. pDevice, m_support, pStream, "BinaryFPOp",
  5628. // this callbacked is called when the test
  5629. // is creating the resource to run the test
  5630. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5631. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  5632. size_t size = sizeof(SBinaryFPOp) * count;
  5633. Data.resize(size);
  5634. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  5635. for (size_t i = 0; i < count; ++i) {
  5636. SBinaryFPOp *p = &pPrimitives[i];
  5637. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5638. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5639. float val1, val2;
  5640. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5641. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5642. p->input1 = val1;
  5643. p->input2 = val2;
  5644. }
  5645. // use shader from data table
  5646. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5647. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5648. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5649. });
  5650. MappedData data;
  5651. test->Test->GetReadBackData("SBinaryFPOp", &data);
  5652. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  5653. WEX::TestExecution::DisableVerifyExceptions dve;
  5654. for (unsigned i = 0; i < count; ++i) {
  5655. SBinaryFPOp *p = &pPrimitives[i];
  5656. if (mode == Float32DenormMode::Any) {
  5657. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5658. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5659. float val1;
  5660. float val2;
  5661. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5662. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5663. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5664. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5665. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  5666. VERIFY_IS_TRUE(
  5667. CompareOutputWithExpectedValueFloat(
  5668. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  5669. CompareOutputWithExpectedValueFloat(
  5670. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  5671. }
  5672. else {
  5673. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5674. float val1;
  5675. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5676. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5677. L"%6.8f, expected = %6.8f(%a)",
  5678. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  5679. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  5680. Validation_Tolerance, mode);
  5681. }
  5682. }
  5683. }
  5684. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  5685. WEX::TestExecution::SetVerifyOutput verifySettings(
  5686. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5687. CComPtr<IStream> pStream;
  5688. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5689. CComPtr<ID3D12Device> pDevice;
  5690. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5691. return;
  5692. }
  5693. // Read data from the table
  5694. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  5695. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  5696. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5697. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5698. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5699. std::vector<WEX::Common::String> *Validation_Input1 =
  5700. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5701. std::vector<WEX::Common::String> *Validation_Input2 =
  5702. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5703. std::vector<WEX::Common::String> *Validation_Input3 =
  5704. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5705. std::vector<WEX::Common::String> *Validation_Expected1 =
  5706. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5707. // two expected outputs for any mode
  5708. std::vector<WEX::Common::String> *Validation_Expected2 =
  5709. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5710. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5711. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5712. size_t count = Validation_Input1->size();
  5713. using namespace hlsl::DXIL;
  5714. Float32DenormMode mode = Float32DenormMode::Any;
  5715. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5716. mode = Float32DenormMode::Preserve;
  5717. }
  5718. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5719. mode = Float32DenormMode::FTZ;
  5720. }
  5721. if (mode == Float32DenormMode::Any) {
  5722. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5723. "must have same number of expected values");
  5724. }
  5725. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5726. pDevice, m_support, pStream, "TertiaryFPOp",
  5727. // this callbacked is called when the test
  5728. // is creating the resource to run the test
  5729. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5730. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5731. size_t size = sizeof(STertiaryFPOp) * count;
  5732. Data.resize(size);
  5733. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5734. for (size_t i = 0; i < count; ++i) {
  5735. STertiaryFPOp *p = &pPrimitives[i];
  5736. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5737. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5738. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5739. float val1, val2, val3;
  5740. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5741. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5742. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5743. p->input1 = val1;
  5744. p->input2 = val2;
  5745. p->input3 = val3;
  5746. }
  5747. // use shader from data table
  5748. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5749. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5750. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5751. });
  5752. MappedData data;
  5753. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5754. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5755. WEX::TestExecution::DisableVerifyExceptions dve;
  5756. for (unsigned i = 0; i < count; ++i) {
  5757. STertiaryFPOp *p = &pPrimitives[i];
  5758. if (mode == Float32DenormMode::Any) {
  5759. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5760. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5761. float val1;
  5762. float val2;
  5763. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5764. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5765. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5766. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5767. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5768. VERIFY_IS_TRUE(
  5769. CompareOutputWithExpectedValueFloat(
  5770. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5771. CompareOutputWithExpectedValueFloat(
  5772. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5773. }
  5774. else {
  5775. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5776. float val1;
  5777. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5778. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5779. L"%6.8f, expected = %6.8f(%a)",
  5780. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5781. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5782. Validation_Tolerance, mode);
  5783. }
  5784. }
  5785. }
  5786. // Setup for wave intrinsics tests
  5787. enum class ShaderOpKind {
  5788. WaveSum,
  5789. WaveProduct,
  5790. WaveActiveMax,
  5791. WaveActiveMin,
  5792. WaveCountBits,
  5793. WaveActiveAllEqual,
  5794. WaveActiveAnyTrue,
  5795. WaveActiveAllTrue,
  5796. WaveActiveBitOr,
  5797. WaveActiveBitAnd,
  5798. WaveActiveBitXor,
  5799. ShaderOpInvalid
  5800. };
  5801. struct ShaderOpKindPair {
  5802. LPCWSTR name;
  5803. ShaderOpKind kind;
  5804. };
  5805. static ShaderOpKindPair ShaderOpKindTable[] = {
  5806. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5807. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5808. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5809. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5810. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5811. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5812. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5813. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5814. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5815. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5816. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5817. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5818. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5819. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5820. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5821. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5822. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5823. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  5824. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  5825. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  5826. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  5827. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  5828. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  5829. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  5830. };
  5831. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  5832. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  5833. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  5834. return ShaderOpKindTable[i].kind;
  5835. }
  5836. }
  5837. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  5838. return ShaderOpKind::ShaderOpInvalid;
  5839. }
  5840. template <typename InType, typename OutType, ShaderOpKind kind>
  5841. struct computeExpected {
  5842. OutType operator()(const std::vector<InType> &inputs,
  5843. const std::vector<int> &masks, int maskValue,
  5844. unsigned int index) {
  5845. return 0;
  5846. }
  5847. };
  5848. template <typename InType, typename OutType>
  5849. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  5850. OutType operator()(const std::vector<InType> &inputs,
  5851. const std::vector<int> &masks, int maskValue,
  5852. unsigned int index) {
  5853. OutType sum = 0;
  5854. for (size_t i = 0; i < index; ++i) {
  5855. if (masks.at(i) == maskValue) {
  5856. sum += inputs.at(i);
  5857. }
  5858. }
  5859. return sum;
  5860. }
  5861. };
  5862. template <typename InType, typename OutType>
  5863. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  5864. OutType operator()(const std::vector<InType> &inputs,
  5865. const std::vector<int> &masks, int maskValue,
  5866. unsigned int index) {
  5867. OutType prod = 1;
  5868. for (size_t i = 0; i < index; ++i) {
  5869. if (masks.at(i) == maskValue) {
  5870. prod *= inputs.at(i);
  5871. }
  5872. }
  5873. return prod;
  5874. }
  5875. };
  5876. template <typename InType, typename OutType>
  5877. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  5878. OutType operator()(const std::vector<InType> &inputs,
  5879. const std::vector<int> &masks, int maskValue,
  5880. unsigned int index) {
  5881. OutType maximum = std::numeric_limits<OutType>::min();
  5882. for (size_t i = 0; i < index; ++i) {
  5883. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  5884. maximum = inputs.at(i);
  5885. }
  5886. return maximum;
  5887. }
  5888. };
  5889. template <typename InType, typename OutType>
  5890. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  5891. OutType operator()(const std::vector<InType> &inputs,
  5892. const std::vector<int> &masks, int maskValue,
  5893. unsigned int index) {
  5894. OutType minimum = std::numeric_limits<OutType>::max();
  5895. for (size_t i = 0; i < index; ++i) {
  5896. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  5897. minimum = inputs.at(i);
  5898. }
  5899. return minimum;
  5900. }
  5901. };
  5902. template <typename InType, typename OutType>
  5903. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  5904. OutType operator()(const std::vector<InType> &inputs,
  5905. const std::vector<int> &masks, int maskValue,
  5906. unsigned int index) {
  5907. OutType count = 0;
  5908. for (size_t i = 0; i < index; ++i) {
  5909. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  5910. count++;
  5911. }
  5912. }
  5913. return count;
  5914. }
  5915. };
  5916. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  5917. // So we cannot use c++ bool type to represent bool in HLSL
  5918. // HLSL returns 0 for false and 1 for true
  5919. template <typename InType, typename OutType>
  5920. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  5921. OutType operator()(const std::vector<InType> &inputs,
  5922. const std::vector<int> &masks, int maskValue,
  5923. unsigned int index) {
  5924. for (size_t i = 0; i < index; ++i) {
  5925. if (masks.at(i) == maskValue && inputs.at(i) != 0) {
  5926. return 1;
  5927. }
  5928. }
  5929. return 0;
  5930. }
  5931. };
  5932. template <typename InType, typename OutType>
  5933. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  5934. OutType operator()(const std::vector<InType> &inputs,
  5935. const std::vector<int> &masks, int maskValue,
  5936. unsigned int index) {
  5937. for (size_t i = 0; i < index; ++i) {
  5938. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  5939. return 0;
  5940. }
  5941. }
  5942. return 1;
  5943. }
  5944. };
  5945. template <typename InType, typename OutType>
  5946. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  5947. OutType operator()(const std::vector<InType> &inputs,
  5948. const std::vector<int> &masks, int maskValue,
  5949. unsigned int index) {
  5950. const InType *val = nullptr;
  5951. for (size_t i = 0; i < index; ++i) {
  5952. if (masks.at(i) == maskValue) {
  5953. if (val && *val != inputs.at(i)) {
  5954. return 0;
  5955. }
  5956. val = &inputs.at(i);
  5957. }
  5958. }
  5959. return 1;
  5960. }
  5961. };
  5962. template <typename InType, typename OutType>
  5963. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  5964. OutType operator()(const std::vector<InType> &inputs,
  5965. const std::vector<int> &masks, int maskValue,
  5966. unsigned int index) {
  5967. OutType bits = 0x00000000;
  5968. for (size_t i = 0; i < index; ++i) {
  5969. if (masks.at(i) == maskValue) {
  5970. bits |= inputs.at(i);
  5971. }
  5972. }
  5973. return bits;
  5974. }
  5975. };
  5976. template <typename InType, typename OutType>
  5977. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  5978. OutType operator()(const std::vector<InType> &inputs,
  5979. const std::vector<int> &masks, int maskValue,
  5980. unsigned int index) {
  5981. OutType bits = 0xffffffff;
  5982. for (size_t i = 0; i < index; ++i) {
  5983. if (masks.at(i) == maskValue) {
  5984. bits &= inputs.at(i);
  5985. }
  5986. }
  5987. return bits;
  5988. }
  5989. };
  5990. template <typename InType, typename OutType>
  5991. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  5992. OutType operator()(const std::vector<InType> &inputs,
  5993. const std::vector<int> &masks, int maskValue,
  5994. unsigned int index) {
  5995. OutType bits = 0x00000000;
  5996. for (size_t i = 0; i < index; ++i) {
  5997. if (masks.at(i) == maskValue) {
  5998. bits ^= inputs.at(i);
  5999. }
  6000. }
  6001. return bits;
  6002. }
  6003. };
  6004. // Mask functions used to control active lanes
  6005. static int MaskAll(int i) {
  6006. UNREFERENCED_PARAMETER(i);
  6007. return 1;
  6008. }
  6009. static int MaskEveryOther(int i) {
  6010. return i % 2 == 0 ? 1 : 0;
  6011. }
  6012. static int MaskEveryThird(int i) {
  6013. return i % 3 == 0 ? 1 : 0;
  6014. }
  6015. typedef int(*MaskFunction)(int);
  6016. static MaskFunction MaskFunctionTable[] = {
  6017. MaskAll, MaskEveryOther, MaskEveryThird
  6018. };
  6019. template <typename InType, typename OutType>
  6020. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  6021. const std::vector<int> &masks,
  6022. int maskValue, unsigned int index,
  6023. LPCWSTR str) {
  6024. ShaderOpKind kind = GetShaderOpKind(str);
  6025. switch (kind) {
  6026. case ShaderOpKind::WaveSum:
  6027. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  6028. case ShaderOpKind::WaveProduct:
  6029. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  6030. case ShaderOpKind::WaveActiveMax:
  6031. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  6032. case ShaderOpKind::WaveActiveMin:
  6033. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  6034. case ShaderOpKind::WaveCountBits:
  6035. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  6036. case ShaderOpKind::WaveActiveBitOr:
  6037. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  6038. case ShaderOpKind::WaveActiveBitAnd:
  6039. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  6040. case ShaderOpKind::WaveActiveBitXor:
  6041. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  6042. case ShaderOpKind::WaveActiveAnyTrue:
  6043. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  6044. case ShaderOpKind::WaveActiveAllTrue:
  6045. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  6046. case ShaderOpKind::WaveActiveAllEqual:
  6047. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  6048. default:
  6049. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  6050. return (OutType) 0;
  6051. }
  6052. };
  6053. // A framework for testing individual wave intrinsics tests.
  6054. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  6055. template <class T1, class T2>
  6056. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  6057. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  6058. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6059. // Resource representation for compute shader
  6060. // firstLaneId is used to group different waves
  6061. // laneIndex is used to identify lane within the wave.
  6062. // Lane ids are not necessarily in same order as thread ids.
  6063. struct PerThreadData {
  6064. unsigned firstLaneId;
  6065. unsigned laneIndex;
  6066. int mask;
  6067. T1 input;
  6068. T2 output;
  6069. };
  6070. unsigned int NumThreadsX = 8;
  6071. unsigned int NumThreadsY = 12;
  6072. unsigned int NumThreadsZ = 1;
  6073. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6074. static const unsigned int DispatchGroupCount = 1;
  6075. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  6076. CComPtr<IStream> pStream;
  6077. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6078. CComPtr<ID3D12Device> pDevice;
  6079. if (!CreateDevice(&pDevice)) {
  6080. return;
  6081. }
  6082. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6083. // Optional feature, so it's correct to not support it if declared as such.
  6084. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6085. return;
  6086. }
  6087. TableParameterHandler handler(pParameterList, numParameter);
  6088. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  6089. // Obtain the list of input lists
  6090. std::vector<std::vector<T1>*> InputDataList;
  6091. for (unsigned int i = 0;
  6092. i < numInputSet; ++i) {
  6093. std::wstring inputName = L"Validation.InputSet";
  6094. inputName.append(std::to_wstring(i + 1));
  6095. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  6096. }
  6097. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  6098. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6099. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6100. // Running compute shader for each input set with different masks
  6101. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  6102. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  6103. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  6104. pDevice, m_support, "WaveIntrinsicsOp",
  6105. // this callbacked is called when the test
  6106. // is creating the resource to run the test
  6107. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6108. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  6109. size_t size = sizeof(PerThreadData) * ThreadCount;
  6110. Data.resize(size);
  6111. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  6112. // 4 different inputs for each operation test
  6113. size_t index = 0;
  6114. std::vector<T1> *IntList = InputDataList[setIndex];
  6115. while (index < ThreadCount) {
  6116. PerThreadData *p = &pPrimitives[index];
  6117. p->firstLaneId = 0xFFFFBFFF;
  6118. p->laneIndex = 0xFFFFBFFF;
  6119. p->mask = MaskFunctionTable[maskIndex]((int)index);
  6120. p->input = (*IntList)[index % IntList->size()];
  6121. p->output = 0xFFFFBFFF;
  6122. index++;
  6123. }
  6124. // use shader from data table
  6125. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6126. }, ShaderOpSet);
  6127. // Check the value
  6128. MappedData data;
  6129. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  6130. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  6131. WEX::TestExecution::DisableVerifyExceptions dve;
  6132. // Grouping data by waves
  6133. std::vector<int> firstLaneIds;
  6134. for (size_t i = 0; i < ThreadCount; ++i) {
  6135. PerThreadData *p = &pPrimitives[i];
  6136. int firstLaneId = p->firstLaneId;
  6137. if (!contains(firstLaneIds, firstLaneId)) {
  6138. firstLaneIds.push_back(firstLaneId);
  6139. }
  6140. }
  6141. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  6142. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6143. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  6144. }
  6145. for (size_t i = 0; i < ThreadCount; ++i) {
  6146. PerThreadData *p = &pPrimitives[i];
  6147. waves[p->firstLaneId].get()->push_back(p);
  6148. }
  6149. // validate for each wave
  6150. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6151. // collect inputs and masks for a given wave
  6152. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  6153. std::vector<T1> inputList(waveData->size());
  6154. std::vector<int> maskList(waveData->size(), -1);
  6155. std::vector<T2> outputList(waveData->size());
  6156. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  6157. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6158. unsigned laneID = waveData->at(j)->laneIndex;
  6159. // ensure that each lane ID is unique and within the range
  6160. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  6161. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  6162. maskList.at(laneID) = waveData->at(j)->mask;
  6163. inputList.at(laneID) = waveData->at(j)->input;
  6164. outputList.at(laneID) = waveData->at(j)->output;
  6165. }
  6166. std::wstring inputStr = L"Wave Inputs: ";
  6167. std::wstring maskStr = L"Wave Masks: ";
  6168. std::wstring outputStr = L"Wave Outputs: ";
  6169. // append input string and mask string in lane id order
  6170. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6171. maskStr.append(std::to_wstring(maskList.at(j)));
  6172. maskStr.append(L" ");
  6173. inputStr.append(std::to_wstring(inputList.at(j)));
  6174. inputStr.append(L" ");
  6175. outputStr.append(std::to_wstring(outputList.at(j)));
  6176. outputStr.append(L" ");
  6177. }
  6178. LogCommentFmt(inputStr.data());
  6179. LogCommentFmt(maskStr.data());
  6180. LogCommentFmt(outputStr.data());
  6181. LogCommentFmt(L"\n");
  6182. // Compute expected output for a given inputs, masks, and index
  6183. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  6184. T2 expected;
  6185. // WaveActive is equivalent to WavePrefix lane # lane count
  6186. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  6187. if (maskList.at(laneIndex) == 1) {
  6188. expected = computeExpectedWithShaderOp<T1, T2>(
  6189. inputList, maskList, 1, index,
  6190. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6191. }
  6192. else {
  6193. expected = computeExpectedWithShaderOp<T1, T2>(
  6194. inputList, maskList, 0, index,
  6195. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6196. }
  6197. // TODO: use different comparison for floating point inputs
  6198. bool equal = outputList.at(laneIndex) == expected;
  6199. if (!equal) {
  6200. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  6201. }
  6202. VERIFY_IS_TRUE(equal);
  6203. }
  6204. }
  6205. }
  6206. }
  6207. }
  6208. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  6209. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  6210. if (GetTestParamUseWARP(true) &&
  6211. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6212. return;
  6213. }
  6214. WaveIntrinsicsActivePrefixTest<int, int>(
  6215. WaveIntrinsicsActiveIntParameters,
  6216. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  6217. /*isPrefix*/ false);
  6218. }
  6219. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  6220. if (GetTestParamUseWARP(true) &&
  6221. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6222. return;
  6223. }
  6224. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6225. WaveIntrinsicsActiveUintParameters,
  6226. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  6227. /*isPrefix*/ false);
  6228. }
  6229. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  6230. if (GetTestParamUseWARP(true) &&
  6231. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6232. return;
  6233. }
  6234. WaveIntrinsicsActivePrefixTest<int, int>(
  6235. WaveIntrinsicsPrefixIntParameters,
  6236. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  6237. /*isPrefix*/ true);
  6238. }
  6239. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  6240. if (GetTestParamUseWARP(true) &&
  6241. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6242. return;
  6243. }
  6244. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6245. WaveIntrinsicsPrefixUintParameters,
  6246. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  6247. /*isPrefix*/ true);
  6248. }
  6249. template <typename T>
  6250. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  6251. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6252. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6253. return static_cast<T>(1);
  6254. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6255. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  6256. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6257. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  6258. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6259. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  6260. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6261. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6262. return static_cast<T>(0);
  6263. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6264. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6265. return static_cast<T>(-1);
  6266. } else {
  6267. return static_cast<T>(0);
  6268. }
  6269. }
  6270. template <typename T>
  6271. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  6272. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6273. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6274. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  6275. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6276. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  6277. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  6278. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6279. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6280. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  6281. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6282. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  6283. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  6284. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6285. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  6286. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  6287. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6288. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6289. // For CountBits, each lane contributes a boolean value. The test input is
  6290. // a zero or non-zero integer. If the input is a non-zero value then the
  6291. // condition is true, thus we contribute one to the bit count.
  6292. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  6293. } else {
  6294. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  6295. }
  6296. }
  6297. template <class T>
  6298. void
  6299. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  6300. size_t numParameters) {
  6301. WEX::TestExecution::SetVerifyOutput
  6302. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6303. struct PerThreadData {
  6304. uint32_t key;
  6305. uint32_t firstLaneId;
  6306. uint32_t laneId;
  6307. uint32_t mask;
  6308. T value;
  6309. T result;
  6310. };
  6311. constexpr size_t NumThreadsX = 8;
  6312. constexpr size_t NumThreadsY = 12;
  6313. constexpr size_t NumThreadsZ = 1;
  6314. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6315. constexpr size_t DispatchGroupSize = 1;
  6316. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  6317. CComPtr<IStream> pStream;
  6318. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6319. CComPtr<ID3D12Device> pDevice;
  6320. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  6321. return;
  6322. }
  6323. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6324. // Optional feature, so it's correct to not support it if declared as such.
  6325. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6326. return;
  6327. }
  6328. std::shared_ptr<st::ShaderOpSet>
  6329. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6330. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6331. TableParameterHandler handler(pParameterList, numParameters);
  6332. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6333. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  6334. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  6335. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  6336. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  6337. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  6338. std::shared_ptr<ShaderOpTestResult> test =
  6339. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  6340. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  6341. UNREFERENCED_PARAMETER(name);
  6342. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  6343. data.resize(dataSize);
  6344. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  6345. for (size_t i = 0; i != ThreadCount; ++i) {
  6346. pThreadData[i].key = keys->at(i % keys->size());
  6347. pThreadData[i].value = values->at(i % values->size());
  6348. pThreadData[i].firstLaneId = 0xdeadbeef;
  6349. pThreadData[i].laneId = 0xdeadbeef;
  6350. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  6351. pThreadData[i].result = 0xdeadbeef;
  6352. }
  6353. pShaderOp->Shaders.at(0).Text = shaderSource;
  6354. pShaderOp->Shaders.at(0).Target = shaderProfile;
  6355. }, ShaderOpSet);
  6356. MappedData mappedData;
  6357. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  6358. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  6359. // Partition our data into waves
  6360. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  6361. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  6362. PerThreadData *elt = &resultData[i];
  6363. // Basic sanity checks
  6364. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  6365. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  6366. waves[elt->firstLaneId].push_back(elt);
  6367. }
  6368. // Verify each wave
  6369. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  6370. for (auto &w : waves) {
  6371. std::vector<PerThreadData *> &waveData = w.second;
  6372. struct {
  6373. bool operator()(PerThreadData *a, PerThreadData *b) const {
  6374. return (a->laneId < b->laneId);
  6375. }
  6376. } compare;
  6377. // Need to sort based on the lane id
  6378. std::sort(waveData.begin(), waveData.end(), compare);
  6379. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  6380. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  6381. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  6382. PerThreadData *data = waveData[i];
  6383. // Compute prefix operation over each previous lane element that has the
  6384. // same key value, and is part of the same active thread group
  6385. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  6386. for (unsigned j = 0; j < i; ++j) {
  6387. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  6388. accum = refFn(accum, waveData[j]->value);
  6389. }
  6390. }
  6391. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  6392. VERIFY_IS_TRUE(accum == data->result);
  6393. }
  6394. LogCommentFmt(L"\n");
  6395. }
  6396. }
  6397. }
  6398. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  6399. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  6400. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  6401. }
  6402. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  6403. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  6404. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  6405. }
  6406. TEST_F(ExecutionTest, CBufferTestHalf) {
  6407. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6408. CComPtr<IStream> pStream;
  6409. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6410. // Single operation test at the moment.
  6411. CComPtr<ID3D12Device> pDevice;
  6412. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  6413. return;
  6414. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6415. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6416. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6417. return;
  6418. }
  6419. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  6420. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  6421. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6422. UNREFERENCED_PARAMETER(pShaderOp);
  6423. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  6424. // use shader from data table.
  6425. Data.resize(sizeof(InputData));
  6426. uint16_t *pData = (uint16_t *)Data.data();
  6427. for (size_t i = 0; i < 4; ++i, ++pData) {
  6428. *pData = InputData[i];
  6429. }
  6430. });
  6431. {
  6432. MappedData data;
  6433. test->Test->GetReadBackData("RTarget", &data);
  6434. const uint16_t *pPixels = (uint16_t *)data.data();
  6435. for (int i = 0; i < 4; ++i) {
  6436. uint16_t output = *(pPixels + i);
  6437. float outputFloat = ConvertFloat16ToFloat32(output);
  6438. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  6439. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  6440. i, inputFloat, InputData[i], outputFloat, output);
  6441. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  6442. }
  6443. }
  6444. }
  6445. TEST_F(ExecutionTest, BarycentricsTest) {
  6446. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6447. CComPtr<IStream> pStream;
  6448. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6449. CComPtr<ID3D12Device> pDevice;
  6450. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  6451. return;
  6452. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  6453. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  6454. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6455. return;
  6456. }
  6457. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  6458. MappedData data;
  6459. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  6460. UINT width = (UINT)D.Width;
  6461. UINT height = D.Height;
  6462. UINT pixelSize = GetByteSizeForFormat(D.Format);
  6463. test->Test->GetReadBackData("RTarget", &data);
  6464. //const uint8_t *pPixels = (uint8_t *)data.data();
  6465. const float *pPixels = (float *)data.data();
  6466. // Get the vertex of barycentric coordinate using VBuffer
  6467. MappedData triangleData;
  6468. test->Test->GetReadBackData("VBuffer", &triangleData);
  6469. const float *pTriangleData = (float*)triangleData.data();
  6470. // get the size of the input data
  6471. unsigned triangleVertexSizeInFloat = 0;
  6472. for (auto element : test->ShaderOp->InputElements)
  6473. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  6474. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  6475. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  6476. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  6477. XMFLOAT3 barycentricWeights[4] = {
  6478. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  6479. XMFLOAT3(0.5f, 0.25f, 0.25f),
  6480. XMFLOAT3(0.25f, 0.5f, 0.25f),
  6481. XMFLOAT3(0.25f, 0.25f, 0.50f)
  6482. };
  6483. float tolerance = 0.001f;
  6484. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  6485. float w0 = barycentricWeights[i].x;
  6486. float w1 = barycentricWeights[i].y;
  6487. float w2 = barycentricWeights[i].z;
  6488. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  6489. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  6490. // map from x1 y1 to rtv pixels
  6491. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  6492. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  6493. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  6494. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  6495. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  6496. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  6497. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  6498. }
  6499. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  6500. }
  6501. static const char RawBufferTestShaderDeclarations[] =
  6502. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  6503. "typedef COMPONENT_TYPE scalar; \r\n"
  6504. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  6505. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  6506. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  6507. "\r\n"
  6508. "struct TestData { \r\n"
  6509. " scalar v1; \r\n"
  6510. " vector2 v2; \r\n"
  6511. " vector3 v3; \r\n"
  6512. " vector4 v4; \r\n"
  6513. "}; \r\n"
  6514. "\r\n"
  6515. "struct UavData {\r\n"
  6516. " TestData input; \r\n"
  6517. " TestData output; \r\n"
  6518. " TestData srvOut; \r\n"
  6519. "}; \r\n"
  6520. "\r\n"
  6521. "ByteAddressBuffer srv0 : register(t0); \r\n"
  6522. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  6523. "ByteAddressBuffer srv2 : register(t2); \r\n"
  6524. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  6525. "\r\n"
  6526. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  6527. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  6528. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  6529. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  6530. static const char RawBufferTestShaderBody[] =
  6531. " // offset of 'out' in 'UavData'\r\n"
  6532. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  6533. "\r\n"
  6534. " // offset of 'srv_out' in 'UavData'\r\n"
  6535. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  6536. "\r\n"
  6537. " // offsets within the 'Data' struct\r\n"
  6538. " const int v1_offset = 0; \r\n"
  6539. " const int v2_offset = COMPONENT_SIZE; \r\n"
  6540. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  6541. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  6542. "\r\n"
  6543. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  6544. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  6545. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  6546. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  6547. "\r\n"
  6548. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  6549. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  6550. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  6551. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  6552. "\r\n"
  6553. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  6554. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  6555. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  6556. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  6557. "\r\n"
  6558. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  6559. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  6560. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  6561. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  6562. "\r\n"
  6563. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  6564. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  6565. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  6566. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  6567. "\r\n"
  6568. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  6569. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  6570. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  6571. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  6572. "\r\n"
  6573. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  6574. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  6575. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  6576. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  6577. "\r\n"
  6578. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  6579. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  6580. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  6581. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  6582. static const char RawBufferTestComputeShaderTemplate[] =
  6583. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6584. "[numthreads(1, 1, 1)]\r\n"
  6585. "void main(uint GI : SV_GroupIndex) {\r\n"
  6586. "%s\r\n" // <- RawBufferTestShaderBody
  6587. "};";
  6588. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  6589. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6590. "struct PSInput { \r\n"
  6591. " float4 pos : SV_POSITION; \r\n"
  6592. "}; \r\n"
  6593. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  6594. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  6595. "%s\r\n" // <- RawBufferTestShaderBody
  6596. " } \r\n"
  6597. " return uint4(1, 2, 3, 4); \r\n"
  6598. "};";
  6599. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  6600. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6601. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  6602. }
  6603. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  6604. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6605. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  6606. }
  6607. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  6608. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6609. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6610. }
  6611. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  6612. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6613. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6614. }
  6615. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  6616. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6617. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  6618. }
  6619. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  6620. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6621. RawBufferLdStTestData<uint16_t> halfData;
  6622. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  6623. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6624. }
  6625. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  6626. }
  6627. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  6628. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6629. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  6630. }
  6631. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  6632. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6633. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  6634. }
  6635. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  6636. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6637. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  6638. }
  6639. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  6640. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6641. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  6642. }
  6643. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  6644. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6645. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  6646. }
  6647. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  6648. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6649. RawBufferLdStTestData<uint16_t> halfData;
  6650. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  6651. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6652. }
  6653. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  6654. }
  6655. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6656. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  6657. char *&sTy, char *&additionalOptions) {
  6658. if (!CreateDevice(&pDevice, shaderModel)) {
  6659. return false;
  6660. }
  6661. additionalOptions = "";
  6662. switch (dataType) {
  6663. case RawBufferLdStType::I64:
  6664. if (!DoesDeviceSupportInt64(pDevice)) {
  6665. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  6666. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6667. return false;
  6668. }
  6669. sTy = "int64_t";
  6670. break;
  6671. case RawBufferLdStType::Double:
  6672. if (!DoesDeviceSupportDouble(pDevice)) {
  6673. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  6674. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6675. return false;
  6676. }
  6677. sTy = "double";
  6678. break;
  6679. case RawBufferLdStType::I16:
  6680. case RawBufferLdStType::Half:
  6681. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6682. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6683. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6684. return false;
  6685. }
  6686. additionalOptions = "-enable-16bit-types";
  6687. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  6688. break;
  6689. case RawBufferLdStType::I32:
  6690. sTy = "int32_t";
  6691. break;
  6692. case RawBufferLdStType::Float:
  6693. sTy = "float";
  6694. break;
  6695. default:
  6696. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  6697. }
  6698. // read shader config
  6699. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6700. return true;
  6701. }
  6702. template <class Ty>
  6703. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6704. // read buffers back & verify expected values
  6705. static const int UavBufferCount = 4;
  6706. char bufferName[11] = "UAVBufferX";
  6707. for (unsigned i = 0; i < UavBufferCount; i++) {
  6708. MappedData dataUav;
  6709. RawBufferLdStUavData<Ty> *pOutData;
  6710. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6711. test->GetReadBackData(bufferName, &dataUav);
  6712. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6713. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6714. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6715. // scalar
  6716. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6717. // vector 2
  6718. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6719. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6720. // vector 3
  6721. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6722. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6723. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6724. // vector 4
  6725. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6726. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6727. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6728. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6729. // verify SRV Store
  6730. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6731. // scalar
  6732. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6733. // vector 2
  6734. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6735. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6736. // vector 3
  6737. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6738. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6739. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6740. // vector 4
  6741. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6742. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6743. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6744. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6745. }
  6746. }
  6747. template <class Ty>
  6748. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6749. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6750. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6751. CComPtr<ID3D12Device> pDevice;
  6752. CComPtr<IStream> pStream;
  6753. char *sTy, *additionalOptions;
  6754. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6755. return;
  6756. }
  6757. // format shader source
  6758. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6759. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6760. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6761. // format compiler args
  6762. char compilerOptions[256];
  6763. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6764. // run the shader
  6765. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6766. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6767. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6768. (Name[9] >= '0' && Name[9] <= '3'));
  6769. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6770. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6771. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6772. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6773. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6774. });
  6775. // verify expected values
  6776. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6777. }
  6778. template <class Ty>
  6779. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6780. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6781. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6782. CComPtr<ID3D12Device> pDevice;
  6783. CComPtr<IStream> pStream;
  6784. char *sTy, *additionalOptions;
  6785. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6786. return;
  6787. }
  6788. // format shader source
  6789. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6790. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6791. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6792. // format compiler args
  6793. char compilerOptions[256];
  6794. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6795. // run the shader
  6796. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6797. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6798. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6799. (Name[9] >= '0' && Name[9] <= '3'));
  6800. // pixel shader is at index 1, vertex shader at index 0
  6801. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6802. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6803. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6804. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6805. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6806. });
  6807. // verify expected values
  6808. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6809. }
  6810. template<typename T>
  6811. uint32_t pack(std::array<T, 4> unpackedVals)
  6812. {
  6813. uint32_t dst = 0;
  6814. constexpr uint32_t bitMask = 0xFF;
  6815. for (uint32_t i = 0U; i < 4U; ++i)
  6816. {
  6817. dst |= (unpackedVals[i] & bitMask) << (i * 8);
  6818. }
  6819. return dst;
  6820. }
  6821. template <typename T>
  6822. uint32_t pack_clamp_u8(std::array<T, 4> unpackedVals)
  6823. {
  6824. int32_t clamp_min = std::numeric_limits<uint8_t>::min();
  6825. int32_t clamp_max = std::numeric_limits<uint8_t>::max();
  6826. uint32_t dst = 0;
  6827. for (uint32_t i = 0U; i < 4U; ++i)
  6828. {
  6829. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6830. dst |= ((uint8_t)clamped) << (i * 8);
  6831. }
  6832. return dst;
  6833. }
  6834. template <typename T>
  6835. uint32_t pack_clamp_s8(std::array<T, 4> unpackedVals)
  6836. {
  6837. int32_t clamp_min = std::numeric_limits<int8_t>::min();
  6838. int32_t clamp_max = std::numeric_limits<int8_t>::max();
  6839. uint32_t dst = 0;
  6840. for (uint32_t i = 0U; i < 4U; ++i)
  6841. {
  6842. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6843. dst |= ((uint8_t)clamped) << (i * 8);
  6844. }
  6845. return dst;
  6846. }
  6847. template<typename T>
  6848. std::array<T, 4> unpack_u(uint32_t packedVal)
  6849. {
  6850. std::array<T, 4> ret;
  6851. ret[0] = (uint8_t)((packedVal & 0x000000FF) >> 0 );
  6852. ret[1] = (uint8_t)((packedVal & 0x0000FF00) >> 8 );
  6853. ret[2] = (uint8_t)((packedVal & 0x00FF0000) >> 16);
  6854. ret[3] = (uint8_t)((packedVal & 0xFF000000) >> 24);
  6855. return ret;
  6856. }
  6857. template<typename T>
  6858. std::array<T, 4> unpack_s(uint32_t packedVal)
  6859. {
  6860. std::array<T, 4> ret;
  6861. ret[0] = (int8_t)((packedVal & 0x000000FF) >> 0 );
  6862. ret[1] = (int8_t)((packedVal & 0x0000FF00) >> 8 );
  6863. ret[2] = (int8_t)((packedVal & 0x00FF0000) >> 16);
  6864. ret[3] = (int8_t)((packedVal & 0xFF000000) >> 24);
  6865. return ret;
  6866. }
  6867. TEST_F(ExecutionTest, PackUnpackTest) {
  6868. WEX::TestExecution::SetVerifyOutput verifySettings(
  6869. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6870. CComPtr<IStream> pStream;
  6871. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6872. CComPtr<ID3D12Device> pDevice;
  6873. #ifdef PACKUNPACK_PLACEHOLDER
  6874. string args = "-enable-16bit-types -DPACKUNPACK_PLACEHOLDER";
  6875. string target = "cs_6_2";
  6876. if (!CreateDevice(&pDevice)) {
  6877. return;
  6878. }
  6879. #else
  6880. string args = "-enable-16bit-types";
  6881. string target = "cs_6_6";
  6882. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  6883. return;
  6884. }
  6885. #endif
  6886. int tableSize = sizeof(PackUnpackOpParameters) / sizeof(TableParameter);
  6887. TableParameterHandler handler(PackUnpackOpParameters, tableSize);
  6888. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6889. std::vector<uint32_t> *validation_input = &handler.GetTableParamByName(L"Validation.Input")->m_uint32Table;
  6890. uint32_t validation_tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_uint;
  6891. size_t count = validation_input->size();
  6892. std::vector<SPackUnpackOpOutPacked> expectedPacked(count / 4);
  6893. std::vector<SPackUnpackOpOutUnpacked> expectedUnpacked(count / 4);
  6894. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  6895. pDevice, m_support, pStream, "PackUnpackOp",
  6896. // this callback is called when the test
  6897. // is creating the resource to run the test
  6898. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6899. if (0 == _stricmp(Name, "g_bufIn"))
  6900. {
  6901. size_t size = sizeof(uint32_t) * 4 * count;
  6902. Data.resize(size);
  6903. uint32_t *pPrimitives = (uint32_t*)Data.data();
  6904. for (size_t i = 0; i < count / 4; ++i) {
  6905. uint32_t *p = &pPrimitives[i * 4];
  6906. uint32_t x = (*validation_input)[i * 4 + 0];
  6907. uint32_t y = (*validation_input)[i * 4 + 1];
  6908. uint32_t z = (*validation_input)[i * 4 + 2];
  6909. uint32_t w = (*validation_input)[i * 4 + 3];
  6910. p[0] = x;
  6911. p[1] = y;
  6912. p[2] = z;
  6913. p[3] = w;
  6914. std::array<uint32_t, 4> inputUint32 = { x, y, z, w };
  6915. std::array<int32_t, 4> inputInt32 = { (int32_t)x, (int32_t)y, (int32_t)z, (int32_t)w };
  6916. std::array<uint16_t, 4> inputUint16 = { (uint16_t)x, (uint16_t)y, (uint16_t)z, (uint16_t)w };
  6917. std::array<int16_t, 4> inputInt16 = { (int16_t)x, (int16_t)y, (int16_t)z, (int16_t)w };
  6918. // Pack unclamped
  6919. expectedPacked[i].packedUint32 = pack(inputUint32);
  6920. expectedPacked[i].packedInt32 = pack(inputInt32);
  6921. expectedPacked[i].packedUint16 = pack(inputUint16);
  6922. expectedPacked[i].packedInt16 = pack(inputInt16);
  6923. // pack clamped
  6924. expectedPacked[i].packedClampedUint32 = pack_clamp_u8(inputInt32);
  6925. expectedPacked[i].packedClampedInt32 = pack_clamp_s8(inputInt32);
  6926. expectedPacked[i].packedClampedUint16 = pack_clamp_u8(inputInt16);
  6927. expectedPacked[i].packedClampedInt16 = pack_clamp_s8(inputInt16);
  6928. // unpack
  6929. expectedUnpacked[i].outputUint32 = unpack_u<uint32_t>(expectedPacked[i].packedUint32);
  6930. expectedUnpacked[i].outputInt32 = unpack_s<int32_t >(expectedPacked[i].packedInt32 );
  6931. expectedUnpacked[i].outputUint16 = unpack_u<uint16_t>(expectedPacked[i].packedUint16);
  6932. expectedUnpacked[i].outputInt16 = unpack_s<int16_t >(expectedPacked[i].packedInt16 );
  6933. expectedUnpacked[i].outputClampedUint32 = unpack_u<uint32_t>(expectedPacked[i].packedClampedUint32);
  6934. expectedUnpacked[i].outputClampedInt32 = unpack_s<int32_t >(expectedPacked[i].packedClampedInt32 );
  6935. expectedUnpacked[i].outputClampedUint16 = unpack_u<uint16_t>(expectedPacked[i].packedClampedUint16);
  6936. expectedUnpacked[i].outputClampedInt16 = unpack_s<int16_t >(expectedPacked[i].packedClampedInt16 );
  6937. }
  6938. }
  6939. else
  6940. {
  6941. std::fill(Data.begin(), Data.end(), 0);
  6942. }
  6943. // use shader from data table
  6944. pShaderOp->Shaders.at(0).Target = target.c_str();
  6945. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6946. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  6947. });
  6948. MappedData packedData;
  6949. test->Test->GetReadBackData("g_bufOutPacked", &packedData);
  6950. SPackUnpackOpOutPacked *readBackPacked = (SPackUnpackOpOutPacked *)packedData.data();
  6951. MappedData unpackedData;
  6952. test->Test->GetReadBackData("g_bufOutPackedUnpacked", &unpackedData);
  6953. SPackUnpackOpOutUnpacked *readBackUnpacked = (SPackUnpackOpOutUnpacked *)unpackedData.data();
  6954. for (size_t i = 0; i < count / 4; ++i)
  6955. {
  6956. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint32, expectedPacked[i].packedUint32, validation_tolerance);
  6957. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt32 , expectedPacked[i].packedInt32 , validation_tolerance);
  6958. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint16, expectedPacked[i].packedUint16, validation_tolerance);
  6959. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt16 , expectedPacked[i].packedInt16 , validation_tolerance);
  6960. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint32, expectedPacked[i].packedClampedUint32, validation_tolerance);
  6961. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt32 , expectedPacked[i].packedClampedInt32 , validation_tolerance);
  6962. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint16, expectedPacked[i].packedClampedUint16, validation_tolerance);
  6963. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt16 , expectedPacked[i].packedClampedInt16 , validation_tolerance);
  6964. for (uint32_t j = 0; j < 4; ++j)
  6965. {
  6966. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint32[j], expectedUnpacked[i].outputUint32[j], validation_tolerance);
  6967. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt32 [j], expectedUnpacked[i].outputInt32 [j], validation_tolerance);
  6968. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint16[j], expectedUnpacked[i].outputUint16[j], validation_tolerance);
  6969. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt16 [j], expectedUnpacked[i].outputInt16 [j], validation_tolerance);
  6970. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint32[j], expectedUnpacked[i].outputClampedUint32[j], validation_tolerance);
  6971. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt32 [j], expectedUnpacked[i].outputClampedInt32 [j], validation_tolerance);
  6972. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint16[j], expectedUnpacked[i].outputClampedUint16[j], validation_tolerance);
  6973. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt16 [j], expectedUnpacked[i].outputClampedInt16 [j], validation_tolerance);
  6974. }
  6975. }
  6976. }
  6977. // This test expects a <pShader> that retrieves a signal value from each of a few
  6978. // resources that are initialized here. <isDynamic> determines if it uses the
  6979. // 6.6 Dynamic Resources feature.
  6980. // Values are read back from the result UAV and compared to the expected signals
  6981. void ExecutionTest::RunResourceTest(ID3D12Device *pDevice, const char *pShader,
  6982. const wchar_t *sm, bool isDynamic) {
  6983. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6984. const int NumSRVs = 3;
  6985. const int NumUAVs = 4;
  6986. const int NumResources = NumSRVs + NumUAVs;
  6987. const int NumSamplers = 2;
  6988. const int valueSize = 16;
  6989. static const int DispatchGroupX = 1;
  6990. static const int DispatchGroupY = 1;
  6991. static const int DispatchGroupZ = 1;
  6992. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  6993. CComPtr<ID3D12CommandQueue> pCommandQueue;
  6994. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  6995. FenceObj FO;
  6996. size_t valueSizeInBytes = valueSize * sizeof(float);
  6997. CreateComputeCommandQueue(pDevice, L"DynamicResourcesTest Command Queue", &pCommandQueue);
  6998. InitFenceObj(pDevice, &FO);
  6999. // Create root signature.
  7000. CComPtr<ID3D12RootSignature> pRootSignature;
  7001. if (!isDynamic) {
  7002. // Not dynamic, create a range for each resource and from them, the root signature
  7003. CD3DX12_DESCRIPTOR_RANGE ranges[NumResources];
  7004. CD3DX12_DESCRIPTOR_RANGE srange[NumSamplers];
  7005. for (int i = 0; i < NumSRVs; i++)
  7006. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, i, 0);
  7007. for (int i = NumSRVs; i < NumResources; i++)
  7008. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, i - NumSRVs, 0);
  7009. for (int i = 0; i < NumSamplers; i++)
  7010. srange[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, i, 0);
  7011. CreateRootSignatureFromRanges(pDevice, &pRootSignature, ranges, NumResources, srange, NumSamplers);
  7012. } else {
  7013. // Dynamic just requires the flags indicating that the builtin arrays should be accessible
  7014. #if !defined(D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)
  7015. #define D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x400
  7016. #define D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x800
  7017. #endif
  7018. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  7019. rootSignatureDesc.Init(0, nullptr, 0, nullptr,
  7020. D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
  7021. D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
  7022. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  7023. }
  7024. // Create pipeline state object.
  7025. CComPtr<ID3D12PipelineState> pComputeState;
  7026. CreateComputePSO(pDevice, pRootSignature, pShader, sm, &pComputeState);
  7027. // Create a command allocator and list for compute.
  7028. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  7029. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  7030. // Set up SRV resources
  7031. CComPtr<ID3D12Resource> pSRVResources[NumSRVs];
  7032. CComPtr<ID3D12Resource> pUAVResources[NumUAVs];
  7033. CComPtr<ID3D12Resource> pUploadResources[NumResources];
  7034. {
  7035. D3D12_RESOURCE_DESC bufDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  7036. float values[valueSize];
  7037. for (int i = 0; i < NumSRVs - 1; i++) {
  7038. for (int j = 0; j < valueSize; j++)
  7039. values[j] = 10.0 + i;
  7040. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufDesc,
  7041. &pSRVResources[i], &pUploadResources[i]);
  7042. }
  7043. D3D12_RESOURCE_DESC tex2dDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 4, 4);
  7044. for (int j = 0; j < valueSize; j++)
  7045. values[j] = 10.0 + (NumSRVs - 1);
  7046. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex2dDesc,
  7047. &pSRVResources[NumSRVs - 1], &pUploadResources[NumSRVs - 1]);
  7048. }
  7049. // Set up UAV resources
  7050. CComPtr<ID3D12Resource> pReadBuffer;
  7051. float values[valueSize];
  7052. for (int i = 0; i < NumUAVs - 2; i++) {
  7053. for (int j = 0; j < valueSize; j++)
  7054. values[j] = 20.0 + i;
  7055. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7056. &pUAVResources[i], &pUploadResources[NumSRVs + i]);
  7057. }
  7058. for (int j = 0; j < valueSize; j++)
  7059. values[j] = 20.0 + (NumUAVs - 1);
  7060. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7061. &pUAVResources[NumUAVs - 2], &pUploadResources[NumResources - 2], &pReadBuffer);
  7062. for (int j = 0; j < valueSize; j++)
  7063. values[j] = 20.0 + (NumUAVs - 2);
  7064. D3D12_RESOURCE_DESC tex1dDesc = CD3DX12_RESOURCE_DESC::Tex1D(DXGI_FORMAT_R32_FLOAT, valueSize, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  7065. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex1dDesc,
  7066. &pUAVResources[NumUAVs - 1], &pUploadResources[NumResources - 1]);
  7067. // Close the command list and execute it to perform the GPU setup.
  7068. pCommandList->Close();
  7069. ExecuteCommandList(pCommandQueue, pCommandList);
  7070. WaitForSignal(pCommandQueue, FO);
  7071. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  7072. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  7073. CComPtr<ID3D12DescriptorHeap> pResHeap;
  7074. CComPtr<ID3D12DescriptorHeap> pSampHeap;
  7075. CreateDefaultDescHeaps(pDevice, NumSRVs + NumUAVs, NumSamplers, &pResHeap, &pSampHeap);
  7076. // Create Rootsignature and descriptor tables
  7077. {
  7078. ID3D12DescriptorHeap *descHeaps[2] = {pResHeap, pSampHeap};
  7079. pCommandList->SetDescriptorHeaps(2, descHeaps);
  7080. pCommandList->SetComputeRootSignature(pRootSignature);
  7081. if (!isDynamic) {
  7082. // Only non-dynamic resources require descriptortables
  7083. pCommandList->SetComputeRootDescriptorTable(0, pResHeap->GetGPUDescriptorHandleForHeapStart());
  7084. pCommandList->SetComputeRootDescriptorTable(1, pSampHeap->GetGPUDescriptorHandleForHeapStart());
  7085. }
  7086. }
  7087. CreateDefaultResourceViews(pDevice, pResHeap->GetCPUDescriptorHandleForHeapStart(), valueSize,
  7088. pSRVResources, NumSRVs, pUAVResources, NumUAVs);
  7089. D3D12_FILTER filters[] = {D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT};
  7090. float borderColors[] = {30.0, 31.0};
  7091. CreateDefaultSamplers(pDevice, pSampHeap->GetCPUDescriptorHandleForHeapStart(),
  7092. filters, borderColors, NumSamplers);
  7093. // Run the compute shader and copy the results back to readable memory.
  7094. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  7095. RecordTransitionBarrier(pCommandList, pUAVResources[NumUAVs - 2], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  7096. pCommandList->CopyResource(pReadBuffer, pUAVResources[NumUAVs - 2]);
  7097. pCommandList->Close();
  7098. ExecuteCommandList(pCommandQueue, pCommandList);
  7099. WaitForSignal(pCommandQueue, FO);
  7100. MappedData data(pReadBuffer, valueSize*sizeof(float));
  7101. const float *pData = (float*)data.data();
  7102. LogCommentFmt(L"Verify bound resources are properly selected");
  7103. VERIFY_ARE_EQUAL(pData[0], 10);
  7104. VERIFY_ARE_EQUAL(pData[1], 11);
  7105. VERIFY_ARE_EQUAL(pData[2], 12);
  7106. VERIFY_ARE_EQUAL(pData[3], 20);
  7107. VERIFY_ARE_EQUAL(pData[4], 21);
  7108. VERIFY_ARE_EQUAL(pData[5], 22);
  7109. VERIFY_ARE_EQUAL(pData[6], 30);
  7110. VERIFY_ARE_EQUAL(pData[7], 1); // samplecmp 1 means it matched 31
  7111. }
  7112. TEST_F(ExecutionTest, SignatureResourcesTest) {
  7113. std::string pShader =
  7114. "ByteAddressBuffer g_rawBuf : register(t0);\n"
  7115. "StructuredBuffer<float> g_structBuf : register(t1);\n"
  7116. "Texture2D<float> g_tex : register(t2);\n"
  7117. "RWByteAddressBuffer g_rwRawBuf : register(u0);\n"
  7118. "RWStructuredBuffer<float> g_rwStructBuf : register(u1);\n"
  7119. "RWBuffer<float> g_result : register(u2);\n"
  7120. "RWTexture1D<float> g_rwTex : register(u3);\n"
  7121. "SamplerState g_samp : register(s0);\n"
  7122. "SamplerComparisonState g_sampCmp : register(s1);\n"
  7123. "[NumThreads(1, 1, 1)]\n"
  7124. "void main(uint ix : SV_GroupIndex) {\n"
  7125. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7126. " g_result[1] = g_structBuf.Load(0);\n"
  7127. " g_result[2] = g_tex.Load(0);\n"
  7128. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7129. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7130. " g_result[5] = g_rwTex.Load(0);\n"
  7131. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7132. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7133. "}\n";
  7134. CComPtr<ID3D12Device> pDevice;
  7135. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7136. return;
  7137. RunResourceTest(pDevice, pShader.c_str(), L"cs_6_6", /*isDynamic*/false);
  7138. }
  7139. TEST_F(ExecutionTest, DynamicResourcesTest) {
  7140. static const char pShader[] =
  7141. "static ByteAddressBuffer g_rawBuf = ResourceDescriptorHeap[0];\n"
  7142. "static StructuredBuffer<float> g_structBuf = ResourceDescriptorHeap[1];\n"
  7143. "static Texture2D<float> g_tex = ResourceDescriptorHeap[2];\n"
  7144. "static RWByteAddressBuffer g_rwRawBuf = ResourceDescriptorHeap[3];\n"
  7145. "static RWStructuredBuffer<float> g_rwStructBuf = ResourceDescriptorHeap[4];\n"
  7146. "static RWBuffer<float> g_result = ResourceDescriptorHeap[5];\n"
  7147. "static RWTexture1D<float> g_rwTex = ResourceDescriptorHeap[6];\n"
  7148. "static SamplerState g_samp = SamplerDescriptorHeap[0];\n"
  7149. "static SamplerComparisonState g_sampCmp = SamplerDescriptorHeap[1];\n"
  7150. "[NumThreads(1, 1, 1)]\n"
  7151. "void main(uint ix : SV_GroupIndex) {\n"
  7152. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7153. " g_result[1] = g_structBuf.Load(0);\n"
  7154. " g_result[2] = g_tex.Load(0);\n"
  7155. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7156. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7157. " g_result[5] = g_rwTex.Load(0);\n"
  7158. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7159. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7160. "}\n";
  7161. CComPtr<ID3D12Device> pDevice;
  7162. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7163. return;
  7164. RunResourceTest(pDevice, pShader, L"cs_6_6", /*isDynamic*/true);
  7165. }
  7166. #define MAX_WAVESIZE 128
  7167. #define strinfigy2(arg) #arg
  7168. #define strinfigy(arg) strinfigy2(arg)
  7169. void ExecutionTest::WaveSizeTest() {
  7170. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7171. CComPtr<ID3D12Device> pDevice;
  7172. CComPtr<IStream> pStream;
  7173. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7174. return;
  7175. }
  7176. // Check Wave support
  7177. if (!DoesDeviceSupportWaveOps(pDevice)) {
  7178. // Optional feature, so it's correct to not support it if declared as such.
  7179. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  7180. return;
  7181. }
  7182. // read shader config
  7183. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7184. // Get supported wave sizes
  7185. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waveOpts;
  7186. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &waveOpts, sizeof(waveOpts)));
  7187. UINT minWaveSize = waveOpts.WaveLaneCountMin;
  7188. UINT maxWaveSize = waveOpts.WaveLaneCountMax;
  7189. DXASSERT_NOMSG(minWaveSize <= maxWaveSize);
  7190. DXASSERT((minWaveSize & (minWaveSize - 1)) == 0, "must be a power of 2");
  7191. DXASSERT((maxWaveSize & (maxWaveSize - 1)) == 0, "must be a power of 2");
  7192. // format shader source
  7193. const char waveSizeTestShader[] =
  7194. "struct TestData { \r\n"
  7195. " uint count; \r\n"
  7196. "}; \r\n"
  7197. "RWStructuredBuffer<TestData> data : register(u0); \r\n"
  7198. "\r\n"
  7199. "// Note: WAVESIZE will be defined via compiler option -D\r\n"
  7200. "[wavesize(WAVESIZE)]\r\n"
  7201. "[numthreads(" strinfigy(MAX_WAVESIZE) "*2,1,1)]\r\n"
  7202. "void main(uint3 tid : SV_DispatchThreadID ) { \r\n"
  7203. " data[tid.x].count = WaveActiveSum(1); \r\n"
  7204. "}\r\n";
  7205. struct WaveSizeTestData {
  7206. uint32_t count;
  7207. };
  7208. for (UINT waveSize = minWaveSize; waveSize <= maxWaveSize; waveSize *= 2) {
  7209. // format compiler args
  7210. char compilerOptions[32];
  7211. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D WAVESIZE=%d", waveSize) != -1);
  7212. // run the shader
  7213. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "WaveSizeTest",
  7214. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7215. VERIFY_IS_TRUE((0 == strncmp(Name, "UAVBuffer0", 10)));
  7216. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  7217. pShaderOp->Shaders.at(0).Text = waveSizeTestShader;
  7218. VERIFY_IS_TRUE(sizeof(WaveSizeTestData)*MAX_WAVESIZE <= Data.size());
  7219. WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
  7220. memset(&pInData, sizeof(WaveSizeTestData)*MAX_WAVESIZE, 0);
  7221. });
  7222. // verify expected values
  7223. MappedData dataUav;
  7224. WaveSizeTestData *pOutData;
  7225. test->Test->GetReadBackData("UAVBuffer0", &dataUav);
  7226. VERIFY_ARE_EQUAL(sizeof(WaveSizeTestData)*MAX_WAVESIZE, dataUav.size());
  7227. pOutData = (WaveSizeTestData*)dataUav.data();
  7228. LogCommentFmt(L"Verifying test result for wave size %d", waveSize);
  7229. for (unsigned i = 0; i < MAX_WAVESIZE; i++) {
  7230. if (!VERIFY_ARE_EQUAL(pOutData[i].count, waveSize))
  7231. break;
  7232. }
  7233. }
  7234. }
  7235. // Atomic operation testing
  7236. // Atomic tests take a single integer index as input and contort it into some
  7237. // kind of interesting contributor to the operation in question.
  7238. // So each vertex, pixel, thread, or other will have a unique index that produces
  7239. // a contributing value to the calculation which is stored in a small resource
  7240. // For arithmetic or bitwise operations, each contributor accumulates to the same
  7241. // location in the resource indexed by the operation type. Addition is in index 0
  7242. // umin/umax are in 1 and 2 and so on.
  7243. // To make sure that the most significant bits are involved in the calculation,
  7244. // particularly in the case of 64-bit values, each contributing value is duplicated
  7245. // to the lower and upper halves of the value. There is an exception to this when
  7246. // addition exceeds the available size and also for compare and exchange explained below.
  7247. // For compare and exchange operations, 64 output locations are shared by the various lanes.
  7248. // Each lane attempts to write to a location that is shared with several others.
  7249. // The first one to write to it determines its contents, which will be the lane index <ix>
  7250. // in the upper bits and the output location index in the lower bits.
  7251. // This ensures that the compare operations consider the upper bits in the comparison.
  7252. // The initial compare store is followed by a compare exchange that compares for the
  7253. // value the current lane would have assigned there. Finally, the output of the cmpxchg
  7254. // is used to determine if the current lane should perform the final unconditional exchange.
  7255. // The values are verified by checking the lower bits for the matching location index
  7256. // and ensuring that the upper bits undergoing the same transformation result in the location index.
  7257. // For lane index <ix> the location is calculated and final result assigned as if by this code:
  7258. // g_outputBuf[(ix/3)%64] = (ix << shBits) | ((ix/3)%64);
  7259. bool AtomicResultMatches(const BYTE *uResults, uint64_t gold, size_t size) {
  7260. if (memcmp(uResults, &gold, size)) {
  7261. if (size == 4)
  7262. LogCommentFmt(L" value %d is not %d", ((uint32_t*)uResults)[0], (uint32_t)gold);
  7263. else
  7264. LogCommentFmt(L" value %lld is not %lld", ((uint64_t*)uResults)[0], gold);
  7265. return false;
  7266. }
  7267. return true;
  7268. }
  7269. // Used to duplicate the lower half bits into the upper half bits of an integer
  7270. // To verify that the full value is being considered, many tests duplicate the results into the upper half
  7271. #define SHIFT(val, bits) (((val)&((1ULL<<(bits))-1ULL)) | ((val) << (bits)))
  7272. // Symbolic constants for the results
  7273. #define ADD_IDX 0
  7274. #define UMIN_IDX 1
  7275. #define UMAX_IDX 2
  7276. #define AND_IDX 3
  7277. #define OR_IDX 4
  7278. #define XOR_IDX 5
  7279. #define SMIN_IDX 0
  7280. #define SMAX_IDX 1
  7281. // Verify results for atomic operations. <uResults> and <sResults> are pointers to
  7282. // the readback resource sections containing unsigned and signed integers respectively.
  7283. // <pXchg> is a poiner to the readback resource containing the results of the compare
  7284. // and exchange operations tests. <stride> is the number of bytes between results for
  7285. // all of the results pointers. <maxIdx> is the number of indices that went into the results
  7286. // which is used to determine what the results should be. <bitSize> is the size in bits of
  7287. // the produced results, either 32 or 64.
  7288. void VerifyAtomicResults(const BYTE *uResults, const BYTE *sResults,
  7289. const BYTE *pXchg, size_t stride, size_t maxIdx, size_t bitSize) {
  7290. // Each atomic test performs the test on the value in the lower half
  7291. // and also duplicated in the upper half of the value. The SHIFT macros account for this.
  7292. // This is to verify that the upper bits are considered
  7293. size_t shBits = bitSize/2;
  7294. size_t byteSize = bitSize/8;
  7295. // Test ADD Operation
  7296. // ADD just sums all the indices. The result should the sum of the highest and lowest indices
  7297. // multiplied by half the number of sums.
  7298. size_t addResult = (maxIdx)*(maxIdx-1)/2;
  7299. LogCommentFmt(L"Verifying %d-bit integer atomic add", bitSize);
  7300. // For 32-bit values, the sum exceeds the 16 bit limit, so we can't duplicate
  7301. // That's fine, the duplication is really for 64-bit values.
  7302. if (bitSize < 64)
  7303. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, addResult, byteSize));
  7304. else
  7305. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, SHIFT(addResult, shBits), byteSize));
  7306. // Test MIN and MAX Operations
  7307. // The result of a simple min and max of any sequence of indices would be fairly uninteresting
  7308. // and certain erroneous behavior might mistakenly produce the correct results.
  7309. // To make it interesting, the contributing values will change depending on the evenness of the index.
  7310. // On an even index, min and max operate on the bitflipped index. For signed compares, this is
  7311. // interpretted as a negative value and for unsigned, a very high value.
  7312. // For unsigned min/max, index 0 will be bitflipped to ~0, which is interpretted as the maximum
  7313. // Because zero is manipulated, this leaves 1 as the lowest value.
  7314. LogCommentFmt(L"Verifying %d-bit integer atomic umin", bitSize);
  7315. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMIN_IDX, SHIFT(1ULL, shBits), byteSize)); // UMin
  7316. LogCommentFmt(L"Verifying %d-bit integer atomic umax", bitSize);
  7317. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMAX_IDX, ~0ULL, byteSize)); // UMax
  7318. // For signed min/max, the index just before the last will be bitflipped (maxIndex is always even).
  7319. // This is interpretted as -maxIndex and will be the lowest
  7320. // The maxIndex will be unaltered and interpretted as the highest.
  7321. LogCommentFmt(L"Verifying %d-bit integer atomic smin", bitSize);
  7322. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMIN_IDX, SHIFT(-(maxIdx-1), shBits), byteSize)); // SMin
  7323. LogCommentFmt(L"Verifying %d-bit integer atomic smax", bitSize);
  7324. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMAX_IDX, SHIFT(maxIdx-1, shBits), byteSize)); // SMax
  7325. // Test AND and OR operations.
  7326. // For AND operations, all indices are bitflipped and ANDed to the previous result.
  7327. // This means that the highest bits, which are never set by the contributing indices will be set
  7328. // for all the indices, so they will be set in the final result.
  7329. // For OR operations, the indices are ORed to the previous result unaltered
  7330. // This means that any bit that is set in any index will be set in the final OR result.
  7331. // In practice, this means that the cumulative result of the AND and OR operations
  7332. // are bitflipped versions of each other.
  7333. // Finding the most significant set bit by the max index or next power of two (pot)
  7334. // gives us the pivot point for these results
  7335. size_t nextPot = 1ULL << (bitSize - 1);
  7336. for (;nextPot && !((maxIdx-1) & (nextPot)); nextPot >>= 1) {}
  7337. nextPot <<= 1;
  7338. LogCommentFmt(L"Verifying %d-bit integer atomic and", bitSize);
  7339. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*AND_IDX, ~SHIFT(nextPot-1, shBits), byteSize)); // And
  7340. LogCommentFmt(L"Verifying %d-bit integer atomic or", bitSize);
  7341. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*OR_IDX, SHIFT(nextPot-1, shBits), byteSize)); // Or
  7342. // Test XOR operation
  7343. // For XOR operations, a 1 is shifted by the number of spaces equal to the index and XORed
  7344. // to the previous result. Because this would rapidely shift off the end of the value,
  7345. // giving undefined and uninteresting results, the index is moduloed to a value that will
  7346. // fit within the type size.
  7347. // Because many of the tests use total numbers of lanes that can be evenly divisible by 32 or 64,
  7348. // these values aren't used for the modulo since the expected result might be zero,
  7349. // which could be encountered through erroneous behavior.
  7350. // Instead, one less than the type size in bits is used for the modulo.
  7351. // Even though we don't know the actual order these operations are performed,
  7352. // indices that make up a contiguous sequence of 31 or 63 values can be thought of as one of a series of "passes".
  7353. // Each "pass" sets or clears the bits depending on what's already there.
  7354. // if the number of the pass is odd, the bits are being unset and all above the mod position should be set.
  7355. // If even, the bits are in the process of being set and bits below the mod position should be set.
  7356. size_t xorResult = ((1ULL<<((maxIdx)%(bitSize-1))) -1);
  7357. if (((maxIdx/(bitSize-1))&1)) {
  7358. xorResult ^= ~0ULL;
  7359. // The XOR above may set uninvolved upper bits, messing up the compare. So AND off the uninvolved bits.
  7360. xorResult &= ((1ULL<<(bitSize-1)) - 1);
  7361. }
  7362. LogCommentFmt(L"Verifying %d-bit integer atomic xor", bitSize);
  7363. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*XOR_IDX, xorResult, byteSize));
  7364. // Test CMP/XCHG Operations
  7365. // This tests CompareStore, CompareExchange, and Exchange operations.
  7366. // Unlike above, every lane isn't contributing to the same resource location
  7367. // Instead, every lane competes with a few others to update the same resource location.
  7368. // The first lane to find the contents of their location uninitialized will
  7369. // update it. To verify that upper bits are considered in the comparison and
  7370. // in the assignment, the value stored in the lowest bits is the location index.
  7371. // This ensures that part will be the same for each of the competing lanes.
  7372. // The uppermost bits are updated with the index of the lane that got there first.
  7373. // Subsequent calls to CompareExchange will verify this value matches and alter
  7374. // the content slightly. Finally, a simple check of the output value to what
  7375. // the current lane would expect and a call to exchange will update the value once more
  7376. // To verify this has gone through properly, the upper portion is converted as
  7377. // if to calculate the location index and compared with the location index.
  7378. // It could be the index of any of several lanes that assign to that location,
  7379. // but this ensures that it is not any lane outside of that group.
  7380. // The lower bits are compared to the location index as well.
  7381. LogCommentFmt(L"Verifying %d-bit integer atomic cmp/xchg results", bitSize);
  7382. for (size_t i = 0; i < 64; i++) {
  7383. uint64_t val = *((uint64_t*)(pXchg + i*stride));
  7384. // Verify lower bits match location index exactly
  7385. VERIFY_ARE_EQUAL(i, val & ((1ULL << shBits) - 1ULL));
  7386. // Verify that upper bits contain original index that transforms to location index
  7387. VERIFY_ARE_EQUAL(((val >> shBits)/3)%64, i);
  7388. }
  7389. }
  7390. void VerifyAtomicsRawTest(std::shared_ptr<ShaderOpTestResult> test,
  7391. size_t maxIdx, size_t bitSize) {
  7392. size_t stride = 8;
  7393. // struct mirroring that in the shader
  7394. struct AtomicStuff {
  7395. float prepad[2][3];
  7396. UINT uintEl[4];
  7397. int sintEl[4];
  7398. struct useless {
  7399. uint32_t unused[3];
  7400. } postpad;
  7401. float last;
  7402. };
  7403. MappedData uintData, xchgData;
  7404. test->Test->GetReadBackData("U0", &uintData);
  7405. test->Test->GetReadBackData("U1", &xchgData);
  7406. const AtomicStuff *pStruct = (AtomicStuff *)uintData.data();
  7407. const AtomicStuff *pStrXchg = (AtomicStuff *)xchgData.data();
  7408. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWStructuredBuffer resource", bitSize);
  7409. VerifyAtomicResults((const BYTE*)&(pStruct[0].uintEl[2]), (const BYTE*)&(pStruct[1].sintEl[2]),
  7410. (const BYTE*)&(pStrXchg[0].uintEl[2]), sizeof(AtomicStuff), maxIdx, bitSize);
  7411. const BYTE *pUint = nullptr;
  7412. const BYTE *pXchg = nullptr;
  7413. test->Test->GetReadBackData("U2", &uintData);
  7414. test->Test->GetReadBackData("U3", &xchgData);
  7415. pUint = (BYTE *)uintData.data();
  7416. pXchg = (BYTE *)xchgData.data();
  7417. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWByteAddressBuffer resource", bitSize);
  7418. VerifyAtomicResults(pUint, pUint + stride*6,
  7419. pXchg, stride, maxIdx, bitSize);
  7420. }
  7421. void VerifyAtomicsTypedTest(std::shared_ptr<ShaderOpTestResult> test,
  7422. size_t maxIdx, size_t bitSize) {
  7423. size_t stride = 8;
  7424. MappedData uintData, sintData, xchgData;
  7425. const BYTE *pUint = nullptr;
  7426. const BYTE *pSint = nullptr;
  7427. const BYTE *pXchg = nullptr;
  7428. // Typed resources can't share between 32 and 64 bits
  7429. if (bitSize == 32) {
  7430. test->Test->GetReadBackData("U4", &uintData);
  7431. test->Test->GetReadBackData("U5", &sintData);
  7432. test->Test->GetReadBackData("U6", &xchgData);
  7433. } else {
  7434. test->Test->GetReadBackData("U12", &uintData);
  7435. test->Test->GetReadBackData("U13", &sintData);
  7436. test->Test->GetReadBackData("U14", &xchgData);
  7437. }
  7438. pUint = (BYTE *)uintData.data();
  7439. pSint = (BYTE *)sintData.data();
  7440. pXchg = (BYTE *)xchgData.data();
  7441. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWBuffer resource", bitSize);
  7442. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7443. // Typed resources can't share between 32 and 64 bits
  7444. if (bitSize == 32) {
  7445. test->Test->GetReadBackData("U7", &uintData);
  7446. test->Test->GetReadBackData("U8", &sintData);
  7447. test->Test->GetReadBackData("U9", &xchgData);
  7448. } else {
  7449. test->Test->GetReadBackData("U15", &uintData);
  7450. test->Test->GetReadBackData("U16", &sintData);
  7451. test->Test->GetReadBackData("U17", &xchgData);
  7452. }
  7453. pUint = (BYTE *)uintData.data();
  7454. pSint = (BYTE *)sintData.data();
  7455. pXchg = (BYTE *)xchgData.data();
  7456. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWTexture resource", bitSize);
  7457. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7458. }
  7459. void VerifyAtomicsSharedTest(std::shared_ptr<ShaderOpTestResult> test,
  7460. size_t maxIdx, size_t bitSize) {
  7461. size_t stride = 8;
  7462. MappedData uintData, xchgData;
  7463. const BYTE *pUint = nullptr;
  7464. const BYTE *pXchg = nullptr;
  7465. test->Test->GetReadBackData("U10", &uintData);
  7466. test->Test->GetReadBackData("U11", &xchgData);
  7467. pUint = (BYTE *)uintData.data();
  7468. pXchg = (BYTE *)xchgData.data();
  7469. LogCommentFmt(L"Verifying %d-bit integer atomic operations on groupshared variables", bitSize);
  7470. VerifyAtomicResults(pUint, pUint + stride*6,
  7471. pXchg, stride, maxIdx, bitSize);
  7472. }
  7473. void VerifyAtomicsTest(std::shared_ptr<ShaderOpTestResult> test,
  7474. size_t maxIdx, size_t bitSize) {
  7475. VerifyAtomicsRawTest(test, maxIdx, bitSize);
  7476. VerifyAtomicsTypedTest(test, maxIdx, bitSize);
  7477. }
  7478. TEST_F(ExecutionTest, AtomicsTest) {
  7479. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7480. CComPtr<IStream> pStream;
  7481. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7482. CComPtr<ID3D12Device> pDevice;
  7483. if (!CreateDevice(&pDevice))
  7484. return;
  7485. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7486. std::make_shared<st::ShaderOpSet>();
  7487. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7488. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7489. // Test compute shader
  7490. LogCommentFmt(L"Verifying 32-bit integer atomic operations in compute shader");
  7491. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7492. VerifyAtomicsTest(test, 32*32, 32);
  7493. VerifyAtomicsSharedTest(test, 32*32, 32);
  7494. // Test mesh shader if available
  7495. pShaderOp->CS = nullptr;
  7496. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7497. LogCommentFmt(L"Verifying 32-bit integer atomic operations in amp/mesh/pixel shaders");
  7498. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7499. VerifyAtomicsTest(test, 8*8*2 + 8*8*2 + 64*64, 32);
  7500. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 32);
  7501. }
  7502. // Test Vertex + Pixel shader
  7503. pShaderOp->MS = nullptr;
  7504. LogCommentFmt(L"Verifying 32-bit integer atomic operations in vert/pixel shaders");
  7505. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7506. VerifyAtomicsTest(test, 64*64+6, 32);
  7507. }
  7508. TEST_F(ExecutionTest, Atomics64Test) {
  7509. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7510. CComPtr<IStream> pStream;
  7511. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7512. CComPtr<ID3D12Device> pDevice;
  7513. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7514. return;
  7515. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7516. std::make_shared<st::ShaderOpSet>();
  7517. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7518. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7519. // Reassign shader stages to 64-bit versions
  7520. // Collect 64-bit shaders
  7521. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7522. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7523. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7524. if (!strcmp(S.Name, "CS64")) CS64 = S.Name;
  7525. if (!strcmp(S.Name, "VS64")) VS64 = S.Name;
  7526. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7527. if (!strcmp(S.Name, "AS64")) AS64 = S.Name;
  7528. if (!strcmp(S.Name, "MS64")) MS64 = S.Name;
  7529. }
  7530. pShaderOp->CS = CS64;
  7531. pShaderOp->VS = VS64;
  7532. pShaderOp->PS = PS64;
  7533. pShaderOp->AS = AS64;
  7534. pShaderOp->MS = MS64;
  7535. // Test compute shader
  7536. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in compute shader");
  7537. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7538. VerifyAtomicsRawTest(test, 32*32, 64);
  7539. // Test mesh shader if available
  7540. pShaderOp->CS = nullptr;
  7541. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7542. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in amp/mesh/pixel shader");
  7543. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7544. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7545. }
  7546. // Test Vertex + Pixel shader
  7547. pShaderOp->MS = nullptr;
  7548. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in vert/pixel shader");
  7549. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7550. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7551. }
  7552. TEST_F(ExecutionTest, AtomicsTyped64Test) {
  7553. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7554. CComPtr<IStream> pStream;
  7555. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7556. CComPtr<ID3D12Device> pDevice;
  7557. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7558. return;
  7559. if (!DoesDeviceSupportInt64(pDevice)) {
  7560. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7561. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7562. return;
  7563. }
  7564. if (!DoesDeviceSupportTyped64Atomics(pDevice)) {
  7565. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on typed resources.");
  7566. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7567. return;
  7568. }
  7569. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7570. std::make_shared<st::ShaderOpSet>();
  7571. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7572. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7573. // Reassign shader stages to 64-bit versions
  7574. // Collect 64-bit shaders
  7575. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7576. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7577. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7578. if (!strcmp(S.Name, "CSTY64")) CS64 = S.Name;
  7579. if (!strcmp(S.Name, "VSTY64")) VS64 = S.Name;
  7580. if (!strcmp(S.Name, "PSTY64")) PS64 = S.Name;
  7581. if (!strcmp(S.Name, "ASTY64")) AS64 = S.Name;
  7582. if (!strcmp(S.Name, "MSTY64")) MS64 = S.Name;
  7583. }
  7584. pShaderOp->CS = CS64;
  7585. pShaderOp->VS = VS64;
  7586. pShaderOp->PS = PS64;
  7587. pShaderOp->AS = AS64;
  7588. pShaderOp->MS = MS64;
  7589. // Test compute shader
  7590. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in compute shader");
  7591. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7592. VerifyAtomicsTypedTest(test, 32*32, 64);
  7593. // Test mesh shader if available
  7594. pShaderOp->CS = nullptr;
  7595. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7596. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in amp/mesh/pixel shader");
  7597. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7598. VerifyAtomicsTypedTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7599. }
  7600. // Test Vertex + Pixel shader
  7601. pShaderOp->MS = nullptr;
  7602. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in vert/pixel shader");
  7603. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7604. VerifyAtomicsTypedTest(test, 64*64+6, 64);
  7605. }
  7606. TEST_F(ExecutionTest, AtomicsShared64Test) {
  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. if (!DoesDeviceSupportInt64(pDevice)) {
  7614. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7615. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7616. return;
  7617. }
  7618. if (!DoesDeviceSupportShared64Atomics(pDevice)) {
  7619. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on groupshared variables.");
  7620. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7621. return;
  7622. }
  7623. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7624. std::make_shared<st::ShaderOpSet>();
  7625. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7626. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7627. // Reassign shader stages to 64-bit versions
  7628. // Collect 64-bit shaders
  7629. LPCSTR CS64 = nullptr, PS64 = nullptr;
  7630. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7631. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7632. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7633. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7634. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7635. if (!strcmp(S.Name, "ASSH64")) AS64 = S.Name;
  7636. if (!strcmp(S.Name, "MSSH64")) MS64 = S.Name;
  7637. }
  7638. pShaderOp->CS = CS64;
  7639. pShaderOp->PS = PS64;
  7640. pShaderOp->AS = AS64;
  7641. pShaderOp->MS = MS64;
  7642. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in compute shader");
  7643. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7644. VerifyAtomicsSharedTest(test, 32*32, 64);
  7645. // Test mesh shader if available
  7646. pShaderOp->CS = nullptr;
  7647. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7648. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in amp/mesh/pixel shader");
  7649. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7650. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 64);
  7651. }
  7652. }
  7653. // Float Atomics
  7654. // These operations are almost the same as for the 32-bit and 64-bit integer tests
  7655. // The difference is that there is no need to verify the upper bits.
  7656. // So there is no storing of different parts in upper and lower halves.
  7657. // Additionally, the only operations that are supported on floats
  7658. // are compare and exchange operations. So that's all that is tested here.
  7659. // Just as above, a number of lanes are assigned the same output value.
  7660. // Unlike above, one location is needed for the result of the special NaN test
  7661. // For this reason, the conversion is reduced by one and shifted by one to leave
  7662. // the zero-indexed location available.
  7663. // Verify results for a particular set of atomics results
  7664. void VerifyAtomicFloatResults(const float *results, size_t maxIdx) {
  7665. // The first entry is for NaN to ensure that compares between NaNs succeed
  7666. // The sentinal value is 0.123, for which this compare is sufficient.
  7667. VERIFY_IS_TRUE(results[0] >= 0.120 && results[0] < 0.125);
  7668. // Start at 1 because 0 is just for NaN tests
  7669. for (size_t i = 1; i < 64; i++) {
  7670. VERIFY_ARE_EQUAL((int(results[i])/3)%63 + 1, i);
  7671. }
  7672. }
  7673. void VerifyAtomicsFloatSharedTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7674. MappedData Data;
  7675. const float *pData = nullptr;
  7676. test->Test->GetReadBackData("U4", &Data);
  7677. pData = (float *)Data.data();
  7678. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on groupshared variables");
  7679. VerifyAtomicFloatResults(pData, maxIdx);
  7680. }
  7681. void VerifyAtomicsFloatTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7682. // struct mirroring that in the shader
  7683. struct AtomicStuff {
  7684. float prepad[2][3];
  7685. float fltEl[2];
  7686. struct useless {
  7687. uint32_t unused[3];
  7688. } postpad;
  7689. };
  7690. // Test Compute Shader
  7691. MappedData Data;
  7692. const float *pData = nullptr;
  7693. test->Test->GetReadBackData("U0", &Data);
  7694. const AtomicStuff *pStructData = (AtomicStuff *)Data.data();
  7695. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWStructuredBuffer resources");
  7696. VERIFY_IS_TRUE(pStructData[0].fltEl[1] >= 0.120 && pStructData[0].fltEl[1] < 0.125);
  7697. for (size_t i = 1; i < 64; i++) {
  7698. VERIFY_ARE_EQUAL((int(pStructData[i].fltEl[1])/3)%63 + 1, i);
  7699. }
  7700. test->Test->GetReadBackData("U1", &Data);
  7701. pData = (float *)Data.data();
  7702. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWByteAddressBuffer resources");
  7703. VerifyAtomicFloatResults(pData, maxIdx);
  7704. test->Test->GetReadBackData("U2", &Data);
  7705. pData = (float *)Data.data();
  7706. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWBuffer resources");
  7707. VerifyAtomicFloatResults(pData, maxIdx);
  7708. test->Test->GetReadBackData("U3", &Data);
  7709. pData = (float *)Data.data();
  7710. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWTexture resources");
  7711. VerifyAtomicFloatResults(pData, maxIdx);
  7712. }
  7713. TEST_F(ExecutionTest, AtomicsFloatTest) {
  7714. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7715. CComPtr<IStream> pStream;
  7716. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7717. CComPtr<ID3D12Device> pDevice;
  7718. if (!CreateDevice(&pDevice))
  7719. return;
  7720. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7721. std::make_shared<st::ShaderOpSet>();
  7722. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7723. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("FloatAtomics");
  7724. // Test compute shader
  7725. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in compute shader");
  7726. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7727. VerifyAtomicsFloatTest(test, 32*32);
  7728. VerifyAtomicsFloatSharedTest(test, 32*32);
  7729. // Test mesh shader if available
  7730. pShaderOp->CS = nullptr;
  7731. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7732. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in amp/mesh/pixel shaders");
  7733. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7734. VerifyAtomicsFloatTest(test, 8*8*2 + 8*8*2 + 64*64);
  7735. VerifyAtomicsFloatSharedTest(test, 8*8*2 + 8*8*2);
  7736. }
  7737. // Test Vertex + Pixel shader
  7738. pShaderOp->MS = nullptr;
  7739. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in vert/pixel shaders");
  7740. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7741. VerifyAtomicsFloatTest(test, 64*64+6);
  7742. }
  7743. #ifndef _HLK_CONF
  7744. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  7745. char **pReadBackDump) {
  7746. std::stringstream str;
  7747. unsigned count = 0;
  7748. for (auto &R : pShaderOp->Resources) {
  7749. if (!R.ReadBack)
  7750. continue;
  7751. ++count;
  7752. str << "Resource: " << R.Name << "\r\n";
  7753. // Find a descriptor that can tell us how to dump this resource.
  7754. bool found = false;
  7755. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  7756. for (auto &D : Heaps.Descriptors) {
  7757. if (_stricmp(D.ResName, R.Name) != 0) {
  7758. continue;
  7759. }
  7760. found = true;
  7761. if (_stricmp(D.Kind, "UAV") != 0) {
  7762. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  7763. break;
  7764. }
  7765. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  7766. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  7767. break;
  7768. }
  7769. // We can map back to the structure if a structured buffer via the shader, but
  7770. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  7771. MappedData data;
  7772. pTest->GetReadBackData(R.Name, &data);
  7773. uint32_t *pData = (uint32_t *)data.data();
  7774. size_t u32_count = R.Desc.Width / sizeof(uint32_t);
  7775. for (size_t i = 0; i < u32_count; ++i) {
  7776. float f = *(float *)pData;
  7777. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  7778. << std::dec << " " << f << "\r\n";
  7779. ++pData;
  7780. }
  7781. break;
  7782. }
  7783. if (found) break;
  7784. }
  7785. if (!found) {
  7786. str << "Unable to find a view for the resource.\r\n";
  7787. }
  7788. }
  7789. str << "Resources read back: " << count << "\r\n";
  7790. std::string s(str.str());
  7791. CComHeapPtr<char> pDump;
  7792. if (!pDump.Allocate(s.size() + 1))
  7793. throw std::bad_alloc();
  7794. memcpy(pDump.m_pData, s.data(), s.size());
  7795. pDump.m_pData[s.size()] = '\0';
  7796. *pReadBackDump = pDump.Detach();
  7797. }
  7798. // This is the exported interface by use from HLSLHost.exe.
  7799. // It's exclusive with the use of the DLL as a TAEF target.
  7800. extern "C" {
  7801. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  7802. HRESULT hr = EnableExperimentalShaderModels();
  7803. if (FAILED(hr)) {
  7804. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  7805. }
  7806. return S_OK;
  7807. }
  7808. __declspec(dllexport) HRESULT WINAPI
  7809. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  7810. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  7811. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  7812. HRESULT hr;
  7813. if (pReadBackDump) *pReadBackDump = nullptr;
  7814. st::SetOutputFn(pStrCtx, pOutputStrFn);
  7815. CComPtr<ID3D12InfoQueue> pInfoQueue;
  7816. CComHeapPtr<char> pDump;
  7817. bool FilterCreation = false;
  7818. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  7819. // Creation is largely driven by inputs, so don't log create/destroy messages.
  7820. pInfoQueue->PushEmptyStorageFilter();
  7821. pInfoQueue->PushEmptyRetrievalFilter();
  7822. if (FilterCreation) {
  7823. D3D12_INFO_QUEUE_FILTER filter;
  7824. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  7825. ZeroMemory(&filter, sizeof(filter));
  7826. filter.DenyList.NumCategories = _countof(denyCategories);
  7827. filter.DenyList.pCategoryList = denyCategories;
  7828. pInfoQueue->PushStorageFilter(&filter);
  7829. }
  7830. }
  7831. else {
  7832. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  7833. }
  7834. try {
  7835. dxc::DxcDllSupport m_support;
  7836. m_support.Initialize();
  7837. const char *pName = nullptr;
  7838. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, strlen(pText));
  7839. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7840. std::make_shared<st::ShaderOpSet>();
  7841. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7842. st::ShaderOp *pShaderOp;
  7843. if (pName == nullptr) {
  7844. if (ShaderOpSet->ShaderOps.size() != 1) {
  7845. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  7846. return E_FAIL;
  7847. }
  7848. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  7849. }
  7850. else {
  7851. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  7852. }
  7853. if (pShaderOp == nullptr) {
  7854. std::string msg = "Unable to find shader op ";
  7855. msg += pName;
  7856. msg += "; available ops";
  7857. const char sep = ':';
  7858. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  7859. msg += sep;
  7860. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  7861. }
  7862. CA2W msgWide(msg.c_str());
  7863. pOutputStrFn(pStrCtx, msgWide);
  7864. return E_FAIL;
  7865. }
  7866. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  7867. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  7868. test->SetDxcSupport(&m_support);
  7869. test->RunShaderOp(pShaderOp);
  7870. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  7871. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  7872. if (!pShaderOp->IsCompute()) {
  7873. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  7874. test->GetPipelineStats(&stats);
  7875. wchar_t statsText[400];
  7876. StringCchPrintfW(statsText, _countof(statsText),
  7877. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  7878. L"Vertex shader invocations: %I64u\r\n"
  7879. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  7880. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  7881. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  7882. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  7883. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  7884. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  7885. stats.DSInvocations, stats.CSInvocations);
  7886. pOutputStrFn(pStrCtx, statsText);
  7887. }
  7888. if (pReadBackDump) {
  7889. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  7890. }
  7891. hr = S_OK;
  7892. }
  7893. catch (const CAtlException &E)
  7894. {
  7895. hr = E.m_hr;
  7896. }
  7897. catch (const std::bad_alloc &)
  7898. {
  7899. hr = E_OUTOFMEMORY;
  7900. }
  7901. catch (const std::exception &)
  7902. {
  7903. hr = E_FAIL;
  7904. }
  7905. // Drain the device message queue if available.
  7906. if (pInfoQueue != nullptr) {
  7907. wchar_t buf[200];
  7908. StringCchPrintfW(buf, _countof(buf),
  7909. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  7910. L"allowed/denied by storage filter=%u/%u "
  7911. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  7912. (unsigned)pInfoQueue->GetNumStoredMessages(),
  7913. (unsigned)pInfoQueue->GetMessageCountLimit(),
  7914. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  7915. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  7916. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  7917. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  7918. pOutputStrFn(pStrCtx, buf);
  7919. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  7920. pInfoQueue->ClearStoredMessages();
  7921. pInfoQueue->PopRetrievalFilter();
  7922. pInfoQueue->PopStorageFilter();
  7923. if (FilterCreation) {
  7924. pInfoQueue->PopStorageFilter();
  7925. }
  7926. }
  7927. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  7928. return hr;
  7929. }
  7930. }
  7931. #endif
  7932. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  7933. // Do not remove the line above - it is used by TranslateExecutionTest.py