ExecutionTest.cpp 374 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // ExecutionTest.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // These tests run by executing compiled programs, and thus involve more //
  9. // moving parts, like the runtime and drivers. //
  10. // //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #include <algorithm>
  13. #include <memory>
  14. #include <array>
  15. #include <vector>
  16. #include <string>
  17. #include <map>
  18. #include <unordered_set>
  19. #include <strstream>
  20. #include <iomanip>
  21. #include "dxc/Test/CompilationResult.h"
  22. #include "dxc/Test/HLSLTestData.h"
  23. #include <Shlwapi.h>
  24. #include <atlcoll.h>
  25. #include <locale>
  26. #include <algorithm>
  27. #undef _read
  28. #include "WexTestClass.h"
  29. #include "dxc/Test/HlslTestUtils.h"
  30. #include "dxc/Test/DxcTestUtils.h"
  31. #include "dxc/Support/Global.h"
  32. #include "dxc/Support/WinIncludes.h"
  33. #include "dxc/Support/FileIOHelper.h"
  34. #include "dxc/Support/Unicode.h"
  35. //
  36. // d3d12.h and dxgi1_4.h are included in the Windows 10 SDK
  37. // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899120(v=vs.85).aspx
  38. // https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
  39. //
  40. #include <d3d12.h>
  41. #include <dxgi1_4.h>
  42. #include <DXGIDebug.h>
  43. #include "dxc/Support/d3dx12.h"
  44. #include <DirectXMath.h>
  45. #include <strsafe.h>
  46. #include <d3dcompiler.h>
  47. #include <wincodec.h>
  48. #include "ShaderOpTest.h"
  49. #pragma comment(lib, "d3dcompiler.lib")
  50. #pragma comment(lib, "windowscodecs.lib")
  51. #pragma comment(lib, "dxguid.lib")
  52. #pragma comment(lib, "version.lib")
  53. // A more recent Windows SDK than currently required is needed for these.
  54. typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)(
  55. UINT NumFeatures,
  56. __in_ecount(NumFeatures) const IID* pIIDs,
  57. __in_ecount_opt(NumFeatures) void* pConfigurationStructs,
  58. __in_ecount_opt(NumFeatures) UINT* pConfigurationStructSizes);
  59. static const GUID D3D12ExperimentalShaderModelsID = { /* 76f5573e-f13a-40f5-b297-81ce9e18933f */
  60. 0x76f5573e,
  61. 0xf13a,
  62. 0x40f5,
  63. { 0xb2, 0x97, 0x81, 0xce, 0x9e, 0x18, 0x93, 0x3f }
  64. };
  65. using namespace DirectX;
  66. using namespace hlsl_test;
  67. template <typename TSequence, typename T>
  68. static bool contains(TSequence s, const T &val) {
  69. return std::cend(s) != std::find(std::cbegin(s), std::cend(s), val);
  70. }
  71. template <typename InputIterator, typename T>
  72. static bool contains(InputIterator b, InputIterator e, const T &val) {
  73. return e != std::find(b, e, val);
  74. }
  75. static HRESULT EnableExperimentalShaderModels() {
  76. HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
  77. if (hRuntime == NULL) {
  78. return HRESULT_FROM_WIN32(GetLastError());
  79. }
  80. D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
  81. (D3D12EnableExperimentalFeaturesFn)GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures");
  82. if (pD3D12EnableExperimentalFeatures == nullptr) {
  83. FreeLibrary(hRuntime);
  84. return HRESULT_FROM_WIN32(GetLastError());
  85. }
  86. HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
  87. FreeLibrary(hRuntime);
  88. return hr;
  89. }
  90. static HRESULT ReportLiveObjects() {
  91. CComPtr<IDXGIDebug1> pDebug;
  92. IFR(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)));
  93. IFR(pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL));
  94. return S_OK;
  95. }
  96. static void WriteInfoQueueMessages(void *pStrCtx, st::OutputStringFn pOutputStrFn, ID3D12InfoQueue *pInfoQueue) {
  97. bool allMessagesOK = true;
  98. UINT64 count = pInfoQueue->GetNumStoredMessages();
  99. CAtlArray<BYTE> message;
  100. for (UINT64 i = 0; i < count; ++i) {
  101. // 'GetMessageA' rather than 'GetMessage' is an artifact of user32 headers.
  102. SIZE_T msgLen = 0;
  103. if (FAILED(pInfoQueue->GetMessageA(i, nullptr, &msgLen))) {
  104. allMessagesOK = false;
  105. continue;
  106. }
  107. if (message.GetCount() < msgLen) {
  108. if (!message.SetCount(msgLen)) {
  109. allMessagesOK = false;
  110. continue;
  111. }
  112. }
  113. D3D12_MESSAGE *pMessage = (D3D12_MESSAGE *)message.GetData();
  114. if (FAILED(pInfoQueue->GetMessageA(i, pMessage, &msgLen))) {
  115. allMessagesOK = false;
  116. continue;
  117. }
  118. CA2W msgW(pMessage->pDescription, CP_ACP);
  119. pOutputStrFn(pStrCtx, msgW.m_psz);
  120. pOutputStrFn(pStrCtx, L"\r\n");
  121. }
  122. if (!allMessagesOK) {
  123. pOutputStrFn(pStrCtx, L"Failed to retrieve some messages.\r\n");
  124. }
  125. }
  126. class CComContext {
  127. private:
  128. bool m_init;
  129. public:
  130. CComContext() : m_init(false) {}
  131. ~CComContext() { Dispose(); }
  132. void Dispose() { if (!m_init) return; m_init = false; CoUninitialize(); }
  133. HRESULT Init() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { m_init = true; } return hr; }
  134. };
  135. static void SavePixelsToFile(LPCVOID pPixels, DXGI_FORMAT format, UINT32 m_width, UINT32 m_height, LPCWSTR pFileName) {
  136. CComContext ctx;
  137. CComPtr<IWICImagingFactory> pFactory;
  138. CComPtr<IWICBitmap> pBitmap;
  139. CComPtr<IWICBitmapEncoder> pEncoder;
  140. CComPtr<IWICBitmapFrameEncode> pFrameEncode;
  141. CComPtr<hlsl::AbstractMemoryStream> pStream;
  142. CComPtr<IMalloc> pMalloc;
  143. struct PF {
  144. DXGI_FORMAT Format;
  145. GUID PixelFormat;
  146. UINT32 PixelSize;
  147. bool operator==(DXGI_FORMAT F) const {
  148. return F == Format;
  149. }
  150. } Vals[] = {
  151. // Add more pixel format mappings as needed.
  152. { DXGI_FORMAT_R8G8B8A8_UNORM, GUID_WICPixelFormat32bppRGBA, 4 }
  153. };
  154. PF *pFormat = std::find(Vals, Vals + _countof(Vals), format);
  155. VERIFY_SUCCEEDED(ctx.Init());
  156. VERIFY_SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory));
  157. VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
  158. VERIFY_SUCCEEDED(hlsl::CreateMemoryStream(pMalloc, &pStream));
  159. VERIFY_ARE_NOT_EQUAL(pFormat, Vals + _countof(Vals));
  160. VERIFY_SUCCEEDED(pFactory->CreateBitmapFromMemory(m_width, m_height, pFormat->PixelFormat, m_width * pFormat->PixelSize, m_width * m_height * pFormat->PixelSize, (BYTE *)pPixels, &pBitmap));
  161. VERIFY_SUCCEEDED(pFactory->CreateEncoder(GUID_ContainerFormatBmp, nullptr, &pEncoder));
  162. VERIFY_SUCCEEDED(pEncoder->Initialize(pStream, WICBitmapEncoderNoCache));
  163. VERIFY_SUCCEEDED(pEncoder->CreateNewFrame(&pFrameEncode, nullptr));
  164. VERIFY_SUCCEEDED(pFrameEncode->Initialize(nullptr));
  165. VERIFY_SUCCEEDED(pFrameEncode->WriteSource(pBitmap, nullptr));
  166. VERIFY_SUCCEEDED(pFrameEncode->Commit());
  167. VERIFY_SUCCEEDED(pEncoder->Commit());
  168. hlsl::WriteBinaryFile(pFileName, pStream->GetPtr(), pStream->GetPtrSize());
  169. }
  170. // Checks if the given warp version supports the given operation.
  171. bool IsValidWarpDllVersion(unsigned int minBuildNumber) {
  172. HMODULE pLibrary = LoadLibrary("D3D10Warp.dll");
  173. if (pLibrary) {
  174. char path[MAX_PATH];
  175. DWORD length = GetModuleFileName(pLibrary, path, MAX_PATH);
  176. if (length) {
  177. DWORD dwVerHnd = 0;
  178. DWORD dwVersionInfoSize = GetFileVersionInfoSize(path, &dwVerHnd);
  179. std::unique_ptr<int[]> VffInfo(new int[dwVersionInfoSize]);
  180. if (GetFileVersionInfo(path, NULL, dwVersionInfoSize, VffInfo.get())) {
  181. LPVOID versionInfo;
  182. UINT size;
  183. if (VerQueryValue(VffInfo.get(), "\\", &versionInfo, &size)) {
  184. if (size) {
  185. VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)versionInfo;
  186. unsigned int warpBuildNumber = verInfo->dwFileVersionLS >> 16 & 0xffff;
  187. if (verInfo->dwSignature == 0xFEEF04BD && warpBuildNumber >= minBuildNumber) {
  188. return true;
  189. }
  190. }
  191. }
  192. }
  193. }
  194. FreeLibrary(pLibrary);
  195. }
  196. return false;
  197. }
  198. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS2
  199. #define D3D12_FEATURE_D3D12_OPTIONS3 ((D3D12_FEATURE)21)
  200. #define NTDDI_WIN10_RS3 0x0A000004 /* ABRACADABRA_WIN10_RS2 */
  201. typedef
  202. enum D3D12_COMMAND_LIST_SUPPORT_FLAGS
  203. {
  204. D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0,
  205. D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT = (1 << D3D12_COMMAND_LIST_TYPE_DIRECT),
  206. D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE = (1 << D3D12_COMMAND_LIST_TYPE_BUNDLE),
  207. D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE = (1 << D3D12_COMMAND_LIST_TYPE_COMPUTE),
  208. D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY = (1 << D3D12_COMMAND_LIST_TYPE_COPY),
  209. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE = (1 << 4),
  210. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS = (1 << 5)
  211. } D3D12_COMMAND_LIST_SUPPORT_FLAGS;
  212. typedef
  213. enum D3D12_VIEW_INSTANCING_TIER
  214. {
  215. D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0,
  216. D3D12_VIEW_INSTANCING_TIER_1 = 1,
  217. D3D12_VIEW_INSTANCING_TIER_2 = 2,
  218. D3D12_VIEW_INSTANCING_TIER_3 = 3
  219. } D3D12_VIEW_INSTANCING_TIER;
  220. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS3
  221. {
  222. _Out_ BOOL CopyQueueTimestampQueriesSupported;
  223. _Out_ BOOL CastingFullyTypedFormatSupported;
  224. _Out_ DWORD WriteBufferImmediateSupportFlags;
  225. _Out_ D3D12_VIEW_INSTANCING_TIER ViewInstancingTier;
  226. _Out_ BOOL BarycentricsSupported;
  227. } D3D12_FEATURE_DATA_D3D12_OPTIONS3;
  228. #endif
  229. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS3
  230. #define D3D12_FEATURE_D3D12_OPTIONS4 ((D3D12_FEATURE)23)
  231. typedef enum D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER
  232. {
  233. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_0,
  234. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1,
  235. } D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER;
  236. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS4
  237. {
  238. _Out_ BOOL ReservedBufferPlacementSupported;
  239. _Out_ D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER SharedResourceCompatibilityTier;
  240. _Out_ BOOL Native16BitShaderOpsSupported;
  241. } D3D12_FEATURE_DATA_D3D12_OPTIONS4;
  242. #endif
  243. // Virtual class to compute the expected result given a set of inputs
  244. struct TableParameter;
  245. class ExecutionTest {
  246. public:
  247. // By default, ignore these tests, which require a recent build to run properly.
  248. BEGIN_TEST_CLASS(ExecutionTest)
  249. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  250. TEST_CLASS_PROPERTY(L"Ignore", L"true")
  251. TEST_METHOD_PROPERTY(L"Priority", L"0")
  252. END_TEST_CLASS()
  253. TEST_CLASS_SETUP(ExecutionTestClassSetup)
  254. TEST_METHOD(BasicComputeTest);
  255. TEST_METHOD(BasicTriangleTest);
  256. TEST_METHOD(BasicTriangleOpTest);
  257. BEGIN_TEST_METHOD(BasicTriangleOpTestHalf)
  258. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  259. END_TEST_METHOD()
  260. TEST_METHOD(OutOfBoundsTest);
  261. TEST_METHOD(SaturateTest);
  262. TEST_METHOD(SignTest);
  263. TEST_METHOD(Int64Test);
  264. TEST_METHOD(LifetimeIntrinsicTest)
  265. TEST_METHOD(WaveIntrinsicsTest);
  266. TEST_METHOD(WaveIntrinsicsDDITest);
  267. TEST_METHOD(WaveIntrinsicsInPSTest);
  268. TEST_METHOD(WaveSizeTest);
  269. TEST_METHOD(PartialDerivTest);
  270. TEST_METHOD(DerivativesTest);
  271. TEST_METHOD(ComputeSampleTest);
  272. TEST_METHOD(AtomicsTest);
  273. TEST_METHOD(Atomics64Test);
  274. TEST_METHOD(AtomicsTyped64Test);
  275. TEST_METHOD(AtomicsShared64Test);
  276. TEST_METHOD(AtomicsFloatTest);
  277. TEST_METHOD(SignatureResourcesTest)
  278. TEST_METHOD(DynamicResourcesTest)
  279. TEST_METHOD(QuadReadTest)
  280. BEGIN_TEST_METHOD(CBufferTestHalf)
  281. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  282. END_TEST_METHOD()
  283. TEST_METHOD(BasicShaderModel61);
  284. BEGIN_TEST_METHOD(BasicShaderModel63)
  285. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  286. END_TEST_METHOD()
  287. BEGIN_TEST_METHOD(WaveIntrinsicsActiveIntTest)
  288. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveIntTable")
  289. END_TEST_METHOD()
  290. BEGIN_TEST_METHOD(WaveIntrinsicsActiveUintTest)
  291. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsActiveUintTable")
  292. END_TEST_METHOD()
  293. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixIntTest)
  294. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixIntTable")
  295. END_TEST_METHOD()
  296. BEGIN_TEST_METHOD(WaveIntrinsicsPrefixUintTest)
  297. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsPrefixUintTable")
  298. END_TEST_METHOD()
  299. BEGIN_TEST_METHOD(WaveIntrinsicsSM65IntTest)
  300. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixIntTable")
  301. END_TEST_METHOD()
  302. BEGIN_TEST_METHOD(WaveIntrinsicsSM65UintTest)
  303. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#WaveIntrinsicsMultiPrefixUintTable")
  304. END_TEST_METHOD()
  305. // TAEF data-driven tests.
  306. BEGIN_TEST_METHOD(UnaryFloatOpTest)
  307. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
  308. END_TEST_METHOD()
  309. BEGIN_TEST_METHOD(BinaryFloatOpTest)
  310. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
  311. END_TEST_METHOD()
  312. BEGIN_TEST_METHOD(TertiaryFloatOpTest)
  313. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
  314. END_TEST_METHOD()
  315. BEGIN_TEST_METHOD(UnaryHalfOpTest)
  316. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryHalfOpTable")
  317. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  318. END_TEST_METHOD()
  319. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  320. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  321. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  322. END_TEST_METHOD()
  323. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  324. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  325. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  326. END_TEST_METHOD()
  327. BEGIN_TEST_METHOD(UnaryIntOpTest)
  328. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  329. END_TEST_METHOD()
  330. BEGIN_TEST_METHOD(BinaryIntOpTest)
  331. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  332. END_TEST_METHOD()
  333. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  334. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  335. END_TEST_METHOD()
  336. BEGIN_TEST_METHOD(UnaryUintOpTest)
  337. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  338. END_TEST_METHOD()
  339. BEGIN_TEST_METHOD(BinaryUintOpTest)
  340. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  341. END_TEST_METHOD()
  342. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  343. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  344. END_TEST_METHOD()
  345. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  346. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  347. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  348. END_TEST_METHOD()
  349. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  350. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  351. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  352. END_TEST_METHOD()
  353. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  354. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  355. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  356. END_TEST_METHOD()
  357. BEGIN_TEST_METHOD(UnaryUint16OpTest)
  358. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  359. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  360. END_TEST_METHOD()
  361. BEGIN_TEST_METHOD(BinaryUint16OpTest)
  362. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  363. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  364. END_TEST_METHOD()
  365. BEGIN_TEST_METHOD(TertiaryUint16OpTest)
  366. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  367. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  368. END_TEST_METHOD()
  369. BEGIN_TEST_METHOD(DotTest)
  370. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  371. END_TEST_METHOD()
  372. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  373. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  374. END_TEST_METHOD()
  375. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  376. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  377. END_TEST_METHOD()
  378. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  379. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  380. END_TEST_METHOD()
  381. BEGIN_TEST_METHOD(Msad4Test)
  382. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  383. END_TEST_METHOD()
  384. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  385. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  386. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  387. END_TEST_METHOD()
  388. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  389. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  390. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.2
  391. END_TEST_METHOD()
  392. TEST_METHOD(BarycentricsTest);
  393. TEST_METHOD(ComputeRawBufferLdStI32);
  394. TEST_METHOD(ComputeRawBufferLdStFloat);
  395. BEGIN_TEST_METHOD(ComputeRawBufferLdStI64)
  396. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  397. END_TEST_METHOD()
  398. BEGIN_TEST_METHOD(ComputeRawBufferLdStDouble)
  399. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  400. END_TEST_METHOD()
  401. BEGIN_TEST_METHOD(ComputeRawBufferLdStI16)
  402. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  403. END_TEST_METHOD()
  404. BEGIN_TEST_METHOD(ComputeRawBufferLdStHalf)
  405. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  406. END_TEST_METHOD()
  407. TEST_METHOD(GraphicsRawBufferLdStI32);
  408. TEST_METHOD(GraphicsRawBufferLdStFloat);
  409. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI64)
  410. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  411. END_TEST_METHOD()
  412. BEGIN_TEST_METHOD(GraphicsRawBufferLdStDouble)
  413. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp supports this feature in Shader Model 6.3
  414. END_TEST_METHOD()
  415. BEGIN_TEST_METHOD(GraphicsRawBufferLdStI16)
  416. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  417. END_TEST_METHOD()
  418. BEGIN_TEST_METHOD(GraphicsRawBufferLdStHalf)
  419. TEST_METHOD_PROPERTY(L"Priority", L"2") // This test is disabled because of a bug in WARP; TODO: enable once the bug is fixed
  420. END_TEST_METHOD()
  421. BEGIN_TEST_METHOD(PackUnpackTest)
  422. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#PackUnpackOpTable")
  423. END_TEST_METHOD()
  424. dxc::DxcDllSupport m_support;
  425. VersionSupportInfo m_ver;
  426. bool m_ExperimentalModeEnabled = false;
  427. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  428. // Do not remove the following line - it is used by TranslateExecutionTest.py
  429. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  430. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  431. // require the Windows 10 SDK.
  432. typedef enum D3D_SHADER_MODEL {
  433. D3D_SHADER_MODEL_5_1 = 0x51,
  434. D3D_SHADER_MODEL_6_0 = 0x60,
  435. D3D_SHADER_MODEL_6_1 = 0x61,
  436. D3D_SHADER_MODEL_6_2 = 0x62,
  437. D3D_SHADER_MODEL_6_3 = 0x63,
  438. D3D_SHADER_MODEL_6_4 = 0x64,
  439. D3D_SHADER_MODEL_6_5 = 0x65,
  440. D3D_SHADER_MODEL_6_6 = 0x66,
  441. } D3D_SHADER_MODEL;
  442. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  443. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  444. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  445. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  446. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  447. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  448. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  449. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  450. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  451. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  452. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  453. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  454. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  455. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  456. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  457. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  458. #else
  459. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  460. #endif
  461. bool UseDxbc() {
  462. #ifdef _HLK_CONF
  463. return false;
  464. #else
  465. return GetTestParamBool(L"DXBC");
  466. #endif
  467. }
  468. bool UseWarpByDefault() {
  469. #ifdef _HLK_CONF
  470. return false;
  471. #else
  472. return true;
  473. #endif
  474. }
  475. bool UseDebugIfaces() {
  476. return true;
  477. }
  478. bool SaveImages() {
  479. return GetTestParamBool(L"SaveImages");
  480. }
  481. void RunResourceTest(ID3D12Device *pDevice, const char *pShader, const wchar_t *sm, bool isDynamic);
  482. template <class T1, class T2>
  483. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  484. size_t numParameter, bool isPrefix);
  485. template <typename T>
  486. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  487. size_t numParameters);
  488. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  489. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  490. enum class RawBufferLdStType {
  491. I32,
  492. Float,
  493. I64,
  494. Double,
  495. I16,
  496. Half
  497. };
  498. template <class Ty>
  499. struct RawBufferLdStTestData {
  500. Ty v1, v2[2], v3[3], v4[4];
  501. };
  502. template <class Ty>
  503. struct RawBufferLdStUavData {
  504. RawBufferLdStTestData<Ty> input, output, srvOut;
  505. };
  506. template <class Ty>
  507. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  508. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  509. template <class Ty>
  510. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  511. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  512. template <class Ty>
  513. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  514. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  515. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  516. template <class Ty>
  517. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  518. template <class Ty>
  519. const wchar_t* BasicShaderModelTest_GetFormatString();
  520. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  521. VERIFY_SUCCEEDED(m_support.Initialize());
  522. CComPtr<IDxcCompiler> pCompiler;
  523. CComPtr<IDxcLibrary> pLibrary;
  524. CComPtr<IDxcBlobEncoding> pTextBlob;
  525. CComPtr<IDxcOperationResult> pResult;
  526. HRESULT resultCode;
  527. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  528. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  529. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  530. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, pOptions, numOptions, nullptr, 0, nullptr, &pResult));
  531. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  532. if (FAILED(resultCode)) {
  533. CComPtr<IDxcBlobEncoding> errors;
  534. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  535. #ifndef _HLK_CONF
  536. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  537. #endif
  538. }
  539. VERIFY_SUCCEEDED(resultCode);
  540. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  541. }
  542. void CreateCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue, D3D12_COMMAND_LIST_TYPE type) {
  543. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  544. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  545. queueDesc.Type = type;
  546. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  547. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  548. }
  549. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  550. CreateCommandQueue(pDevice, pName, ppCommandQueue, D3D12_COMMAND_LIST_TYPE_COMPUTE);
  551. }
  552. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, LPCWSTR pTargetProfile, ID3D12PipelineState **ppComputeState, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  553. CComPtr<ID3DBlob> pComputeShader;
  554. // Load and compile shaders.
  555. if (UseDxbc()) {
  556. #ifndef _HLK_CONF
  557. DXBCFromText(pShader, L"main", pTargetProfile, &pComputeShader);
  558. #endif
  559. }
  560. else {
  561. CompileFromText(pShader, L"main", pTargetProfile, &pComputeShader, pOptions, numOptions);
  562. }
  563. // Describe and create the compute pipeline state object (PSO).
  564. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  565. computePsoDesc.pRootSignature = pRootSignature;
  566. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  567. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  568. }
  569. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  570. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true,
  571. bool enableRayTracing = false) {
  572. if (testModel > HIGHEST_SHADER_MODEL) {
  573. UINT minor = (UINT)testModel & 0x0f;
  574. LogCommentFmt(L"Installed SDK does not support "
  575. L"shader model 6.%1u", minor);
  576. if (skipUnsupported) {
  577. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  578. }
  579. return false;
  580. }
  581. const D3D_FEATURE_LEVEL FeatureLevelRequired = enableRayTracing ? D3D_FEATURE_LEVEL_12_0 : D3D_FEATURE_LEVEL_11_0;
  582. CComPtr<IDXGIFactory4> factory;
  583. CComPtr<ID3D12Device> pDevice;
  584. *ppDevice = nullptr;
  585. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  586. if (GetTestParamUseWARP(UseWarpByDefault())) {
  587. CComPtr<IDXGIAdapter> warpAdapter;
  588. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  589. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  590. IID_PPV_ARGS(&pDevice));
  591. if (FAILED(createHR)) {
  592. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  593. if (skipUnsupported) {
  594. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  595. }
  596. return false;
  597. }
  598. } else {
  599. CComPtr<IDXGIAdapter1> hardwareAdapter;
  600. WEX::Common::String AdapterValue;
  601. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  602. AdapterValue);
  603. if (SUCCEEDED(hr)) {
  604. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  605. } else {
  606. WEX::Logging::Log::Comment(
  607. L"Using default hardware adapter with D3D12 support.");
  608. }
  609. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  610. IID_PPV_ARGS(&pDevice)));
  611. }
  612. // retrieve adapter information
  613. LUID adapterID = pDevice->GetAdapterLuid();
  614. CComPtr<IDXGIAdapter> adapter;
  615. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  616. DXGI_ADAPTER_DESC AdapterDesc;
  617. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  618. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  619. if (pDevice == nullptr)
  620. return false;
  621. if (!UseDxbc()) {
  622. // Check for DXIL support.
  623. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  624. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  625. } D3D12_FEATURE_DATA_SHADER_MODEL;
  626. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  627. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  628. SMData.HighestShaderModel = testModel;
  629. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
  630. (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
  631. if (SMData.HighestShaderModel < testModel) {
  632. UINT minor = (UINT)testModel & 0x0f;
  633. LogCommentFmt(L"The selected device does not support "
  634. L"shader model 6.%1u", minor);
  635. if (skipUnsupported) {
  636. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  637. }
  638. return false;
  639. }
  640. }
  641. if (UseDebugIfaces()) {
  642. CComPtr<ID3D12InfoQueue> pInfoQueue;
  643. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  644. pInfoQueue->SetMuteDebugOutput(FALSE);
  645. }
  646. }
  647. *ppDevice = pDevice.Detach();
  648. return true;
  649. }
  650. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  651. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  652. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  653. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  654. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  655. }
  656. void CreateGraphicsCommandQueueAndList(
  657. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  658. ID3D12CommandAllocator **ppAllocator,
  659. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  660. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  661. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  662. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  663. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  664. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  665. IID_PPV_ARGS(ppCommandList)));
  666. }
  667. void CreateGraphicsPSO(ID3D12Device *pDevice,
  668. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  669. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  670. ID3D12PipelineState **ppPSO) {
  671. CComPtr<ID3DBlob> vertexShader;
  672. CComPtr<ID3DBlob> pixelShader;
  673. if (UseDxbc()) {
  674. #ifndef _HLK_CONF
  675. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  676. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  677. #endif
  678. } else {
  679. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  680. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  681. }
  682. // Describe and create the graphics pipeline state object (PSO).
  683. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  684. psoDesc.InputLayout = *pInputLayout;
  685. psoDesc.pRootSignature = pRootSignature;
  686. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  687. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  688. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  689. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  690. psoDesc.DepthStencilState.DepthEnable = FALSE;
  691. psoDesc.DepthStencilState.StencilEnable = FALSE;
  692. psoDesc.SampleMask = UINT_MAX;
  693. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  694. psoDesc.NumRenderTargets = 1;
  695. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  696. psoDesc.SampleDesc.Count = 1;
  697. VERIFY_SUCCEEDED(
  698. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  699. }
  700. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  701. ID3D12DescriptorHeap *pHeap, UINT width,
  702. UINT height,
  703. ID3D12Resource **ppRenderTarget,
  704. ID3D12Resource **ppBuffer) {
  705. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  706. const size_t formatElementSize = 4;
  707. CComPtr<ID3D12Resource> pRenderTarget;
  708. CComPtr<ID3D12Resource> pBuffer;
  709. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  710. pHeap->GetCPUDescriptorHandleForHeapStart());
  711. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  712. CD3DX12_RESOURCE_DESC rtDesc(
  713. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  714. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  715. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  716. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  717. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  718. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  719. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  720. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  721. // resource.
  722. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  723. CD3DX12_RESOURCE_DESC readDesc(
  724. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  725. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  726. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  727. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  728. *ppRenderTarget = pRenderTarget.Detach();
  729. *ppBuffer = pBuffer.Detach();
  730. }
  731. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  732. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  733. ID3D12RootSignature **pRootSig) {
  734. CComPtr<ID3DBlob> signature;
  735. CComPtr<ID3DBlob> error;
  736. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  737. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  738. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  739. IID_PPV_ARGS(pRootSig)));
  740. }
  741. void CreateRootSignatureFromRanges(ID3D12Device *pDevice, ID3D12RootSignature **pRootSig,
  742. CD3DX12_DESCRIPTOR_RANGE *resRanges, UINT resCt,
  743. CD3DX12_DESCRIPTOR_RANGE *sampRanges = nullptr, UINT sampCt = 0,
  744. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
  745. CD3DX12_ROOT_PARAMETER rootParameters[2];
  746. rootParameters[0].InitAsDescriptorTable(resCt, resRanges, D3D12_SHADER_VISIBILITY_ALL);
  747. rootParameters[1].InitAsDescriptorTable(sampCt, sampRanges, D3D12_SHADER_VISIBILITY_ALL);
  748. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  749. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, flags);
  750. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, pRootSig);
  751. }
  752. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  753. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  754. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  755. rtvHeapDesc.NumDescriptors = numDescriptors;
  756. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  757. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  758. VERIFY_SUCCEEDED(
  759. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  760. if (rtvDescriptorSize != nullptr) {
  761. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  762. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  763. }
  764. }
  765. void CreateTestResources(ID3D12Device *pDevice,
  766. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  767. UINT32 valueSizeInBytes, D3D12_RESOURCE_DESC resDesc,
  768. ID3D12Resource **ppResource,
  769. ID3D12Resource **ppUploadResource,
  770. ID3D12Resource **ppReadBuffer = nullptr) {
  771. CComPtr<ID3D12Resource> pResource;
  772. CComPtr<ID3D12Resource> pReadBuffer;
  773. CComPtr<ID3D12Resource> pUploadResource;
  774. D3D12_SUBRESOURCE_DATA transferData;
  775. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  776. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  777. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  778. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  779. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  780. pDevice->GetCopyableFootprints(&resDesc, 0, 1/*mipleveles*/, 0, nullptr, nullptr, nullptr, &uploadBufferDesc.Width);
  781. uploadBufferDesc.Height = 1;
  782. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  783. &defaultHeapProperties,
  784. D3D12_HEAP_FLAG_NONE,
  785. &resDesc,
  786. D3D12_RESOURCE_STATE_COPY_DEST,
  787. nullptr,
  788. IID_PPV_ARGS(&pResource)));
  789. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  790. &uploadHeapProperties,
  791. D3D12_HEAP_FLAG_NONE,
  792. &uploadBufferDesc,
  793. D3D12_RESOURCE_STATE_GENERIC_READ,
  794. nullptr,
  795. IID_PPV_ARGS(&pUploadResource)));
  796. if (ppReadBuffer)
  797. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  798. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  799. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  800. transferData.pData = values;
  801. transferData.RowPitch = valueSizeInBytes/resDesc.Height;
  802. transferData.SlicePitch = valueSizeInBytes;
  803. UpdateSubresources<1>(pCommandList, pResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  804. if (resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
  805. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  806. else
  807. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
  808. *ppResource = pResource.Detach();
  809. *ppUploadResource = pUploadResource.Detach();
  810. if (ppReadBuffer)
  811. *ppReadBuffer = pReadBuffer.Detach();
  812. }
  813. void CreateTestUavs(ID3D12Device *pDevice,
  814. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  815. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  816. ID3D12Resource **ppUploadResource = nullptr,
  817. ID3D12Resource **ppReadBuffer = nullptr) {
  818. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  819. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufferDesc,
  820. ppUavResource, ppUploadResource, ppReadBuffer);
  821. }
  822. // Create and return descriptor heaps for the given device
  823. // with the given number of resources and samples.
  824. // using some reasonable defaults
  825. void CreateDefaultDescHeaps(ID3D12Device *pDevice,
  826. int NumResources, int NumSamplers,
  827. ID3D12DescriptorHeap **ppResHeap, ID3D12DescriptorHeap **ppSampHeap) {
  828. // Describe and create descriptor heaps.
  829. ID3D12DescriptorHeap *pResHeap, *pSampHeap;
  830. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  831. heapDesc.NumDescriptors = NumResources;
  832. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  833. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  834. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pResHeap)));
  835. heapDesc.NumDescriptors = NumSamplers;
  836. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
  837. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pSampHeap)));
  838. *ppResHeap = pResHeap;
  839. *ppSampHeap = pSampHeap;
  840. }
  841. void CreateSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  842. DXGI_FORMAT format, D3D12_SRV_DIMENSION viewDimension, UINT numElements, UINT stride,
  843. const CComPtr<ID3D12Resource> pResource) {
  844. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  845. // Create SRV
  846. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  847. srvDesc.Format = format;
  848. srvDesc.ViewDimension = viewDimension;
  849. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  850. switch (viewDimension) {
  851. case D3D12_SRV_DIMENSION_BUFFER:
  852. srvDesc.Buffer.FirstElement = 0;
  853. srvDesc.Buffer.NumElements = numElements;
  854. srvDesc.Buffer.StructureByteStride = stride;
  855. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  856. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
  857. else
  858. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
  859. break;
  860. case D3D12_SRV_DIMENSION_TEXTURE1D:
  861. srvDesc.Texture1D.MostDetailedMip = 0;
  862. srvDesc.Texture1D.MipLevels = 1;
  863. srvDesc.Texture1D.ResourceMinLODClamp = 0;
  864. break;
  865. case D3D12_SRV_DIMENSION_TEXTURE2D:
  866. srvDesc.Texture2D.MostDetailedMip = 0;
  867. srvDesc.Texture2D.MipLevels = 1;
  868. srvDesc.Texture2D.PlaneSlice = 0;
  869. srvDesc.Texture2D.ResourceMinLODClamp = 0;
  870. break;
  871. }
  872. pDevice->CreateShaderResourceView(pResource, &srvDesc, baseHandle);
  873. baseHandle.Offset(descriptorSize);
  874. }
  875. void CreateRawSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  876. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  877. CreateSRV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  878. }
  879. void CreateStructSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  880. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  881. CreateSRV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_SRV_DIMENSION_BUFFER, numElements, stride, pResource);
  882. }
  883. void CreateTypedSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  884. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  885. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  886. }
  887. void CreateTex1DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  888. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  889. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  890. }
  891. void CreateTex2DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  892. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  893. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  894. }
  895. void CreateUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  896. DXGI_FORMAT format, D3D12_UAV_DIMENSION viewDimension, UINT numElements, UINT stride,
  897. const CComPtr<ID3D12Resource> pResource) {
  898. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  899. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  900. uavDesc.Format = format;
  901. uavDesc.ViewDimension = viewDimension;
  902. switch (viewDimension) {
  903. case D3D12_UAV_DIMENSION_BUFFER:
  904. uavDesc.Buffer.FirstElement = 0;
  905. uavDesc.Buffer.NumElements = numElements;
  906. uavDesc.Buffer.StructureByteStride = stride;
  907. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  908. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  909. else
  910. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  911. break;
  912. case D3D12_UAV_DIMENSION_TEXTURE1D:
  913. uavDesc.Texture1D.MipSlice = 0;
  914. break;
  915. case D3D12_UAV_DIMENSION_TEXTURE2D:
  916. uavDesc.Texture2D.MipSlice = 0;
  917. uavDesc.Texture2D.PlaneSlice = 0;
  918. break;
  919. }
  920. pDevice->CreateUnorderedAccessView(pResource, nullptr, &uavDesc, baseHandle);
  921. baseHandle.Offset(descriptorSize);
  922. }
  923. void CreateRawUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  924. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  925. CreateUAV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  926. }
  927. void CreateStructUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  928. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  929. CreateUAV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_UAV_DIMENSION_BUFFER, numElements, stride, pResource);
  930. }
  931. void CreateTypedUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  932. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  933. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  934. }
  935. void CreateTex1DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  936. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  937. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  938. }
  939. void CreateTex2DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  940. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  941. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  942. }
  943. // Create Samplers for <pDevice> given the filter and border color information provided
  944. // using some reasonable defaults
  945. void CreateDefaultSamplers(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  946. D3D12_FILTER filters[], float BorderColors[], int NumSamplers) {
  947. CD3DX12_CPU_DESCRIPTOR_HANDLE sampHandle(heapStart);
  948. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
  949. D3D12_SAMPLER_DESC sampDesc = {};
  950. sampDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  951. sampDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  952. sampDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  953. sampDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  954. sampDesc.MipLODBias = 0;
  955. sampDesc.MaxAnisotropy = 1;
  956. sampDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_EQUAL;
  957. sampDesc.MinLOD = 0;
  958. sampDesc.MaxLOD = 0;
  959. for (int i = 0; i < NumSamplers; i++) {
  960. sampDesc.Filter = filters[i];
  961. for (int j = 0; j < 4; j++)
  962. sampDesc.BorderColor[j] = BorderColors[i];
  963. pDevice->CreateSampler(&sampDesc, sampHandle);
  964. sampHandle = sampHandle.Offset(descriptorSize);
  965. }
  966. }
  967. template <typename TVertex, int len>
  968. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  969. ID3D12Resource **ppVertexBuffer,
  970. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  971. size_t vertexBufferSize = sizeof(vertices);
  972. CComPtr<ID3D12Resource> pVertexBuffer;
  973. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  974. CD3DX12_RESOURCE_DESC bufferDesc(
  975. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  976. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  977. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  978. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  979. IID_PPV_ARGS(&pVertexBuffer)));
  980. UINT8 *pVertexDataBegin;
  981. CD3DX12_RANGE readRange(0, 0);
  982. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  983. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  984. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  985. pVertexBuffer->Unmap(0, nullptr);
  986. // Initialize the vertex buffer view.
  987. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  988. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  989. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  990. *ppVertexBuffer = pVertexBuffer.Detach();
  991. }
  992. // Requires Anniversary Edition headers, so simplifying things for current setup.
  993. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  994. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  995. BOOL WaveOps;
  996. UINT WaveLaneCountMin;
  997. UINT WaveLaneCountMax;
  998. UINT TotalLaneCount;
  999. BOOL ExpandedComputeResourceStates;
  1000. BOOL Int64ShaderOps;
  1001. };
  1002. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  1003. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1004. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1005. return false;
  1006. return O.Int64ShaderOps != FALSE;
  1007. }
  1008. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  1009. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  1010. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  1011. return false;
  1012. return O.DoublePrecisionFloatShaderOps != FALSE;
  1013. }
  1014. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  1015. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1016. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1017. return false;
  1018. return O.WaveOps != FALSE;
  1019. }
  1020. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  1021. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  1022. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  1023. return false;
  1024. return O.BarycentricsSupported != FALSE;
  1025. }
  1026. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  1027. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  1028. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  1029. return false;
  1030. return O.Native16BitShaderOpsSupported != FALSE;
  1031. }
  1032. bool DoesDeviceSupportMeshShaders(ID3D12Device *pDevice) {
  1033. #if defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB
  1034. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1035. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))))
  1036. return false;
  1037. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
  1038. #else
  1039. return false;
  1040. #endif
  1041. }
  1042. bool DoesDeviceSupportRayTracing(ID3D12Device *pDevice) {
  1043. #if WDK_NTDDI_VERSION > NTDDI_WIN10_RS4
  1044. D3D12_FEATURE_DATA_D3D12_OPTIONS5 O5;
  1045. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS5, &O5, sizeof(O5))))
  1046. return false;
  1047. return O5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
  1048. #else
  1049. return false;
  1050. #endif
  1051. }
  1052. // Replace with appropriate WDK check when available
  1053. #define SM66_RUNTIME_SUPPORT 0
  1054. bool DoesDeviceSupportMeshAmpDerivatives(ID3D12Device *pDevice) {
  1055. #if SM66_RUNTIME_SUPPORT
  1056. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1057. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1058. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))) ||
  1059. FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1060. return false;
  1061. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED &&
  1062. O9.DerivativesInMeshAndAmplificationShadersSupported != FALSE;
  1063. #else
  1064. return false;
  1065. #endif
  1066. }
  1067. bool DoesDeviceSupportTyped64Atomics(ID3D12Device *pDevice) {
  1068. #if SM66_RUNTIME_SUPPORT
  1069. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1070. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1071. return false;
  1072. return O9.AtomicInt64OnTypedResourceSupported != FALSE;
  1073. #else
  1074. return false;
  1075. #endif
  1076. }
  1077. bool DoesDeviceSupportShared64Atomics(ID3D12Device *pDevice) {
  1078. #if SM66_RUNTIME_SUPPORT
  1079. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1080. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1081. return false;
  1082. return O9.AtomicInt64OnGroupSharedSupported != FALSE;
  1083. #else
  1084. return false;
  1085. #endif
  1086. }
  1087. #ifndef _HLK_CONF
  1088. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  1089. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  1090. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  1091. CComPtr<ID3DBlob> pErrors;
  1092. D3D_SHADER_MACRO d3dMacro[2];
  1093. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  1094. d3dMacro[0].Definition = "1";
  1095. d3dMacro[0].Name = "USING_DXBC";
  1096. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  1097. if (pErrors != nullptr) {
  1098. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  1099. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  1100. }
  1101. VERIFY_SUCCEEDED(hr);
  1102. }
  1103. #endif
  1104. HRESULT EnableDebugLayer() {
  1105. // The debug layer does net yet validate DXIL programs that require rewriting,
  1106. // but basic logging should work properly.
  1107. HRESULT hr = S_FALSE;
  1108. if (UseDebugIfaces()) {
  1109. CComPtr<ID3D12Debug> debugController;
  1110. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  1111. if (SUCCEEDED(hr)) {
  1112. debugController->EnableDebugLayer();
  1113. hr = S_OK;
  1114. }
  1115. }
  1116. return hr;
  1117. }
  1118. #ifndef _HLK_CONF
  1119. HRESULT EnableExperimentalMode() {
  1120. if (m_ExperimentalModeEnabled) {
  1121. return S_OK;
  1122. }
  1123. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1124. return S_FALSE;
  1125. }
  1126. HRESULT hr = EnableExperimentalShaderModels();
  1127. if (SUCCEEDED(hr)) {
  1128. m_ExperimentalModeEnabled = true;
  1129. }
  1130. return hr;
  1131. }
  1132. #endif
  1133. struct FenceObj {
  1134. HANDLE m_fenceEvent = NULL;
  1135. CComPtr<ID3D12Fence> m_fence;
  1136. UINT64 m_fenceValue;
  1137. ~FenceObj() {
  1138. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  1139. }
  1140. };
  1141. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  1142. pObj->m_fenceValue = 1;
  1143. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  1144. IID_PPV_ARGS(&pObj->m_fence)));
  1145. // Create an event handle to use for frame synchronization.
  1146. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  1147. if (pObj->m_fenceEvent == nullptr) {
  1148. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  1149. }
  1150. }
  1151. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  1152. VERIFY_SUCCEEDED(m_support.Initialize());
  1153. CComPtr<IDxcLibrary> pLibrary;
  1154. CComPtr<IDxcBlobEncoding> pBlob;
  1155. CComPtr<IStream> pStream;
  1156. std::wstring path = GetPathToHlslDataFile(relativePath);
  1157. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  1158. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  1159. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  1160. *ppStream = pStream.Detach();
  1161. }
  1162. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  1163. ID3D12DescriptorHeap *pRtvHeap,
  1164. UINT rtvDescriptorSize,
  1165. UINT instanceCount,
  1166. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  1167. ID3D12RootSignature *pRootSig,
  1168. ID3D12Resource *pRenderTarget,
  1169. ID3D12Resource *pReadBuffer) {
  1170. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  1171. D3D12_VIEWPORT viewport;
  1172. D3D12_RECT scissorRect;
  1173. memset(&viewport, 0, sizeof(viewport));
  1174. viewport.Height = (float)rtDesc.Height;
  1175. viewport.Width = (float)rtDesc.Width;
  1176. viewport.MaxDepth = 1.0f;
  1177. memset(&scissorRect, 0, sizeof(scissorRect));
  1178. scissorRect.right = (long)rtDesc.Width;
  1179. scissorRect.bottom = rtDesc.Height;
  1180. if (pRootSig != nullptr) {
  1181. pList->SetGraphicsRootSignature(pRootSig);
  1182. }
  1183. pList->RSSetViewports(1, &viewport);
  1184. pList->RSSetScissorRects(1, &scissorRect);
  1185. // Indicate that the buffer will be used as a render target.
  1186. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  1187. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  1188. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  1189. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  1190. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  1191. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  1192. pList->DrawInstanced(3, instanceCount, 0, 0);
  1193. // Transition to copy source and copy into read-back buffer.
  1194. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1195. // Copy into read-back buffer.
  1196. UINT64 rowPitch = rtDesc.Width * 4;
  1197. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  1198. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  1199. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  1200. Footprint.Offset = 0;
  1201. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  1202. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  1203. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  1204. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  1205. }
  1206. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  1207. void RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR shader, D3D_SHADER_MODEL shaderModel, bool useLibTarget, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1208. void RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1209. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1210. void RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1211. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions);
  1212. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  1213. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  1214. pCommandList->SetDescriptorHeaps(1, pHeaps);
  1215. }
  1216. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  1217. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  1218. }
  1219. };
  1220. #define WAVE_INTRINSIC_DXBC_GUARD \
  1221. "#ifdef USING_DXBC\r\n" \
  1222. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  1223. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  1224. "bool WaveIsFirstLane() { return true; }\r\n" \
  1225. "uint WaveGetLaneCount() { return 1; }\r\n" \
  1226. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  1227. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  1228. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  1229. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  1230. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  1231. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  1232. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  1233. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  1234. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  1235. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  1236. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  1237. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  1238. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  1239. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  1240. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  1241. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  1242. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  1243. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  1244. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  1245. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  1246. "#endif\r\n"
  1247. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  1248. size_t count) {
  1249. values.resize(count); // one element per dispatch group, in bytes
  1250. for (size_t i = 0; i < count; ++i) {
  1251. values[i] = (uint32_t)i;
  1252. }
  1253. }
  1254. bool ExecutionTest::ExecutionTestClassSetup() {
  1255. #ifdef _HLK_CONF
  1256. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1257. VERIFY_SUCCEEDED(m_support.Initialize());
  1258. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1259. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1260. if (m_EnableDebugLayer) {
  1261. EnableDebugLayer();
  1262. }
  1263. return true;
  1264. #else
  1265. HRESULT hr = EnableExperimentalMode();
  1266. if (FAILED(hr)) {
  1267. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1268. }
  1269. else if (hr == S_FALSE) {
  1270. LogCommentFmt(L"Experimental mode not enabled.");
  1271. }
  1272. else {
  1273. LogCommentFmt(L"Experimental mode enabled.");
  1274. }
  1275. hr = EnableDebugLayer();
  1276. if (FAILED(hr)) {
  1277. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1278. }
  1279. else {
  1280. LogCommentFmt(L"Debug layer enabled.");
  1281. }
  1282. return true;
  1283. #endif
  1284. }
  1285. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1286. static const int DispatchGroupX = 1;
  1287. static const int DispatchGroupY = 1;
  1288. static const int DispatchGroupZ = 1;
  1289. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1290. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1291. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1292. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1293. UINT uavDescriptorSize;
  1294. FenceObj FO;
  1295. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1296. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1297. InitFenceObj(pDevice, &FO);
  1298. // Describe and create a UAV descriptor heap.
  1299. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1300. heapDesc.NumDescriptors = 1;
  1301. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1302. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1303. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1304. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1305. // Create root signature.
  1306. CComPtr<ID3D12RootSignature> pRootSignature;
  1307. {
  1308. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1309. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1310. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1311. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1312. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1313. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1314. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1315. }
  1316. // Create pipeline state object.
  1317. CComPtr<ID3D12PipelineState> pComputeState;
  1318. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1319. // Create a command allocator and list for compute.
  1320. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1321. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1322. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1323. // Set up UAV resource.
  1324. CComPtr<ID3D12Resource> pUavResource;
  1325. CComPtr<ID3D12Resource> pReadBuffer;
  1326. CComPtr<ID3D12Resource> pUploadResource;
  1327. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1328. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1329. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1330. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1331. // Close the command list and execute it to perform the GPU setup.
  1332. pCommandList->Close();
  1333. ExecuteCommandList(pCommandQueue, pCommandList);
  1334. WaitForSignal(pCommandQueue, FO);
  1335. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1336. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1337. // Run the compute shader and copy the results back to readable memory.
  1338. {
  1339. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1340. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1341. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1342. uavDesc.Buffer.FirstElement = 0;
  1343. uavDesc.Buffer.NumElements = (UINT)values.size();
  1344. uavDesc.Buffer.StructureByteStride = 0;
  1345. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1346. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1347. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1348. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1349. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1350. SetDescriptorHeap(pCommandList, pUavHeap);
  1351. pCommandList->SetComputeRootSignature(pRootSignature);
  1352. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1353. }
  1354. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1355. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1356. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1357. pCommandList->Close();
  1358. ExecuteCommandList(pCommandQueue, pCommandList);
  1359. WaitForSignal(pCommandQueue, FO);
  1360. {
  1361. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1362. uint32_t *pData = (uint32_t *)mappedData.data();
  1363. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1364. }
  1365. WaitForSignal(pCommandQueue, FO);
  1366. }
  1367. void ExecutionTest::RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1368. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1369. // Create command queue.
  1370. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1371. CreateComputeCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue);
  1372. FenceObj FO;
  1373. InitFenceObj(pDevice, &FO);
  1374. // Compile shader "main" and create pipeline state object.
  1375. CComPtr<ID3D12PipelineState> pComputeState;
  1376. CreateComputePSO(pDevice, pRootSignature, pShader, pTargetProfile, &pComputeState, pOptions, numOptions);
  1377. // Create a command allocator and list for compute.
  1378. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1379. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1380. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1381. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1382. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1383. // Set up UAV resource.
  1384. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1385. CComPtr<ID3D12Resource> pUavResource;
  1386. CComPtr<ID3D12Resource> pReadBuffer;
  1387. CComPtr<ID3D12Resource> pUploadResource;
  1388. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1389. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunLifetimeIntrinsicTest UAV"));
  1390. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunLifetimeIntrinsicTest UAV Read Buffer"));
  1391. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunLifetimeIntrinsicTest UAV Upload Buffer"));
  1392. // Close the command list and execute it to perform the GPU setup.
  1393. pCommandList->Close();
  1394. ExecuteCommandList(pCommandQueue, pCommandList);
  1395. WaitForSignal(pCommandQueue, FO);
  1396. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1397. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1398. // Run the compute shader and copy the results back to readable memory.
  1399. {
  1400. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1401. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1402. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1403. uavDesc.Buffer.FirstElement = 0;
  1404. uavDesc.Buffer.NumElements = (UINT)values.size();
  1405. uavDesc.Buffer.StructureByteStride = 0;
  1406. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1407. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1408. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1409. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1410. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1411. SetDescriptorHeap(pCommandList, pUavHeap);
  1412. pCommandList->SetComputeRootSignature(pRootSignature);
  1413. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1414. }
  1415. static const int DispatchGroupX = 1;
  1416. static const int DispatchGroupY = 1;
  1417. static const int DispatchGroupZ = 1;
  1418. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1419. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1420. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1421. pCommandList->Close();
  1422. ExecuteCommandList(pCommandQueue, pCommandList);
  1423. WaitForSignal(pCommandQueue, FO);
  1424. {
  1425. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1426. uint32_t *pData = (uint32_t *)mappedData.data();
  1427. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1428. }
  1429. WaitForSignal(pCommandQueue, FO);
  1430. }
  1431. void ExecutionTest::RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1432. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions) {
  1433. // Create command queue.
  1434. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1435. CreateCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue, D3D12_COMMAND_LIST_TYPE_DIRECT);
  1436. FenceObj FO;
  1437. InitFenceObj(pDevice, &FO);
  1438. // Compile raygen shader.
  1439. CComPtr<ID3DBlob> pShaderLib;
  1440. CompileFromText(pShader, L"RayGen", pTargetProfile, &pShaderLib, pOptions, numOptions);
  1441. // Describe and create the RT pipeline state object (RTPSO).
  1442. CD3DX12_STATE_OBJECT_DESC stateObjectDesc(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
  1443. auto lib = stateObjectDesc.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
  1444. CD3DX12_SHADER_BYTECODE byteCode(pShaderLib);
  1445. lib->SetDXILLibrary(&byteCode);
  1446. lib->DefineExport(L"RayGen");
  1447. const int payloadCount = 4;
  1448. const int attributeCount = 2;
  1449. const int maxRecursion = 2;
  1450. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT>()->Config(payloadCount * sizeof(float), attributeCount * sizeof(float));
  1451. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT>()->Config(maxRecursion);
  1452. // Create (local!) root sig subobject and associate with shader.
  1453. auto localRootSigSubObj = stateObjectDesc.CreateSubobject<CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT>();
  1454. localRootSigSubObj->SetRootSignature(pRootSignature);
  1455. auto x = stateObjectDesc.CreateSubobject<CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT>();
  1456. x->SetSubobjectToAssociate(*localRootSigSubObj);
  1457. x->AddExport(L"RayGen");
  1458. CComPtr<ID3D12StateObject> pStateObject;
  1459. VERIFY_SUCCEEDED(pDevice->CreateStateObject(stateObjectDesc, IID_PPV_ARGS(&pStateObject)));
  1460. // Create a command allocator and list.
  1461. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1462. CComPtr<ID3D12GraphicsCommandList4> pCommandList;
  1463. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator)));
  1464. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, nullptr, IID_PPV_ARGS(&pCommandList)));
  1465. pCommandList->SetPipelineState1(pStateObject);
  1466. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1467. // Close the command list and execute it to kick-off compilation in the driver.
  1468. // NOTE: We don't care about anything else, so we're not setting up any resources and don't actually execute the shader.
  1469. pCommandList->Close();
  1470. ExecuteCommandList(pCommandQueue, pCommandList);
  1471. WaitForSignal(pCommandQueue, FO);
  1472. }
  1473. void ExecutionTest::RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR pShader, D3D_SHADER_MODEL shaderModel, bool useLibTarget,
  1474. LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1475. LPCWSTR pTargetProfile;
  1476. switch (shaderModel) {
  1477. default: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_0"; break; // Default to 6.3 for lib, 6.0 otherwise.
  1478. case D3D_SHADER_MODEL_6_0: pTargetProfile = useLibTarget ? L"lib_6_0" : L"cs_6_0"; break;
  1479. case D3D_SHADER_MODEL_6_3: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_3"; break;
  1480. case D3D_SHADER_MODEL_6_5: pTargetProfile = useLibTarget ? L"lib_6_5" : L"cs_6_5"; break;
  1481. case D3D_SHADER_MODEL_6_6: pTargetProfile = useLibTarget ? L"lib_6_6" : L"cs_6_6"; break;
  1482. }
  1483. // Describe a UAV descriptor heap.
  1484. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1485. heapDesc.NumDescriptors = 1;
  1486. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1487. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1488. // Create the UAV descriptor heap.
  1489. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1490. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1491. // Create root signature.
  1492. CComPtr<ID3D12RootSignature> pRootSignature;
  1493. {
  1494. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1495. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1496. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1497. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1498. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1499. D3D12_ROOT_SIGNATURE_FLAGS rootSigFlag = useLibTarget ? D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE : D3D12_ROOT_SIGNATURE_FLAG_NONE;
  1500. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSigFlag);
  1501. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1502. }
  1503. if (useLibTarget)
  1504. RunLifetimeIntrinsicLibTest(reinterpret_cast<ID3D12Device5*>(pDevice), pShader, pRootSignature, pTargetProfile, pOptions, numOptions);
  1505. else
  1506. RunLifetimeIntrinsicComputeTest(pDevice, pShader, pUavHeap, pRootSignature, pTargetProfile, pOptions, numOptions, values);
  1507. }
  1508. TEST_F(ExecutionTest, LifetimeIntrinsicTest) {
  1509. // The only thing we test here is that existence of lifetime intrinsics or
  1510. // their fallback replacement (store undef or store zeroinitializer) do not
  1511. // cause any issues in the runtime and driver stack.
  1512. // The easiest way to force placement of intrinsics is to create an array in
  1513. // a local scope that is dynamically indexed. It must not be optimized away,
  1514. // so we do some bogus initialization that prevents this. Since all the code
  1515. // is guarded by a conditional that is dynamically always false, the actual
  1516. // effect of the shader is that the same value that was read is written back.
  1517. static const char* pShader = R"(
  1518. RWByteAddressBuffer g_bab : register(u0);
  1519. void fn(uint GI) {
  1520. const uint addr = GI * 4;
  1521. const int val = g_bab.Load(addr);
  1522. int res = val;
  1523. if (val < 0) { // Never true.
  1524. int arr[200];
  1525. for (int i = 0; i < 200; ++i) {
  1526. arr[i] = arr[val - i];
  1527. }
  1528. res += arr[val];
  1529. }
  1530. g_bab.Store(addr, (uint)res);
  1531. }
  1532. [numthreads(8,8,1)]
  1533. void main(uint GI : SV_GroupIndex) {
  1534. fn(GI);
  1535. }
  1536. [shader("raygeneration")]
  1537. void RayGen() {
  1538. const uint d = DispatchRaysIndex().x;
  1539. const uint g = g > 64 ? 63 : g;
  1540. fn(g);
  1541. }
  1542. )";
  1543. static const int NumThreadsX = 8;
  1544. static const int NumThreadsY = 8;
  1545. static const int NumThreadsZ = 1;
  1546. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1547. static const int DispatchGroupCount = 1;
  1548. // TODO: There's probably a lot of things in the rest of this test that could be stripped away.
  1549. CComPtr<ID3D12Device5> pDevice;
  1550. if (!CreateDevice(reinterpret_cast<ID3D12Device**>(&pDevice), D3D_SHADER_MODEL_6_6, true, true)) {
  1551. WEX::Logging::Log::Comment(L"Lifetime test not run pre 6.6");
  1552. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  1553. return;
  1554. }
  1555. std::vector<uint32_t> values;
  1556. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1557. // Run a number of tests for different configurations that will cause
  1558. // lifetime intrinsics to be placed directly, be replaced by a zeroinitializer
  1559. // store, or be replaced by an undef store.
  1560. LPCWSTR pOptions15[] = {L"/validator-version 1.5"};
  1561. LPCWSTR pOptions16[] = {L"/validator-version 1.6", L"/Vd"};
  1562. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1563. // Test regular shader with zeroinitializer store.
  1564. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions15, _countof(pOptions15), values);
  1565. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1566. if (DoesDeviceSupportRayTracing(pDevice)) {
  1567. // Test library with zeroinitializer store.
  1568. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions15, _countof(pOptions15), values);
  1569. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1570. }
  1571. // Testing SM 6.6 and validator version 1.6 requires experimental shaders
  1572. // being turned on.
  1573. if (!m_ExperimentalModeEnabled)
  1574. return;
  1575. // Test regular shader with undef store.
  1576. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions16, _countof(pOptions16), values);
  1577. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1578. if (DoesDeviceSupportRayTracing(pDevice)) {
  1579. // Test library with undef store.
  1580. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions16, _countof(pOptions16), values);
  1581. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1582. }
  1583. // Test regular shader with lifetime intrinsics.
  1584. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, false, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1585. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1586. if (DoesDeviceSupportRayTracing(pDevice)) {
  1587. // Test library with lifetime intrinsics.
  1588. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, true, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1589. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1590. }
  1591. }
  1592. TEST_F(ExecutionTest, BasicComputeTest) {
  1593. #ifndef _HLK_CONF
  1594. //
  1595. // BasicComputeTest is a simple compute shader that can be used as the basis
  1596. // for more interesting compute execution tests.
  1597. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1598. // rendering code paths for comparison.
  1599. //
  1600. static const char pShader[] =
  1601. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1602. "[numthreads(8,8,1)]\r\n"
  1603. "void main(uint GI : SV_GroupIndex) {"
  1604. " uint addr = GI * 4;\r\n"
  1605. " uint val = g_bab.Load(addr);\r\n"
  1606. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1607. " g_bab.Store(addr, val + 1);\r\n"
  1608. "}";
  1609. static const int NumThreadsX = 8;
  1610. static const int NumThreadsY = 8;
  1611. static const int NumThreadsZ = 1;
  1612. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1613. static const int DispatchGroupCount = 1;
  1614. CComPtr<ID3D12Device> pDevice;
  1615. if (!CreateDevice(&pDevice))
  1616. return;
  1617. std::vector<uint32_t> values;
  1618. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1619. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1620. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1621. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1622. #endif
  1623. }
  1624. TEST_F(ExecutionTest, BasicTriangleTest) {
  1625. #ifndef _HLK_CONF
  1626. static const UINT FrameCount = 2;
  1627. static const UINT m_width = 320;
  1628. static const UINT m_height = 200;
  1629. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1630. struct Vertex {
  1631. XMFLOAT3 position;
  1632. XMFLOAT4 color;
  1633. };
  1634. // Pipeline objects.
  1635. CComPtr<ID3D12Device> pDevice;
  1636. CComPtr<ID3D12Resource> pRenderTarget;
  1637. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1638. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1639. CComPtr<ID3D12RootSignature> pRootSig;
  1640. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1641. CComPtr<ID3D12PipelineState> pPipelineState;
  1642. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1643. CComPtr<ID3D12Resource> pReadBuffer;
  1644. UINT rtvDescriptorSize;
  1645. CComPtr<ID3D12Resource> pVertexBuffer;
  1646. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1647. // Synchronization objects.
  1648. FenceObj FO;
  1649. // Shaders.
  1650. static const char pShaders[] =
  1651. "struct PSInput {\r\n"
  1652. " float4 position : SV_POSITION;\r\n"
  1653. " float4 color : COLOR;\r\n"
  1654. "};\r\n\r\n"
  1655. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1656. " PSInput result;\r\n"
  1657. "\r\n"
  1658. " result.position = position;\r\n"
  1659. " result.color = color;\r\n"
  1660. " return result;\r\n"
  1661. "}\r\n\r\n"
  1662. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1663. " return 1; //input.color;\r\n"
  1664. "};\r\n";
  1665. if (!CreateDevice(&pDevice))
  1666. return;
  1667. struct BasicTestChecker {
  1668. CComPtr<ID3D12Device> m_pDevice;
  1669. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1670. bool m_OK = false;
  1671. void SetOK(bool value) { m_OK = value; }
  1672. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1673. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1674. return;
  1675. m_pInfoQueue->PushEmptyStorageFilter();
  1676. m_pInfoQueue->PushEmptyRetrievalFilter();
  1677. }
  1678. ~BasicTestChecker() {
  1679. if (!m_OK && m_pInfoQueue != nullptr) {
  1680. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1681. bool invalidBytecodeFound = false;
  1682. CAtlArray<BYTE> m_pBytes;
  1683. for (UINT64 i = 0; i < count; ++i) {
  1684. SIZE_T len = 0;
  1685. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1686. continue;
  1687. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1688. continue;
  1689. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1690. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1691. continue;
  1692. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1693. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1694. invalidBytecodeFound = true;
  1695. break;
  1696. }
  1697. }
  1698. if (invalidBytecodeFound) {
  1699. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1700. L"typically indicates that experimental mode "
  1701. L"is not set up properly.");
  1702. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1703. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1704. }
  1705. }
  1706. else {
  1707. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1708. L"queue - dumping complete queue.");
  1709. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1710. }
  1711. }
  1712. }
  1713. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1714. LogCommentFmt(L"%s", pMsg);
  1715. }
  1716. };
  1717. BasicTestChecker BTC(pDevice);
  1718. {
  1719. InitFenceObj(pDevice, &FO);
  1720. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1721. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1722. // Create an empty root signature.
  1723. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1724. rootSignatureDesc.Init(
  1725. 0, nullptr, 0, nullptr,
  1726. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1727. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1728. // Create the pipeline state, which includes compiling and loading shaders.
  1729. // Define the vertex input layout.
  1730. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1731. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1732. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1733. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1734. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1735. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1736. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1737. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1738. &pCommandAllocator, &pCommandList,
  1739. pPipelineState);
  1740. // Define the geometry for a triangle.
  1741. Vertex triangleVertices[] = {
  1742. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1743. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1744. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1745. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1746. WaitForSignal(pCommandQueue, FO);
  1747. }
  1748. // Render and execute the command list.
  1749. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1750. &vertexBufferView, pRootSig, pRenderTarget,
  1751. pReadBuffer);
  1752. VERIFY_SUCCEEDED(pCommandList->Close());
  1753. ExecuteCommandList(pCommandQueue, pCommandList);
  1754. // Wait for previous frame.
  1755. WaitForSignal(pCommandQueue, FO);
  1756. // At this point, we've verified that execution succeeded with DXIL.
  1757. BTC.SetOK(true);
  1758. // Read back to CPU and examine contents.
  1759. {
  1760. MappedData data(pReadBuffer, m_width * m_height * 4);
  1761. const uint32_t *pPixels = (uint32_t *)data.data();
  1762. if (SaveImages()) {
  1763. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1764. }
  1765. uint32_t top = pPixels[m_width / 2]; // Top center.
  1766. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1767. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1768. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1769. }
  1770. #endif
  1771. }
  1772. TEST_F(ExecutionTest, Int64Test) {
  1773. static const char pShader[] =
  1774. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1775. "[numthreads(8,8,1)]\r\n"
  1776. "void main(uint GI : SV_GroupIndex) {"
  1777. " uint addr = GI * 4;\r\n"
  1778. " uint val = g_bab.Load(addr);\r\n"
  1779. " uint64_t u64 = val;\r\n"
  1780. " u64 *= val;\r\n"
  1781. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1782. "}";
  1783. static const int NumThreadsX = 8;
  1784. static const int NumThreadsY = 8;
  1785. static const int NumThreadsZ = 1;
  1786. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1787. static const int DispatchGroupCount = 1;
  1788. CComPtr<ID3D12Device> pDevice;
  1789. if (!CreateDevice(&pDevice))
  1790. return;
  1791. if (!DoesDeviceSupportInt64(pDevice)) {
  1792. // Optional feature, so it's correct to not support it if declared as such.
  1793. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1794. return;
  1795. }
  1796. std::vector<uint32_t> values;
  1797. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1798. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1799. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1800. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1801. }
  1802. TEST_F(ExecutionTest, SignTest) {
  1803. static const char pShader[] =
  1804. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1805. "[numthreads(8,1,1)]\r\n"
  1806. "void main(uint GI : SV_GroupIndex) {"
  1807. " uint addr = GI * 4;\r\n"
  1808. " int val = g_bab.Load(addr);\r\n"
  1809. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1810. "}";
  1811. static const int NumThreadsX = 8;
  1812. static const int NumThreadsY = 1;
  1813. static const int NumThreadsZ = 1;
  1814. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1815. static const int DispatchGroupCount = 1;
  1816. CComPtr<ID3D12Device> pDevice;
  1817. if (!CreateDevice(&pDevice))
  1818. return;
  1819. const uint32_t neg1 = (uint32_t)-1;
  1820. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1821. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1822. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1823. VERIFY_ARE_EQUAL(values[0], neg1);
  1824. VERIFY_ARE_EQUAL(values[1], neg1);
  1825. VERIFY_ARE_EQUAL(values[2], neg1);
  1826. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1827. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1828. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1829. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1830. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1831. }
  1832. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1833. #ifndef _HLK_CONF
  1834. CComPtr<ID3D12Device> pDevice;
  1835. if (!CreateDevice(&pDevice))
  1836. return;
  1837. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1838. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1839. return;
  1840. bool waveSupported = O.WaveOps;
  1841. UINT laneCountMin = O.WaveLaneCountMin;
  1842. UINT laneCountMax = O.WaveLaneCountMax;
  1843. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1844. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1845. if (waveSupported) {
  1846. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1847. }
  1848. else {
  1849. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1850. }
  1851. #endif
  1852. }
  1853. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1854. #ifndef _HLK_CONF
  1855. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1856. struct PerThreadData {
  1857. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1858. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1859. uint32_t pfBC, pfSum, pfProd;
  1860. uint32_t ballot[4];
  1861. uint32_t diver; // divergent value, used in calculation
  1862. int32_t i_diver; // divergent value, used in calculation
  1863. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1864. int32_t i_pfSum, i_pfProd;
  1865. };
  1866. static const char pShader[] =
  1867. WAVE_INTRINSIC_DXBC_GUARD
  1868. "struct PerThreadData {\r\n"
  1869. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1870. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1871. " uint pfBC, pfSum, pfProd;\r\n"
  1872. " uint4 ballot;\r\n"
  1873. " uint diver;\r\n"
  1874. " int i_diver;\r\n"
  1875. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1876. " int i_pfSum, i_pfProd;\r\n"
  1877. "};\r\n"
  1878. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1879. "[numthreads(8,8,1)]\r\n"
  1880. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1881. " PerThreadData pts = g_sb[GI];\r\n"
  1882. " uint diver = GTID.x + 2;\r\n"
  1883. " pts.diver = diver;\r\n"
  1884. " pts.flags = 0;\r\n"
  1885. " pts.preds = 0;\r\n"
  1886. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1887. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1888. " pts.laneCount = WaveGetLaneCount();\r\n"
  1889. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1890. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1891. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1892. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1893. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1894. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1895. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1896. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1897. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1898. "\r\n"
  1899. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1900. " pts.allSum = WaveActiveSum(diver);\r\n"
  1901. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1902. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1903. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1904. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1905. " pts.allMin = WaveActiveMin(diver);\r\n"
  1906. " pts.allMax = WaveActiveMax(diver);\r\n"
  1907. "\r\n"
  1908. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1909. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1910. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1911. "\r\n"
  1912. " int i_diver = pts.i_diver;\r\n"
  1913. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1914. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1915. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1916. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1917. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1918. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1919. "\r\n"
  1920. " g_sb[GI] = pts;\r\n"
  1921. "}";
  1922. static const int NumtheadsX = 8;
  1923. static const int NumtheadsY = 8;
  1924. static const int NumtheadsZ = 1;
  1925. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1926. static const int DispatchGroupCount = 1;
  1927. CComPtr<ID3D12Device> pDevice;
  1928. if (!CreateDevice(&pDevice))
  1929. return;
  1930. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1931. // Optional feature, so it's correct to not support it if declared as such.
  1932. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1933. return;
  1934. }
  1935. std::vector<PerThreadData> values;
  1936. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1937. for (size_t i = 0; i < values.size(); ++i) {
  1938. memset(&values[i], 0, sizeof(PerThreadData));
  1939. values[i].id = i;
  1940. values[i].i_diver = (int)i;
  1941. values[i].i_diver *= (i % 2) ? 1 : -1;
  1942. }
  1943. static const int DispatchGroupX = 1;
  1944. static const int DispatchGroupY = 1;
  1945. static const int DispatchGroupZ = 1;
  1946. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1947. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1948. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1949. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1950. UINT uavDescriptorSize;
  1951. FenceObj FO;
  1952. bool dxbc = UseDxbc();
  1953. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1954. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1955. InitFenceObj(pDevice, &FO);
  1956. // Describe and create a UAV descriptor heap.
  1957. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1958. heapDesc.NumDescriptors = 1;
  1959. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1960. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1961. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1962. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1963. // Create root signature.
  1964. CComPtr<ID3D12RootSignature> pRootSignature;
  1965. {
  1966. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1967. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1968. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1969. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1970. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1971. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1972. CComPtr<ID3DBlob> signature;
  1973. CComPtr<ID3DBlob> error;
  1974. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  1975. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  1976. }
  1977. // Create pipeline state object.
  1978. CComPtr<ID3D12PipelineState> pComputeState;
  1979. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1980. // Create a command allocator and list for compute.
  1981. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1982. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1983. // Set up UAV resource.
  1984. CComPtr<ID3D12Resource> pUavResource;
  1985. CComPtr<ID3D12Resource> pReadBuffer;
  1986. CComPtr<ID3D12Resource> pUploadResource;
  1987. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1988. // Close the command list and execute it to perform the GPU setup.
  1989. pCommandList->Close();
  1990. ExecuteCommandList(pCommandQueue, pCommandList);
  1991. WaitForSignal(pCommandQueue, FO);
  1992. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1993. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1994. // Run the compute shader and copy the results back to readable memory.
  1995. {
  1996. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1997. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  1998. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1999. uavDesc.Buffer.FirstElement = 0;
  2000. uavDesc.Buffer.NumElements = values.size();
  2001. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  2002. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2003. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2004. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2005. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2006. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  2007. SetDescriptorHeap(pCommandList, pUavHeap);
  2008. pCommandList->SetComputeRootSignature(pRootSignature);
  2009. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  2010. }
  2011. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  2012. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2013. pCommandList->CopyResource(pReadBuffer, pUavResource);
  2014. pCommandList->Close();
  2015. ExecuteCommandList(pCommandQueue, pCommandList);
  2016. WaitForSignal(pCommandQueue, FO);
  2017. {
  2018. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  2019. PerThreadData *pData = (PerThreadData *)mappedData.data();
  2020. memcpy(values.data(), pData, valueSizeInBytes);
  2021. // Gather some general data.
  2022. // The 'firstLaneId' captures a unique number per first-lane per wave.
  2023. // Counting the number distinct firstLaneIds gives us the number of waves.
  2024. std::vector<uint32_t> firstLaneIds;
  2025. for (size_t i = 0; i < values.size(); ++i) {
  2026. PerThreadData &pts = values[i];
  2027. uint32_t firstLaneId = pts.firstLaneId;
  2028. if (!contains(firstLaneIds, firstLaneId)) {
  2029. firstLaneIds.push_back(firstLaneId);
  2030. }
  2031. }
  2032. // Waves should cover 4 threads or more.
  2033. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  2034. if (!dxbc) {
  2035. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  2036. }
  2037. // Now, group threads into waves.
  2038. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  2039. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  2040. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  2041. }
  2042. for (size_t i = 0; i < values.size(); ++i) {
  2043. PerThreadData &pts = values[i];
  2044. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2045. wave->push_back(&pts);
  2046. }
  2047. // Verify that all the wave values are coherent across the wave.
  2048. for (size_t i = 0; i < values.size(); ++i) {
  2049. PerThreadData &pts = values[i];
  2050. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2051. // Sort the lanes by increasing lane ID.
  2052. struct LaneIdOrderPred {
  2053. bool operator()(PerThreadData *a, PerThreadData *b) {
  2054. return a->laneIndex < b->laneIndex;
  2055. }
  2056. };
  2057. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  2058. // Verify some interesting properties of the first lane.
  2059. uint32_t pfBC, pfSum, pfProd;
  2060. int32_t i_pfSum, i_pfProd;
  2061. int32_t i_allMax, i_allMin;
  2062. {
  2063. PerThreadData *ptdFirst = wave->front();
  2064. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  2065. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  2066. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  2067. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  2068. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  2069. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  2070. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  2071. pfSum = ptdFirst->diver;
  2072. pfProd = ptdFirst->diver;
  2073. i_pfSum = ptdFirst->i_diver;
  2074. i_pfProd = ptdFirst->i_diver;
  2075. i_allMax = i_allMin = ptdFirst->i_diver;
  2076. }
  2077. // Calculate values which take into consideration all lanes.
  2078. uint32_t preds = 0;
  2079. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  2080. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  2081. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  2082. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  2083. uint32_t ballot[4] = { 0, 0, 0, 0 };
  2084. int32_t i_allSum = 0, i_allProd = 1;
  2085. for (size_t n = 0; n < wave->size(); ++n) {
  2086. std::vector<PerThreadData *> &lanes = *wave.get();
  2087. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  2088. if (lanes[n]->diver == 1) preds |= (1 << 0);
  2089. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  2090. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  2091. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  2092. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  2093. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  2094. if (lanes[n]->diver > 3) {
  2095. // This is the uint4 result layout:
  2096. // .x -> bits 0 .. 31
  2097. // .y -> bits 32 .. 63
  2098. // .z -> bits 64 .. 95
  2099. // .w -> bits 96 ..127
  2100. uint32_t component = lanes[n]->laneIndex / 32;
  2101. uint32_t bit = lanes[n]->laneIndex % 32;
  2102. ballot[component] |= 1 << bit;
  2103. }
  2104. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  2105. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  2106. i_allProd *= lanes[n]->i_diver;
  2107. i_allSum += lanes[n]->i_diver;
  2108. }
  2109. for (size_t n = 1; n < wave->size(); ++n) {
  2110. // 'All' operations are uniform across the wave.
  2111. std::vector<PerThreadData *> &lanes = *wave.get();
  2112. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  2113. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  2114. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  2115. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  2116. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  2117. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  2118. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  2119. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  2120. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  2121. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  2122. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  2123. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  2124. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  2125. // first-lane reads and uniform reads are uniform across the wave.
  2126. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  2127. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  2128. // the lane count is uniform across the wave.
  2129. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  2130. // The predicates are uniform across the wave.
  2131. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  2132. // the lane index is distinct per thread.
  2133. for (size_t prior = 0; prior < n; ++prior) {
  2134. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  2135. }
  2136. // Ballot results are uniform across the wave.
  2137. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  2138. // Keep running total of prefix calculation. Prefix values are exclusive to
  2139. // the executing lane.
  2140. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  2141. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  2142. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  2143. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  2144. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  2145. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  2146. pfSum += lanes[n]->diver;
  2147. pfProd *= lanes[n]->diver;
  2148. i_pfSum += lanes[n]->i_diver;
  2149. i_pfProd *= lanes[n]->i_diver;
  2150. }
  2151. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  2152. }
  2153. // Compare each value of each per-thread element.
  2154. for (size_t i = 0; i < values.size(); ++i) {
  2155. PerThreadData &pts = values[i];
  2156. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  2157. }
  2158. }
  2159. #endif
  2160. }
  2161. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  2162. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  2163. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2164. struct Vertex {
  2165. XMFLOAT3 position;
  2166. };
  2167. struct PerPixelData {
  2168. XMFLOAT4 position;
  2169. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  2170. uint32_t id0, id1, id2, id3;
  2171. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  2172. };
  2173. const UINT RTWidth = 128;
  2174. const UINT RTHeight = 128;
  2175. // Shaders.
  2176. static const char pShaders[] =
  2177. WAVE_INTRINSIC_DXBC_GUARD
  2178. "struct PSInput {\r\n"
  2179. " float4 position : SV_POSITION;\r\n"
  2180. "};\r\n\r\n"
  2181. "PSInput VSMain(float4 position : POSITION) {\r\n"
  2182. " PSInput result;\r\n"
  2183. "\r\n"
  2184. " result.position = position;\r\n"
  2185. " return result;\r\n"
  2186. "}\r\n\r\n"
  2187. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  2188. "struct PerPixelData {\r\n"
  2189. " float4 position;\r\n"
  2190. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  2191. " uint id0, id1, id2, id3;\r\n"
  2192. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  2193. "};\r\n"
  2194. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  2195. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  2196. " uint one = 1;\r\n"
  2197. " PerPixelData d;\r\n"
  2198. " d.position = input.position;\r\n"
  2199. " d.id = pos_to_id(input.position);\r\n"
  2200. " d.flags = 0;\r\n"
  2201. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  2202. " d.laneIndex = WaveGetLaneIndex();\r\n"
  2203. " d.laneCount = WaveGetLaneCount();\r\n"
  2204. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  2205. " d.sum1 = WaveActiveSum(one);\r\n"
  2206. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  2207. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  2208. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  2209. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  2210. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  2211. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  2212. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  2213. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  2214. " g_sb.Append(d);\r\n"
  2215. " return 1;\r\n"
  2216. "};\r\n";
  2217. CComPtr<ID3D12Device> pDevice;
  2218. CComPtr<ID3D12CommandQueue> pCommandQueue;
  2219. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  2220. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  2221. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  2222. CComPtr<ID3D12PipelineState> pPSO;
  2223. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  2224. UINT uavDescriptorSize, rtvDescriptorSize;
  2225. CComPtr<ID3D12Resource> pVertexBuffer;
  2226. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  2227. if (!CreateDevice(&pDevice))
  2228. return;
  2229. if (!DoesDeviceSupportWaveOps(pDevice)) {
  2230. // Optional feature, so it's correct to not support it if declared as such.
  2231. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  2232. return;
  2233. }
  2234. FenceObj FO;
  2235. InitFenceObj(pDevice, &FO);
  2236. // Describe and create a UAV descriptor heap.
  2237. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  2238. heapDesc.NumDescriptors = 1;
  2239. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  2240. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  2241. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  2242. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2243. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  2244. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  2245. // Create root signature: one UAV.
  2246. CComPtr<ID3D12RootSignature> pRootSignature;
  2247. {
  2248. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2249. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  2250. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2251. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2252. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2253. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  2254. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  2255. }
  2256. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  2257. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  2258. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  2259. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  2260. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  2261. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  2262. &pCommandList, pPSO);
  2263. // Single triangle covering half the target.
  2264. Vertex vertices[] = {
  2265. { { -1.0f, 1.0f, 0.0f } },
  2266. { { 1.0f, 1.0f, 0.0f } },
  2267. { { -1.0f, -1.0f, 0.0f } } };
  2268. const UINT TriangleCount = _countof(vertices) / 3;
  2269. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  2270. bool dxbc = UseDxbc();
  2271. // Set up UAV resource.
  2272. std::vector<PerPixelData> values;
  2273. values.resize(RTWidth * RTHeight * 2);
  2274. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  2275. memset(values.data(), 0, valueSizeInBytes);
  2276. CComPtr<ID3D12Resource> pUavResource;
  2277. CComPtr<ID3D12Resource> pUavReadBuffer;
  2278. CComPtr<ID3D12Resource> pUploadResource;
  2279. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pUavReadBuffer);
  2280. // Set up the append counter resource.
  2281. CComPtr<ID3D12Resource> pUavCounterResource;
  2282. CComPtr<ID3D12Resource> pReadCounterBuffer;
  2283. CComPtr<ID3D12Resource> pUploadCounterResource;
  2284. BYTE zero[sizeof(UINT)] = { 0 };
  2285. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pUploadCounterResource, &pReadCounterBuffer);
  2286. // Close the command list and execute it to perform the GPU setup.
  2287. pCommandList->Close();
  2288. ExecuteCommandList(pCommandQueue, pCommandList);
  2289. WaitForSignal(pCommandQueue, FO);
  2290. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2291. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  2292. pCommandList->SetGraphicsRootSignature(pRootSignature);
  2293. SetDescriptorHeap(pCommandList, pUavHeap);
  2294. {
  2295. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2296. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2297. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2298. uavDesc.Buffer.FirstElement = 0;
  2299. uavDesc.Buffer.NumElements = (UINT)values.size();
  2300. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  2301. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2302. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2303. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2304. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2305. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  2306. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  2307. }
  2308. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  2309. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2310. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2311. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  2312. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  2313. VERIFY_SUCCEEDED(pCommandList->Close());
  2314. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  2315. ExecuteCommandList(pCommandQueue, pCommandList);
  2316. WaitForSignal(pCommandQueue, FO);
  2317. {
  2318. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  2319. const uint32_t *pPixels = (uint32_t *)data.data();
  2320. if (SaveImages()) {
  2321. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  2322. }
  2323. }
  2324. uint32_t appendCount;
  2325. {
  2326. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  2327. appendCount = *((uint32_t *)mappedData.data());
  2328. LogCommentFmt(L"%u elements in append buffer", appendCount);
  2329. }
  2330. {
  2331. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  2332. PerPixelData *pData = (PerPixelData *)mappedData.data();
  2333. memcpy(values.data(), pData, valueSizeInBytes);
  2334. // DXBC is handy to test pipeline setup, but interesting functions are
  2335. // stubbed out, so there is no point in further validation.
  2336. if (dxbc)
  2337. return;
  2338. uint32_t maxActiveLaneCount = 0;
  2339. uint32_t maxLaneCount = 0;
  2340. for (uint32_t i = 0; i < appendCount; ++i) {
  2341. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  2342. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  2343. }
  2344. uint32_t peerOfHelperLanes = 0;
  2345. for (uint32_t i = 0; i < appendCount; ++i) {
  2346. if (values[i].sum1 != maxActiveLaneCount) {
  2347. ++peerOfHelperLanes;
  2348. }
  2349. }
  2350. LogCommentFmt(
  2351. L"Found: %u threads. Waves reported up to %u total lanes, up "
  2352. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  2353. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  2354. // Group threads into quad invocations.
  2355. uint32_t singlePixelCount = 0;
  2356. uint32_t multiPixelCount = 0;
  2357. std::unordered_set<uint32_t> ids;
  2358. std::multimap<uint32_t, PerPixelData *> idGroups;
  2359. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  2360. for (uint32_t i = 0; i < appendCount; ++i) {
  2361. ids.insert(values[i].id);
  2362. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  2363. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  2364. }
  2365. for (uint32_t id : ids) {
  2366. if (idGroups.count(id) == 1)
  2367. ++singlePixelCount;
  2368. else
  2369. ++multiPixelCount;
  2370. }
  2371. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  2372. singlePixelCount, multiPixelCount);
  2373. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  2374. // Where every pixel is distinct, it's very straightforward to validate.
  2375. {
  2376. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  2377. while (cur != end) {
  2378. bool simpleWave = true;
  2379. uint32_t firstId = (*cur).first;
  2380. auto groupEnd = cur;
  2381. while (groupEnd != end && (*groupEnd).first == firstId) {
  2382. if (idGroups.count((*groupEnd).second->id) > 1)
  2383. simpleWave = false;
  2384. ++groupEnd;
  2385. }
  2386. if (simpleWave) {
  2387. // Break the wave into quads.
  2388. struct QuadData {
  2389. unsigned count;
  2390. PerPixelData *data[4];
  2391. };
  2392. std::map<uint32_t, QuadData> quads;
  2393. for (auto i = cur; i != groupEnd; ++i) {
  2394. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  2395. uint32_t laneId = (*i).second->id;
  2396. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  2397. (*i).second->id2, (*i).second->id3};
  2398. // Since this is a simple wave, each lane has an unique id and
  2399. // therefore should not have any ids in there.
  2400. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  2401. // check if QuadReadLaneAt is returning same values in a single quad.
  2402. bool newQuad = true;
  2403. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  2404. auto match = quads.find(laneIds[quadIndex]);
  2405. if (match != quads.end()) {
  2406. (*match).second.data[(*match).second.count++] = (*i).second;
  2407. newQuad = false;
  2408. break;
  2409. }
  2410. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  2411. if (quadMemberData != idGroups.end()) {
  2412. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  2413. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  2414. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  2415. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  2416. }
  2417. }
  2418. if (newQuad) {
  2419. QuadData qdata;
  2420. qdata.count = 1;
  2421. qdata.data[0] = (*i).second;
  2422. quads.insert(std::make_pair(laneId, qdata));
  2423. }
  2424. }
  2425. for (auto quadPair : quads) {
  2426. unsigned count = quadPair.second.count;
  2427. // There could be only one pixel data on the edge of the triangle
  2428. if (count < 2) continue;
  2429. PerPixelData **data = quadPair.second.data;
  2430. bool isTop[4];
  2431. bool isLeft[4];
  2432. PerPixelData helperData;
  2433. memset(&helperData, sizeof(helperData), 0);
  2434. PerPixelData *layout[4]; // tl,tr,bl,br
  2435. memset(layout, sizeof(layout), 0);
  2436. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  2437. int idx = top ? 0 : 2;
  2438. idx += left ? 0 : 1;
  2439. return &layout[idx];
  2440. };
  2441. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  2442. PerPixelData **pResult = fnToLayout(top, left);
  2443. if (*pResult == nullptr) return &helperData;
  2444. return *pResult;
  2445. };
  2446. VERIFY_IS_TRUE(count <= 4);
  2447. if (count == 2) {
  2448. isTop[0] = data[0]->position.y < data[1]->position.y;
  2449. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  2450. isLeft[0] = data[0]->position.x < data[1]->position.x;
  2451. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  2452. }
  2453. else {
  2454. // with at least three samples, we have distinct x and y coordinates.
  2455. float left = std::min(data[0]->position.x, data[1]->position.x);
  2456. left = std::min(data[2]->position.x, left);
  2457. float top = std::min(data[0]->position.y, data[1]->position.y);
  2458. top = std::min(data[2]->position.y, top);
  2459. for (unsigned i = 0; i < count; ++i) {
  2460. isTop[i] = data[i]->position.y == top;
  2461. isLeft[i] = data[i]->position.x == left;
  2462. }
  2463. }
  2464. for (unsigned i = 0; i < count; ++i) {
  2465. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  2466. }
  2467. // Finally, we have a proper quad reconstructed. Validate.
  2468. for (unsigned i = 0; i < count; ++i) {
  2469. PerPixelData *d = data[i];
  2470. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  2471. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  2472. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  2473. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  2474. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  2475. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  2476. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  2477. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2478. }
  2479. }
  2480. }
  2481. cur = groupEnd;
  2482. }
  2483. }
  2484. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2485. //
  2486. // Consider: for pixels that were shaded multiple times, check whether
  2487. // some grouping of threads into quads satisfies all value requirements.
  2488. }
  2489. }
  2490. struct ShaderOpTestResult {
  2491. st::ShaderOp *ShaderOp;
  2492. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2493. std::shared_ptr<st::ShaderOpTest> Test;
  2494. };
  2495. struct SPrimitives {
  2496. float f_float;
  2497. float f_float2;
  2498. float f_float_o;
  2499. float f_float2_o;
  2500. };
  2501. std::shared_ptr<ShaderOpTestResult>
  2502. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2503. LPCSTR pName,
  2504. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2505. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2506. st::ShaderOp *pShaderOp;
  2507. if (pName == nullptr) {
  2508. if (ShaderOpSet->ShaderOps.size() != 1) {
  2509. VERIFY_FAIL(L"Expected a single shader operation.");
  2510. }
  2511. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2512. }
  2513. else {
  2514. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2515. }
  2516. if (pShaderOp == nullptr) {
  2517. std::string msg = "Unable to find shader op ";
  2518. msg += pName;
  2519. msg += "; available ops";
  2520. const char sep = ':';
  2521. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2522. msg += sep;
  2523. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2524. }
  2525. CA2W msgWide(msg.c_str());
  2526. VERIFY_FAIL(msgWide.m_psz);
  2527. }
  2528. // This won't actually be used since we're supplying the device,
  2529. // but let's make it consistent.
  2530. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2531. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2532. test->SetDxcSupport(&support);
  2533. test->SetInitCallback(pInitCallback);
  2534. test->SetDevice(pDevice);
  2535. test->RunShaderOp(pShaderOp);
  2536. std::shared_ptr<ShaderOpTestResult> result =
  2537. std::make_shared<ShaderOpTestResult>();
  2538. result->ShaderOpSet = ShaderOpSet;
  2539. result->Test = test;
  2540. result->ShaderOp = pShaderOp;
  2541. return result;
  2542. }
  2543. std::shared_ptr<ShaderOpTestResult>
  2544. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2545. IStream *pStream, LPCSTR pName,
  2546. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2547. DXASSERT_NOMSG(pStream != nullptr);
  2548. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2549. std::make_shared<st::ShaderOpSet>();
  2550. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2551. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2552. }
  2553. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2554. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2555. CComPtr<IStream> pStream;
  2556. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2557. // Single operation test at the moment.
  2558. CComPtr<ID3D12Device> pDevice;
  2559. if (!CreateDevice(&pDevice))
  2560. return;
  2561. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2562. MappedData data;
  2563. // Read back to CPU and examine contents - should get pure red.
  2564. {
  2565. MappedData data;
  2566. test->Test->GetReadBackData("RTarget", &data);
  2567. const uint32_t *pPixels = (uint32_t *)data.data();
  2568. uint32_t first = *pPixels;
  2569. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2570. }
  2571. }
  2572. TEST_F(ExecutionTest, SaturateTest) {
  2573. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2574. CComPtr<IStream> pStream;
  2575. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2576. // Single operation test at the moment.
  2577. CComPtr<ID3D12Device> pDevice;
  2578. if (!CreateDevice(&pDevice))
  2579. return;
  2580. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2581. MappedData data;
  2582. test->Test->GetReadBackData("U0", &data);
  2583. const float *pValues = (float *)data.data();
  2584. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2585. const float ExpectedCases[9] = {
  2586. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2587. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2588. 0.0f // nan
  2589. };
  2590. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2591. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2592. ++pValues;
  2593. }
  2594. }
  2595. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2596. #ifdef _HLK_CONF
  2597. UNREFERENCED_PARAMETER(ShaderOpName);
  2598. UNREFERENCED_PARAMETER(FileName);
  2599. UNREFERENCED_PARAMETER(testModel);
  2600. #else
  2601. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2602. CComPtr<IStream> pStream;
  2603. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2604. // Single operation test at the moment.
  2605. CComPtr<ID3D12Device> pDevice;
  2606. if (!CreateDevice(&pDevice, testModel))
  2607. return;
  2608. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2609. MappedData data;
  2610. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2611. UINT width = (UINT64)D.Width;
  2612. UINT height = (UINT64)D.Height;
  2613. test->Test->GetReadBackData("RTarget", &data);
  2614. const uint32_t *pPixels = (uint32_t *)data.data();
  2615. if (SaveImages()) {
  2616. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2617. }
  2618. uint32_t top = pPixels[width / 2]; // Top center.
  2619. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2620. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2621. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2622. // This is the basic validation test for shader operations, so it's good to
  2623. // check this here at least for this one test case.
  2624. data.reset();
  2625. test.reset();
  2626. ReportLiveObjects();
  2627. #endif
  2628. }
  2629. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2630. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2631. }
  2632. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2633. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2634. }
  2635. void VerifyDerivResults(const float *pPixels, UINT offsetCenter) {
  2636. // pixel at the center
  2637. float CenterDDXFine = pPixels[offsetCenter];
  2638. float CenterDDYFine = pPixels[offsetCenter + 1];
  2639. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2640. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2641. LogCommentFmt(
  2642. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2643. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2644. // The texture for the 9 pixels in the center should look like the following
  2645. // 256 32 64
  2646. // 2048 256 512
  2647. // 1 .125 .25
  2648. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2649. // So for fine derivatives there can be up to two possible results for the center pixel,
  2650. // while for coarse derivatives there can be up to six possible results.
  2651. int ulpTolerance = 1;
  2652. // 512 - 256 or 2048 - 256
  2653. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2654. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2655. // 256 - 32 or 256 - .125
  2656. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2657. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2658. if (top && left) {
  2659. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2660. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2661. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2662. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2663. }
  2664. else if (top) { // top right quad
  2665. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2666. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2667. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2668. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2669. }
  2670. else if (left) { // bottom left quad
  2671. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2672. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2673. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2674. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2675. }
  2676. else { // bottom right
  2677. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2678. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2679. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2680. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2681. }
  2682. }
  2683. // Rendering two right triangles forming a square and assigning a texture value
  2684. // for each pixel to calculate derivates.
  2685. TEST_F(ExecutionTest, PartialDerivTest) {
  2686. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2687. CComPtr<IStream> pStream;
  2688. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2689. CComPtr<ID3D12Device> pDevice;
  2690. if (!CreateDevice(&pDevice))
  2691. return;
  2692. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2693. MappedData data;
  2694. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2695. UINT width = (UINT)D.Width;
  2696. UINT height = D.Height;
  2697. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2698. test->Test->GetReadBackData("RTarget", &data);
  2699. const float *pPixels = (float *)data.data();
  2700. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2701. UINT offsetCenter = centerIndex * pixelSize;
  2702. VerifyDerivResults(pPixels, offsetCenter);
  2703. }
  2704. TEST_F(ExecutionTest, DerivativesTest) {
  2705. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2706. CComPtr<IStream> pStream;
  2707. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2708. CComPtr<ID3D12Device> pDevice;
  2709. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2710. return;
  2711. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2712. std::make_shared<st::ShaderOpSet>();
  2713. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2714. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Derivatives");
  2715. LPCSTR CS = pShaderOp->CS;
  2716. struct Dispatch {
  2717. int x, y, z;
  2718. int mx, my, mz;
  2719. };
  2720. std::vector<Dispatch> dispatches =
  2721. {
  2722. {32, 32, 1, 8, 8, 1},
  2723. {64, 4, 1, 64, 2, 1},
  2724. {1, 4, 64, 1, 4, 32},
  2725. {64, 1, 1, 64, 1, 1},
  2726. {1, 64, 1, 1, 64, 1},
  2727. {1, 1, 64, 1, 1, 64},
  2728. {16, 16, 3, 4, 4, 3},
  2729. {32, 3, 8, 8, 3, 2},
  2730. {3, 1, 64, 3, 1, 32}
  2731. };
  2732. char compilerOptions[256];
  2733. for (Dispatch &D : dispatches) {
  2734. UINT width = D.x;
  2735. UINT height = D.y;
  2736. UINT depth = D.z;
  2737. UINT mwidth = D.mx;
  2738. UINT mheight = D.my;
  2739. UINT mdepth = D.mz;
  2740. UINT pixelSize = 4; // always float4
  2741. // format compiler args
  2742. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2743. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2744. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2745. width, height, depth, mwidth, mheight, mdepth));
  2746. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2747. S.Arguments = compilerOptions;
  2748. pShaderOp->DispatchX = width;
  2749. pShaderOp->DispatchY = height;
  2750. pShaderOp->DispatchZ = depth;
  2751. // Test Compute Shader
  2752. pShaderOp->CS = CS;
  2753. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2754. MappedData data;
  2755. test->Test->GetReadBackData("U0", &data);
  2756. const float *pPixels = (float *)data.data();
  2757. // To find roughly the center for compute, divide the pixel count in half,
  2758. // truncate to next lowest power of 16 (4x4), which is the repeating period
  2759. // and then add 10 to reach the point the test expects
  2760. UINT centerIndex = (((UINT64)(width * height * depth)/2) & ~0xF) + 10;
  2761. UINT offsetCenter = centerIndex * pixelSize;
  2762. LogCommentFmt(L"Verifying derivatives in compute shader results");
  2763. VerifyDerivResults(pPixels, offsetCenter);
  2764. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2765. // Disable CS so mesh goes forward
  2766. pShaderOp->CS = nullptr;
  2767. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2768. test->Test->GetReadBackData("U1", &data);
  2769. pPixels = (float *)data.data();
  2770. centerIndex = (((UINT64)(mwidth * mheight * mdepth)/2) & ~0xF) + 10;
  2771. offsetCenter = centerIndex * pixelSize;
  2772. LogCommentFmt(L"Verifying derivatives in mesh shader results");
  2773. VerifyDerivResults(pPixels, offsetCenter);
  2774. test->Test->GetReadBackData("U2", &data);
  2775. pPixels = (float *)data.data();
  2776. LogCommentFmt(L"Verifying derivatives in amplification shader results");
  2777. VerifyDerivResults(pPixels, offsetCenter);
  2778. }
  2779. }
  2780. // Final test with not divisible by 4 dispatch size just to make sure it runs
  2781. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2782. S.Arguments = "-D DISPATCHX=3 -D DISPATCHY=3 -D DISPATCHZ=3 "
  2783. "-D MESHDISPATCHX=3 -D MESHDISPATCHY=3 -D MESHDISPATCHZ=3";
  2784. pShaderOp->DispatchX = 3;
  2785. pShaderOp->DispatchY = 3;
  2786. pShaderOp->DispatchZ = 3;
  2787. // Test Compute Shader
  2788. pShaderOp->CS = CS;
  2789. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2790. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2791. pShaderOp->CS = nullptr;
  2792. test = RunShaderOpTestAfterParse(pDevice, m_support, "Derivatives", nullptr, ShaderOpSet);
  2793. }
  2794. }
  2795. // Verify the results for the quad starting with the given index
  2796. void VerifyQuadReadResults(const UINT *pPixels, UINT quadIndex) {
  2797. for (UINT i = 0; i < 4; i++) {
  2798. UINT ix = quadIndex + i;
  2799. VERIFY_ARE_EQUAL(pPixels[4*ix + 0], ix); // ReadLaneAt own quad index
  2800. VERIFY_ARE_EQUAL(pPixels[4*ix + 1], (ix^1));// ReadAcrossX
  2801. VERIFY_ARE_EQUAL(pPixels[4*ix + 2], (ix^2));// ReadAcrossY
  2802. VERIFY_ARE_EQUAL(pPixels[4*ix + 3], (ix^3));// ReadAcrossDiagonal
  2803. }
  2804. }
  2805. TEST_F(ExecutionTest, QuadReadTest) {
  2806. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2807. CComPtr<IStream> pStream;
  2808. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2809. CComPtr<ID3D12Device> pDevice;
  2810. if (!CreateDevice(&pDevice))
  2811. return;
  2812. if (GetTestParamUseWARP(UseWarpByDefault())) {
  2813. WEX::Logging::Log::Comment(L"WARP does not support QuadRead in compute shaders.");
  2814. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2815. return;
  2816. }
  2817. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2818. std::make_shared<st::ShaderOpSet>();
  2819. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2820. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("QuadRead");
  2821. LPCSTR CS = pShaderOp->CS;
  2822. struct Dispatch {
  2823. int x, y, z;
  2824. int mx, my, mz;
  2825. };
  2826. //std::vector<std::tuple<int, int, int, int, int>> dispatches =
  2827. std::vector<Dispatch> dispatches =
  2828. {
  2829. {32, 32, 1, 8, 8, 1},
  2830. {64, 4, 1, 64, 2, 1},
  2831. {1, 4, 64, 1, 4, 32},
  2832. {64, 1, 1, 64, 1, 1},
  2833. {1, 64, 1, 1, 64, 1},
  2834. {1, 1, 64, 1, 1, 64},
  2835. {16, 16, 3, 4, 4, 3},
  2836. {32, 3, 8, 8, 3, 2},
  2837. {3, 1, 64, 3, 1, 32}
  2838. };
  2839. for (Dispatch &D : dispatches) {
  2840. UINT width = D.x;
  2841. UINT height = D.y;
  2842. UINT depth = D.z;
  2843. UINT mwidth = D.mx;
  2844. UINT mheight = D.my;
  2845. UINT mdepth = D.mz;
  2846. // format compiler args
  2847. char compilerOptions[256];
  2848. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2849. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2850. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2851. width, height, depth, mwidth, mheight, mdepth));
  2852. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2853. S.Arguments = compilerOptions;
  2854. pShaderOp->DispatchX = width;
  2855. pShaderOp->DispatchY = height;
  2856. pShaderOp->DispatchZ = depth;
  2857. // Test Compute Shader
  2858. pShaderOp->CS = CS;
  2859. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2860. MappedData data;
  2861. test->Test->GetReadBackData("U0", &data);
  2862. const UINT *pPixels = (UINT *)data.data();
  2863. // To find roughly the center for compute, divide the pixel count in half
  2864. // and truncate to next lowest power of 4 to start at a quad
  2865. UINT offsetCenter = ((UINT64)(width * height * depth)/2) & ~0x3;
  2866. // Test first, second and center quads
  2867. LogCommentFmt(L"Verifying QuadRead* in compute shader results");
  2868. VerifyQuadReadResults(pPixels, 0);
  2869. VerifyQuadReadResults(pPixels, 4);
  2870. VerifyQuadReadResults(pPixels, offsetCenter);
  2871. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2872. offsetCenter = ((UINT64)(mwidth * mheight * mdepth)/2) & ~0x3;
  2873. // Disable CS so mesh goes forward
  2874. pShaderOp->CS = nullptr;
  2875. test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2876. test->Test->GetReadBackData("U1", &data);
  2877. pPixels = (UINT *)data.data();
  2878. // Test first, second and center quads
  2879. LogCommentFmt(L"Verifying QuadRead* in mesh shader results");
  2880. VerifyQuadReadResults(pPixels, 0);
  2881. VerifyQuadReadResults(pPixels, 4);
  2882. VerifyQuadReadResults(pPixels, offsetCenter);
  2883. test->Test->GetReadBackData("U2", &data);
  2884. pPixels = (UINT *)data.data();
  2885. // Test first, second and center quads
  2886. LogCommentFmt(L"Verifying QuadRead* in amplification shader results");
  2887. VerifyQuadReadResults(pPixels, 0);
  2888. VerifyQuadReadResults(pPixels, 4);
  2889. VerifyQuadReadResults(pPixels, offsetCenter);
  2890. }
  2891. }
  2892. }
  2893. void VerifySampleResults(const UINT *pPixels) {
  2894. UINT xlod = 0;
  2895. UINT ylod = 0;
  2896. // Each pixel contains 4 samples and 4 LOD calculations.
  2897. // 2 of these (called 'left' and 'right') have X values that vary and a constant Y
  2898. // 2 others (called 'top' and 'bot') have Y values that vary and a constant X
  2899. // Only of the X variant sample results and one of the Y variant results
  2900. // are actually reported for the pixel.
  2901. // The other 2 serve as "helpers" to the other pixels in the quad.
  2902. // On the left side of the quad, the 'left' samples are reported.
  2903. // Op the top of the quad, the 'top' samples are reported and so on.
  2904. // The varying coordinate values alternate between zero and a
  2905. // value whose magnitude increases with the index.
  2906. // As a result, the LOD level should steadily increas.
  2907. // Due to vagaries of implementation, the same derivatives
  2908. // in both directions might result in different levels for different locations
  2909. // in the quad. So only comparisons between sample results and LOD calculations
  2910. // and ensuring that the LOD increased and reaches the max can be tested reliably.
  2911. for (unsigned i = 0; i < 64; i++) {
  2912. // CalculateLOD and Sample from texture with mip levels containing LOD index should match
  2913. VERIFY_ARE_EQUAL(pPixels[4*i + 0], pPixels[4*i + 1]);
  2914. VERIFY_ARE_EQUAL(pPixels[4*i + 2], pPixels[4*i + 3]);
  2915. // Make sure LODs are ever climbing as magnitudes increase
  2916. VERIFY_IS_TRUE(pPixels[4*i] >= xlod);
  2917. xlod = pPixels[4*i];
  2918. VERIFY_IS_TRUE(pPixels[4*i + 2] >= ylod);
  2919. ylod = pPixels[4*i + 2];
  2920. }
  2921. // Make sure we reached the max lod level for both tracks
  2922. VERIFY_ARE_EQUAL(xlod, 6);
  2923. VERIFY_ARE_EQUAL(ylod, 6);
  2924. }
  2925. TEST_F(ExecutionTest, ComputeSampleTest) {
  2926. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2927. CComPtr<IStream> pStream;
  2928. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2929. CComPtr<ID3D12Device> pDevice;
  2930. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2931. return;
  2932. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2933. std::make_shared<st::ShaderOpSet>();
  2934. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2935. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("ComputeSample");
  2936. D3D12_RESOURCE_DESC &texDesc = pShaderOp->GetResourceByName("T0")->Desc;
  2937. UINT texWidth = (UINT)texDesc.Width;
  2938. UINT texHeight = (UINT)texDesc.Height;
  2939. // Initialize texture with the LOD number in each corresponding mip level
  2940. auto SampleInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2941. VERIFY_ARE_EQUAL(0, _stricmp(Name, "T0"));
  2942. size_t size = sizeof(float) * texWidth * texHeight * 2;
  2943. Data.resize(size);
  2944. float *pPrimitives = (float *)Data.data();
  2945. float lod = 0.0;
  2946. int ix = 0;
  2947. while (texHeight > 0 && texWidth > 0) {
  2948. if(!texHeight) texHeight = 1;
  2949. if(!texWidth) texWidth = 1;
  2950. for (size_t j = 0; j < texHeight; ++j) {
  2951. for (size_t i = 0; i < texWidth; ++i) {
  2952. pPrimitives[ix++] = lod;
  2953. }
  2954. }
  2955. lod += 1.0;
  2956. texHeight >>= 1;
  2957. texWidth >>= 1;
  2958. }
  2959. };
  2960. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2961. MappedData data;
  2962. test->Test->GetReadBackData("U0", &data);
  2963. const UINT *pPixels = (UINT *)data.data();
  2964. VerifySampleResults(pPixels);
  2965. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2966. // Disable CS so mesh goes forward
  2967. pShaderOp->CS = nullptr;
  2968. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2969. }
  2970. }
  2971. // Executing a simple binop to verify shadel model 6.1 support; runs with
  2972. // ShaderModel61.CoreRequirement
  2973. TEST_F(ExecutionTest, BasicShaderModel61) {
  2974. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  2975. }
  2976. // Executing a simple binop to verify shadel model 6.3 support; runs with
  2977. // ShaderModel63.CoreRequirement
  2978. TEST_F(ExecutionTest, BasicShaderModel63) {
  2979. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  2980. }
  2981. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  2982. WEX::TestExecution::SetVerifyOutput verifySettings(
  2983. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2984. CComPtr<ID3D12Device> pDevice;
  2985. if (!CreateDevice(&pDevice, shaderModel)) {
  2986. return;
  2987. }
  2988. char *pShaderModelStr;
  2989. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  2990. pShaderModelStr = "cs_6_1";
  2991. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  2992. pShaderModelStr = "cs_6_3";
  2993. } else {
  2994. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  2995. pShaderModelStr = nullptr;
  2996. }
  2997. const char shaderTemplate[] =
  2998. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  2999. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  3000. "[numthreads(8,8,1)]"
  3001. "void main(uint GI : SV_GroupIndex) {"
  3002. " SBinaryOp l = g_buf[GI];"
  3003. " l.output = l.input1 + l.input2;"
  3004. " g_buf[GI] = l;"
  3005. "}";
  3006. char shader[sizeof(shaderTemplate) + 50];
  3007. // Run simple shader with float data types
  3008. char* sTy = "float";
  3009. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  3010. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3011. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  3012. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  3013. // Run simple shader with double data types
  3014. if (DoesDeviceSupportDouble(pDevice)) {
  3015. sTy = "double";
  3016. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  3017. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3018. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  3019. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  3020. }
  3021. else {
  3022. // Optional feature, so it's correct to not support it if declared as such.
  3023. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  3024. }
  3025. // Run simple shader with int64 types
  3026. if (DoesDeviceSupportInt64(pDevice)) {
  3027. sTy = "int64_t";
  3028. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  3029. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3030. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  3031. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  3032. }
  3033. else {
  3034. // Optional feature, so it's correct to not support it if declared as such.
  3035. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  3036. }
  3037. }
  3038. template <class Ty>
  3039. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  3040. DXASSERT_NOMSG("Unsupported type");
  3041. return "";
  3042. }
  3043. template <>
  3044. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  3045. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  3046. }
  3047. template <>
  3048. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  3049. return BasicShaderModelTest_GetFormatString<float>();
  3050. }
  3051. template <>
  3052. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  3053. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  3054. }
  3055. template <class Ty>
  3056. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  3057. Ty *pInputDataPairs, unsigned inputDataCount) {
  3058. struct SBinaryOp {
  3059. Ty input1;
  3060. Ty input2;
  3061. Ty output;
  3062. };
  3063. CComPtr<IStream> pStream;
  3064. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3065. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3066. pDevice, m_support, pStream, "BinaryFPOp",
  3067. // this callbacked is called when the test is creating the resource to run the test
  3068. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3069. UNREFERENCED_PARAMETER(Name);
  3070. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  3071. pShaderOp->Shaders.at(0).Text = pShader;
  3072. size_t size = sizeof(SBinaryOp) * inputDataCount;
  3073. Data.resize(size);
  3074. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  3075. Ty *pIn = pInputDataPairs;
  3076. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  3077. SBinaryOp *p = &pPrimitives[i];
  3078. p->input1 = pIn[0];
  3079. p->input2 = pIn[1];
  3080. }
  3081. });
  3082. VERIFY_SUCCEEDED(S_OK);
  3083. MappedData data;
  3084. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3085. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  3086. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  3087. Ty *pIn = pInputDataPairs;
  3088. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  3089. Ty expValue = pIn[0] + pIn[1];
  3090. SBinaryOp *p = &pPrimitives[i];
  3091. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  3092. VERIFY_ARE_EQUAL(p->output, expValue);
  3093. }
  3094. }
  3095. // Resource structure for data-driven tests.
  3096. struct SUnaryFPOp {
  3097. float input;
  3098. float output;
  3099. };
  3100. struct SBinaryFPOp {
  3101. float input1;
  3102. float input2;
  3103. float output1;
  3104. float output2;
  3105. };
  3106. struct STertiaryFPOp {
  3107. float input1;
  3108. float input2;
  3109. float input3;
  3110. float output;
  3111. };
  3112. struct SUnaryHalfOp {
  3113. uint16_t input;
  3114. uint16_t output;
  3115. };
  3116. struct SBinaryHalfOp {
  3117. uint16_t input1;
  3118. uint16_t input2;
  3119. uint16_t output1;
  3120. uint16_t output2;
  3121. };
  3122. struct STertiaryHalfOp {
  3123. uint16_t input1;
  3124. uint16_t input2;
  3125. uint16_t input3;
  3126. uint16_t output;
  3127. };
  3128. struct SUnaryIntOp {
  3129. int input;
  3130. int output;
  3131. };
  3132. struct SUnaryUintOp {
  3133. unsigned int input;
  3134. unsigned int output;
  3135. };
  3136. struct SBinaryIntOp {
  3137. int input1;
  3138. int input2;
  3139. int output1;
  3140. int output2;
  3141. };
  3142. struct STertiaryIntOp {
  3143. int input1;
  3144. int input2;
  3145. int input3;
  3146. int output;
  3147. };
  3148. struct SBinaryUintOp {
  3149. unsigned int input1;
  3150. unsigned int input2;
  3151. unsigned int output1;
  3152. unsigned int output2;
  3153. };
  3154. struct STertiaryUintOp {
  3155. unsigned int input1;
  3156. unsigned int input2;
  3157. unsigned int input3;
  3158. unsigned int output;
  3159. };
  3160. struct SUnaryInt16Op {
  3161. short input;
  3162. short output;
  3163. };
  3164. struct SUnaryUint16Op {
  3165. unsigned short input;
  3166. unsigned short output;
  3167. };
  3168. struct SBinaryInt16Op {
  3169. short input1;
  3170. short input2;
  3171. short output1;
  3172. short output2;
  3173. };
  3174. struct STertiaryInt16Op {
  3175. short input1;
  3176. short input2;
  3177. short input3;
  3178. short output;
  3179. };
  3180. struct SBinaryUint16Op {
  3181. unsigned short input1;
  3182. unsigned short input2;
  3183. unsigned short output1;
  3184. unsigned short output2;
  3185. };
  3186. struct STertiaryUint16Op {
  3187. unsigned short input1;
  3188. unsigned short input2;
  3189. unsigned short input3;
  3190. unsigned short output;
  3191. };
  3192. // representation for HLSL float vectors
  3193. struct SDotOp {
  3194. XMFLOAT4 input1;
  3195. XMFLOAT4 input2;
  3196. float o_dot2;
  3197. float o_dot3;
  3198. float o_dot4;
  3199. };
  3200. struct Half2
  3201. {
  3202. uint16_t x;
  3203. uint16_t y;
  3204. Half2() = default;
  3205. Half2(const Half2&) = default;
  3206. Half2& operator=(const Half2&) = default;
  3207. Half2(Half2&&) = default;
  3208. Half2& operator=(Half2&&) = default;
  3209. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  3210. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  3211. };
  3212. struct SDot2AddHalfOp {
  3213. Half2 input1;
  3214. Half2 input2;
  3215. float acc;
  3216. float result;
  3217. };
  3218. struct SDot4AddI8PackedOp {
  3219. uint32_t input1;
  3220. uint32_t input2;
  3221. int32_t acc;
  3222. int32_t result;
  3223. };
  3224. struct SDot4AddU8PackedOp {
  3225. uint32_t input1;
  3226. uint32_t input2;
  3227. uint32_t acc;
  3228. uint32_t result;
  3229. };
  3230. struct SMsad4 {
  3231. unsigned int ref;
  3232. XMUINT2 src;
  3233. XMUINT4 accum;
  3234. XMUINT4 result;
  3235. };
  3236. struct SPackUnpackOpOutPacked
  3237. {
  3238. uint32_t packedUint32;
  3239. uint32_t packedInt32;
  3240. uint32_t packedUint16;
  3241. uint32_t packedInt16;
  3242. uint32_t packedClampedUint32;
  3243. uint32_t packedClampedInt32;
  3244. uint32_t packedClampedUint16;
  3245. uint32_t packedClampedInt16;
  3246. };
  3247. struct SPackUnpackOpOutUnpacked {
  3248. std::array<uint32_t, 4> outputUint32;
  3249. std::array<int32_t, 4> outputInt32;
  3250. std::array<uint16_t, 4> outputUint16;
  3251. std::array<int16_t, 4> outputInt16;
  3252. std::array<uint32_t, 4> outputClampedUint32;
  3253. std::array<int32_t, 4> outputClampedInt32;
  3254. std::array<uint16_t, 4> outputClampedUint16;
  3255. std::array<int16_t, 4> outputClampedInt16;
  3256. };
  3257. // Parameter representation for taef data-driven tests
  3258. struct TableParameter {
  3259. LPCWSTR m_name;
  3260. enum TableParameterType {
  3261. INT8,
  3262. INT16,
  3263. INT32,
  3264. UINT,
  3265. FLOAT,
  3266. HALF,
  3267. DOUBLE,
  3268. STRING,
  3269. BOOL,
  3270. INT8_TABLE,
  3271. INT16_TABLE,
  3272. INT32_TABLE,
  3273. FLOAT_TABLE,
  3274. HALF_TABLE,
  3275. DOUBLE_TABLE,
  3276. STRING_TABLE,
  3277. UINT8_TABLE,
  3278. UINT16_TABLE,
  3279. UINT32_TABLE,
  3280. BOOL_TABLE
  3281. };
  3282. TableParameterType m_type;
  3283. bool m_required; // required parameter
  3284. int8_t m_int8;
  3285. int16_t m_int16;
  3286. int m_int32;
  3287. unsigned int m_uint;
  3288. float m_float;
  3289. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  3290. double m_double;
  3291. bool m_bool;
  3292. WEX::Common::String m_str;
  3293. std::vector<int8_t> m_int8Table;
  3294. std::vector<int16_t> m_int16Table;
  3295. std::vector<int> m_int32Table;
  3296. std::vector<uint8_t> m_uint8Table;
  3297. std::vector<uint16_t> m_uint16Table;
  3298. std::vector<unsigned int> m_uint32Table;
  3299. std::vector<float> m_floatTable;
  3300. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  3301. std::vector<double> m_doubleTable;
  3302. std::vector<bool> m_boolTable;
  3303. std::vector<WEX::Common::String> m_StringTable;
  3304. };
  3305. class TableParameterHandler {
  3306. private:
  3307. HRESULT ParseTableRow();
  3308. public:
  3309. TableParameter* m_table;
  3310. size_t m_tableSize;
  3311. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  3312. clearTableParameter();
  3313. VERIFY_SUCCEEDED(ParseTableRow());
  3314. }
  3315. TableParameter* GetTableParamByName(LPCWSTR name) {
  3316. for (size_t i = 0; i < m_tableSize; ++i) {
  3317. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3318. return &m_table[i];
  3319. }
  3320. }
  3321. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3322. return nullptr;
  3323. }
  3324. void clearTableParameter() {
  3325. for (size_t i = 0; i < m_tableSize; ++i) {
  3326. m_table[i].m_int32 = 0;
  3327. m_table[i].m_uint = 0;
  3328. m_table[i].m_double = 0;
  3329. m_table[i].m_bool = false;
  3330. m_table[i].m_str = WEX::Common::String();
  3331. }
  3332. }
  3333. template <class T1>
  3334. std::vector<T1> *GetDataArray(LPCWSTR name) {
  3335. return nullptr;
  3336. }
  3337. template <>
  3338. std::vector<int> *GetDataArray(LPCWSTR name) {
  3339. for (size_t i = 0; i < m_tableSize; ++i) {
  3340. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3341. return &(m_table[i].m_int32Table);
  3342. }
  3343. }
  3344. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3345. return nullptr;
  3346. }
  3347. template <>
  3348. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  3349. for (size_t i = 0; i < m_tableSize; ++i) {
  3350. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3351. return &(m_table[i].m_int8Table);
  3352. }
  3353. }
  3354. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3355. return nullptr;
  3356. }
  3357. template <>
  3358. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  3359. for (size_t i = 0; i < m_tableSize; ++i) {
  3360. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3361. return &(m_table[i].m_int16Table);
  3362. }
  3363. }
  3364. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3365. return nullptr;
  3366. }
  3367. template <>
  3368. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  3369. for (size_t i = 0; i < m_tableSize; ++i) {
  3370. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3371. return &(m_table[i].m_uint32Table);
  3372. }
  3373. }
  3374. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3375. return nullptr;
  3376. }
  3377. template <>
  3378. std::vector<float> *GetDataArray(LPCWSTR name) {
  3379. for (size_t i = 0; i < m_tableSize; ++i) {
  3380. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3381. return &(m_table[i].m_floatTable);
  3382. }
  3383. }
  3384. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3385. return nullptr;
  3386. }
  3387. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  3388. template <>
  3389. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  3390. for (size_t i = 0; i < m_tableSize; ++i) {
  3391. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3392. return &(m_table[i].m_halfTable);
  3393. }
  3394. }
  3395. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3396. return nullptr;
  3397. }
  3398. template <>
  3399. std::vector<double> *GetDataArray(LPCWSTR name) {
  3400. for (size_t i = 0; i < m_tableSize; ++i) {
  3401. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3402. return &(m_table[i].m_doubleTable);
  3403. }
  3404. }
  3405. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3406. return nullptr;
  3407. }
  3408. template <>
  3409. std::vector<bool> *GetDataArray(LPCWSTR name) {
  3410. for (size_t i = 0; i < m_tableSize; ++i) {
  3411. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3412. return &(m_table[i].m_boolTable);
  3413. }
  3414. }
  3415. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3416. return nullptr;
  3417. }
  3418. };
  3419. static TableParameter UnaryFPOpParameters[] = {
  3420. { L"ShaderOp.Target", TableParameter::STRING, true },
  3421. { L"ShaderOp.Text", TableParameter::STRING, true },
  3422. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3423. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3424. { L"Validation.Type", TableParameter::STRING, true },
  3425. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3426. { L"Warp.Version", TableParameter::UINT, false }
  3427. };
  3428. static TableParameter BinaryFPOpParameters[] = {
  3429. { L"ShaderOp.Target", TableParameter::STRING, true },
  3430. { L"ShaderOp.Text", TableParameter::STRING, true },
  3431. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3432. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3433. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3434. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  3435. { L"Validation.Type", TableParameter::STRING, true },
  3436. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3437. };
  3438. static TableParameter TertiaryFPOpParameters[] = {
  3439. { L"ShaderOp.Target", TableParameter::STRING, true },
  3440. { L"ShaderOp.Text", TableParameter::STRING, true },
  3441. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3442. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3443. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3444. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3445. { L"Validation.Type", TableParameter::STRING, true },
  3446. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3447. };
  3448. static TableParameter UnaryHalfOpParameters[] = {
  3449. { L"ShaderOp.Target", TableParameter::STRING, true },
  3450. { L"ShaderOp.Text", TableParameter::STRING, true },
  3451. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3452. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3453. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3454. { L"Validation.Type", TableParameter::STRING, true },
  3455. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3456. { L"Warp.Version", TableParameter::UINT, false }
  3457. };
  3458. static TableParameter BinaryHalfOpParameters[] = {
  3459. { L"ShaderOp.Target", TableParameter::STRING, true },
  3460. { L"ShaderOp.Text", TableParameter::STRING, true },
  3461. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3462. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3463. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3464. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3465. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  3466. { L"Validation.Type", TableParameter::STRING, true },
  3467. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3468. };
  3469. static TableParameter TertiaryHalfOpParameters[] = {
  3470. { L"ShaderOp.Target", TableParameter::STRING, true },
  3471. { L"ShaderOp.Text", TableParameter::STRING, true },
  3472. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3473. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3474. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3475. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  3476. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3477. { L"Validation.Type", TableParameter::STRING, true },
  3478. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3479. };
  3480. static TableParameter UnaryIntOpParameters[] = {
  3481. { L"ShaderOp.Target", TableParameter::STRING, true },
  3482. { L"ShaderOp.Text", TableParameter::STRING, true },
  3483. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3484. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3485. { L"Validation.Tolerance", TableParameter::INT32, true },
  3486. };
  3487. static TableParameter UnaryUintOpParameters[] = {
  3488. { L"ShaderOp.Target", TableParameter::STRING, true },
  3489. { L"ShaderOp.Text", TableParameter::STRING, true },
  3490. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3491. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3492. { L"Validation.Tolerance", TableParameter::INT32, true },
  3493. };
  3494. static TableParameter BinaryIntOpParameters[] = {
  3495. { L"ShaderOp.Target", TableParameter::STRING, true },
  3496. { L"ShaderOp.Text", TableParameter::STRING, true },
  3497. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3498. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3499. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3500. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  3501. { L"Validation.Tolerance", TableParameter::INT32, true },
  3502. };
  3503. static TableParameter TertiaryIntOpParameters[] = {
  3504. { L"ShaderOp.Target", TableParameter::STRING, true },
  3505. { L"ShaderOp.Text", TableParameter::STRING, true },
  3506. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3507. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3508. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3509. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3510. { L"Validation.Tolerance", TableParameter::INT32, true },
  3511. };
  3512. static TableParameter BinaryUintOpParameters[] = {
  3513. { L"ShaderOp.Target", TableParameter::STRING, true },
  3514. { L"ShaderOp.Text", TableParameter::STRING, true },
  3515. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3516. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3517. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3518. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  3519. { L"Validation.Tolerance", TableParameter::INT32, true },
  3520. };
  3521. static TableParameter TertiaryUintOpParameters[] = {
  3522. { L"ShaderOp.Target", TableParameter::STRING, true },
  3523. { L"ShaderOp.Text", TableParameter::STRING, true },
  3524. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3525. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3526. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3527. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3528. { L"Validation.Tolerance", TableParameter::INT32, true },
  3529. };
  3530. static TableParameter UnaryInt16OpParameters[] = {
  3531. { L"ShaderOp.Target", TableParameter::STRING, true },
  3532. { L"ShaderOp.Text", TableParameter::STRING, true },
  3533. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3534. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3535. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3536. { L"Validation.Tolerance", TableParameter::INT32, true },
  3537. };
  3538. static TableParameter UnaryUint16OpParameters[] = {
  3539. { L"ShaderOp.Target", TableParameter::STRING, true },
  3540. { L"ShaderOp.Text", TableParameter::STRING, true },
  3541. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3542. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3543. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3544. { L"Validation.Tolerance", TableParameter::INT32, true },
  3545. };
  3546. static TableParameter BinaryInt16OpParameters[] = {
  3547. { L"ShaderOp.Target", TableParameter::STRING, true },
  3548. { L"ShaderOp.Text", TableParameter::STRING, true },
  3549. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3550. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3551. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3552. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3553. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  3554. { L"Validation.Tolerance", TableParameter::INT32, true },
  3555. };
  3556. static TableParameter TertiaryInt16OpParameters[] = {
  3557. { L"ShaderOp.Target", TableParameter::STRING, true },
  3558. { L"ShaderOp.Text", TableParameter::STRING, true },
  3559. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3560. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3561. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3562. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  3563. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3564. { L"Validation.Tolerance", TableParameter::INT32, true },
  3565. };
  3566. static TableParameter BinaryUint16OpParameters[] = {
  3567. { L"ShaderOp.Target", TableParameter::STRING, true },
  3568. { L"ShaderOp.Text", TableParameter::STRING, true },
  3569. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3570. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3571. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3572. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3573. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  3574. { L"Validation.Tolerance", TableParameter::INT32, true },
  3575. };
  3576. static TableParameter TertiaryUint16OpParameters[] = {
  3577. { L"ShaderOp.Target", TableParameter::STRING, true },
  3578. { L"ShaderOp.Text", TableParameter::STRING, true },
  3579. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3580. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3581. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3582. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  3583. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3584. { L"Validation.Tolerance", TableParameter::INT32, true },
  3585. };
  3586. static TableParameter DotOpParameters[] = {
  3587. { L"ShaderOp.Target", TableParameter::STRING, true },
  3588. { L"ShaderOp.Text", TableParameter::STRING, true },
  3589. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3590. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3591. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3592. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  3593. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  3594. { L"Validation.Type", TableParameter::STRING, true },
  3595. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3596. };
  3597. static TableParameter Dot2AddHalfOpParameters[] = {
  3598. { L"ShaderOp.Target", TableParameter::STRING, true },
  3599. { L"ShaderOp.Text", TableParameter::STRING, true },
  3600. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3601. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3602. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3603. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3604. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3605. { L"Validation.Type", TableParameter::STRING, true },
  3606. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3607. };
  3608. static TableParameter Dot4AddI8PackedOpParameters[] = {
  3609. { L"ShaderOp.Target", TableParameter::STRING, true },
  3610. { L"ShaderOp.Text", TableParameter::STRING, true },
  3611. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3612. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3613. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3614. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3615. };
  3616. static TableParameter Dot4AddU8PackedOpParameters[] = {
  3617. { L"ShaderOp.Target", TableParameter::STRING, true },
  3618. { L"ShaderOp.Text", TableParameter::STRING, true },
  3619. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3620. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3621. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3622. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3623. };
  3624. static TableParameter Msad4OpParameters[] = {
  3625. { L"ShaderOp.Text", TableParameter::STRING, true },
  3626. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3627. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  3628. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3629. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3630. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  3631. };
  3632. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  3633. { L"ShaderOp.Name", TableParameter::STRING, true },
  3634. { L"ShaderOp.Text", TableParameter::STRING, true },
  3635. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3636. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3637. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3638. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3639. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3640. };
  3641. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  3642. { L"ShaderOp.Name", TableParameter::STRING, true },
  3643. { L"ShaderOp.Text", TableParameter::STRING, true },
  3644. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3645. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3646. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3647. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3648. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3649. };
  3650. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  3651. { L"ShaderOp.Name", TableParameter::STRING, true },
  3652. { L"ShaderOp.Text", TableParameter::STRING, true },
  3653. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3654. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3655. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3656. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3657. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3658. };
  3659. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  3660. { L"ShaderOp.Name", TableParameter::STRING, true },
  3661. { L"ShaderOp.Text", TableParameter::STRING, true },
  3662. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3663. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3664. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3665. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3666. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3667. };
  3668. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  3669. { L"ShaderOp.Name", TableParameter::STRING, true },
  3670. { L"ShaderOp.Target", TableParameter::STRING, true },
  3671. { L"ShaderOp.Text", TableParameter::STRING, true },
  3672. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  3673. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  3674. };
  3675. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  3676. { L"ShaderOp.Name", TableParameter::STRING, true },
  3677. { L"ShaderOp.Target", TableParameter::STRING, true },
  3678. { L"ShaderOp.Text", TableParameter::STRING, true },
  3679. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  3680. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  3681. };
  3682. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  3683. { L"ShaderOp.Name", TableParameter::STRING, true },
  3684. { L"ShaderOp.Text", TableParameter::STRING, true },
  3685. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3686. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  3687. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  3688. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  3689. };
  3690. static TableParameter CBufferTestHalfParameters[] = {
  3691. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  3692. };
  3693. static TableParameter DenormBinaryFPOpParameters[] = {
  3694. { L"ShaderOp.Target", TableParameter::STRING, true },
  3695. { L"ShaderOp.Text", TableParameter::STRING, true },
  3696. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3697. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3698. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3699. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3700. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3701. { L"Validation.Type", TableParameter::STRING, true },
  3702. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3703. };
  3704. static TableParameter DenormTertiaryFPOpParameters[] = {
  3705. { L"ShaderOp.Target", TableParameter::STRING, true },
  3706. { L"ShaderOp.Text", TableParameter::STRING, true },
  3707. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3708. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3709. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3710. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3711. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3712. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3713. { L"Validation.Type", TableParameter::STRING, true },
  3714. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3715. };
  3716. static TableParameter PackUnpackOpParameters[] = {
  3717. { L"ShaderOp.Text", TableParameter::STRING, true },
  3718. { L"Validation.Type", TableParameter::STRING, true },
  3719. { L"Validation.Tolerance", TableParameter::UINT, true },
  3720. { L"Validation.Input", TableParameter::UINT32_TABLE, true },
  3721. };
  3722. static bool IsHexString(PCWSTR str, uint16_t *value) {
  3723. std::wstring wString(str);
  3724. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3725. LPCWSTR wstr = wString.c_str();
  3726. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  3727. *value = (uint16_t)wcstol(wstr, NULL, 0);
  3728. return true;
  3729. }
  3730. return false;
  3731. }
  3732. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  3733. std::wstring wString(str);
  3734. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3735. PCWSTR wstr = wString.data();
  3736. if (_wcsicmp(wstr, L"NaN") == 0) {
  3737. value = NAN;
  3738. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  3739. value = -(INFINITY);
  3740. } else if (_wcsicmp(wstr, L"inf") == 0) {
  3741. value = INFINITY;
  3742. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  3743. value = -(FLT_MIN / 2);
  3744. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  3745. value = FLT_MIN / 2;
  3746. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  3747. _wcsicmp(wstr, L"-0") == 0) {
  3748. value = -0.0f;
  3749. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  3750. _wcsicmp(wstr, L"0") == 0) {
  3751. value = 0.0f;
  3752. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  3753. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  3754. value = (float&)temp_i;
  3755. }
  3756. else {
  3757. // evaluate the expression of wstring
  3758. double val = _wtof(wstr);
  3759. if (val == 0) {
  3760. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  3761. return E_FAIL;
  3762. }
  3763. value = (float)val;
  3764. }
  3765. return S_OK;
  3766. }
  3767. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  3768. std::wstring wString(str);
  3769. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3770. PCWSTR wstr = wString.data();
  3771. // evaluate the expression of string
  3772. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  3773. value = 0;
  3774. return S_OK;
  3775. }
  3776. int val = _wtoi(wstr);
  3777. if (val == 0) {
  3778. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3779. return E_FAIL;
  3780. }
  3781. value = val;
  3782. return S_OK;
  3783. }
  3784. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3785. std::wstring wString(str);
  3786. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3787. PCWSTR wstr = wString.data();
  3788. // evaluate the expression of string
  3789. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3790. value = 0;
  3791. return S_OK;
  3792. }
  3793. wchar_t *end;
  3794. unsigned int val = std::wcstoul(wstr, &end, 0);
  3795. if (val == 0) {
  3796. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3797. return E_FAIL;
  3798. }
  3799. value = val;
  3800. return S_OK;
  3801. }
  3802. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3803. std::wstring wstr(str);
  3804. size_t curPosition = 0;
  3805. // parse a string of dot product separated by commas
  3806. for (size_t i = 0; i < count; ++i) {
  3807. size_t nextPosition = wstr.find(L",", curPosition);
  3808. if (FAILED(ParseDataToFloat(
  3809. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3810. *(ptr + i)))) {
  3811. return E_FAIL;
  3812. }
  3813. curPosition = nextPosition + 1;
  3814. }
  3815. return S_OK;
  3816. }
  3817. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3818. std::wstring wstr(str);
  3819. size_t curPosition = 0;
  3820. // parse a string of dot product separated by commas
  3821. for (size_t i = 0; i < count; ++i) {
  3822. size_t nextPosition = wstr.find(L",", curPosition);
  3823. float floatValue;
  3824. if (FAILED(ParseDataToFloat(
  3825. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3826. return E_FAIL;
  3827. }
  3828. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3829. curPosition = nextPosition + 1;
  3830. }
  3831. return S_OK;
  3832. }
  3833. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3834. std::wstring wstr(str);
  3835. size_t curPosition = 0;
  3836. // parse a string of dot product separated by commas
  3837. for (size_t i = 0; i < count; ++i) {
  3838. size_t nextPosition = wstr.find(L",", curPosition);
  3839. if (FAILED(ParseDataToUint(
  3840. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3841. *(ptr + i)))) {
  3842. return E_FAIL;
  3843. }
  3844. curPosition = nextPosition + 1;
  3845. }
  3846. return S_OK;
  3847. }
  3848. HRESULT TableParameterHandler::ParseTableRow() {
  3849. TableParameter *table = m_table;
  3850. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3851. switch (table[i].m_type) {
  3852. case TableParameter::INT8:
  3853. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3854. table[i].m_int32)) && table[i].m_required) {
  3855. // TryGetValue does not suppport reading from int16
  3856. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3857. return E_FAIL;
  3858. }
  3859. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3860. break;
  3861. case TableParameter::INT16:
  3862. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3863. table[i].m_int32)) && table[i].m_required) {
  3864. // TryGetValue does not suppport reading from int16
  3865. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3866. return E_FAIL;
  3867. }
  3868. table[i].m_int16 = (short)(table[i].m_int32);
  3869. break;
  3870. case TableParameter::INT32:
  3871. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3872. table[i].m_int32)) && table[i].m_required) {
  3873. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3874. return E_FAIL;
  3875. }
  3876. break;
  3877. case TableParameter::UINT:
  3878. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3879. table[i].m_uint)) && table[i].m_required) {
  3880. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3881. return E_FAIL;
  3882. }
  3883. break;
  3884. case TableParameter::DOUBLE:
  3885. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3886. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3887. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3888. return E_FAIL;
  3889. }
  3890. break;
  3891. case TableParameter::STRING:
  3892. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3893. table[i].m_str)) && table[i].m_required) {
  3894. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3895. return E_FAIL;
  3896. }
  3897. break;
  3898. case TableParameter::BOOL:
  3899. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3900. table[i].m_str)) && table[i].m_bool) {
  3901. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3902. return E_FAIL;
  3903. }
  3904. break;
  3905. case TableParameter::INT8_TABLE: {
  3906. WEX::TestExecution::TestDataArray<int> tempTable;
  3907. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3908. table[i].m_name, tempTable)) && table[i].m_required) {
  3909. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3910. return E_FAIL;
  3911. }
  3912. // TryGetValue does not suppport reading from int8
  3913. table[i].m_int8Table.resize(tempTable.GetSize());
  3914. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3915. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  3916. }
  3917. break;
  3918. }
  3919. case TableParameter::INT16_TABLE: {
  3920. WEX::TestExecution::TestDataArray<int> tempTable;
  3921. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3922. table[i].m_name, tempTable)) && table[i].m_required) {
  3923. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3924. return E_FAIL;
  3925. }
  3926. // TryGetValue does not suppport reading from int8
  3927. table[i].m_int16Table.resize(tempTable.GetSize());
  3928. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3929. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  3930. }
  3931. break;
  3932. }case TableParameter::INT32_TABLE: {
  3933. WEX::TestExecution::TestDataArray<int> tempTable;
  3934. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3935. table[i].m_name, tempTable)) && table[i].m_required) {
  3936. // TryGetValue does not suppport reading from int8
  3937. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3938. return E_FAIL;
  3939. }
  3940. table[i].m_int32Table.resize(tempTable.GetSize());
  3941. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3942. table[i].m_int32Table[j] = tempTable[j];
  3943. }
  3944. break;
  3945. }
  3946. case TableParameter::UINT8_TABLE: {
  3947. WEX::TestExecution::TestDataArray<int> tempTable;
  3948. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3949. table[i].m_name, tempTable)) && table[i].m_required) {
  3950. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3951. return E_FAIL;
  3952. }
  3953. // TryGetValue does not suppport reading from int8
  3954. table[i].m_int8Table.resize(tempTable.GetSize());
  3955. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3956. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  3957. }
  3958. break;
  3959. }
  3960. case TableParameter::UINT16_TABLE: {
  3961. WEX::TestExecution::TestDataArray<int> tempTable;
  3962. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3963. table[i].m_name, tempTable)) && table[i].m_required) {
  3964. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3965. return E_FAIL;
  3966. }
  3967. // TryGetValue does not suppport reading from int8
  3968. table[i].m_uint16Table.resize(tempTable.GetSize());
  3969. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3970. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  3971. }
  3972. break;
  3973. }
  3974. case TableParameter::UINT32_TABLE: {
  3975. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  3976. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3977. table[i].m_name, tempTable)) && table[i].m_required) {
  3978. // TryGetValue does not suppport reading from int8
  3979. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3980. return E_FAIL;
  3981. }
  3982. table[i].m_uint32Table.resize(tempTable.GetSize());
  3983. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3984. table[i].m_uint32Table[j] = tempTable[j];
  3985. }
  3986. break;
  3987. }
  3988. case TableParameter::FLOAT_TABLE: {
  3989. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  3990. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3991. table[i].m_name, tempTable)) && table[i].m_required) {
  3992. // TryGetValue does not suppport reading from int8
  3993. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3994. return E_FAIL;
  3995. }
  3996. table[i].m_floatTable.resize(tempTable.GetSize());
  3997. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3998. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  3999. }
  4000. break;
  4001. }
  4002. case TableParameter::HALF_TABLE: {
  4003. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4004. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4005. table[i].m_name, tempTable)) && table[i].m_required) {
  4006. // TryGetValue does not suppport reading from int8
  4007. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4008. return E_FAIL;
  4009. }
  4010. table[i].m_halfTable.resize(tempTable.GetSize());
  4011. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4012. uint16_t value = 0;
  4013. if (IsHexString(tempTable[j], &value)) {
  4014. table[i].m_halfTable[j] = value;
  4015. }
  4016. else {
  4017. float val;
  4018. ParseDataToFloat(tempTable[j], val);
  4019. if (isdenorm(val))
  4020. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  4021. else
  4022. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  4023. }
  4024. }
  4025. break;
  4026. }
  4027. case TableParameter::DOUBLE_TABLE: {
  4028. WEX::TestExecution::TestDataArray<double> tempTable;
  4029. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4030. table[i].m_name, tempTable)) && table[i].m_required) {
  4031. // TryGetValue does not suppport reading from int8
  4032. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4033. return E_FAIL;
  4034. }
  4035. table[i].m_doubleTable.resize(tempTable.GetSize());
  4036. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4037. table[i].m_doubleTable[j] = tempTable[j];
  4038. }
  4039. break;
  4040. }
  4041. case TableParameter::BOOL_TABLE: {
  4042. WEX::TestExecution::TestDataArray<bool> tempTable;
  4043. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4044. table[i].m_name, tempTable)) && table[i].m_required) {
  4045. // TryGetValue does not suppport reading from int8
  4046. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4047. return E_FAIL;
  4048. }
  4049. table[i].m_boolTable.resize(tempTable.GetSize());
  4050. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4051. table[i].m_boolTable[j] = tempTable[j];
  4052. }
  4053. break;
  4054. }
  4055. case TableParameter::STRING_TABLE: {
  4056. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4057. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4058. table[i].m_name, tempTable)) && table[i].m_required) {
  4059. // TryGetValue does not suppport reading from int8
  4060. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4061. return E_FAIL;
  4062. }
  4063. table[i].m_StringTable.resize(tempTable.GetSize());
  4064. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4065. table[i].m_StringTable[j] = tempTable[j];
  4066. }
  4067. break;
  4068. }
  4069. default:
  4070. DXASSERT_NOMSG("Invalid Parameter Type");
  4071. }
  4072. if (errno == ERANGE) {
  4073. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  4074. return E_FAIL;
  4075. }
  4076. }
  4077. return S_OK;
  4078. }
  4079. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  4080. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4081. }
  4082. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  4083. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4084. }
  4085. static void VerifyOutputWithExpectedValueFloat(
  4086. float output, float ref, LPCWSTR type, double tolerance,
  4087. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4088. if (_wcsicmp(type, L"Relative") == 0) {
  4089. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  4090. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4091. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  4092. } else if (_wcsicmp(type, L"ULP") == 0) {
  4093. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  4094. } else {
  4095. LogErrorFmt(L"Failed to read comparison type %S", type);
  4096. }
  4097. }
  4098. static bool CompareOutputWithExpectedValueFloat(
  4099. float output, float ref, LPCWSTR type, double tolerance,
  4100. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4101. if (_wcsicmp(type, L"Relative") == 0) {
  4102. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  4103. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4104. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  4105. } else if (_wcsicmp(type, L"ULP") == 0) {
  4106. return CompareFloatULP(output, ref, (int)tolerance, mode);
  4107. } else {
  4108. LogErrorFmt(L"Failed to read comparison type %S", type);
  4109. return false;
  4110. }
  4111. }
  4112. static void VerifyOutputWithExpectedValueHalf(
  4113. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  4114. if (_wcsicmp(type, L"Relative") == 0) {
  4115. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  4116. }
  4117. else if (_wcsicmp(type, L"Epsilon") == 0) {
  4118. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  4119. }
  4120. else if (_wcsicmp(type, L"ULP") == 0) {
  4121. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  4122. }
  4123. else {
  4124. LogErrorFmt(L"Failed to read comparison type %S", type);
  4125. }
  4126. }
  4127. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  4128. WEX::TestExecution::SetVerifyOutput verifySettings(
  4129. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4130. CComPtr<IStream> pStream;
  4131. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4132. CComPtr<ID3D12Device> pDevice;
  4133. if (!CreateDevice(&pDevice)) {
  4134. return;
  4135. }
  4136. // Read data from the table
  4137. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  4138. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  4139. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4140. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4141. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4142. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4143. return;
  4144. }
  4145. std::vector<float> *Validation_Input =
  4146. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4147. std::vector<float> *Validation_Expected =
  4148. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4149. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4150. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4151. size_t count = Validation_Input->size();
  4152. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4153. pDevice, m_support, pStream, "UnaryFPOp",
  4154. // this callbacked is called when the test
  4155. // is creating the resource to run the test
  4156. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4157. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4158. size_t size = sizeof(SUnaryFPOp) * count;
  4159. Data.resize(size);
  4160. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  4161. for (size_t i = 0; i < count; ++i) {
  4162. SUnaryFPOp *p = &pPrimitives[i];
  4163. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4164. }
  4165. // use shader from data table
  4166. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4167. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4168. });
  4169. MappedData data;
  4170. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4171. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  4172. WEX::TestExecution::DisableVerifyExceptions dve;
  4173. for (unsigned i = 0; i < count; ++i) {
  4174. SUnaryFPOp *p = &pPrimitives[i];
  4175. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4176. LogCommentFmt(
  4177. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  4178. p->input, p->output, val);
  4179. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  4180. }
  4181. }
  4182. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  4183. WEX::TestExecution::SetVerifyOutput verifySettings(
  4184. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4185. CComPtr<IStream> pStream;
  4186. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4187. CComPtr<ID3D12Device> pDevice;
  4188. if (!CreateDevice(&pDevice)) {
  4189. return;
  4190. }
  4191. // Read data from the table
  4192. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  4193. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  4194. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4195. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4196. std::vector<float> *Validation_Input1 =
  4197. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4198. std::vector<float> *Validation_Input2 =
  4199. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4200. std::vector<float> *Validation_Expected1 =
  4201. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4202. std::vector<float> *Validation_Expected2 =
  4203. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  4204. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4205. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4206. size_t count = Validation_Input1->size();
  4207. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4208. pDevice, m_support, pStream, "BinaryFPOp",
  4209. // this callbacked is called when the test
  4210. // is creating the resource to run the test
  4211. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4212. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4213. size_t size = sizeof(SBinaryFPOp) * count;
  4214. Data.resize(size);
  4215. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4216. for (size_t i = 0; i < count; ++i) {
  4217. SBinaryFPOp *p = &pPrimitives[i];
  4218. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4219. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4220. }
  4221. // use shader from data table
  4222. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4223. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4224. });
  4225. MappedData data;
  4226. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4227. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4228. WEX::TestExecution::DisableVerifyExceptions dve;
  4229. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4230. if (numExpected == 2) {
  4231. for (unsigned i = 0; i < count; ++i) {
  4232. SBinaryFPOp *p = &pPrimitives[i];
  4233. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4234. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4235. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4236. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  4237. i, p->input1, p->input2, p->output1, val1, p->output2,
  4238. val2);
  4239. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4240. Validation_Tolerance);
  4241. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  4242. Validation_Tolerance);
  4243. }
  4244. }
  4245. else if (numExpected == 1) {
  4246. for (unsigned i = 0; i < count; ++i) {
  4247. SBinaryFPOp *p = &pPrimitives[i];
  4248. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4249. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4250. L"%6.8f, expected1 = %6.8f",
  4251. i, p->input1, p->input2, p->output1, val1);
  4252. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4253. Validation_Tolerance);
  4254. }
  4255. }
  4256. else {
  4257. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4258. }
  4259. }
  4260. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  4261. WEX::TestExecution::SetVerifyOutput verifySettings(
  4262. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4263. CComPtr<IStream> pStream;
  4264. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4265. CComPtr<ID3D12Device> pDevice;
  4266. if (!CreateDevice(&pDevice)) {
  4267. return;
  4268. }
  4269. // Read data from the table
  4270. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  4271. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  4272. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4273. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4274. std::vector<float> *Validation_Input1 =
  4275. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4276. std::vector<float> *Validation_Input2 =
  4277. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4278. std::vector<float> *Validation_Input3 =
  4279. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  4280. std::vector<float> *Validation_Expected =
  4281. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4282. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4283. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4284. size_t count = Validation_Input1->size();
  4285. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4286. pDevice, m_support, pStream, "TertiaryFPOp",
  4287. // this callbacked is called when the test
  4288. // is creating the resource to run the test
  4289. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4290. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4291. size_t size = sizeof(STertiaryFPOp) * count;
  4292. Data.resize(size);
  4293. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  4294. for (size_t i = 0; i < count; ++i) {
  4295. STertiaryFPOp *p = &pPrimitives[i];
  4296. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4297. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4298. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4299. }
  4300. // use shader from data table
  4301. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4302. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4303. });
  4304. MappedData data;
  4305. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4306. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  4307. WEX::TestExecution::DisableVerifyExceptions dve;
  4308. for (unsigned i = 0; i < count; ++i) {
  4309. STertiaryFPOp *p = &pPrimitives[i];
  4310. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4311. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  4312. L"%6.8f, expected = %6.8f",
  4313. i, p->input1, p->input2, p->input3, p->output, val);
  4314. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  4315. Validation_Tolerance);
  4316. }
  4317. }
  4318. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  4319. WEX::TestExecution::SetVerifyOutput verifySettings(
  4320. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4321. CComPtr<IStream> pStream;
  4322. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4323. CComPtr<ID3D12Device> pDevice;
  4324. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4325. return;
  4326. }
  4327. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4328. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4329. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4330. return;
  4331. }
  4332. // Read data from the table
  4333. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  4334. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  4335. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4336. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4337. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4338. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4339. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4340. return;
  4341. }
  4342. std::vector<uint16_t> *Validation_Input =
  4343. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4344. std::vector<uint16_t> *Validation_Expected =
  4345. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4346. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4347. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4348. size_t count = Validation_Input->size();
  4349. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4350. pDevice, m_support, pStream, "UnaryFPOp",
  4351. // this callbacked is called when the test
  4352. // is creating the resource to run the test
  4353. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4354. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4355. size_t size = sizeof(SUnaryHalfOp) * count;
  4356. Data.resize(size);
  4357. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  4358. for (size_t i = 0; i < count; ++i) {
  4359. SUnaryHalfOp *p = &pPrimitives[i];
  4360. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4361. }
  4362. // use shader from data table
  4363. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4364. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4365. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4366. });
  4367. MappedData data;
  4368. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4369. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  4370. WEX::TestExecution::DisableVerifyExceptions dve;
  4371. for (unsigned i = 0; i < count; ++i) {
  4372. SUnaryHalfOp *p = &pPrimitives[i];
  4373. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  4374. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4375. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4376. i, ConvertFloat16ToFloat32(p->input), p->input,
  4377. ConvertFloat16ToFloat32(p->output), p->output,
  4378. ConvertFloat16ToFloat32(expected), expected);
  4379. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4380. }
  4381. }
  4382. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  4383. WEX::TestExecution::SetVerifyOutput verifySettings(
  4384. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4385. CComPtr<IStream> pStream;
  4386. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4387. CComPtr<ID3D12Device> pDevice;
  4388. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4389. return;
  4390. }
  4391. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4392. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4393. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4394. return;
  4395. }
  4396. // Read data from the table
  4397. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  4398. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  4399. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4400. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4401. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4402. std::vector<uint16_t> *Validation_Input1 =
  4403. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4404. std::vector<uint16_t> *Validation_Input2 =
  4405. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4406. std::vector<uint16_t> *Validation_Expected1 =
  4407. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4408. std::vector<uint16_t> *Validation_Expected2 =
  4409. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  4410. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4411. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4412. size_t count = Validation_Input1->size();
  4413. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4414. pDevice, m_support, pStream, "BinaryFPOp",
  4415. // this callbacked is called when the test
  4416. // is creating the resource to run the test
  4417. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4418. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4419. size_t size = sizeof(SBinaryHalfOp) * count;
  4420. Data.resize(size);
  4421. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  4422. for (size_t i = 0; i < count; ++i) {
  4423. SBinaryHalfOp *p = &pPrimitives[i];
  4424. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4425. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4426. }
  4427. // use shader from data table
  4428. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4429. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4430. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4431. });
  4432. MappedData data;
  4433. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4434. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  4435. WEX::TestExecution::DisableVerifyExceptions dve;
  4436. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4437. if (numExpected == 2) {
  4438. for (unsigned i = 0; i < count; ++i) {
  4439. SBinaryHalfOp *p = &pPrimitives[i];
  4440. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  4441. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  4442. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  4443. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  4444. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4445. ConvertFloat16ToFloat32(p->input2), p->input2,
  4446. ConvertFloat16ToFloat32(p->output1), p->output1,
  4447. ConvertFloat16ToFloat32(p->output2), p->output2,
  4448. ConvertFloat16ToFloat32(expected1), expected1,
  4449. ConvertFloat16ToFloat32(expected2), expected2);
  4450. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  4451. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  4452. }
  4453. }
  4454. else if (numExpected == 1) {
  4455. for (unsigned i = 0; i < count; ++i) {
  4456. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  4457. SBinaryHalfOp *p = &pPrimitives[i];
  4458. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4459. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4460. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4461. ConvertFloat16ToFloat32(p->output1), p->output1,
  4462. ConvertFloat16ToFloat32(expected), expected);
  4463. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  4464. }
  4465. }
  4466. else {
  4467. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4468. }
  4469. }
  4470. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  4471. WEX::TestExecution::SetVerifyOutput verifySettings(
  4472. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4473. CComPtr<IStream> pStream;
  4474. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4475. CComPtr<ID3D12Device> pDevice;
  4476. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4477. return;
  4478. }
  4479. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4480. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4481. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4482. return;
  4483. }
  4484. // Read data from the table
  4485. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  4486. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  4487. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4488. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4489. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4490. std::vector<uint16_t> *Validation_Input1 =
  4491. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4492. std::vector<uint16_t> *Validation_Input2 =
  4493. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4494. std::vector<uint16_t> *Validation_Input3 =
  4495. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  4496. std::vector<uint16_t> *Validation_Expected =
  4497. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4498. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4499. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4500. size_t count = Validation_Input1->size();
  4501. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4502. pDevice, m_support, pStream, "TertiaryFPOp",
  4503. // this callbacked is called when the test
  4504. // is creating the resource to run the test
  4505. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4506. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4507. size_t size = sizeof(STertiaryHalfOp) * count;
  4508. Data.resize(size);
  4509. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  4510. for (size_t i = 0; i < count; ++i) {
  4511. STertiaryHalfOp *p = &pPrimitives[i];
  4512. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4513. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4514. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4515. }
  4516. // use shader from data table
  4517. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4518. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4519. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4520. });
  4521. MappedData data;
  4522. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4523. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  4524. WEX::TestExecution::DisableVerifyExceptions dve;
  4525. for (unsigned i = 0; i < count; ++i) {
  4526. STertiaryHalfOp *p = &pPrimitives[i];
  4527. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  4528. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  4529. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4530. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4531. ConvertFloat16ToFloat32(p->input2), p->input2,
  4532. ConvertFloat16ToFloat32(p->input3), p->input3,
  4533. ConvertFloat16ToFloat32(p->output), p->output,
  4534. ConvertFloat16ToFloat32(expected), expected);
  4535. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4536. }
  4537. }
  4538. TEST_F(ExecutionTest, UnaryIntOpTest) {
  4539. WEX::TestExecution::SetVerifyOutput verifySettings(
  4540. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4541. CComPtr<IStream> pStream;
  4542. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4543. CComPtr<ID3D12Device> pDevice;
  4544. if (!CreateDevice(&pDevice)) {
  4545. return;
  4546. }
  4547. // Read data from the table
  4548. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  4549. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  4550. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4551. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4552. std::vector<int> *Validation_Input =
  4553. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4554. std::vector<int> *Validation_Expected =
  4555. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4556. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4557. size_t count = Validation_Input->size();
  4558. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4559. pDevice, m_support, pStream, "UnaryIntOp",
  4560. // this callbacked is called when the test
  4561. // is creating the resource to run the test
  4562. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4563. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4564. size_t size = sizeof(SUnaryIntOp) * count;
  4565. Data.resize(size);
  4566. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  4567. for (size_t i = 0; i < count; ++i) {
  4568. SUnaryIntOp *p = &pPrimitives[i];
  4569. int val = (*Validation_Input)[i % Validation_Input->size()];
  4570. p->input = val;
  4571. }
  4572. // use shader data table
  4573. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4574. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4575. });
  4576. MappedData data;
  4577. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4578. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  4579. WEX::TestExecution::DisableVerifyExceptions dve;
  4580. for (unsigned i = 0; i < count; ++i) {
  4581. SUnaryIntOp *p = &pPrimitives[i];
  4582. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4583. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  4584. L"expected = %11i(0x%08x)",
  4585. i, p->input, p->input, p->output, p->output, val, val);
  4586. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4587. }
  4588. }
  4589. TEST_F(ExecutionTest, UnaryUintOpTest) {
  4590. WEX::TestExecution::SetVerifyOutput verifySettings(
  4591. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4592. CComPtr<IStream> pStream;
  4593. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4594. CComPtr<ID3D12Device> pDevice;
  4595. if (!CreateDevice(&pDevice)) {
  4596. return;
  4597. }
  4598. // Read data from the table
  4599. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  4600. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  4601. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4602. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4603. std::vector<unsigned int> *Validation_Input =
  4604. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4605. std::vector<unsigned int> *Validation_Expected =
  4606. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4607. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4608. size_t count = Validation_Input->size();
  4609. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4610. pDevice, m_support, pStream, "UnaryUintOp",
  4611. // this callbacked is called when the test
  4612. // is creating the resource to run the test
  4613. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4614. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4615. size_t size = sizeof(SUnaryUintOp) * count;
  4616. Data.resize(size);
  4617. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  4618. for (size_t i = 0; i < count; ++i) {
  4619. SUnaryUintOp *p = &pPrimitives[i];
  4620. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  4621. p->input = val;
  4622. }
  4623. // use shader data table
  4624. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4625. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4626. });
  4627. MappedData data;
  4628. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4629. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  4630. WEX::TestExecution::DisableVerifyExceptions dve;
  4631. for (unsigned i = 0; i < count; ++i) {
  4632. SUnaryUintOp *p = &pPrimitives[i];
  4633. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4634. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  4635. L"expected = %11u(0x%08x)",
  4636. i, p->input, p->input, p->output, p->output, val, val);
  4637. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4638. }
  4639. }
  4640. TEST_F(ExecutionTest, BinaryIntOpTest) {
  4641. WEX::TestExecution::SetVerifyOutput verifySettings(
  4642. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4643. CComPtr<IStream> pStream;
  4644. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4645. CComPtr<ID3D12Device> pDevice;
  4646. if (!CreateDevice(&pDevice)) {
  4647. return;
  4648. }
  4649. // Read data from the table
  4650. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  4651. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  4652. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4653. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4654. std::vector<int> *Validation_Input1 =
  4655. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4656. std::vector<int> *Validation_Input2 =
  4657. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4658. std::vector<int> *Validation_Expected1 =
  4659. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4660. std::vector<int> *Validation_Expected2 =
  4661. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  4662. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4663. size_t count = Validation_Input1->size();
  4664. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4665. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4666. pDevice, m_support, pStream, "BinaryIntOp",
  4667. // this callbacked is called when the test
  4668. // is creating the resource to run the test
  4669. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4670. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4671. size_t size = sizeof(SBinaryIntOp) * count;
  4672. Data.resize(size);
  4673. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  4674. for (size_t i = 0; i < count; ++i) {
  4675. SBinaryIntOp *p = &pPrimitives[i];
  4676. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4677. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4678. p->input1 = val1;
  4679. p->input2 = val2;
  4680. }
  4681. // use shader from data table
  4682. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4683. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4684. });
  4685. MappedData data;
  4686. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4687. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  4688. WEX::TestExecution::DisableVerifyExceptions dve;
  4689. if (numExpected == 2) {
  4690. for (unsigned i = 0; i < count; ++i) {
  4691. SBinaryIntOp *p = &pPrimitives[i];
  4692. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4693. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4694. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4695. L"%11i(0x%08x), output1 = "
  4696. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  4697. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  4698. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4699. p->output1, val1, val1, p->output2, p->output2, val2,
  4700. val2);
  4701. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4702. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4703. }
  4704. }
  4705. else if (numExpected == 1) {
  4706. for (unsigned i = 0; i < count; ++i) {
  4707. SBinaryIntOp *p = &pPrimitives[i];
  4708. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4709. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4710. L"%11i(0x%08x), output = "
  4711. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  4712. p->input1, p->input1, p->input2, p->input2,
  4713. p->output1, p->output1, val1, val1);
  4714. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4715. }
  4716. }
  4717. else {
  4718. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4719. }
  4720. }
  4721. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  4722. WEX::TestExecution::SetVerifyOutput verifySettings(
  4723. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4724. CComPtr<IStream> pStream;
  4725. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4726. CComPtr<ID3D12Device> pDevice;
  4727. if (!CreateDevice(&pDevice)) {
  4728. return;
  4729. }
  4730. // Read data from the table
  4731. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  4732. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  4733. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4734. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4735. std::vector<int> *Validation_Input1 =
  4736. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4737. std::vector<int> *Validation_Input2 =
  4738. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4739. std::vector<int> *Validation_Input3 =
  4740. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4741. std::vector<int> *Validation_Expected =
  4742. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4743. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4744. size_t count = Validation_Input1->size();
  4745. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4746. pDevice, m_support, pStream, "TertiaryIntOp",
  4747. // this callbacked is called when the test
  4748. // is creating the resource to run the test
  4749. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4750. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4751. size_t size = sizeof(STertiaryIntOp) * count;
  4752. Data.resize(size);
  4753. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  4754. for (size_t i = 0; i < count; ++i) {
  4755. STertiaryIntOp *p = &pPrimitives[i];
  4756. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4757. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4758. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4759. p->input1 = val1;
  4760. p->input2 = val2;
  4761. p->input3 = val3;
  4762. }
  4763. // use shader from data table
  4764. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4765. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4766. });
  4767. MappedData data;
  4768. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4769. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  4770. WEX::TestExecution::DisableVerifyExceptions dve;
  4771. for (unsigned i = 0; i < count; ++i) {
  4772. STertiaryIntOp *p = &pPrimitives[i];
  4773. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4774. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4775. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4776. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4777. i, p->input1, p->input1, p->input2, p->input2,
  4778. p->input3, p->input3, p->output, p->output, val1,
  4779. val1);
  4780. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4781. }
  4782. }
  4783. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4784. WEX::TestExecution::SetVerifyOutput verifySettings(
  4785. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4786. CComPtr<IStream> pStream;
  4787. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4788. CComPtr<ID3D12Device> pDevice;
  4789. if (!CreateDevice(&pDevice)) {
  4790. return;
  4791. }
  4792. // Read data from the table
  4793. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4794. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4795. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4796. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4797. std::vector<unsigned int> *Validation_Input1 =
  4798. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4799. std::vector<unsigned int> *Validation_Input2 =
  4800. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4801. std::vector<unsigned int> *Validation_Expected1 =
  4802. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4803. std::vector<unsigned int> *Validation_Expected2 =
  4804. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4805. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4806. size_t count = Validation_Input1->size();
  4807. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4808. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4809. pDevice, m_support, pStream, "BinaryUintOp",
  4810. // this callbacked is called when the test
  4811. // is creating the resource to run the test
  4812. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4813. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4814. size_t size = sizeof(SBinaryUintOp) * count;
  4815. Data.resize(size);
  4816. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4817. for (size_t i = 0; i < count; ++i) {
  4818. SBinaryUintOp *p = &pPrimitives[i];
  4819. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4820. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4821. p->input1 = val1;
  4822. p->input2 = val2;
  4823. }
  4824. // use shader from data table
  4825. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4826. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4827. });
  4828. MappedData data;
  4829. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4830. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4831. WEX::TestExecution::DisableVerifyExceptions dve;
  4832. if (numExpected == 2) {
  4833. for (unsigned i = 0; i < count; ++i) {
  4834. SBinaryUintOp *p = &pPrimitives[i];
  4835. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4836. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4837. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4838. L"%11u(0x%08x), output1 = "
  4839. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4840. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4841. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4842. p->output1, val1, val1, p->output2, p->output2, val2,
  4843. val2);
  4844. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4845. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4846. }
  4847. }
  4848. else if (numExpected == 1) {
  4849. for (unsigned i = 0; i < count; ++i) {
  4850. SBinaryUintOp *p = &pPrimitives[i];
  4851. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4852. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4853. L"%11u(0x%08x), output = "
  4854. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4855. p->input1, p->input1, p->input2, p->input2,
  4856. p->output1, p->output1, val1, val1);
  4857. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4858. }
  4859. }
  4860. else {
  4861. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4862. }
  4863. }
  4864. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4865. WEX::TestExecution::SetVerifyOutput verifySettings(
  4866. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4867. CComPtr<IStream> pStream;
  4868. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4869. CComPtr<ID3D12Device> pDevice;
  4870. if (!CreateDevice(&pDevice)) {
  4871. return;
  4872. }
  4873. // Read data from the table
  4874. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4875. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4876. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4877. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4878. std::vector<unsigned int> *Validation_Input1 =
  4879. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4880. std::vector<unsigned int> *Validation_Input2 =
  4881. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4882. std::vector<unsigned int> *Validation_Input3 =
  4883. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4884. std::vector<unsigned int> *Validation_Expected =
  4885. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4886. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4887. size_t count = Validation_Input1->size();
  4888. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4889. pDevice, m_support, pStream, "TertiaryUintOp",
  4890. // this callbacked is called when the test
  4891. // is creating the resource to run the test
  4892. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4893. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4894. size_t size = sizeof(STertiaryUintOp) * count;
  4895. Data.resize(size);
  4896. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4897. for (size_t i = 0; i < count; ++i) {
  4898. STertiaryUintOp *p = &pPrimitives[i];
  4899. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4900. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4901. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4902. p->input1 = val1;
  4903. p->input2 = val2;
  4904. p->input3 = val3;
  4905. }
  4906. // use shader from data table
  4907. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4908. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4909. });
  4910. MappedData data;
  4911. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4912. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  4913. WEX::TestExecution::DisableVerifyExceptions dve;
  4914. for (unsigned i = 0; i < count; ++i) {
  4915. STertiaryUintOp *p = &pPrimitives[i];
  4916. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4917. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4918. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  4919. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4920. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4921. p->output, p->output, val1, val1);
  4922. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4923. }
  4924. }
  4925. // 16 bit integer type tests
  4926. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  4927. WEX::TestExecution::SetVerifyOutput verifySettings(
  4928. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4929. CComPtr<IStream> pStream;
  4930. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4931. CComPtr<ID3D12Device> pDevice;
  4932. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4933. return;
  4934. }
  4935. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4936. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4937. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4938. return;
  4939. }
  4940. // Read data from the table
  4941. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  4942. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  4943. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4944. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4945. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4946. std::vector<short> *Validation_Input =
  4947. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  4948. std::vector<short> *Validation_Expected =
  4949. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  4950. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4951. size_t count = Validation_Input->size();
  4952. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4953. pDevice, m_support, pStream, "UnaryIntOp",
  4954. // this callbacked is called when the test
  4955. // is creating the resource to run the test
  4956. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4957. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4958. size_t size = sizeof(SUnaryInt16Op) * count;
  4959. Data.resize(size);
  4960. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  4961. for (size_t i = 0; i < count; ++i) {
  4962. SUnaryInt16Op *p = &pPrimitives[i];
  4963. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4964. }
  4965. // use shader data table
  4966. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4967. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4968. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4969. });
  4970. MappedData data;
  4971. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4972. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  4973. WEX::TestExecution::DisableVerifyExceptions dve;
  4974. for (unsigned i = 0; i < count; ++i) {
  4975. SUnaryInt16Op *p = &pPrimitives[i];
  4976. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  4977. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  4978. L"expected = %5hi(0x%08x)",
  4979. i, p->input, p->input, p->output, p->output, val, val);
  4980. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4981. }
  4982. }
  4983. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  4984. WEX::TestExecution::SetVerifyOutput verifySettings(
  4985. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4986. CComPtr<IStream> pStream;
  4987. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4988. CComPtr<ID3D12Device> pDevice;
  4989. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4990. return;
  4991. }
  4992. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4993. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4994. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4995. return;
  4996. }
  4997. // Read data from the table
  4998. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  4999. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  5000. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5001. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5002. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5003. std::vector<unsigned short> *Validation_Input =
  5004. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5005. std::vector<unsigned short> *Validation_Expected =
  5006. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5007. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5008. size_t count = Validation_Input->size();
  5009. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5010. pDevice, m_support, pStream, "UnaryUintOp",
  5011. // this callbacked is called when the test
  5012. // is creating the resource to run the test
  5013. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5014. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  5015. size_t size = sizeof(SUnaryUint16Op) * count;
  5016. Data.resize(size);
  5017. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  5018. for (size_t i = 0; i < count; ++i) {
  5019. SUnaryUint16Op *p = &pPrimitives[i];
  5020. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5021. }
  5022. // use shader data table
  5023. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5024. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5025. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5026. });
  5027. MappedData data;
  5028. test->Test->GetReadBackData("SUnaryUintOp", &data);
  5029. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  5030. WEX::TestExecution::DisableVerifyExceptions dve;
  5031. for (unsigned i = 0; i < count; ++i) {
  5032. SUnaryUint16Op *p = &pPrimitives[i];
  5033. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5034. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  5035. L"expected = %5hu(0x%08x)",
  5036. i, p->input, p->input, p->output, p->output, val, val);
  5037. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5038. }
  5039. }
  5040. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  5041. WEX::TestExecution::SetVerifyOutput verifySettings(
  5042. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5043. CComPtr<IStream> pStream;
  5044. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5045. CComPtr<ID3D12Device> pDevice;
  5046. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5047. return;
  5048. }
  5049. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5050. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5051. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5052. return;
  5053. }
  5054. // Read data from the table
  5055. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  5056. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  5057. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5058. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5059. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5060. std::vector<short> *Validation_Input1 =
  5061. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5062. std::vector<short> *Validation_Input2 =
  5063. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5064. std::vector<short> *Validation_Expected1 =
  5065. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5066. std::vector<short> *Validation_Expected2 =
  5067. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  5068. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5069. size_t count = Validation_Input1->size();
  5070. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5071. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5072. pDevice, m_support, pStream, "BinaryIntOp",
  5073. // this callbacked is called when the test
  5074. // is creating the resource to run the test
  5075. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5076. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  5077. size_t size = sizeof(SBinaryInt16Op) * count;
  5078. Data.resize(size);
  5079. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  5080. for (size_t i = 0; i < count; ++i) {
  5081. SBinaryInt16Op *p = &pPrimitives[i];
  5082. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5083. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5084. }
  5085. // use shader from data table
  5086. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5087. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5088. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5089. });
  5090. MappedData data;
  5091. test->Test->GetReadBackData("SBinaryIntOp", &data);
  5092. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  5093. WEX::TestExecution::DisableVerifyExceptions dve;
  5094. if (numExpected == 2) {
  5095. for (unsigned i = 0; i < count; ++i) {
  5096. SBinaryInt16Op *p = &pPrimitives[i];
  5097. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5098. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5099. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5100. L"%5hi(0x%08x), output1 = "
  5101. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  5102. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  5103. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5104. p->output1, val1, val1, p->output2, p->output2, val2,
  5105. val2);
  5106. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5107. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5108. }
  5109. }
  5110. else if (numExpected == 1) {
  5111. for (unsigned i = 0; i < count; ++i) {
  5112. SBinaryInt16Op *p = &pPrimitives[i];
  5113. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5114. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5115. L"%5hi(0x%08x), output = "
  5116. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  5117. p->input1, p->input1, p->input2, p->input2,
  5118. p->output1, p->output1, val1, val1);
  5119. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5120. }
  5121. }
  5122. else {
  5123. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5124. }
  5125. }
  5126. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  5127. WEX::TestExecution::SetVerifyOutput verifySettings(
  5128. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5129. CComPtr<IStream> pStream;
  5130. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5131. CComPtr<ID3D12Device> pDevice;
  5132. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5133. return;
  5134. }
  5135. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5136. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5137. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5138. return;
  5139. }
  5140. // Read data from the table
  5141. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  5142. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  5143. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5144. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5145. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5146. std::vector<short> *Validation_Input1 =
  5147. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5148. std::vector<short> *Validation_Input2 =
  5149. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5150. std::vector<short> *Validation_Input3 =
  5151. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  5152. std::vector<short> *Validation_Expected =
  5153. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5154. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5155. size_t count = Validation_Input1->size();
  5156. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5157. pDevice, m_support, pStream, "TertiaryIntOp",
  5158. // this callbacked is called when the test
  5159. // is creating the resource to run the test
  5160. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5161. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  5162. size_t size = sizeof(STertiaryInt16Op) * count;
  5163. Data.resize(size);
  5164. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  5165. for (size_t i = 0; i < count; ++i) {
  5166. STertiaryInt16Op *p = &pPrimitives[i];
  5167. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5168. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5169. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5170. }
  5171. // use shader from data table
  5172. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5173. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5174. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5175. });
  5176. MappedData data;
  5177. test->Test->GetReadBackData("STertiaryIntOp", &data);
  5178. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  5179. WEX::TestExecution::DisableVerifyExceptions dve;
  5180. for (unsigned i = 0; i < count; ++i) {
  5181. STertiaryInt16Op *p = &pPrimitives[i];
  5182. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5183. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  5184. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  5185. L"%11i(0x%08x), expected = %11i(0x%08x)",
  5186. i, p->input1, p->input1, p->input2, p->input2,
  5187. p->input3, p->input3, p->output, p->output, val1,
  5188. val1);
  5189. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5190. }
  5191. }
  5192. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  5193. WEX::TestExecution::SetVerifyOutput verifySettings(
  5194. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5195. CComPtr<IStream> pStream;
  5196. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5197. CComPtr<ID3D12Device> pDevice;
  5198. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5199. return;
  5200. }
  5201. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5202. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5203. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5204. return;
  5205. }
  5206. // Read data from the table
  5207. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  5208. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  5209. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5210. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5211. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5212. std::vector<unsigned short> *Validation_Input1 =
  5213. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5214. std::vector<unsigned short> *Validation_Input2 =
  5215. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5216. std::vector<unsigned short> *Validation_Expected1 =
  5217. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5218. std::vector<unsigned short> *Validation_Expected2 =
  5219. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  5220. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5221. size_t count = Validation_Input1->size();
  5222. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5223. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5224. pDevice, m_support, pStream, "BinaryUintOp",
  5225. // this callbacked is called when the test
  5226. // is creating the resource to run the test
  5227. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5228. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  5229. size_t size = sizeof(SBinaryUint16Op) * count;
  5230. Data.resize(size);
  5231. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  5232. for (size_t i = 0; i < count; ++i) {
  5233. SBinaryUint16Op *p = &pPrimitives[i];
  5234. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5235. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5236. }
  5237. // use shader from data table
  5238. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5239. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5240. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5241. });
  5242. MappedData data;
  5243. test->Test->GetReadBackData("SBinaryUintOp", &data);
  5244. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  5245. WEX::TestExecution::DisableVerifyExceptions dve;
  5246. if (numExpected == 2) {
  5247. for (unsigned i = 0; i < count; ++i) {
  5248. SBinaryUint16Op *p = &pPrimitives[i];
  5249. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5250. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5251. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5252. L"%5hu(0x%08x), output1 = "
  5253. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  5254. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  5255. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5256. p->output1, val1, val1, p->output2, p->output2, val2,
  5257. val2);
  5258. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5259. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5260. }
  5261. }
  5262. else if (numExpected == 1) {
  5263. for (unsigned i = 0; i < count; ++i) {
  5264. SBinaryUint16Op *p = &pPrimitives[i];
  5265. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5266. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5267. L"%5hu(0x%08x), output = "
  5268. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5269. p->input1, p->input1, p->input2, p->input2,
  5270. p->output1, p->output1, val1, val1);
  5271. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5272. }
  5273. }
  5274. else {
  5275. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5276. }
  5277. }
  5278. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  5279. WEX::TestExecution::SetVerifyOutput verifySettings(
  5280. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5281. CComPtr<IStream> pStream;
  5282. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5283. CComPtr<ID3D12Device> pDevice;
  5284. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5285. return;
  5286. }
  5287. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5288. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5289. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5290. return;
  5291. }
  5292. // Read data from the table
  5293. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  5294. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  5295. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5296. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5297. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5298. std::vector<unsigned short> *Validation_Input1 =
  5299. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5300. std::vector<unsigned short> *Validation_Input2 =
  5301. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5302. std::vector<unsigned short> *Validation_Input3 =
  5303. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  5304. std::vector<unsigned short> *Validation_Expected =
  5305. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5306. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5307. size_t count = Validation_Input1->size();
  5308. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5309. pDevice, m_support, pStream, "TertiaryUintOp",
  5310. // this callbacked is called when the test
  5311. // is creating the resource to run the test
  5312. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5313. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  5314. size_t size = sizeof(STertiaryUint16Op) * count;
  5315. Data.resize(size);
  5316. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  5317. for (size_t i = 0; i < count; ++i) {
  5318. STertiaryUint16Op *p = &pPrimitives[i];
  5319. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5320. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5321. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5322. }
  5323. // use shader from data table
  5324. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5325. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5326. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5327. });
  5328. MappedData data;
  5329. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5330. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  5331. WEX::TestExecution::DisableVerifyExceptions dve;
  5332. for (unsigned i = 0; i < count; ++i) {
  5333. STertiaryUint16Op *p = &pPrimitives[i];
  5334. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5335. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5336. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  5337. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5338. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5339. p->output, p->output, val1, val1);
  5340. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5341. }
  5342. }
  5343. TEST_F(ExecutionTest, DotTest) {
  5344. WEX::TestExecution::SetVerifyOutput verifySettings(
  5345. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5346. CComPtr<IStream> pStream;
  5347. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5348. CComPtr<ID3D12Device> pDevice;
  5349. if (!CreateDevice(&pDevice)) {
  5350. return;
  5351. }
  5352. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  5353. TableParameterHandler handler(DotOpParameters, tableSize);
  5354. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5355. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5356. std::vector<WEX::Common::String> *Validation_Input1 =
  5357. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5358. std::vector<WEX::Common::String> *Validation_Input2 =
  5359. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5360. std::vector<WEX::Common::String> *Validation_dot2 =
  5361. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5362. std::vector<WEX::Common::String> *Validation_dot3 =
  5363. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  5364. std::vector<WEX::Common::String> *Validation_dot4 =
  5365. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  5366. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5367. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5368. size_t count = Validation_Input1->size();
  5369. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5370. pDevice, m_support, pStream, "DotOp",
  5371. // this callbacked is called when the test
  5372. // is creating the resource to run the test
  5373. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5374. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  5375. size_t size = sizeof(SDotOp) * count;
  5376. Data.resize(size);
  5377. SDotOp *pPrimitives = (SDotOp*)Data.data();
  5378. for (size_t i = 0; i < count; ++i) {
  5379. SDotOp *p = &pPrimitives[i];
  5380. XMFLOAT4 val1,val2;
  5381. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  5382. (float *)&val1, 4));
  5383. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  5384. (float *)&val2, 4));
  5385. p->input1 = val1;
  5386. p->input2 = val2;
  5387. }
  5388. // use shader from data table
  5389. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5390. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5391. });
  5392. MappedData data;
  5393. test->Test->GetReadBackData("SDotOp", &data);
  5394. SDotOp *pPrimitives = (SDotOp*)data.data();
  5395. WEX::TestExecution::DisableVerifyExceptions dve;
  5396. for (size_t i = 0; i < count; ++i) {
  5397. SDotOp *p = &pPrimitives[i];
  5398. float dot2, dot3, dot4;
  5399. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  5400. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  5401. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  5402. LogCommentFmt(
  5403. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  5404. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  5405. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  5406. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  5407. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  5408. p->o_dot4, dot4);
  5409. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  5410. tolerance);
  5411. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  5412. tolerance);
  5413. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  5414. tolerance);
  5415. }
  5416. }
  5417. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  5418. WEX::TestExecution::SetVerifyOutput verifySettings(
  5419. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5420. CComPtr<IStream> pStream;
  5421. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5422. CComPtr<ID3D12Device> pDevice;
  5423. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5424. return;
  5425. }
  5426. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5427. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5428. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5429. return;
  5430. }
  5431. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  5432. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  5433. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5434. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5435. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5436. std::vector<WEX::Common::String> *validation_input1 =
  5437. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5438. std::vector<WEX::Common::String> *validation_input2 =
  5439. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5440. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  5441. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  5442. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5443. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5444. size_t count = validation_input1->size();
  5445. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5446. pDevice, m_support, pStream, "Dot2AddHalfOp",
  5447. // this callback is called when the test
  5448. // is creating the resource to run the test
  5449. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5450. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  5451. size_t size = sizeof(SDot2AddHalfOp) * count;
  5452. Data.resize(size);
  5453. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  5454. for (size_t i = 0; i < count; ++i) {
  5455. SDot2AddHalfOp *p = &pPrimitives[i];
  5456. Half2 val1,val2;
  5457. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  5458. (uint16_t *)&val1, 2));
  5459. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  5460. (uint16_t *)&val2, 2));
  5461. p->input1 = val1;
  5462. p->input2 = val2;
  5463. p->acc = (*validation_acc)[i];
  5464. }
  5465. // use shader from data table
  5466. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5467. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5468. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5469. });
  5470. MappedData data;
  5471. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  5472. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  5473. WEX::TestExecution::DisableVerifyExceptions dve;
  5474. for (size_t i = 0; i < count; ++i) {
  5475. SDot2AddHalfOp *p = &pPrimitives[i];
  5476. float expectedResult = (*validation_result)[i];
  5477. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  5478. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  5479. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  5480. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  5481. LogCommentFmt(
  5482. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  5483. L"result = %f, result_expected = %f",
  5484. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  5485. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  5486. }
  5487. }
  5488. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  5489. WEX::TestExecution::SetVerifyOutput verifySettings(
  5490. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5491. CComPtr<IStream> pStream;
  5492. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5493. CComPtr<ID3D12Device> pDevice;
  5494. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5495. return;
  5496. }
  5497. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  5498. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  5499. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5500. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5501. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5502. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5503. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  5504. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  5505. size_t count = validation_input1->size();
  5506. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5507. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  5508. // this callback is called when the test
  5509. // is creating the resource to run the test
  5510. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5511. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  5512. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  5513. Data.resize(size);
  5514. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  5515. for (size_t i = 0; i < count; ++i) {
  5516. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5517. p->input1 = (*validation_input1)[i];
  5518. p->input2 = (*validation_input2)[i];
  5519. p->acc = (*validation_acc)[i];
  5520. }
  5521. // use shader from data table
  5522. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5523. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5524. });
  5525. MappedData data;
  5526. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  5527. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  5528. WEX::TestExecution::DisableVerifyExceptions dve;
  5529. for (size_t i = 0; i < count; ++i) {
  5530. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5531. int32_t expectedResult = (*validation_result)[i];
  5532. LogCommentFmt(
  5533. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  5534. L"result = %d, result_expected = %d",
  5535. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5536. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  5537. }
  5538. }
  5539. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  5540. WEX::TestExecution::SetVerifyOutput verifySettings(
  5541. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5542. CComPtr<IStream> pStream;
  5543. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5544. CComPtr<ID3D12Device> pDevice;
  5545. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5546. return;
  5547. }
  5548. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  5549. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  5550. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5551. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5552. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5553. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5554. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  5555. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  5556. size_t count = validation_input1->size();
  5557. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5558. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  5559. // this callback is called when the test
  5560. // is creating the resource to run the test
  5561. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5562. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  5563. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  5564. Data.resize(size);
  5565. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  5566. for (size_t i = 0; i < count; ++i) {
  5567. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5568. p->input1 = (*validation_input1)[i];
  5569. p->input2 = (*validation_input2)[i];
  5570. p->acc = (*validation_acc)[i];
  5571. }
  5572. // use shader from data table
  5573. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5574. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5575. });
  5576. MappedData data;
  5577. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  5578. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  5579. WEX::TestExecution::DisableVerifyExceptions dve;
  5580. for (size_t i = 0; i < count; ++i) {
  5581. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5582. uint32_t expectedResult = (*validation_result)[i];
  5583. LogCommentFmt(
  5584. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  5585. L"result = %u, result_expected = %u, ",
  5586. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5587. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  5588. }
  5589. }
  5590. TEST_F(ExecutionTest, Msad4Test) {
  5591. WEX::TestExecution::SetVerifyOutput verifySettings(
  5592. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5593. CComPtr<IStream> pStream;
  5594. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5595. CComPtr<ID3D12Device> pDevice;
  5596. if (!CreateDevice(&pDevice)) {
  5597. return;
  5598. }
  5599. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  5600. TableParameterHandler handler(Msad4OpParameters, tableSize);
  5601. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5602. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5603. std::vector<unsigned int> *Validation_Reference =
  5604. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5605. std::vector<WEX::Common::String> *Validation_Source =
  5606. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5607. std::vector<WEX::Common::String> *Validation_Accum =
  5608. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  5609. std::vector<WEX::Common::String> *Validation_Expected =
  5610. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5611. size_t count = Validation_Expected->size();
  5612. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5613. pDevice, m_support, pStream, "Msad4",
  5614. // this callbacked is called when the test
  5615. // is creating the resource to run the test
  5616. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5617. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  5618. size_t size = sizeof(SMsad4) * count;
  5619. Data.resize(size);
  5620. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  5621. for (size_t i = 0; i < count; ++i) {
  5622. SMsad4 *p = &pPrimitives[i];
  5623. XMUINT2 src;
  5624. XMUINT4 accum;
  5625. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  5626. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  5627. p->ref = (*Validation_Reference)[i];
  5628. p->src = src;
  5629. p->accum = accum;
  5630. }
  5631. // use shader from data table
  5632. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5633. });
  5634. MappedData data;
  5635. test->Test->GetReadBackData("SMsad4", &data);
  5636. SMsad4 *pPrimitives = (SMsad4*)data.data();
  5637. WEX::TestExecution::DisableVerifyExceptions dve;
  5638. for (size_t i = 0; i < count; ++i) {
  5639. SMsad4 *p = &pPrimitives[i];
  5640. XMUINT4 result;
  5641. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  5642. (unsigned int *)&result, 4));
  5643. LogCommentFmt(
  5644. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  5645. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5646. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5647. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  5648. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  5649. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  5650. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  5651. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  5652. result.x, result.x, result.y, result.y, result.z, result.z,
  5653. result.w, result.w);
  5654. int toleranceInt = (int)tolerance;
  5655. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  5656. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  5657. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  5658. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  5659. }
  5660. }
  5661. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  5662. WEX::TestExecution::SetVerifyOutput verifySettings(
  5663. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5664. CComPtr<IStream> pStream;
  5665. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5666. CComPtr<ID3D12Device> pDevice;
  5667. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5668. return;
  5669. }
  5670. // Read data from the table
  5671. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  5672. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  5673. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5674. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5675. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5676. std::vector<WEX::Common::String> *Validation_Input1 =
  5677. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5678. std::vector<WEX::Common::String> *Validation_Input2 =
  5679. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5680. std::vector<WEX::Common::String> *Validation_Expected1 =
  5681. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5682. // two expected outputs for any mode
  5683. std::vector<WEX::Common::String> *Validation_Expected2 =
  5684. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5685. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5686. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5687. size_t count = Validation_Input1->size();
  5688. using namespace hlsl::DXIL;
  5689. Float32DenormMode mode = Float32DenormMode::Any;
  5690. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5691. mode = Float32DenormMode::Preserve;
  5692. }
  5693. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5694. mode = Float32DenormMode::FTZ;
  5695. }
  5696. if (mode == Float32DenormMode::Any) {
  5697. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5698. "must have same number of expected values");
  5699. }
  5700. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5701. pDevice, m_support, pStream, "BinaryFPOp",
  5702. // this callbacked is called when the test
  5703. // is creating the resource to run the test
  5704. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5705. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  5706. size_t size = sizeof(SBinaryFPOp) * count;
  5707. Data.resize(size);
  5708. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  5709. for (size_t i = 0; i < count; ++i) {
  5710. SBinaryFPOp *p = &pPrimitives[i];
  5711. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5712. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5713. float val1, val2;
  5714. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5715. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5716. p->input1 = val1;
  5717. p->input2 = val2;
  5718. }
  5719. // use shader from data table
  5720. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5721. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5722. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5723. });
  5724. MappedData data;
  5725. test->Test->GetReadBackData("SBinaryFPOp", &data);
  5726. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  5727. WEX::TestExecution::DisableVerifyExceptions dve;
  5728. for (unsigned i = 0; i < count; ++i) {
  5729. SBinaryFPOp *p = &pPrimitives[i];
  5730. if (mode == Float32DenormMode::Any) {
  5731. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5732. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5733. float val1;
  5734. float val2;
  5735. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5736. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5737. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5738. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5739. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  5740. VERIFY_IS_TRUE(
  5741. CompareOutputWithExpectedValueFloat(
  5742. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  5743. CompareOutputWithExpectedValueFloat(
  5744. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  5745. }
  5746. else {
  5747. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5748. float val1;
  5749. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5750. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5751. L"%6.8f, expected = %6.8f(%a)",
  5752. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  5753. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  5754. Validation_Tolerance, mode);
  5755. }
  5756. }
  5757. }
  5758. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  5759. WEX::TestExecution::SetVerifyOutput verifySettings(
  5760. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5761. CComPtr<IStream> pStream;
  5762. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5763. CComPtr<ID3D12Device> pDevice;
  5764. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5765. return;
  5766. }
  5767. // Read data from the table
  5768. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  5769. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  5770. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5771. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5772. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5773. std::vector<WEX::Common::String> *Validation_Input1 =
  5774. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5775. std::vector<WEX::Common::String> *Validation_Input2 =
  5776. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5777. std::vector<WEX::Common::String> *Validation_Input3 =
  5778. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5779. std::vector<WEX::Common::String> *Validation_Expected1 =
  5780. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5781. // two expected outputs for any mode
  5782. std::vector<WEX::Common::String> *Validation_Expected2 =
  5783. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5784. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5785. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5786. size_t count = Validation_Input1->size();
  5787. using namespace hlsl::DXIL;
  5788. Float32DenormMode mode = Float32DenormMode::Any;
  5789. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5790. mode = Float32DenormMode::Preserve;
  5791. }
  5792. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5793. mode = Float32DenormMode::FTZ;
  5794. }
  5795. if (mode == Float32DenormMode::Any) {
  5796. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5797. "must have same number of expected values");
  5798. }
  5799. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5800. pDevice, m_support, pStream, "TertiaryFPOp",
  5801. // this callbacked is called when the test
  5802. // is creating the resource to run the test
  5803. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5804. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5805. size_t size = sizeof(STertiaryFPOp) * count;
  5806. Data.resize(size);
  5807. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5808. for (size_t i = 0; i < count; ++i) {
  5809. STertiaryFPOp *p = &pPrimitives[i];
  5810. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5811. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5812. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5813. float val1, val2, val3;
  5814. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5815. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5816. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5817. p->input1 = val1;
  5818. p->input2 = val2;
  5819. p->input3 = val3;
  5820. }
  5821. // use shader from data table
  5822. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5823. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5824. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5825. });
  5826. MappedData data;
  5827. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5828. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5829. WEX::TestExecution::DisableVerifyExceptions dve;
  5830. for (unsigned i = 0; i < count; ++i) {
  5831. STertiaryFPOp *p = &pPrimitives[i];
  5832. if (mode == Float32DenormMode::Any) {
  5833. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5834. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5835. float val1;
  5836. float val2;
  5837. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5838. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5839. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5840. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5841. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5842. VERIFY_IS_TRUE(
  5843. CompareOutputWithExpectedValueFloat(
  5844. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5845. CompareOutputWithExpectedValueFloat(
  5846. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5847. }
  5848. else {
  5849. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5850. float val1;
  5851. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5852. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5853. L"%6.8f, expected = %6.8f(%a)",
  5854. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5855. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5856. Validation_Tolerance, mode);
  5857. }
  5858. }
  5859. }
  5860. // Setup for wave intrinsics tests
  5861. enum class ShaderOpKind {
  5862. WaveSum,
  5863. WaveProduct,
  5864. WaveActiveMax,
  5865. WaveActiveMin,
  5866. WaveCountBits,
  5867. WaveActiveAllEqual,
  5868. WaveActiveAnyTrue,
  5869. WaveActiveAllTrue,
  5870. WaveActiveBitOr,
  5871. WaveActiveBitAnd,
  5872. WaveActiveBitXor,
  5873. ShaderOpInvalid
  5874. };
  5875. struct ShaderOpKindPair {
  5876. LPCWSTR name;
  5877. ShaderOpKind kind;
  5878. };
  5879. static ShaderOpKindPair ShaderOpKindTable[] = {
  5880. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5881. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5882. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5883. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5884. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5885. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5886. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5887. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5888. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5889. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5890. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5891. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5892. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5893. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5894. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5895. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5896. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5897. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  5898. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  5899. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  5900. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  5901. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  5902. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  5903. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  5904. };
  5905. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  5906. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  5907. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  5908. return ShaderOpKindTable[i].kind;
  5909. }
  5910. }
  5911. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  5912. return ShaderOpKind::ShaderOpInvalid;
  5913. }
  5914. template <typename InType, typename OutType, ShaderOpKind kind>
  5915. struct computeExpected {
  5916. OutType operator()(const std::vector<InType> &inputs,
  5917. const std::vector<int> &masks, int maskValue,
  5918. unsigned int index) {
  5919. return 0;
  5920. }
  5921. };
  5922. template <typename InType, typename OutType>
  5923. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  5924. OutType operator()(const std::vector<InType> &inputs,
  5925. const std::vector<int> &masks, int maskValue,
  5926. unsigned int index) {
  5927. OutType sum = 0;
  5928. for (size_t i = 0; i < index; ++i) {
  5929. if (masks.at(i) == maskValue) {
  5930. sum += inputs.at(i);
  5931. }
  5932. }
  5933. return sum;
  5934. }
  5935. };
  5936. template <typename InType, typename OutType>
  5937. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  5938. OutType operator()(const std::vector<InType> &inputs,
  5939. const std::vector<int> &masks, int maskValue,
  5940. unsigned int index) {
  5941. OutType prod = 1;
  5942. for (size_t i = 0; i < index; ++i) {
  5943. if (masks.at(i) == maskValue) {
  5944. prod *= inputs.at(i);
  5945. }
  5946. }
  5947. return prod;
  5948. }
  5949. };
  5950. template <typename InType, typename OutType>
  5951. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  5952. OutType operator()(const std::vector<InType> &inputs,
  5953. const std::vector<int> &masks, int maskValue,
  5954. unsigned int index) {
  5955. OutType maximum = std::numeric_limits<OutType>::min();
  5956. for (size_t i = 0; i < index; ++i) {
  5957. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  5958. maximum = inputs.at(i);
  5959. }
  5960. return maximum;
  5961. }
  5962. };
  5963. template <typename InType, typename OutType>
  5964. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  5965. OutType operator()(const std::vector<InType> &inputs,
  5966. const std::vector<int> &masks, int maskValue,
  5967. unsigned int index) {
  5968. OutType minimum = std::numeric_limits<OutType>::max();
  5969. for (size_t i = 0; i < index; ++i) {
  5970. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  5971. minimum = inputs.at(i);
  5972. }
  5973. return minimum;
  5974. }
  5975. };
  5976. template <typename InType, typename OutType>
  5977. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  5978. OutType operator()(const std::vector<InType> &inputs,
  5979. const std::vector<int> &masks, int maskValue,
  5980. unsigned int index) {
  5981. OutType count = 0;
  5982. for (size_t i = 0; i < index; ++i) {
  5983. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  5984. count++;
  5985. }
  5986. }
  5987. return count;
  5988. }
  5989. };
  5990. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  5991. // So we cannot use c++ bool type to represent bool in HLSL
  5992. // HLSL returns 0 for false and 1 for true
  5993. template <typename InType, typename OutType>
  5994. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  5995. OutType operator()(const std::vector<InType> &inputs,
  5996. const std::vector<int> &masks, int maskValue,
  5997. unsigned int index) {
  5998. for (size_t i = 0; i < index; ++i) {
  5999. if (masks.at(i) == maskValue && inputs.at(i) != 0) {
  6000. return 1;
  6001. }
  6002. }
  6003. return 0;
  6004. }
  6005. };
  6006. template <typename InType, typename OutType>
  6007. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  6008. OutType operator()(const std::vector<InType> &inputs,
  6009. const std::vector<int> &masks, int maskValue,
  6010. unsigned int index) {
  6011. for (size_t i = 0; i < index; ++i) {
  6012. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  6013. return 0;
  6014. }
  6015. }
  6016. return 1;
  6017. }
  6018. };
  6019. template <typename InType, typename OutType>
  6020. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  6021. OutType operator()(const std::vector<InType> &inputs,
  6022. const std::vector<int> &masks, int maskValue,
  6023. unsigned int index) {
  6024. const InType *val = nullptr;
  6025. for (size_t i = 0; i < index; ++i) {
  6026. if (masks.at(i) == maskValue) {
  6027. if (val && *val != inputs.at(i)) {
  6028. return 0;
  6029. }
  6030. val = &inputs.at(i);
  6031. }
  6032. }
  6033. return 1;
  6034. }
  6035. };
  6036. template <typename InType, typename OutType>
  6037. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  6038. OutType operator()(const std::vector<InType> &inputs,
  6039. const std::vector<int> &masks, int maskValue,
  6040. unsigned int index) {
  6041. OutType bits = 0x00000000;
  6042. for (size_t i = 0; i < index; ++i) {
  6043. if (masks.at(i) == maskValue) {
  6044. bits |= inputs.at(i);
  6045. }
  6046. }
  6047. return bits;
  6048. }
  6049. };
  6050. template <typename InType, typename OutType>
  6051. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  6052. OutType operator()(const std::vector<InType> &inputs,
  6053. const std::vector<int> &masks, int maskValue,
  6054. unsigned int index) {
  6055. OutType bits = 0xffffffff;
  6056. for (size_t i = 0; i < index; ++i) {
  6057. if (masks.at(i) == maskValue) {
  6058. bits &= inputs.at(i);
  6059. }
  6060. }
  6061. return bits;
  6062. }
  6063. };
  6064. template <typename InType, typename OutType>
  6065. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  6066. OutType operator()(const std::vector<InType> &inputs,
  6067. const std::vector<int> &masks, int maskValue,
  6068. unsigned int index) {
  6069. OutType bits = 0x00000000;
  6070. for (size_t i = 0; i < index; ++i) {
  6071. if (masks.at(i) == maskValue) {
  6072. bits ^= inputs.at(i);
  6073. }
  6074. }
  6075. return bits;
  6076. }
  6077. };
  6078. // Mask functions used to control active lanes
  6079. static int MaskAll(int i) {
  6080. UNREFERENCED_PARAMETER(i);
  6081. return 1;
  6082. }
  6083. static int MaskEveryOther(int i) {
  6084. return i % 2 == 0 ? 1 : 0;
  6085. }
  6086. static int MaskEveryThird(int i) {
  6087. return i % 3 == 0 ? 1 : 0;
  6088. }
  6089. typedef int(*MaskFunction)(int);
  6090. static MaskFunction MaskFunctionTable[] = {
  6091. MaskAll, MaskEveryOther, MaskEveryThird
  6092. };
  6093. template <typename InType, typename OutType>
  6094. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  6095. const std::vector<int> &masks,
  6096. int maskValue, unsigned int index,
  6097. LPCWSTR str) {
  6098. ShaderOpKind kind = GetShaderOpKind(str);
  6099. switch (kind) {
  6100. case ShaderOpKind::WaveSum:
  6101. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  6102. case ShaderOpKind::WaveProduct:
  6103. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  6104. case ShaderOpKind::WaveActiveMax:
  6105. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  6106. case ShaderOpKind::WaveActiveMin:
  6107. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  6108. case ShaderOpKind::WaveCountBits:
  6109. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  6110. case ShaderOpKind::WaveActiveBitOr:
  6111. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  6112. case ShaderOpKind::WaveActiveBitAnd:
  6113. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  6114. case ShaderOpKind::WaveActiveBitXor:
  6115. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  6116. case ShaderOpKind::WaveActiveAnyTrue:
  6117. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  6118. case ShaderOpKind::WaveActiveAllTrue:
  6119. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  6120. case ShaderOpKind::WaveActiveAllEqual:
  6121. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  6122. default:
  6123. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  6124. return (OutType) 0;
  6125. }
  6126. };
  6127. // A framework for testing individual wave intrinsics tests.
  6128. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  6129. template <class T1, class T2>
  6130. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  6131. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  6132. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6133. // Resource representation for compute shader
  6134. // firstLaneId is used to group different waves
  6135. // laneIndex is used to identify lane within the wave.
  6136. // Lane ids are not necessarily in same order as thread ids.
  6137. struct PerThreadData {
  6138. unsigned firstLaneId;
  6139. unsigned laneIndex;
  6140. int mask;
  6141. T1 input;
  6142. T2 output;
  6143. };
  6144. unsigned int NumThreadsX = 8;
  6145. unsigned int NumThreadsY = 12;
  6146. unsigned int NumThreadsZ = 1;
  6147. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6148. static const unsigned int DispatchGroupCount = 1;
  6149. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  6150. CComPtr<IStream> pStream;
  6151. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6152. CComPtr<ID3D12Device> pDevice;
  6153. if (!CreateDevice(&pDevice)) {
  6154. return;
  6155. }
  6156. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6157. // Optional feature, so it's correct to not support it if declared as such.
  6158. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6159. return;
  6160. }
  6161. TableParameterHandler handler(pParameterList, numParameter);
  6162. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  6163. // Obtain the list of input lists
  6164. std::vector<std::vector<T1>*> InputDataList;
  6165. for (unsigned int i = 0;
  6166. i < numInputSet; ++i) {
  6167. std::wstring inputName = L"Validation.InputSet";
  6168. inputName.append(std::to_wstring(i + 1));
  6169. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  6170. }
  6171. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  6172. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6173. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6174. // Running compute shader for each input set with different masks
  6175. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  6176. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  6177. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  6178. pDevice, m_support, "WaveIntrinsicsOp",
  6179. // this callbacked is called when the test
  6180. // is creating the resource to run the test
  6181. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6182. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  6183. size_t size = sizeof(PerThreadData) * ThreadCount;
  6184. Data.resize(size);
  6185. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  6186. // 4 different inputs for each operation test
  6187. size_t index = 0;
  6188. std::vector<T1> *IntList = InputDataList[setIndex];
  6189. while (index < ThreadCount) {
  6190. PerThreadData *p = &pPrimitives[index];
  6191. p->firstLaneId = 0xFFFFBFFF;
  6192. p->laneIndex = 0xFFFFBFFF;
  6193. p->mask = MaskFunctionTable[maskIndex]((int)index);
  6194. p->input = (*IntList)[index % IntList->size()];
  6195. p->output = 0xFFFFBFFF;
  6196. index++;
  6197. }
  6198. // use shader from data table
  6199. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6200. }, ShaderOpSet);
  6201. // Check the value
  6202. MappedData data;
  6203. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  6204. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  6205. WEX::TestExecution::DisableVerifyExceptions dve;
  6206. // Grouping data by waves
  6207. std::vector<int> firstLaneIds;
  6208. for (size_t i = 0; i < ThreadCount; ++i) {
  6209. PerThreadData *p = &pPrimitives[i];
  6210. int firstLaneId = p->firstLaneId;
  6211. if (!contains(firstLaneIds, firstLaneId)) {
  6212. firstLaneIds.push_back(firstLaneId);
  6213. }
  6214. }
  6215. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  6216. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6217. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  6218. }
  6219. for (size_t i = 0; i < ThreadCount; ++i) {
  6220. PerThreadData *p = &pPrimitives[i];
  6221. waves[p->firstLaneId].get()->push_back(p);
  6222. }
  6223. // validate for each wave
  6224. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6225. // collect inputs and masks for a given wave
  6226. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  6227. std::vector<T1> inputList(waveData->size());
  6228. std::vector<int> maskList(waveData->size(), -1);
  6229. std::vector<T2> outputList(waveData->size());
  6230. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  6231. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6232. unsigned laneID = waveData->at(j)->laneIndex;
  6233. // ensure that each lane ID is unique and within the range
  6234. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  6235. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  6236. maskList.at(laneID) = waveData->at(j)->mask;
  6237. inputList.at(laneID) = waveData->at(j)->input;
  6238. outputList.at(laneID) = waveData->at(j)->output;
  6239. }
  6240. std::wstring inputStr = L"Wave Inputs: ";
  6241. std::wstring maskStr = L"Wave Masks: ";
  6242. std::wstring outputStr = L"Wave Outputs: ";
  6243. // append input string and mask string in lane id order
  6244. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6245. maskStr.append(std::to_wstring(maskList.at(j)));
  6246. maskStr.append(L" ");
  6247. inputStr.append(std::to_wstring(inputList.at(j)));
  6248. inputStr.append(L" ");
  6249. outputStr.append(std::to_wstring(outputList.at(j)));
  6250. outputStr.append(L" ");
  6251. }
  6252. LogCommentFmt(inputStr.data());
  6253. LogCommentFmt(maskStr.data());
  6254. LogCommentFmt(outputStr.data());
  6255. LogCommentFmt(L"\n");
  6256. // Compute expected output for a given inputs, masks, and index
  6257. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  6258. T2 expected;
  6259. // WaveActive is equivalent to WavePrefix lane # lane count
  6260. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  6261. if (maskList.at(laneIndex) == 1) {
  6262. expected = computeExpectedWithShaderOp<T1, T2>(
  6263. inputList, maskList, 1, index,
  6264. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6265. }
  6266. else {
  6267. expected = computeExpectedWithShaderOp<T1, T2>(
  6268. inputList, maskList, 0, index,
  6269. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6270. }
  6271. // TODO: use different comparison for floating point inputs
  6272. bool equal = outputList.at(laneIndex) == expected;
  6273. if (!equal) {
  6274. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  6275. }
  6276. VERIFY_IS_TRUE(equal);
  6277. }
  6278. }
  6279. }
  6280. }
  6281. }
  6282. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  6283. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  6284. if (GetTestParamUseWARP(true) &&
  6285. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6286. return;
  6287. }
  6288. WaveIntrinsicsActivePrefixTest<int, int>(
  6289. WaveIntrinsicsActiveIntParameters,
  6290. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  6291. /*isPrefix*/ false);
  6292. }
  6293. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  6294. if (GetTestParamUseWARP(true) &&
  6295. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6296. return;
  6297. }
  6298. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6299. WaveIntrinsicsActiveUintParameters,
  6300. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  6301. /*isPrefix*/ false);
  6302. }
  6303. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  6304. if (GetTestParamUseWARP(true) &&
  6305. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6306. return;
  6307. }
  6308. WaveIntrinsicsActivePrefixTest<int, int>(
  6309. WaveIntrinsicsPrefixIntParameters,
  6310. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  6311. /*isPrefix*/ true);
  6312. }
  6313. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  6314. if (GetTestParamUseWARP(true) &&
  6315. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6316. return;
  6317. }
  6318. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6319. WaveIntrinsicsPrefixUintParameters,
  6320. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  6321. /*isPrefix*/ true);
  6322. }
  6323. template <typename T>
  6324. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  6325. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6326. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6327. return static_cast<T>(1);
  6328. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6329. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  6330. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6331. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  6332. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6333. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  6334. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6335. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6336. return static_cast<T>(0);
  6337. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6338. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6339. return static_cast<T>(-1);
  6340. } else {
  6341. return static_cast<T>(0);
  6342. }
  6343. }
  6344. template <typename T>
  6345. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  6346. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6347. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6348. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  6349. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6350. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  6351. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  6352. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6353. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6354. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  6355. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6356. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  6357. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  6358. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6359. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  6360. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  6361. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6362. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6363. // For CountBits, each lane contributes a boolean value. The test input is
  6364. // a zero or non-zero integer. If the input is a non-zero value then the
  6365. // condition is true, thus we contribute one to the bit count.
  6366. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  6367. } else {
  6368. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  6369. }
  6370. }
  6371. template <class T>
  6372. void
  6373. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  6374. size_t numParameters) {
  6375. WEX::TestExecution::SetVerifyOutput
  6376. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6377. struct PerThreadData {
  6378. uint32_t key;
  6379. uint32_t firstLaneId;
  6380. uint32_t laneId;
  6381. uint32_t mask;
  6382. T value;
  6383. T result;
  6384. };
  6385. constexpr size_t NumThreadsX = 8;
  6386. constexpr size_t NumThreadsY = 12;
  6387. constexpr size_t NumThreadsZ = 1;
  6388. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6389. constexpr size_t DispatchGroupSize = 1;
  6390. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  6391. CComPtr<IStream> pStream;
  6392. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6393. CComPtr<ID3D12Device> pDevice;
  6394. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  6395. return;
  6396. }
  6397. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6398. // Optional feature, so it's correct to not support it if declared as such.
  6399. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6400. return;
  6401. }
  6402. std::shared_ptr<st::ShaderOpSet>
  6403. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6404. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6405. TableParameterHandler handler(pParameterList, numParameters);
  6406. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6407. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  6408. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  6409. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  6410. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  6411. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  6412. std::shared_ptr<ShaderOpTestResult> test =
  6413. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  6414. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  6415. UNREFERENCED_PARAMETER(name);
  6416. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  6417. data.resize(dataSize);
  6418. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  6419. for (size_t i = 0; i != ThreadCount; ++i) {
  6420. pThreadData[i].key = keys->at(i % keys->size());
  6421. pThreadData[i].value = values->at(i % values->size());
  6422. pThreadData[i].firstLaneId = 0xdeadbeef;
  6423. pThreadData[i].laneId = 0xdeadbeef;
  6424. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  6425. pThreadData[i].result = 0xdeadbeef;
  6426. }
  6427. pShaderOp->Shaders.at(0).Text = shaderSource;
  6428. pShaderOp->Shaders.at(0).Target = shaderProfile;
  6429. }, ShaderOpSet);
  6430. MappedData mappedData;
  6431. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  6432. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  6433. // Partition our data into waves
  6434. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  6435. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  6436. PerThreadData *elt = &resultData[i];
  6437. // Basic sanity checks
  6438. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  6439. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  6440. waves[elt->firstLaneId].push_back(elt);
  6441. }
  6442. // Verify each wave
  6443. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  6444. for (auto &w : waves) {
  6445. std::vector<PerThreadData *> &waveData = w.second;
  6446. struct {
  6447. bool operator()(PerThreadData *a, PerThreadData *b) const {
  6448. return (a->laneId < b->laneId);
  6449. }
  6450. } compare;
  6451. // Need to sort based on the lane id
  6452. std::sort(waveData.begin(), waveData.end(), compare);
  6453. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  6454. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  6455. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  6456. PerThreadData *data = waveData[i];
  6457. // Compute prefix operation over each previous lane element that has the
  6458. // same key value, and is part of the same active thread group
  6459. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  6460. for (unsigned j = 0; j < i; ++j) {
  6461. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  6462. accum = refFn(accum, waveData[j]->value);
  6463. }
  6464. }
  6465. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  6466. VERIFY_IS_TRUE(accum == data->result);
  6467. }
  6468. LogCommentFmt(L"\n");
  6469. }
  6470. }
  6471. }
  6472. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  6473. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  6474. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  6475. }
  6476. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  6477. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  6478. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  6479. }
  6480. TEST_F(ExecutionTest, CBufferTestHalf) {
  6481. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6482. CComPtr<IStream> pStream;
  6483. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6484. // Single operation test at the moment.
  6485. CComPtr<ID3D12Device> pDevice;
  6486. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  6487. return;
  6488. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6489. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6490. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6491. return;
  6492. }
  6493. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  6494. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  6495. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6496. UNREFERENCED_PARAMETER(pShaderOp);
  6497. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  6498. // use shader from data table.
  6499. Data.resize(sizeof(InputData));
  6500. uint16_t *pData = (uint16_t *)Data.data();
  6501. for (size_t i = 0; i < 4; ++i, ++pData) {
  6502. *pData = InputData[i];
  6503. }
  6504. });
  6505. {
  6506. MappedData data;
  6507. test->Test->GetReadBackData("RTarget", &data);
  6508. const uint16_t *pPixels = (uint16_t *)data.data();
  6509. for (int i = 0; i < 4; ++i) {
  6510. uint16_t output = *(pPixels + i);
  6511. float outputFloat = ConvertFloat16ToFloat32(output);
  6512. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  6513. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  6514. i, inputFloat, InputData[i], outputFloat, output);
  6515. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  6516. }
  6517. }
  6518. }
  6519. TEST_F(ExecutionTest, BarycentricsTest) {
  6520. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6521. CComPtr<IStream> pStream;
  6522. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6523. CComPtr<ID3D12Device> pDevice;
  6524. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  6525. return;
  6526. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  6527. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  6528. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6529. return;
  6530. }
  6531. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  6532. MappedData data;
  6533. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  6534. UINT width = (UINT)D.Width;
  6535. UINT height = D.Height;
  6536. UINT pixelSize = GetByteSizeForFormat(D.Format);
  6537. test->Test->GetReadBackData("RTarget", &data);
  6538. //const uint8_t *pPixels = (uint8_t *)data.data();
  6539. const float *pPixels = (float *)data.data();
  6540. // Get the vertex of barycentric coordinate using VBuffer
  6541. MappedData triangleData;
  6542. test->Test->GetReadBackData("VBuffer", &triangleData);
  6543. const float *pTriangleData = (float*)triangleData.data();
  6544. // get the size of the input data
  6545. unsigned triangleVertexSizeInFloat = 0;
  6546. for (auto element : test->ShaderOp->InputElements)
  6547. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  6548. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  6549. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  6550. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  6551. XMFLOAT3 barycentricWeights[4] = {
  6552. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  6553. XMFLOAT3(0.5f, 0.25f, 0.25f),
  6554. XMFLOAT3(0.25f, 0.5f, 0.25f),
  6555. XMFLOAT3(0.25f, 0.25f, 0.50f)
  6556. };
  6557. float tolerance = 0.001f;
  6558. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  6559. float w0 = barycentricWeights[i].x;
  6560. float w1 = barycentricWeights[i].y;
  6561. float w2 = barycentricWeights[i].z;
  6562. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  6563. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  6564. // map from x1 y1 to rtv pixels
  6565. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  6566. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  6567. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  6568. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  6569. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  6570. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  6571. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  6572. }
  6573. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  6574. }
  6575. static const char RawBufferTestShaderDeclarations[] =
  6576. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  6577. "typedef COMPONENT_TYPE scalar; \r\n"
  6578. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  6579. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  6580. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  6581. "\r\n"
  6582. "struct TestData { \r\n"
  6583. " scalar v1; \r\n"
  6584. " vector2 v2; \r\n"
  6585. " vector3 v3; \r\n"
  6586. " vector4 v4; \r\n"
  6587. "}; \r\n"
  6588. "\r\n"
  6589. "struct UavData {\r\n"
  6590. " TestData input; \r\n"
  6591. " TestData output; \r\n"
  6592. " TestData srvOut; \r\n"
  6593. "}; \r\n"
  6594. "\r\n"
  6595. "ByteAddressBuffer srv0 : register(t0); \r\n"
  6596. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  6597. "ByteAddressBuffer srv2 : register(t2); \r\n"
  6598. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  6599. "\r\n"
  6600. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  6601. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  6602. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  6603. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  6604. static const char RawBufferTestShaderBody[] =
  6605. " // offset of 'out' in 'UavData'\r\n"
  6606. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  6607. "\r\n"
  6608. " // offset of 'srv_out' in 'UavData'\r\n"
  6609. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  6610. "\r\n"
  6611. " // offsets within the 'Data' struct\r\n"
  6612. " const int v1_offset = 0; \r\n"
  6613. " const int v2_offset = COMPONENT_SIZE; \r\n"
  6614. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  6615. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  6616. "\r\n"
  6617. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  6618. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  6619. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  6620. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  6621. "\r\n"
  6622. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  6623. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  6624. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  6625. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  6626. "\r\n"
  6627. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  6628. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  6629. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  6630. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  6631. "\r\n"
  6632. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  6633. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  6634. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  6635. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  6636. "\r\n"
  6637. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  6638. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  6639. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  6640. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  6641. "\r\n"
  6642. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  6643. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  6644. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  6645. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  6646. "\r\n"
  6647. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  6648. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  6649. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  6650. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  6651. "\r\n"
  6652. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  6653. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  6654. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  6655. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  6656. static const char RawBufferTestComputeShaderTemplate[] =
  6657. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6658. "[numthreads(1, 1, 1)]\r\n"
  6659. "void main(uint GI : SV_GroupIndex) {\r\n"
  6660. "%s\r\n" // <- RawBufferTestShaderBody
  6661. "};";
  6662. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  6663. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6664. "struct PSInput { \r\n"
  6665. " float4 pos : SV_POSITION; \r\n"
  6666. "}; \r\n"
  6667. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  6668. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  6669. "%s\r\n" // <- RawBufferTestShaderBody
  6670. " } \r\n"
  6671. " return uint4(1, 2, 3, 4); \r\n"
  6672. "};";
  6673. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  6674. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6675. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  6676. }
  6677. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  6678. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6679. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  6680. }
  6681. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  6682. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6683. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6684. }
  6685. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  6686. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6687. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6688. }
  6689. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  6690. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6691. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  6692. }
  6693. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  6694. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6695. RawBufferLdStTestData<uint16_t> halfData;
  6696. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  6697. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6698. }
  6699. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  6700. }
  6701. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  6702. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6703. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  6704. }
  6705. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  6706. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6707. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  6708. }
  6709. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  6710. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6711. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  6712. }
  6713. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  6714. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6715. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  6716. }
  6717. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  6718. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6719. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  6720. }
  6721. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  6722. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6723. RawBufferLdStTestData<uint16_t> halfData;
  6724. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  6725. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6726. }
  6727. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  6728. }
  6729. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6730. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  6731. char *&sTy, char *&additionalOptions) {
  6732. if (!CreateDevice(&pDevice, shaderModel)) {
  6733. return false;
  6734. }
  6735. additionalOptions = "";
  6736. switch (dataType) {
  6737. case RawBufferLdStType::I64:
  6738. if (!DoesDeviceSupportInt64(pDevice)) {
  6739. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  6740. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6741. return false;
  6742. }
  6743. sTy = "int64_t";
  6744. break;
  6745. case RawBufferLdStType::Double:
  6746. if (!DoesDeviceSupportDouble(pDevice)) {
  6747. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  6748. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6749. return false;
  6750. }
  6751. sTy = "double";
  6752. break;
  6753. case RawBufferLdStType::I16:
  6754. case RawBufferLdStType::Half:
  6755. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6756. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6757. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6758. return false;
  6759. }
  6760. additionalOptions = "-enable-16bit-types";
  6761. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  6762. break;
  6763. case RawBufferLdStType::I32:
  6764. sTy = "int32_t";
  6765. break;
  6766. case RawBufferLdStType::Float:
  6767. sTy = "float";
  6768. break;
  6769. default:
  6770. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  6771. }
  6772. // read shader config
  6773. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6774. return true;
  6775. }
  6776. template <class Ty>
  6777. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6778. // read buffers back & verify expected values
  6779. static const int UavBufferCount = 4;
  6780. char bufferName[11] = "UAVBufferX";
  6781. for (unsigned i = 0; i < UavBufferCount; i++) {
  6782. MappedData dataUav;
  6783. RawBufferLdStUavData<Ty> *pOutData;
  6784. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6785. test->GetReadBackData(bufferName, &dataUav);
  6786. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6787. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6788. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6789. // scalar
  6790. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6791. // vector 2
  6792. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6793. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6794. // vector 3
  6795. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6796. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6797. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6798. // vector 4
  6799. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6800. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6801. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6802. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6803. // verify SRV Store
  6804. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6805. // scalar
  6806. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6807. // vector 2
  6808. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6809. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6810. // vector 3
  6811. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6812. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6813. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6814. // vector 4
  6815. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6816. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6817. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6818. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6819. }
  6820. }
  6821. template <class Ty>
  6822. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6823. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6824. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6825. CComPtr<ID3D12Device> pDevice;
  6826. CComPtr<IStream> pStream;
  6827. char *sTy, *additionalOptions;
  6828. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6829. return;
  6830. }
  6831. // format shader source
  6832. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6833. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6834. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6835. // format compiler args
  6836. char compilerOptions[256];
  6837. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6838. // run the shader
  6839. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6840. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6841. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6842. (Name[9] >= '0' && Name[9] <= '3'));
  6843. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6844. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6845. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6846. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6847. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6848. });
  6849. // verify expected values
  6850. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6851. }
  6852. template <class Ty>
  6853. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6854. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6855. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6856. CComPtr<ID3D12Device> pDevice;
  6857. CComPtr<IStream> pStream;
  6858. char *sTy, *additionalOptions;
  6859. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6860. return;
  6861. }
  6862. // format shader source
  6863. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6864. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6865. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6866. // format compiler args
  6867. char compilerOptions[256];
  6868. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6869. // run the shader
  6870. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6871. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6872. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6873. (Name[9] >= '0' && Name[9] <= '3'));
  6874. // pixel shader is at index 1, vertex shader at index 0
  6875. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6876. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6877. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6878. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6879. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6880. });
  6881. // verify expected values
  6882. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6883. }
  6884. template<typename T>
  6885. uint32_t pack(std::array<T, 4> unpackedVals)
  6886. {
  6887. uint32_t dst = 0;
  6888. constexpr uint32_t bitMask = 0xFF;
  6889. for (uint32_t i = 0U; i < 4U; ++i)
  6890. {
  6891. dst |= (unpackedVals[i] & bitMask) << (i * 8);
  6892. }
  6893. return dst;
  6894. }
  6895. template <typename T>
  6896. uint32_t pack_clamp_u8(std::array<T, 4> unpackedVals)
  6897. {
  6898. int32_t clamp_min = std::numeric_limits<uint8_t>::min();
  6899. int32_t clamp_max = std::numeric_limits<uint8_t>::max();
  6900. uint32_t dst = 0;
  6901. for (uint32_t i = 0U; i < 4U; ++i)
  6902. {
  6903. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6904. dst |= ((uint8_t)clamped) << (i * 8);
  6905. }
  6906. return dst;
  6907. }
  6908. template <typename T>
  6909. uint32_t pack_clamp_s8(std::array<T, 4> unpackedVals)
  6910. {
  6911. int32_t clamp_min = std::numeric_limits<int8_t>::min();
  6912. int32_t clamp_max = std::numeric_limits<int8_t>::max();
  6913. uint32_t dst = 0;
  6914. for (uint32_t i = 0U; i < 4U; ++i)
  6915. {
  6916. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6917. dst |= ((uint8_t)clamped) << (i * 8);
  6918. }
  6919. return dst;
  6920. }
  6921. template<typename T>
  6922. std::array<T, 4> unpack_u(uint32_t packedVal)
  6923. {
  6924. std::array<T, 4> ret;
  6925. ret[0] = (uint8_t)((packedVal & 0x000000FF) >> 0 );
  6926. ret[1] = (uint8_t)((packedVal & 0x0000FF00) >> 8 );
  6927. ret[2] = (uint8_t)((packedVal & 0x00FF0000) >> 16);
  6928. ret[3] = (uint8_t)((packedVal & 0xFF000000) >> 24);
  6929. return ret;
  6930. }
  6931. template<typename T>
  6932. std::array<T, 4> unpack_s(uint32_t packedVal)
  6933. {
  6934. std::array<T, 4> ret;
  6935. ret[0] = (int8_t)((packedVal & 0x000000FF) >> 0 );
  6936. ret[1] = (int8_t)((packedVal & 0x0000FF00) >> 8 );
  6937. ret[2] = (int8_t)((packedVal & 0x00FF0000) >> 16);
  6938. ret[3] = (int8_t)((packedVal & 0xFF000000) >> 24);
  6939. return ret;
  6940. }
  6941. TEST_F(ExecutionTest, PackUnpackTest) {
  6942. WEX::TestExecution::SetVerifyOutput verifySettings(
  6943. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6944. CComPtr<IStream> pStream;
  6945. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6946. CComPtr<ID3D12Device> pDevice;
  6947. #ifdef PACKUNPACK_PLACEHOLDER
  6948. string args = "-enable-16bit-types -DPACKUNPACK_PLACEHOLDER";
  6949. string target = "cs_6_2";
  6950. if (!CreateDevice(&pDevice)) {
  6951. return;
  6952. }
  6953. #else
  6954. string args = "-enable-16bit-types";
  6955. string target = "cs_6_6";
  6956. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  6957. return;
  6958. }
  6959. #endif
  6960. int tableSize = sizeof(PackUnpackOpParameters) / sizeof(TableParameter);
  6961. TableParameterHandler handler(PackUnpackOpParameters, tableSize);
  6962. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6963. std::vector<uint32_t> *validation_input = &handler.GetTableParamByName(L"Validation.Input")->m_uint32Table;
  6964. uint32_t validation_tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_uint;
  6965. size_t count = validation_input->size();
  6966. std::vector<SPackUnpackOpOutPacked> expectedPacked(count / 4);
  6967. std::vector<SPackUnpackOpOutUnpacked> expectedUnpacked(count / 4);
  6968. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  6969. pDevice, m_support, pStream, "PackUnpackOp",
  6970. // this callback is called when the test
  6971. // is creating the resource to run the test
  6972. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6973. if (0 == _stricmp(Name, "g_bufIn"))
  6974. {
  6975. size_t size = sizeof(uint32_t) * 4 * count;
  6976. Data.resize(size);
  6977. uint32_t *pPrimitives = (uint32_t*)Data.data();
  6978. for (size_t i = 0; i < count / 4; ++i) {
  6979. uint32_t *p = &pPrimitives[i * 4];
  6980. uint32_t x = (*validation_input)[i * 4 + 0];
  6981. uint32_t y = (*validation_input)[i * 4 + 1];
  6982. uint32_t z = (*validation_input)[i * 4 + 2];
  6983. uint32_t w = (*validation_input)[i * 4 + 3];
  6984. p[0] = x;
  6985. p[1] = y;
  6986. p[2] = z;
  6987. p[3] = w;
  6988. std::array<uint32_t, 4> inputUint32 = { x, y, z, w };
  6989. std::array<int32_t, 4> inputInt32 = { (int32_t)x, (int32_t)y, (int32_t)z, (int32_t)w };
  6990. std::array<uint16_t, 4> inputUint16 = { (uint16_t)x, (uint16_t)y, (uint16_t)z, (uint16_t)w };
  6991. std::array<int16_t, 4> inputInt16 = { (int16_t)x, (int16_t)y, (int16_t)z, (int16_t)w };
  6992. // Pack unclamped
  6993. expectedPacked[i].packedUint32 = pack(inputUint32);
  6994. expectedPacked[i].packedInt32 = pack(inputInt32);
  6995. expectedPacked[i].packedUint16 = pack(inputUint16);
  6996. expectedPacked[i].packedInt16 = pack(inputInt16);
  6997. // pack clamped
  6998. expectedPacked[i].packedClampedUint32 = pack_clamp_u8(inputInt32);
  6999. expectedPacked[i].packedClampedInt32 = pack_clamp_s8(inputInt32);
  7000. expectedPacked[i].packedClampedUint16 = pack_clamp_u8(inputInt16);
  7001. expectedPacked[i].packedClampedInt16 = pack_clamp_s8(inputInt16);
  7002. // unpack
  7003. expectedUnpacked[i].outputUint32 = unpack_u<uint32_t>(expectedPacked[i].packedUint32);
  7004. expectedUnpacked[i].outputInt32 = unpack_s<int32_t >(expectedPacked[i].packedInt32 );
  7005. expectedUnpacked[i].outputUint16 = unpack_u<uint16_t>(expectedPacked[i].packedUint16);
  7006. expectedUnpacked[i].outputInt16 = unpack_s<int16_t >(expectedPacked[i].packedInt16 );
  7007. expectedUnpacked[i].outputClampedUint32 = unpack_u<uint32_t>(expectedPacked[i].packedClampedUint32);
  7008. expectedUnpacked[i].outputClampedInt32 = unpack_s<int32_t >(expectedPacked[i].packedClampedInt32 );
  7009. expectedUnpacked[i].outputClampedUint16 = unpack_u<uint16_t>(expectedPacked[i].packedClampedUint16);
  7010. expectedUnpacked[i].outputClampedInt16 = unpack_s<int16_t >(expectedPacked[i].packedClampedInt16 );
  7011. }
  7012. }
  7013. else
  7014. {
  7015. std::fill(Data.begin(), Data.end(), 0);
  7016. }
  7017. // use shader from data table
  7018. pShaderOp->Shaders.at(0).Target = target.c_str();
  7019. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  7020. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7021. });
  7022. MappedData packedData;
  7023. test->Test->GetReadBackData("g_bufOutPacked", &packedData);
  7024. SPackUnpackOpOutPacked *readBackPacked = (SPackUnpackOpOutPacked *)packedData.data();
  7025. MappedData unpackedData;
  7026. test->Test->GetReadBackData("g_bufOutPackedUnpacked", &unpackedData);
  7027. SPackUnpackOpOutUnpacked *readBackUnpacked = (SPackUnpackOpOutUnpacked *)unpackedData.data();
  7028. for (size_t i = 0; i < count / 4; ++i)
  7029. {
  7030. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint32, expectedPacked[i].packedUint32, validation_tolerance);
  7031. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt32 , expectedPacked[i].packedInt32 , validation_tolerance);
  7032. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint16, expectedPacked[i].packedUint16, validation_tolerance);
  7033. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt16 , expectedPacked[i].packedInt16 , validation_tolerance);
  7034. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint32, expectedPacked[i].packedClampedUint32, validation_tolerance);
  7035. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt32 , expectedPacked[i].packedClampedInt32 , validation_tolerance);
  7036. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint16, expectedPacked[i].packedClampedUint16, validation_tolerance);
  7037. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt16 , expectedPacked[i].packedClampedInt16 , validation_tolerance);
  7038. for (uint32_t j = 0; j < 4; ++j)
  7039. {
  7040. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint32[j], expectedUnpacked[i].outputUint32[j], validation_tolerance);
  7041. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt32 [j], expectedUnpacked[i].outputInt32 [j], validation_tolerance);
  7042. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint16[j], expectedUnpacked[i].outputUint16[j], validation_tolerance);
  7043. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt16 [j], expectedUnpacked[i].outputInt16 [j], validation_tolerance);
  7044. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint32[j], expectedUnpacked[i].outputClampedUint32[j], validation_tolerance);
  7045. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt32 [j], expectedUnpacked[i].outputClampedInt32 [j], validation_tolerance);
  7046. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint16[j], expectedUnpacked[i].outputClampedUint16[j], validation_tolerance);
  7047. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt16 [j], expectedUnpacked[i].outputClampedInt16 [j], validation_tolerance);
  7048. }
  7049. }
  7050. }
  7051. // This test expects a <pShader> that retrieves a signal value from each of a few
  7052. // resources that are initialized here. <isDynamic> determines if it uses the
  7053. // 6.6 Dynamic Resources feature.
  7054. // Values are read back from the result UAV and compared to the expected signals
  7055. void ExecutionTest::RunResourceTest(ID3D12Device *pDevice, const char *pShader,
  7056. const wchar_t *sm, bool isDynamic) {
  7057. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7058. const int NumSRVs = 3;
  7059. const int NumUAVs = 4;
  7060. const int NumResources = NumSRVs + NumUAVs;
  7061. const int NumSamplers = 2;
  7062. const int valueSize = 16;
  7063. static const int DispatchGroupX = 1;
  7064. static const int DispatchGroupY = 1;
  7065. static const int DispatchGroupZ = 1;
  7066. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  7067. CComPtr<ID3D12CommandQueue> pCommandQueue;
  7068. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  7069. FenceObj FO;
  7070. size_t valueSizeInBytes = valueSize * sizeof(float);
  7071. CreateComputeCommandQueue(pDevice, L"DynamicResourcesTest Command Queue", &pCommandQueue);
  7072. InitFenceObj(pDevice, &FO);
  7073. // Create root signature.
  7074. CComPtr<ID3D12RootSignature> pRootSignature;
  7075. if (!isDynamic) {
  7076. // Not dynamic, create a range for each resource and from them, the root signature
  7077. CD3DX12_DESCRIPTOR_RANGE ranges[NumResources];
  7078. CD3DX12_DESCRIPTOR_RANGE srange[NumSamplers];
  7079. for (int i = 0; i < NumSRVs; i++)
  7080. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, i, 0);
  7081. for (int i = NumSRVs; i < NumResources; i++)
  7082. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, i - NumSRVs, 0);
  7083. for (int i = 0; i < NumSamplers; i++)
  7084. srange[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, i, 0);
  7085. CreateRootSignatureFromRanges(pDevice, &pRootSignature, ranges, NumResources, srange, NumSamplers);
  7086. } else {
  7087. // Dynamic just requires the flags indicating that the builtin arrays should be accessible
  7088. #if !defined(D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)
  7089. #define D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x400
  7090. #define D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x800
  7091. #endif
  7092. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  7093. rootSignatureDesc.Init(0, nullptr, 0, nullptr,
  7094. D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
  7095. D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
  7096. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  7097. }
  7098. // Create pipeline state object.
  7099. CComPtr<ID3D12PipelineState> pComputeState;
  7100. CreateComputePSO(pDevice, pRootSignature, pShader, sm, &pComputeState);
  7101. // Create a command allocator and list for compute.
  7102. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  7103. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  7104. // Set up SRV resources
  7105. CComPtr<ID3D12Resource> pSRVResources[NumSRVs];
  7106. CComPtr<ID3D12Resource> pUAVResources[NumUAVs];
  7107. CComPtr<ID3D12Resource> pUploadResources[NumResources];
  7108. {
  7109. D3D12_RESOURCE_DESC bufDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  7110. float values[valueSize];
  7111. for (int i = 0; i < NumSRVs - 1; i++) {
  7112. for (int j = 0; j < valueSize; j++)
  7113. values[j] = 10.0 + i;
  7114. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufDesc,
  7115. &pSRVResources[i], &pUploadResources[i]);
  7116. }
  7117. D3D12_RESOURCE_DESC tex2dDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 4, 4);
  7118. for (int j = 0; j < valueSize; j++)
  7119. values[j] = 10.0 + (NumSRVs - 1);
  7120. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex2dDesc,
  7121. &pSRVResources[NumSRVs - 1], &pUploadResources[NumSRVs - 1]);
  7122. }
  7123. // Set up UAV resources
  7124. CComPtr<ID3D12Resource> pReadBuffer;
  7125. float values[valueSize];
  7126. for (int i = 0; i < NumUAVs - 2; i++) {
  7127. for (int j = 0; j < valueSize; j++)
  7128. values[j] = 20.0 + i;
  7129. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7130. &pUAVResources[i], &pUploadResources[NumSRVs + i]);
  7131. }
  7132. for (int j = 0; j < valueSize; j++)
  7133. values[j] = 20.0 + (NumUAVs - 1);
  7134. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7135. &pUAVResources[NumUAVs - 2], &pUploadResources[NumResources - 2], &pReadBuffer);
  7136. for (int j = 0; j < valueSize; j++)
  7137. values[j] = 20.0 + (NumUAVs - 2);
  7138. D3D12_RESOURCE_DESC tex1dDesc = CD3DX12_RESOURCE_DESC::Tex1D(DXGI_FORMAT_R32_FLOAT, valueSize, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  7139. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex1dDesc,
  7140. &pUAVResources[NumUAVs - 1], &pUploadResources[NumResources - 1]);
  7141. // Close the command list and execute it to perform the GPU setup.
  7142. pCommandList->Close();
  7143. ExecuteCommandList(pCommandQueue, pCommandList);
  7144. WaitForSignal(pCommandQueue, FO);
  7145. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  7146. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  7147. CComPtr<ID3D12DescriptorHeap> pResHeap;
  7148. CComPtr<ID3D12DescriptorHeap> pSampHeap;
  7149. CreateDefaultDescHeaps(pDevice, NumSRVs + NumUAVs, NumSamplers, &pResHeap, &pSampHeap);
  7150. // Create Rootsignature and descriptor tables
  7151. {
  7152. ID3D12DescriptorHeap *descHeaps[2] = {pResHeap, pSampHeap};
  7153. pCommandList->SetDescriptorHeaps(2, descHeaps);
  7154. pCommandList->SetComputeRootSignature(pRootSignature);
  7155. if (!isDynamic) {
  7156. // Only non-dynamic resources require descriptortables
  7157. pCommandList->SetComputeRootDescriptorTable(0, pResHeap->GetGPUDescriptorHandleForHeapStart());
  7158. pCommandList->SetComputeRootDescriptorTable(1, pSampHeap->GetGPUDescriptorHandleForHeapStart());
  7159. }
  7160. }
  7161. CD3DX12_CPU_DESCRIPTOR_HANDLE baseHandle(pResHeap->GetCPUDescriptorHandleForHeapStart());
  7162. // Create SRVs
  7163. CreateRawSRV(pDevice, baseHandle, valueSize, pSRVResources[0]);
  7164. CreateStructSRV(pDevice, baseHandle, valueSize, sizeof(float), pSRVResources[1]);
  7165. CreateTex2DSRV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pSRVResources[2]);
  7166. // Create UAVs
  7167. CreateRawUAV(pDevice, baseHandle, valueSize, pUAVResources[0]);
  7168. CreateStructUAV(pDevice, baseHandle, valueSize, sizeof(float), pUAVResources[1]);
  7169. CreateTypedUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[2]);
  7170. CreateTex1DUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[3]);
  7171. D3D12_FILTER filters[] = {D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT};
  7172. float borderColors[] = {30.0, 31.0};
  7173. CreateDefaultSamplers(pDevice, pSampHeap->GetCPUDescriptorHandleForHeapStart(),
  7174. filters, borderColors, NumSamplers);
  7175. // Run the compute shader and copy the results back to readable memory.
  7176. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  7177. RecordTransitionBarrier(pCommandList, pUAVResources[NumUAVs - 2], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  7178. pCommandList->CopyResource(pReadBuffer, pUAVResources[NumUAVs - 2]);
  7179. pCommandList->Close();
  7180. ExecuteCommandList(pCommandQueue, pCommandList);
  7181. WaitForSignal(pCommandQueue, FO);
  7182. MappedData data(pReadBuffer, valueSize*sizeof(float));
  7183. const float *pData = (float*)data.data();
  7184. LogCommentFmt(L"Verify bound resources are properly selected");
  7185. VERIFY_ARE_EQUAL(pData[0], 10);
  7186. VERIFY_ARE_EQUAL(pData[1], 11);
  7187. VERIFY_ARE_EQUAL(pData[2], 12);
  7188. VERIFY_ARE_EQUAL(pData[3], 20);
  7189. VERIFY_ARE_EQUAL(pData[4], 21);
  7190. VERIFY_ARE_EQUAL(pData[5], 22);
  7191. VERIFY_ARE_EQUAL(pData[6], 30);
  7192. VERIFY_ARE_EQUAL(pData[7], 1); // samplecmp 1 means it matched 31
  7193. }
  7194. TEST_F(ExecutionTest, SignatureResourcesTest) {
  7195. std::string pShader =
  7196. "ByteAddressBuffer g_rawBuf : register(t0);\n"
  7197. "StructuredBuffer<float> g_structBuf : register(t1);\n"
  7198. "Texture2D<float> g_tex : register(t2);\n"
  7199. "RWByteAddressBuffer g_rwRawBuf : register(u0);\n"
  7200. "RWStructuredBuffer<float> g_rwStructBuf : register(u1);\n"
  7201. "RWBuffer<float> g_result : register(u2);\n"
  7202. "RWTexture1D<float> g_rwTex : register(u3);\n"
  7203. "SamplerState g_samp : register(s0);\n"
  7204. "SamplerComparisonState g_sampCmp : register(s1);\n"
  7205. "[NumThreads(1, 1, 1)]\n"
  7206. "void main(uint ix : SV_GroupIndex) {\n"
  7207. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7208. " g_result[1] = g_structBuf.Load(0);\n"
  7209. " g_result[2] = g_tex.Load(0);\n"
  7210. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7211. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7212. " g_result[5] = g_rwTex.Load(0);\n"
  7213. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7214. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7215. "}\n";
  7216. CComPtr<ID3D12Device> pDevice;
  7217. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7218. return;
  7219. RunResourceTest(pDevice, pShader.c_str(), L"cs_6_6", /*isDynamic*/false);
  7220. }
  7221. TEST_F(ExecutionTest, DynamicResourcesTest) {
  7222. static const char pShader[] =
  7223. "static ByteAddressBuffer g_rawBuf = ResourceDescriptorHeap[0];\n"
  7224. "static StructuredBuffer<float> g_structBuf = ResourceDescriptorHeap[1];\n"
  7225. "static Texture2D<float> g_tex = ResourceDescriptorHeap[2];\n"
  7226. "static RWByteAddressBuffer g_rwRawBuf = ResourceDescriptorHeap[3];\n"
  7227. "static RWStructuredBuffer<float> g_rwStructBuf = ResourceDescriptorHeap[4];\n"
  7228. "static RWBuffer<float> g_result = ResourceDescriptorHeap[5];\n"
  7229. "static RWTexture1D<float> g_rwTex = ResourceDescriptorHeap[6];\n"
  7230. "static SamplerState g_samp = SamplerDescriptorHeap[0];\n"
  7231. "static SamplerComparisonState g_sampCmp = SamplerDescriptorHeap[1];\n"
  7232. "[NumThreads(1, 1, 1)]\n"
  7233. "void main(uint ix : SV_GroupIndex) {\n"
  7234. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7235. " g_result[1] = g_structBuf.Load(0);\n"
  7236. " g_result[2] = g_tex.Load(0);\n"
  7237. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7238. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7239. " g_result[5] = g_rwTex.Load(0);\n"
  7240. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7241. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7242. "}\n";
  7243. CComPtr<ID3D12Device> pDevice;
  7244. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7245. return;
  7246. RunResourceTest(pDevice, pShader, L"cs_6_6", /*isDynamic*/true);
  7247. }
  7248. #define MAX_WAVESIZE 128
  7249. #define strinfigy2(arg) #arg
  7250. #define strinfigy(arg) strinfigy2(arg)
  7251. void ExecutionTest::WaveSizeTest() {
  7252. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7253. CComPtr<ID3D12Device> pDevice;
  7254. CComPtr<IStream> pStream;
  7255. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7256. return;
  7257. }
  7258. // Check Wave support
  7259. if (!DoesDeviceSupportWaveOps(pDevice)) {
  7260. // Optional feature, so it's correct to not support it if declared as such.
  7261. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  7262. return;
  7263. }
  7264. // read shader config
  7265. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7266. // Get supported wave sizes
  7267. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waveOpts;
  7268. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &waveOpts, sizeof(waveOpts)));
  7269. UINT minWaveSize = waveOpts.WaveLaneCountMin;
  7270. UINT maxWaveSize = waveOpts.WaveLaneCountMax;
  7271. DXASSERT_NOMSG(minWaveSize <= maxWaveSize);
  7272. DXASSERT((minWaveSize & (minWaveSize - 1)) == 0, "must be a power of 2");
  7273. DXASSERT((maxWaveSize & (maxWaveSize - 1)) == 0, "must be a power of 2");
  7274. // format shader source
  7275. const char waveSizeTestShader[] =
  7276. "struct TestData { \r\n"
  7277. " uint count; \r\n"
  7278. "}; \r\n"
  7279. "RWStructuredBuffer<TestData> data : register(u0); \r\n"
  7280. "\r\n"
  7281. "// Note: WAVESIZE will be defined via compiler option -D\r\n"
  7282. "[wavesize(WAVESIZE)]\r\n"
  7283. "[numthreads(" strinfigy(MAX_WAVESIZE) "*2,1,1)]\r\n"
  7284. "void main(uint3 tid : SV_DispatchThreadID ) { \r\n"
  7285. " data[tid.x].count = WaveActiveSum(1); \r\n"
  7286. "}\r\n";
  7287. struct WaveSizeTestData {
  7288. uint32_t count;
  7289. };
  7290. for (UINT waveSize = minWaveSize; waveSize <= maxWaveSize; waveSize *= 2) {
  7291. // format compiler args
  7292. char compilerOptions[32];
  7293. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D WAVESIZE=%d", waveSize) != -1);
  7294. // run the shader
  7295. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "WaveSizeTest",
  7296. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7297. VERIFY_IS_TRUE((0 == strncmp(Name, "UAVBuffer0", 10)));
  7298. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  7299. pShaderOp->Shaders.at(0).Text = waveSizeTestShader;
  7300. VERIFY_IS_TRUE(sizeof(WaveSizeTestData)*MAX_WAVESIZE <= Data.size());
  7301. WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
  7302. memset(&pInData, sizeof(WaveSizeTestData)*MAX_WAVESIZE, 0);
  7303. });
  7304. // verify expected values
  7305. MappedData dataUav;
  7306. WaveSizeTestData *pOutData;
  7307. test->Test->GetReadBackData("UAVBuffer0", &dataUav);
  7308. VERIFY_ARE_EQUAL(sizeof(WaveSizeTestData)*MAX_WAVESIZE, dataUav.size());
  7309. pOutData = (WaveSizeTestData*)dataUav.data();
  7310. LogCommentFmt(L"Verifying test result for wave size %d", waveSize);
  7311. for (unsigned i = 0; i < MAX_WAVESIZE; i++) {
  7312. if (!VERIFY_ARE_EQUAL(pOutData[i].count, waveSize))
  7313. break;
  7314. }
  7315. }
  7316. }
  7317. // Atomic operation testing
  7318. // Atomic tests take a single integer index as input and contort it into some
  7319. // kind of interesting contributor to the operation in question.
  7320. // So each vertex, pixel, thread, or other will have a unique index that produces
  7321. // a contributing value to the calculation which is stored in a small resource
  7322. // For arithmetic or bitwise operations, each contributor accumulates to the same
  7323. // location in the resource indexed by the operation type. Addition is in index 0
  7324. // umin/umax are in 1 and 2 and so on.
  7325. // To make sure that the most significant bits are involved in the calculation,
  7326. // particularly in the case of 64-bit values, each contributing value is duplicated
  7327. // to the lower and upper halves of the value. There is an exception to this when
  7328. // addition exceeds the available size and also for compare and exchange explained below.
  7329. // For compare and exchange operations, 64 output locations are shared by the various lanes.
  7330. // Each lane attempts to write to a location that is shared with several others.
  7331. // The first one to write to it determines its contents, which will be the lane index <ix>
  7332. // in the upper bits and the output location index in the lower bits.
  7333. // This ensures that the compare operations consider the upper bits in the comparison.
  7334. // The initial compare store is followed by a compare exchange that compares for the
  7335. // value the current lane would have assigned there. Finally, the output of the cmpxchg
  7336. // is used to determine if the current lane should perform the final unconditional exchange.
  7337. // The values are verified by checking the lower bits for the matching location index
  7338. // and ensuring that the upper bits undergoing the same transformation result in the location index.
  7339. // For lane index <ix> the location is calculated and final result assigned as if by this code:
  7340. // g_outputBuf[(ix/3)%64] = (ix << shBits) | ((ix/3)%64);
  7341. bool AtomicResultMatches(const BYTE *uResults, uint64_t gold, size_t size) {
  7342. if (memcmp(uResults, &gold, size)) {
  7343. if (size == 4)
  7344. LogCommentFmt(L" value %d is not %d", ((uint32_t*)uResults)[0], (uint32_t)gold);
  7345. else
  7346. LogCommentFmt(L" value %lld is not %lld", ((uint64_t*)uResults)[0], gold);
  7347. return false;
  7348. }
  7349. return true;
  7350. }
  7351. // Used to duplicate the lower half bits into the upper half bits of an integer
  7352. // To verify that the full value is being considered, many tests duplicate the results into the upper half
  7353. #define SHIFT(val, bits) (((val)&((1ULL<<(bits))-1ULL)) | ((val) << (bits)))
  7354. // Symbolic constants for the results
  7355. #define ADD_IDX 0
  7356. #define UMIN_IDX 1
  7357. #define UMAX_IDX 2
  7358. #define AND_IDX 3
  7359. #define OR_IDX 4
  7360. #define XOR_IDX 5
  7361. #define SMIN_IDX 0
  7362. #define SMAX_IDX 1
  7363. // Verify results for atomic operations. <uResults> and <sResults> are pointers to
  7364. // the readback resource sections containing unsigned and signed integers respectively.
  7365. // <pXchg> is a poiner to the readback resource containing the results of the compare
  7366. // and exchange operations tests. <stride> is the number of bytes between results for
  7367. // all of the results pointers. <maxIdx> is the number of indices that went into the results
  7368. // which is used to determine what the results should be. <bitSize> is the size in bits of
  7369. // the produced results, either 32 or 64.
  7370. void VerifyAtomicResults(const BYTE *uResults, const BYTE *sResults,
  7371. const BYTE *pXchg, size_t stride, size_t maxIdx, size_t bitSize) {
  7372. // Each atomic test performs the test on the value in the lower half
  7373. // and also duplicated in the upper half of the value. The SHIFT macros account for this.
  7374. // This is to verify that the upper bits are considered
  7375. size_t shBits = bitSize/2;
  7376. size_t byteSize = bitSize/8;
  7377. // Test ADD Operation
  7378. // ADD just sums all the indices. The result should the sum of the highest and lowest indices
  7379. // multiplied by half the number of sums.
  7380. size_t addResult = (maxIdx)*(maxIdx-1)/2;
  7381. LogCommentFmt(L"Verifying %d-bit integer atomic add", bitSize);
  7382. // For 32-bit values, the sum exceeds the 16 bit limit, so we can't duplicate
  7383. // That's fine, the duplication is really for 64-bit values.
  7384. if (bitSize < 64)
  7385. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, addResult, byteSize));
  7386. else
  7387. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, SHIFT(addResult, shBits), byteSize));
  7388. // Test MIN and MAX Operations
  7389. // The result of a simple min and max of any sequence of indices would be fairly uninteresting
  7390. // and certain erroneous behavior might mistakenly produce the correct results.
  7391. // To make it interesting, the contributing values will change depending on the evenness of the index.
  7392. // On an even index, min and max operate on the bitflipped index. For signed compares, this is
  7393. // interpretted as a negative value and for unsigned, a very high value.
  7394. // For unsigned min/max, index 0 will be bitflipped to ~0, which is interpretted as the maximum
  7395. // Because zero is manipulated, this leaves 1 as the lowest value.
  7396. LogCommentFmt(L"Verifying %d-bit integer atomic umin", bitSize);
  7397. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMIN_IDX, SHIFT(1ULL, shBits), byteSize)); // UMin
  7398. LogCommentFmt(L"Verifying %d-bit integer atomic umax", bitSize);
  7399. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMAX_IDX, ~0ULL, byteSize)); // UMax
  7400. // For signed min/max, the index just before the last will be bitflipped (maxIndex is always even).
  7401. // This is interpretted as -maxIndex and will be the lowest
  7402. // The maxIndex will be unaltered and interpretted as the highest.
  7403. LogCommentFmt(L"Verifying %d-bit integer atomic smin", bitSize);
  7404. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMIN_IDX, SHIFT(-(maxIdx-1), shBits), byteSize)); // SMin
  7405. LogCommentFmt(L"Verifying %d-bit integer atomic smax", bitSize);
  7406. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMAX_IDX, SHIFT(maxIdx-1, shBits), byteSize)); // SMax
  7407. // Test AND and OR operations.
  7408. // For AND operations, all indices are bitflipped and ANDed to the previous result.
  7409. // This means that the highest bits, which are never set by the contributing indices will be set
  7410. // for all the indices, so they will be set in the final result.
  7411. // For OR operations, the indices are ORed to the previous result unaltered
  7412. // This means that any bit that is set in any index will be set in the final OR result.
  7413. // In practice, this means that the cumulative result of the AND and OR operations
  7414. // are bitflipped versions of each other.
  7415. // Finding the most significant set bit by the max index or next power of two (pot)
  7416. // gives us the pivot point for these results
  7417. size_t nextPot = 1ULL << (bitSize - 1);
  7418. for (;nextPot && !((maxIdx-1) & (nextPot)); nextPot >>= 1) {}
  7419. nextPot <<= 1;
  7420. LogCommentFmt(L"Verifying %d-bit integer atomic and", bitSize);
  7421. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*AND_IDX, ~SHIFT(nextPot-1, shBits), byteSize)); // And
  7422. LogCommentFmt(L"Verifying %d-bit integer atomic or", bitSize);
  7423. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*OR_IDX, SHIFT(nextPot-1, shBits), byteSize)); // Or
  7424. // Test XOR operation
  7425. // For XOR operations, a 1 is shifted by the number of spaces equal to the index and XORed
  7426. // to the previous result. Because this would rapidely shift off the end of the value,
  7427. // giving undefined and uninteresting results, the index is moduloed to a value that will
  7428. // fit within the type size.
  7429. // Because many of the tests use total numbers of lanes that can be evenly divisible by 32 or 64,
  7430. // these values aren't used for the modulo since the expected result might be zero,
  7431. // which could be encountered through erroneous behavior.
  7432. // Instead, one less than the type size in bits is used for the modulo.
  7433. // Even though we don't know the actual order these operations are performed,
  7434. // indices that make up a contiguous sequence of 31 or 63 values can be thought of as one of a series of "passes".
  7435. // Each "pass" sets or clears the bits depending on what's already there.
  7436. // if the number of the pass is odd, the bits are being unset and all above the mod position should be set.
  7437. // If even, the bits are in the process of being set and bits below the mod position should be set.
  7438. size_t xorResult = ((1ULL<<((maxIdx)%(bitSize-1))) -1);
  7439. if (((maxIdx/(bitSize-1))&1)) {
  7440. xorResult ^= ~0ULL;
  7441. // The XOR above may set uninvolved upper bits, messing up the compare. So AND off the uninvolved bits.
  7442. xorResult &= ((1ULL<<(bitSize-1)) - 1);
  7443. }
  7444. LogCommentFmt(L"Verifying %d-bit integer atomic xor", bitSize);
  7445. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*XOR_IDX, xorResult, byteSize));
  7446. // Test CMP/XCHG Operations
  7447. // This tests CompareStore, CompareExchange, and Exchange operations.
  7448. // Unlike above, every lane isn't contributing to the same resource location
  7449. // Instead, every lane competes with a few others to update the same resource location.
  7450. // The first lane to find the contents of their location uninitialized will
  7451. // update it. To verify that upper bits are considered in the comparison and
  7452. // in the assignment, the value stored in the lowest bits is the location index.
  7453. // This ensures that part will be the same for each of the competing lanes.
  7454. // The uppermost bits are updated with the index of the lane that got there first.
  7455. // Subsequent calls to CompareExchange will verify this value matches and alter
  7456. // the content slightly. Finally, a simple check of the output value to what
  7457. // the current lane would expect and a call to exchange will update the value once more
  7458. // To verify this has gone through properly, the upper portion is converted as
  7459. // if to calculate the location index and compared with the location index.
  7460. // It could be the index of any of several lanes that assign to that location,
  7461. // but this ensures that it is not any lane outside of that group.
  7462. // The lower bits are compared to the location index as well.
  7463. LogCommentFmt(L"Verifying %d-bit integer atomic cmp/xchg results", bitSize);
  7464. for (size_t i = 0; i < 64; i++) {
  7465. uint64_t val = *((uint64_t*)(pXchg + i*stride));
  7466. // Verify lower bits match location index exactly
  7467. VERIFY_ARE_EQUAL(i, val & ((1ULL << shBits) - 1ULL));
  7468. // Verify that upper bits contain original index that transforms to location index
  7469. VERIFY_ARE_EQUAL(((val >> shBits)/3)%64, i);
  7470. }
  7471. }
  7472. void VerifyAtomicsRawTest(std::shared_ptr<ShaderOpTestResult> test,
  7473. size_t maxIdx, size_t bitSize) {
  7474. size_t stride = 8;
  7475. // struct mirroring that in the shader
  7476. struct AtomicStuff {
  7477. float prepad[2][3];
  7478. UINT uintEl[4];
  7479. int sintEl[4];
  7480. struct useless {
  7481. uint32_t unused[3];
  7482. } postpad;
  7483. float last;
  7484. };
  7485. MappedData uintData, xchgData;
  7486. test->Test->GetReadBackData("U0", &uintData);
  7487. test->Test->GetReadBackData("U1", &xchgData);
  7488. const AtomicStuff *pStruct = (AtomicStuff *)uintData.data();
  7489. const AtomicStuff *pStrXchg = (AtomicStuff *)xchgData.data();
  7490. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWStructuredBuffer resource", bitSize);
  7491. VerifyAtomicResults((const BYTE*)&(pStruct[0].uintEl[2]), (const BYTE*)&(pStruct[1].sintEl[2]),
  7492. (const BYTE*)&(pStrXchg[0].uintEl[2]), sizeof(AtomicStuff), maxIdx, bitSize);
  7493. const BYTE *pUint = nullptr;
  7494. const BYTE *pXchg = nullptr;
  7495. test->Test->GetReadBackData("U2", &uintData);
  7496. test->Test->GetReadBackData("U3", &xchgData);
  7497. pUint = (BYTE *)uintData.data();
  7498. pXchg = (BYTE *)xchgData.data();
  7499. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWByteAddressBuffer resource", bitSize);
  7500. VerifyAtomicResults(pUint, pUint + stride*6,
  7501. pXchg, stride, maxIdx, bitSize);
  7502. }
  7503. void VerifyAtomicsTypedTest(std::shared_ptr<ShaderOpTestResult> test,
  7504. size_t maxIdx, size_t bitSize) {
  7505. size_t stride = 8;
  7506. MappedData uintData, sintData, xchgData;
  7507. const BYTE *pUint = nullptr;
  7508. const BYTE *pSint = nullptr;
  7509. const BYTE *pXchg = nullptr;
  7510. // Typed resources can't share between 32 and 64 bits
  7511. if (bitSize == 32) {
  7512. test->Test->GetReadBackData("U4", &uintData);
  7513. test->Test->GetReadBackData("U5", &sintData);
  7514. test->Test->GetReadBackData("U6", &xchgData);
  7515. } else {
  7516. test->Test->GetReadBackData("U12", &uintData);
  7517. test->Test->GetReadBackData("U13", &sintData);
  7518. test->Test->GetReadBackData("U14", &xchgData);
  7519. }
  7520. pUint = (BYTE *)uintData.data();
  7521. pSint = (BYTE *)sintData.data();
  7522. pXchg = (BYTE *)xchgData.data();
  7523. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWBuffer resource", bitSize);
  7524. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7525. // Typed resources can't share between 32 and 64 bits
  7526. if (bitSize == 32) {
  7527. test->Test->GetReadBackData("U7", &uintData);
  7528. test->Test->GetReadBackData("U8", &sintData);
  7529. test->Test->GetReadBackData("U9", &xchgData);
  7530. } else {
  7531. test->Test->GetReadBackData("U15", &uintData);
  7532. test->Test->GetReadBackData("U16", &sintData);
  7533. test->Test->GetReadBackData("U17", &xchgData);
  7534. }
  7535. pUint = (BYTE *)uintData.data();
  7536. pSint = (BYTE *)sintData.data();
  7537. pXchg = (BYTE *)xchgData.data();
  7538. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWTexture resource", bitSize);
  7539. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7540. }
  7541. void VerifyAtomicsSharedTest(std::shared_ptr<ShaderOpTestResult> test,
  7542. size_t maxIdx, size_t bitSize) {
  7543. size_t stride = 8;
  7544. MappedData uintData, xchgData;
  7545. const BYTE *pUint = nullptr;
  7546. const BYTE *pXchg = nullptr;
  7547. test->Test->GetReadBackData("U10", &uintData);
  7548. test->Test->GetReadBackData("U11", &xchgData);
  7549. pUint = (BYTE *)uintData.data();
  7550. pXchg = (BYTE *)xchgData.data();
  7551. LogCommentFmt(L"Verifying %d-bit integer atomic operations on groupshared variables", bitSize);
  7552. VerifyAtomicResults(pUint, pUint + stride*6,
  7553. pXchg, stride, maxIdx, bitSize);
  7554. }
  7555. void VerifyAtomicsTest(std::shared_ptr<ShaderOpTestResult> test,
  7556. size_t maxIdx, size_t bitSize) {
  7557. VerifyAtomicsRawTest(test, maxIdx, bitSize);
  7558. VerifyAtomicsTypedTest(test, maxIdx, bitSize);
  7559. }
  7560. TEST_F(ExecutionTest, AtomicsTest) {
  7561. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7562. CComPtr<IStream> pStream;
  7563. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7564. CComPtr<ID3D12Device> pDevice;
  7565. if (!CreateDevice(&pDevice))
  7566. return;
  7567. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7568. std::make_shared<st::ShaderOpSet>();
  7569. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7570. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7571. // Test compute shader
  7572. LogCommentFmt(L"Verifying 32-bit integer atomic operations in compute shader");
  7573. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7574. VerifyAtomicsTest(test, 32*32, 32);
  7575. VerifyAtomicsSharedTest(test, 32*32, 32);
  7576. // Test mesh shader if available
  7577. pShaderOp->CS = nullptr;
  7578. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7579. LogCommentFmt(L"Verifying 32-bit integer atomic operations in amp/mesh/pixel shaders");
  7580. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7581. VerifyAtomicsTest(test, 8*8*2 + 8*8*2 + 64*64, 32);
  7582. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 32);
  7583. }
  7584. // Test Vertex + Pixel shader
  7585. pShaderOp->MS = nullptr;
  7586. LogCommentFmt(L"Verifying 32-bit integer atomic operations in vert/pixel shaders");
  7587. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7588. VerifyAtomicsTest(test, 64*64+6, 32);
  7589. }
  7590. TEST_F(ExecutionTest, Atomics64Test) {
  7591. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7592. CComPtr<IStream> pStream;
  7593. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7594. CComPtr<ID3D12Device> pDevice;
  7595. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7596. return;
  7597. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7598. std::make_shared<st::ShaderOpSet>();
  7599. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7600. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7601. // Reassign shader stages to 64-bit versions
  7602. // Collect 64-bit shaders
  7603. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7604. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7605. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7606. if (!strcmp(S.Name, "CS64")) CS64 = S.Name;
  7607. if (!strcmp(S.Name, "VS64")) VS64 = S.Name;
  7608. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7609. if (!strcmp(S.Name, "AS64")) AS64 = S.Name;
  7610. if (!strcmp(S.Name, "MS64")) MS64 = S.Name;
  7611. }
  7612. pShaderOp->CS = CS64;
  7613. pShaderOp->VS = VS64;
  7614. pShaderOp->PS = PS64;
  7615. pShaderOp->AS = AS64;
  7616. pShaderOp->MS = MS64;
  7617. // Test compute shader
  7618. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in compute shader");
  7619. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7620. VerifyAtomicsRawTest(test, 32*32, 64);
  7621. // Test mesh shader if available
  7622. pShaderOp->CS = nullptr;
  7623. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7624. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in amp/mesh/pixel shader");
  7625. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7626. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7627. }
  7628. // Test Vertex + Pixel shader
  7629. pShaderOp->MS = nullptr;
  7630. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in vert/pixel shader");
  7631. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7632. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7633. }
  7634. TEST_F(ExecutionTest, AtomicsTyped64Test) {
  7635. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7636. CComPtr<IStream> pStream;
  7637. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7638. CComPtr<ID3D12Device> pDevice;
  7639. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7640. return;
  7641. if (!DoesDeviceSupportInt64(pDevice)) {
  7642. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7643. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7644. return;
  7645. }
  7646. if (!DoesDeviceSupportTyped64Atomics(pDevice)) {
  7647. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on typed resources.");
  7648. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7649. return;
  7650. }
  7651. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7652. std::make_shared<st::ShaderOpSet>();
  7653. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7654. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7655. // Reassign shader stages to 64-bit versions
  7656. // Collect 64-bit shaders
  7657. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7658. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7659. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7660. if (!strcmp(S.Name, "CSTY64")) CS64 = S.Name;
  7661. if (!strcmp(S.Name, "VSTY64")) VS64 = S.Name;
  7662. if (!strcmp(S.Name, "PSTY64")) PS64 = S.Name;
  7663. if (!strcmp(S.Name, "ASTY64")) AS64 = S.Name;
  7664. if (!strcmp(S.Name, "MSTY64")) MS64 = S.Name;
  7665. }
  7666. pShaderOp->CS = CS64;
  7667. pShaderOp->VS = VS64;
  7668. pShaderOp->PS = PS64;
  7669. pShaderOp->AS = AS64;
  7670. pShaderOp->MS = MS64;
  7671. // Test compute shader
  7672. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in compute shader");
  7673. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7674. VerifyAtomicsTypedTest(test, 32*32, 64);
  7675. // Test mesh shader if available
  7676. pShaderOp->CS = nullptr;
  7677. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7678. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in amp/mesh/pixel shader");
  7679. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7680. VerifyAtomicsTypedTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7681. }
  7682. // Test Vertex + Pixel shader
  7683. pShaderOp->MS = nullptr;
  7684. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in vert/pixel shader");
  7685. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7686. VerifyAtomicsTypedTest(test, 64*64+6, 64);
  7687. }
  7688. TEST_F(ExecutionTest, AtomicsShared64Test) {
  7689. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7690. CComPtr<IStream> pStream;
  7691. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7692. CComPtr<ID3D12Device> pDevice;
  7693. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7694. return;
  7695. if (!DoesDeviceSupportInt64(pDevice)) {
  7696. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7697. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7698. return;
  7699. }
  7700. if (!DoesDeviceSupportShared64Atomics(pDevice)) {
  7701. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on groupshared variables.");
  7702. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7703. return;
  7704. }
  7705. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7706. std::make_shared<st::ShaderOpSet>();
  7707. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7708. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7709. // Reassign shader stages to 64-bit versions
  7710. // Collect 64-bit shaders
  7711. LPCSTR CS64 = nullptr, PS64 = nullptr;
  7712. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7713. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7714. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7715. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7716. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7717. if (!strcmp(S.Name, "ASSH64")) AS64 = S.Name;
  7718. if (!strcmp(S.Name, "MSSH64")) MS64 = S.Name;
  7719. }
  7720. pShaderOp->CS = CS64;
  7721. pShaderOp->PS = PS64;
  7722. pShaderOp->AS = AS64;
  7723. pShaderOp->MS = MS64;
  7724. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in compute shader");
  7725. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7726. VerifyAtomicsSharedTest(test, 32*32, 64);
  7727. // Test mesh shader if available
  7728. pShaderOp->CS = nullptr;
  7729. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7730. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in amp/mesh/pixel shader");
  7731. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7732. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 64);
  7733. }
  7734. }
  7735. // Float Atomics
  7736. // These operations are almost the same as for the 32-bit and 64-bit integer tests
  7737. // The difference is that there is no need to verify the upper bits.
  7738. // So there is no storing of different parts in upper and lower halves.
  7739. // Additionally, the only operations that are supported on floats
  7740. // are compare and exchange operations. So that's all that is tested here.
  7741. // Just as above, a number of lanes are assigned the same output value.
  7742. // Unlike above, one location is needed for the result of the special NaN test
  7743. // For this reason, the conversion is reduced by one and shifted by one to leave
  7744. // the zero-indexed location available.
  7745. // Verify results for a particular set of atomics results
  7746. void VerifyAtomicFloatResults(const float *results, size_t maxIdx) {
  7747. // The first entry is for NaN to ensure that compares between NaNs succeed
  7748. // The sentinal value is 0.123, for which this compare is sufficient.
  7749. VERIFY_IS_TRUE(results[0] >= 0.120 && results[0] < 0.125);
  7750. // Start at 1 because 0 is just for NaN tests
  7751. for (size_t i = 1; i < 64; i++) {
  7752. VERIFY_ARE_EQUAL((int(results[i])/3)%63 + 1, i);
  7753. }
  7754. }
  7755. void VerifyAtomicsFloatSharedTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7756. MappedData Data;
  7757. const float *pData = nullptr;
  7758. test->Test->GetReadBackData("U4", &Data);
  7759. pData = (float *)Data.data();
  7760. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on groupshared variables");
  7761. VerifyAtomicFloatResults(pData, maxIdx);
  7762. }
  7763. void VerifyAtomicsFloatTest(std::shared_ptr<ShaderOpTestResult> test, size_t maxIdx) {
  7764. // struct mirroring that in the shader
  7765. struct AtomicStuff {
  7766. float prepad[2][3];
  7767. float fltEl[2];
  7768. struct useless {
  7769. uint32_t unused[3];
  7770. } postpad;
  7771. };
  7772. // Test Compute Shader
  7773. MappedData Data;
  7774. const float *pData = nullptr;
  7775. test->Test->GetReadBackData("U0", &Data);
  7776. const AtomicStuff *pStructData = (AtomicStuff *)Data.data();
  7777. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWStructuredBuffer resources");
  7778. VERIFY_IS_TRUE(pStructData[0].fltEl[1] >= 0.120 && pStructData[0].fltEl[1] < 0.125);
  7779. for (size_t i = 1; i < 64; i++) {
  7780. VERIFY_ARE_EQUAL((int(pStructData[i].fltEl[1])/3)%63 + 1, i);
  7781. }
  7782. test->Test->GetReadBackData("U1", &Data);
  7783. pData = (float *)Data.data();
  7784. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWByteAddressBuffer resources");
  7785. VerifyAtomicFloatResults(pData, maxIdx);
  7786. test->Test->GetReadBackData("U2", &Data);
  7787. pData = (float *)Data.data();
  7788. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWBuffer resources");
  7789. VerifyAtomicFloatResults(pData, maxIdx);
  7790. test->Test->GetReadBackData("U3", &Data);
  7791. pData = (float *)Data.data();
  7792. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWTexture resources");
  7793. VerifyAtomicFloatResults(pData, maxIdx);
  7794. }
  7795. TEST_F(ExecutionTest, AtomicsFloatTest) {
  7796. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7797. CComPtr<IStream> pStream;
  7798. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7799. CComPtr<ID3D12Device> pDevice;
  7800. if (!CreateDevice(&pDevice))
  7801. return;
  7802. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7803. std::make_shared<st::ShaderOpSet>();
  7804. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7805. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("FloatAtomics");
  7806. // Test compute shader
  7807. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in compute shader");
  7808. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7809. VerifyAtomicsFloatTest(test, 32*32);
  7810. VerifyAtomicsFloatSharedTest(test, 32*32);
  7811. // Test mesh shader if available
  7812. pShaderOp->CS = nullptr;
  7813. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7814. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in amp/mesh/pixel shaders");
  7815. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7816. VerifyAtomicsFloatTest(test, 8*8*2 + 8*8*2 + 64*64);
  7817. VerifyAtomicsFloatSharedTest(test, 8*8*2 + 8*8*2);
  7818. }
  7819. // Test Vertex + Pixel shader
  7820. pShaderOp->MS = nullptr;
  7821. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in vert/pixel shaders");
  7822. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7823. VerifyAtomicsFloatTest(test, 64*64+6);
  7824. }
  7825. #ifndef _HLK_CONF
  7826. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  7827. char **pReadBackDump) {
  7828. std::stringstream str;
  7829. unsigned count = 0;
  7830. for (auto &R : pShaderOp->Resources) {
  7831. if (!R.ReadBack)
  7832. continue;
  7833. ++count;
  7834. str << "Resource: " << R.Name << "\r\n";
  7835. // Find a descriptor that can tell us how to dump this resource.
  7836. bool found = false;
  7837. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  7838. for (auto &D : Heaps.Descriptors) {
  7839. if (_stricmp(D.ResName, R.Name) != 0) {
  7840. continue;
  7841. }
  7842. found = true;
  7843. if (_stricmp(D.Kind, "UAV") != 0) {
  7844. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  7845. break;
  7846. }
  7847. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  7848. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  7849. break;
  7850. }
  7851. // We can map back to the structure if a structured buffer via the shader, but
  7852. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  7853. MappedData data;
  7854. pTest->GetReadBackData(R.Name, &data);
  7855. uint32_t *pData = (uint32_t *)data.data();
  7856. size_t u32_count = R.Desc.Width / sizeof(uint32_t);
  7857. for (size_t i = 0; i < u32_count; ++i) {
  7858. float f = *(float *)pData;
  7859. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  7860. << std::dec << " " << f << "\r\n";
  7861. ++pData;
  7862. }
  7863. break;
  7864. }
  7865. if (found) break;
  7866. }
  7867. if (!found) {
  7868. str << "Unable to find a view for the resource.\r\n";
  7869. }
  7870. }
  7871. str << "Resources read back: " << count << "\r\n";
  7872. std::string s(str.str());
  7873. CComHeapPtr<char> pDump;
  7874. if (!pDump.Allocate(s.size() + 1))
  7875. throw std::bad_alloc();
  7876. memcpy(pDump.m_pData, s.data(), s.size());
  7877. pDump.m_pData[s.size()] = '\0';
  7878. *pReadBackDump = pDump.Detach();
  7879. }
  7880. // This is the exported interface by use from HLSLHost.exe.
  7881. // It's exclusive with the use of the DLL as a TAEF target.
  7882. extern "C" {
  7883. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  7884. HRESULT hr = EnableExperimentalShaderModels();
  7885. if (FAILED(hr)) {
  7886. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  7887. }
  7888. return S_OK;
  7889. }
  7890. __declspec(dllexport) HRESULT WINAPI
  7891. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  7892. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  7893. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  7894. HRESULT hr;
  7895. if (pReadBackDump) *pReadBackDump = nullptr;
  7896. st::SetOutputFn(pStrCtx, pOutputStrFn);
  7897. CComPtr<ID3D12InfoQueue> pInfoQueue;
  7898. CComHeapPtr<char> pDump;
  7899. bool FilterCreation = false;
  7900. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  7901. // Creation is largely driven by inputs, so don't log create/destroy messages.
  7902. pInfoQueue->PushEmptyStorageFilter();
  7903. pInfoQueue->PushEmptyRetrievalFilter();
  7904. if (FilterCreation) {
  7905. D3D12_INFO_QUEUE_FILTER filter;
  7906. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  7907. ZeroMemory(&filter, sizeof(filter));
  7908. filter.DenyList.NumCategories = _countof(denyCategories);
  7909. filter.DenyList.pCategoryList = denyCategories;
  7910. pInfoQueue->PushStorageFilter(&filter);
  7911. }
  7912. }
  7913. else {
  7914. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  7915. }
  7916. try {
  7917. dxc::DxcDllSupport m_support;
  7918. m_support.Initialize();
  7919. const char *pName = nullptr;
  7920. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, strlen(pText));
  7921. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7922. std::make_shared<st::ShaderOpSet>();
  7923. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7924. st::ShaderOp *pShaderOp;
  7925. if (pName == nullptr) {
  7926. if (ShaderOpSet->ShaderOps.size() != 1) {
  7927. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  7928. return E_FAIL;
  7929. }
  7930. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  7931. }
  7932. else {
  7933. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  7934. }
  7935. if (pShaderOp == nullptr) {
  7936. std::string msg = "Unable to find shader op ";
  7937. msg += pName;
  7938. msg += "; available ops";
  7939. const char sep = ':';
  7940. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  7941. msg += sep;
  7942. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  7943. }
  7944. CA2W msgWide(msg.c_str());
  7945. pOutputStrFn(pStrCtx, msgWide);
  7946. return E_FAIL;
  7947. }
  7948. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  7949. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  7950. test->SetDxcSupport(&m_support);
  7951. test->RunShaderOp(pShaderOp);
  7952. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  7953. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  7954. if (!pShaderOp->IsCompute()) {
  7955. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  7956. test->GetPipelineStats(&stats);
  7957. wchar_t statsText[400];
  7958. StringCchPrintfW(statsText, _countof(statsText),
  7959. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  7960. L"Vertex shader invocations: %I64u\r\n"
  7961. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  7962. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  7963. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  7964. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  7965. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  7966. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  7967. stats.DSInvocations, stats.CSInvocations);
  7968. pOutputStrFn(pStrCtx, statsText);
  7969. }
  7970. if (pReadBackDump) {
  7971. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  7972. }
  7973. hr = S_OK;
  7974. }
  7975. catch (const CAtlException &E)
  7976. {
  7977. hr = E.m_hr;
  7978. }
  7979. catch (const std::bad_alloc &)
  7980. {
  7981. hr = E_OUTOFMEMORY;
  7982. }
  7983. catch (const std::exception &)
  7984. {
  7985. hr = E_FAIL;
  7986. }
  7987. // Drain the device message queue if available.
  7988. if (pInfoQueue != nullptr) {
  7989. wchar_t buf[200];
  7990. StringCchPrintfW(buf, _countof(buf),
  7991. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  7992. L"allowed/denied by storage filter=%u/%u "
  7993. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  7994. (unsigned)pInfoQueue->GetNumStoredMessages(),
  7995. (unsigned)pInfoQueue->GetMessageCountLimit(),
  7996. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  7997. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  7998. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  7999. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  8000. pOutputStrFn(pStrCtx, buf);
  8001. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  8002. pInfoQueue->ClearStoredMessages();
  8003. pInfoQueue->PopRetrievalFilter();
  8004. pInfoQueue->PopStorageFilter();
  8005. if (FilterCreation) {
  8006. pInfoQueue->PopStorageFilter();
  8007. }
  8008. }
  8009. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  8010. return hr;
  8011. }
  8012. }
  8013. #endif
  8014. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  8015. // Do not remove the line above - it is used by TranslateExecutionTest.py