ExecutionTest.cpp 275 KB

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