ExecutionTest.cpp 389 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578
  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. // We need to keep & fix these warnings to integrate smoothly with HLK
  13. #pragma warning(error: 4100 4146 4242 4244 4267 4701 4389)
  14. #include <algorithm>
  15. #include <memory>
  16. #include <array>
  17. #include <vector>
  18. #include <string>
  19. #include <map>
  20. #include <unordered_set>
  21. #include <strstream>
  22. #include <iomanip>
  23. #include "dxc/Test/CompilationResult.h"
  24. #include "dxc/Test/HLSLTestData.h"
  25. #include <Shlwapi.h>
  26. #include <atlcoll.h>
  27. #include <locale>
  28. #include <algorithm>
  29. #undef _read
  30. #include "WexTestClass.h"
  31. #include "dxc/Test/HlslTestUtils.h"
  32. #include "dxc/Test/DxcTestUtils.h"
  33. #include "dxc/Support/Global.h"
  34. #include "dxc/Support/WinIncludes.h"
  35. #include "dxc/Support/FileIOHelper.h"
  36. #include "dxc/Support/Unicode.h"
  37. //
  38. // d3d12.h and dxgi1_4.h are included in the Windows 10 SDK
  39. // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899120(v=vs.85).aspx
  40. // https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
  41. //
  42. #include <d3d12.h>
  43. #include <dxgi1_4.h>
  44. #include <DXGIDebug.h>
  45. #include "dxc/Support/d3dx12.h"
  46. #include <DirectXMath.h>
  47. #include <strsafe.h>
  48. #include <d3dcompiler.h>
  49. #include <wincodec.h>
  50. #include "ShaderOpTest.h"
  51. #pragma comment(lib, "d3dcompiler.lib")
  52. #pragma comment(lib, "windowscodecs.lib")
  53. #pragma comment(lib, "dxguid.lib")
  54. #pragma comment(lib, "version.lib")
  55. // A more recent Windows SDK than currently required is needed for these.
  56. typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)(
  57. UINT NumFeatures,
  58. __in_ecount(NumFeatures) const IID* pIIDs,
  59. __in_ecount_opt(NumFeatures) void* pConfigurationStructs,
  60. __in_ecount_opt(NumFeatures) UINT* pConfigurationStructSizes);
  61. static const GUID D3D12ExperimentalShaderModelsID = { /* 76f5573e-f13a-40f5-b297-81ce9e18933f */
  62. 0x76f5573e,
  63. 0xf13a,
  64. 0x40f5,
  65. { 0xb2, 0x97, 0x81, 0xce, 0x9e, 0x18, 0x93, 0x3f }
  66. };
  67. using namespace DirectX;
  68. using namespace hlsl_test;
  69. template <typename TSequence, typename T>
  70. static bool contains(TSequence s, const T &val) {
  71. return std::cend(s) != std::find(std::cbegin(s), std::cend(s), val);
  72. }
  73. template <typename InputIterator, typename T>
  74. static bool contains(InputIterator b, InputIterator e, const T &val) {
  75. return e != std::find(b, e, val);
  76. }
  77. static HRESULT EnableExperimentalShaderModels() {
  78. HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
  79. if (hRuntime == NULL) {
  80. return HRESULT_FROM_WIN32(GetLastError());
  81. }
  82. D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
  83. (D3D12EnableExperimentalFeaturesFn)GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures");
  84. if (pD3D12EnableExperimentalFeatures == nullptr) {
  85. FreeLibrary(hRuntime);
  86. return HRESULT_FROM_WIN32(GetLastError());
  87. }
  88. HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
  89. FreeLibrary(hRuntime);
  90. return hr;
  91. }
  92. static HRESULT ReportLiveObjects() {
  93. CComPtr<IDXGIDebug1> pDebug;
  94. IFR(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)));
  95. IFR(pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL));
  96. return S_OK;
  97. }
  98. static void WriteInfoQueueMessages(void *pStrCtx, st::OutputStringFn pOutputStrFn, ID3D12InfoQueue *pInfoQueue) {
  99. bool allMessagesOK = true;
  100. UINT64 count = pInfoQueue->GetNumStoredMessages();
  101. CAtlArray<BYTE> message;
  102. for (UINT64 i = 0; i < count; ++i) {
  103. // 'GetMessageA' rather than 'GetMessage' is an artifact of user32 headers.
  104. SIZE_T msgLen = 0;
  105. if (FAILED(pInfoQueue->GetMessageA(i, nullptr, &msgLen))) {
  106. allMessagesOK = false;
  107. continue;
  108. }
  109. if (message.GetCount() < msgLen) {
  110. if (!message.SetCount(msgLen)) {
  111. allMessagesOK = false;
  112. continue;
  113. }
  114. }
  115. D3D12_MESSAGE *pMessage = (D3D12_MESSAGE *)message.GetData();
  116. if (FAILED(pInfoQueue->GetMessageA(i, pMessage, &msgLen))) {
  117. allMessagesOK = false;
  118. continue;
  119. }
  120. CA2W msgW(pMessage->pDescription, CP_ACP);
  121. pOutputStrFn(pStrCtx, msgW.m_psz);
  122. pOutputStrFn(pStrCtx, L"\r\n");
  123. }
  124. if (!allMessagesOK) {
  125. pOutputStrFn(pStrCtx, L"Failed to retrieve some messages.\r\n");
  126. }
  127. }
  128. class CComContext {
  129. private:
  130. bool m_init;
  131. public:
  132. CComContext() : m_init(false) {}
  133. ~CComContext() { Dispose(); }
  134. void Dispose() { if (!m_init) return; m_init = false; CoUninitialize(); }
  135. HRESULT Init() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { m_init = true; } return hr; }
  136. };
  137. static void SavePixelsToFile(LPCVOID pPixels, DXGI_FORMAT format, UINT32 m_width, UINT32 m_height, LPCWSTR pFileName) {
  138. CComContext ctx;
  139. CComPtr<IWICImagingFactory> pFactory;
  140. CComPtr<IWICBitmap> pBitmap;
  141. CComPtr<IWICBitmapEncoder> pEncoder;
  142. CComPtr<IWICBitmapFrameEncode> pFrameEncode;
  143. CComPtr<hlsl::AbstractMemoryStream> pStream;
  144. CComPtr<IMalloc> pMalloc;
  145. struct PF {
  146. DXGI_FORMAT Format;
  147. GUID PixelFormat;
  148. UINT32 PixelSize;
  149. bool operator==(DXGI_FORMAT F) const {
  150. return F == Format;
  151. }
  152. } Vals[] = {
  153. // Add more pixel format mappings as needed.
  154. { DXGI_FORMAT_R8G8B8A8_UNORM, GUID_WICPixelFormat32bppRGBA, 4 }
  155. };
  156. PF *pFormat = std::find(Vals, Vals + _countof(Vals), format);
  157. VERIFY_SUCCEEDED(ctx.Init());
  158. VERIFY_SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory));
  159. VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
  160. VERIFY_SUCCEEDED(hlsl::CreateMemoryStream(pMalloc, &pStream));
  161. VERIFY_ARE_NOT_EQUAL(pFormat, Vals + _countof(Vals));
  162. VERIFY_SUCCEEDED(pFactory->CreateBitmapFromMemory(m_width, m_height, pFormat->PixelFormat, m_width * pFormat->PixelSize, m_width * m_height * pFormat->PixelSize, (BYTE *)pPixels, &pBitmap));
  163. VERIFY_SUCCEEDED(pFactory->CreateEncoder(GUID_ContainerFormatBmp, nullptr, &pEncoder));
  164. VERIFY_SUCCEEDED(pEncoder->Initialize(pStream, WICBitmapEncoderNoCache));
  165. VERIFY_SUCCEEDED(pEncoder->CreateNewFrame(&pFrameEncode, nullptr));
  166. VERIFY_SUCCEEDED(pFrameEncode->Initialize(nullptr));
  167. VERIFY_SUCCEEDED(pFrameEncode->WriteSource(pBitmap, nullptr));
  168. VERIFY_SUCCEEDED(pFrameEncode->Commit());
  169. VERIFY_SUCCEEDED(pEncoder->Commit());
  170. hlsl::WriteBinaryFile(pFileName, pStream->GetPtr(), pStream->GetPtrSize());
  171. }
  172. // Checks if the given warp version supports the given operation.
  173. bool IsValidWarpDllVersion(unsigned int minBuildNumber) {
  174. HMODULE pLibrary = LoadLibrary("D3D10Warp.dll");
  175. if (pLibrary) {
  176. char path[MAX_PATH];
  177. DWORD length = GetModuleFileName(pLibrary, path, MAX_PATH);
  178. if (length) {
  179. DWORD dwVerHnd = 0;
  180. DWORD dwVersionInfoSize = GetFileVersionInfoSize(path, &dwVerHnd);
  181. std::unique_ptr<int[]> VffInfo(new int[dwVersionInfoSize]);
  182. if (GetFileVersionInfo(path, NULL, dwVersionInfoSize, VffInfo.get())) {
  183. LPVOID versionInfo;
  184. UINT size;
  185. if (VerQueryValue(VffInfo.get(), "\\", &versionInfo, &size)) {
  186. if (size) {
  187. VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)versionInfo;
  188. unsigned int warpBuildNumber = verInfo->dwFileVersionLS >> 16 & 0xffff;
  189. if (verInfo->dwSignature == 0xFEEF04BD && warpBuildNumber >= minBuildNumber) {
  190. return true;
  191. }
  192. }
  193. }
  194. }
  195. }
  196. FreeLibrary(pLibrary);
  197. }
  198. return false;
  199. }
  200. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS2
  201. #define D3D12_FEATURE_D3D12_OPTIONS3 ((D3D12_FEATURE)21)
  202. #define NTDDI_WIN10_RS3 0x0A000004 /* ABRACADABRA_WIN10_RS2 */
  203. typedef
  204. enum D3D12_COMMAND_LIST_SUPPORT_FLAGS
  205. {
  206. D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0,
  207. D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT = (1 << D3D12_COMMAND_LIST_TYPE_DIRECT),
  208. D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE = (1 << D3D12_COMMAND_LIST_TYPE_BUNDLE),
  209. D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE = (1 << D3D12_COMMAND_LIST_TYPE_COMPUTE),
  210. D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY = (1 << D3D12_COMMAND_LIST_TYPE_COPY),
  211. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE = (1 << 4),
  212. D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS = (1 << 5)
  213. } D3D12_COMMAND_LIST_SUPPORT_FLAGS;
  214. typedef
  215. enum D3D12_VIEW_INSTANCING_TIER
  216. {
  217. D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0,
  218. D3D12_VIEW_INSTANCING_TIER_1 = 1,
  219. D3D12_VIEW_INSTANCING_TIER_2 = 2,
  220. D3D12_VIEW_INSTANCING_TIER_3 = 3
  221. } D3D12_VIEW_INSTANCING_TIER;
  222. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS3
  223. {
  224. _Out_ BOOL CopyQueueTimestampQueriesSupported;
  225. _Out_ BOOL CastingFullyTypedFormatSupported;
  226. _Out_ DWORD WriteBufferImmediateSupportFlags;
  227. _Out_ D3D12_VIEW_INSTANCING_TIER ViewInstancingTier;
  228. _Out_ BOOL BarycentricsSupported;
  229. } D3D12_FEATURE_DATA_D3D12_OPTIONS3;
  230. #endif
  231. #if WDK_NTDDI_VERSION <= NTDDI_WIN10_RS3
  232. #define D3D12_FEATURE_D3D12_OPTIONS4 ((D3D12_FEATURE)23)
  233. typedef enum D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER
  234. {
  235. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_0,
  236. D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1,
  237. } D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER;
  238. typedef struct D3D12_FEATURE_DATA_D3D12_OPTIONS4
  239. {
  240. _Out_ BOOL ReservedBufferPlacementSupported;
  241. _Out_ D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER SharedResourceCompatibilityTier;
  242. _Out_ BOOL Native16BitShaderOpsSupported;
  243. } D3D12_FEATURE_DATA_D3D12_OPTIONS4;
  244. #endif
  245. // Virtual class to compute the expected result given a set of inputs
  246. struct TableParameter;
  247. class ExecutionTest {
  248. public:
  249. // By default, ignore these tests, which require a recent build to run properly.
  250. BEGIN_TEST_CLASS(ExecutionTest)
  251. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  252. TEST_CLASS_PROPERTY(L"Ignore", L"true")
  253. TEST_METHOD_PROPERTY(L"Priority", L"0")
  254. END_TEST_CLASS()
  255. TEST_CLASS_SETUP(ExecutionTestClassSetup)
  256. TEST_METHOD(BasicComputeTest);
  257. TEST_METHOD(BasicTriangleTest);
  258. TEST_METHOD(BasicTriangleOpTest);
  259. TEST_METHOD(BasicTriangleOpTestHalf);
  260. TEST_METHOD(OutOfBoundsTest);
  261. TEST_METHOD(SaturateTest);
  262. TEST_METHOD(SignTest);
  263. TEST_METHOD(Int64Test);
  264. TEST_METHOD(LifetimeIntrinsicTest)
  265. TEST_METHOD(WaveIntrinsicsTest);
  266. TEST_METHOD(WaveIntrinsicsDDITest);
  267. TEST_METHOD(WaveIntrinsicsInPSTest);
  268. TEST_METHOD(WaveSizeTest);
  269. TEST_METHOD(PartialDerivTest);
  270. TEST_METHOD(DerivativesTest);
  271. TEST_METHOD(ComputeSampleTest);
  272. TEST_METHOD(AtomicsTest);
  273. TEST_METHOD(Atomics64Test);
  274. TEST_METHOD(AtomicsTyped64Test);
  275. TEST_METHOD(AtomicsShared64Test);
  276. TEST_METHOD(AtomicsFloatTest);
  277. TEST_METHOD(HelperLaneTest);
  278. BEGIN_TEST_METHOD(HelperLaneTestWave)
  279. TEST_METHOD_PROPERTY(L"Priority", L"2") // Remove this line once warp handles this
  280. END_TEST_METHOD()
  281. TEST_METHOD(SignatureResourcesTest)
  282. TEST_METHOD(DynamicResourcesTest)
  283. TEST_METHOD(QuadReadTest)
  284. TEST_METHOD(CBufferTestHalf);
  285. TEST_METHOD(BasicShaderModel61);
  286. TEST_METHOD(BasicShaderModel63);
  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. END_TEST_METHOD()
  318. BEGIN_TEST_METHOD(BinaryHalfOpTest)
  319. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryHalfOpTable")
  320. END_TEST_METHOD()
  321. BEGIN_TEST_METHOD(TertiaryHalfOpTest)
  322. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryHalfOpTable")
  323. END_TEST_METHOD()
  324. BEGIN_TEST_METHOD(UnaryIntOpTest)
  325. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
  326. END_TEST_METHOD()
  327. BEGIN_TEST_METHOD(BinaryIntOpTest)
  328. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
  329. END_TEST_METHOD()
  330. BEGIN_TEST_METHOD(TertiaryIntOpTest)
  331. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
  332. END_TEST_METHOD()
  333. BEGIN_TEST_METHOD(UnaryUintOpTest)
  334. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
  335. END_TEST_METHOD()
  336. BEGIN_TEST_METHOD(BinaryUintOpTest)
  337. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
  338. END_TEST_METHOD()
  339. BEGIN_TEST_METHOD(TertiaryUintOpTest)
  340. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
  341. END_TEST_METHOD()
  342. BEGIN_TEST_METHOD(UnaryInt16OpTest)
  343. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryInt16OpTable")
  344. END_TEST_METHOD()
  345. BEGIN_TEST_METHOD(BinaryInt16OpTest)
  346. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryInt16OpTable")
  347. END_TEST_METHOD()
  348. BEGIN_TEST_METHOD(TertiaryInt16OpTest)
  349. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryInt16OpTable")
  350. END_TEST_METHOD()
  351. BEGIN_TEST_METHOD(UnaryUint16OpTest)
  352. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUint16OpTable")
  353. END_TEST_METHOD()
  354. BEGIN_TEST_METHOD(BinaryUint16OpTest)
  355. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUint16OpTable")
  356. END_TEST_METHOD()
  357. BEGIN_TEST_METHOD(TertiaryUint16OpTest)
  358. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUint16OpTable")
  359. END_TEST_METHOD()
  360. BEGIN_TEST_METHOD(DotTest)
  361. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
  362. END_TEST_METHOD()
  363. BEGIN_TEST_METHOD(Dot2AddHalfTest)
  364. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot2AddHalfOpTable")
  365. END_TEST_METHOD()
  366. BEGIN_TEST_METHOD(Dot4AddI8PackedTest)
  367. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddI8PackedOpTable")
  368. END_TEST_METHOD()
  369. BEGIN_TEST_METHOD(Dot4AddU8PackedTest)
  370. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Dot4AddU8PackedOpTable")
  371. END_TEST_METHOD()
  372. BEGIN_TEST_METHOD(Msad4Test)
  373. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
  374. END_TEST_METHOD()
  375. BEGIN_TEST_METHOD(DenormBinaryFloatOpTest)
  376. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormBinaryFloatOpTable")
  377. END_TEST_METHOD()
  378. BEGIN_TEST_METHOD(DenormTertiaryFloatOpTest)
  379. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DenormTertiaryFloatOpTable")
  380. END_TEST_METHOD()
  381. TEST_METHOD(BarycentricsTest);
  382. TEST_METHOD(ComputeRawBufferLdStI32);
  383. TEST_METHOD(ComputeRawBufferLdStFloat);
  384. TEST_METHOD(ComputeRawBufferLdStI64);
  385. TEST_METHOD(ComputeRawBufferLdStDouble);
  386. TEST_METHOD(ComputeRawBufferLdStI16);
  387. TEST_METHOD(ComputeRawBufferLdStHalf);
  388. TEST_METHOD(GraphicsRawBufferLdStI32);
  389. TEST_METHOD(GraphicsRawBufferLdStFloat);
  390. TEST_METHOD(GraphicsRawBufferLdStI64);
  391. TEST_METHOD(GraphicsRawBufferLdStDouble);
  392. TEST_METHOD(GraphicsRawBufferLdStI16);
  393. TEST_METHOD(GraphicsRawBufferLdStHalf);
  394. BEGIN_TEST_METHOD(PackUnpackTest)
  395. TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#PackUnpackOpTable")
  396. END_TEST_METHOD()
  397. dxc::DxcDllSupport m_support;
  398. VersionSupportInfo m_ver;
  399. bool m_ExperimentalModeEnabled = false;
  400. const float ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
  401. // Do not remove the following line - it is used by TranslateExecutionTest.py
  402. // MARKER: ExecutionTest/DxilConf Shared Implementation Start
  403. // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
  404. // require the Windows 10 SDK.
  405. typedef enum D3D_SHADER_MODEL {
  406. D3D_SHADER_MODEL_5_1 = 0x51,
  407. D3D_SHADER_MODEL_6_0 = 0x60,
  408. D3D_SHADER_MODEL_6_1 = 0x61,
  409. D3D_SHADER_MODEL_6_2 = 0x62,
  410. D3D_SHADER_MODEL_6_3 = 0x63,
  411. D3D_SHADER_MODEL_6_4 = 0x64,
  412. D3D_SHADER_MODEL_6_5 = 0x65,
  413. D3D_SHADER_MODEL_6_6 = 0x66,
  414. } D3D_SHADER_MODEL;
  415. #if WDK_NTDDI_VERSION == NTDDI_WIN10_RS2
  416. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_0;
  417. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS3
  418. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_1;
  419. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS4
  420. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_2;
  421. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_RS5
  422. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_3;
  423. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_19H1
  424. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_4;
  425. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_VB
  426. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  427. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_MN
  428. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_5;
  429. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_FE
  430. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  431. #elif WDK_NTDDI_VERSION == NTDDI_WIN10_CO
  432. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  433. #else
  434. static const D3D_SHADER_MODEL HIGHEST_SHADER_MODEL = D3D_SHADER_MODEL_6_6;
  435. #endif
  436. bool UseDxbc() {
  437. #ifdef _HLK_CONF
  438. return false;
  439. #else
  440. return GetTestParamBool(L"DXBC");
  441. #endif
  442. }
  443. bool UseWarpByDefault() {
  444. #ifdef _HLK_CONF
  445. return false;
  446. #else
  447. return true;
  448. #endif
  449. }
  450. bool UseDebugIfaces() {
  451. return true;
  452. }
  453. bool SaveImages() {
  454. return GetTestParamBool(L"SaveImages");
  455. }
  456. void RunResourceTest(ID3D12Device *pDevice, const char *pShader, const wchar_t *sm, bool isDynamic);
  457. template <class T1, class T2>
  458. void WaveIntrinsicsActivePrefixTest(TableParameter *pParameterList,
  459. size_t numParameter, bool isPrefix);
  460. template <typename T>
  461. void WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  462. size_t numParameters);
  463. void BasicTriangleTestSetup(LPCSTR OpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel);
  464. void RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel);
  465. enum class RawBufferLdStType {
  466. I32,
  467. Float,
  468. I64,
  469. Double,
  470. I16,
  471. Half
  472. };
  473. template <class Ty>
  474. struct RawBufferLdStTestData {
  475. Ty v1, v2[2], v3[3], v4[4];
  476. };
  477. template <class Ty>
  478. struct RawBufferLdStUavData {
  479. RawBufferLdStTestData<Ty> input, output, srvOut;
  480. };
  481. template <class Ty>
  482. void RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  483. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  484. template <class Ty>
  485. void RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  486. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData);
  487. template <class Ty>
  488. void VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData);
  489. bool SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType, CComPtr<ID3D12Device> &pDevice,
  490. CComPtr<IStream> &pStream, char *&sTy, char *&additionalOptions);
  491. template <class Ty>
  492. void RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader, Ty *pInputDataPairs, unsigned inputDataCount);
  493. template <class Ty>
  494. const wchar_t* BasicShaderModelTest_GetFormatString();
  495. void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  496. VERIFY_SUCCEEDED(m_support.Initialize());
  497. CComPtr<IDxcCompiler> pCompiler;
  498. CComPtr<IDxcLibrary> pLibrary;
  499. CComPtr<IDxcBlobEncoding> pTextBlob;
  500. CComPtr<IDxcOperationResult> pResult;
  501. HRESULT resultCode;
  502. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  503. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  504. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned(pText, (UINT32)strlen(pText), CP_UTF8, &pTextBlob));
  505. VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, pOptions, numOptions, nullptr, 0, nullptr, &pResult));
  506. VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
  507. if (FAILED(resultCode)) {
  508. CComPtr<IDxcBlobEncoding> errors;
  509. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
  510. #ifndef _HLK_CONF
  511. LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
  512. #endif
  513. }
  514. VERIFY_SUCCEEDED(resultCode);
  515. VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
  516. }
  517. void CreateCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue, D3D12_COMMAND_LIST_TYPE type) {
  518. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  519. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  520. queueDesc.Type = type;
  521. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  522. VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
  523. }
  524. void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
  525. CreateCommandQueue(pDevice, pName, ppCommandQueue, D3D12_COMMAND_LIST_TYPE_COMPUTE);
  526. }
  527. void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, LPCWSTR pTargetProfile, ID3D12PipelineState **ppComputeState, LPCWSTR *pOptions = nullptr, int numOptions = 0) {
  528. CComPtr<ID3DBlob> pComputeShader;
  529. // Load and compile shaders.
  530. if (UseDxbc()) {
  531. #ifndef _HLK_CONF
  532. DXBCFromText(pShader, L"main", pTargetProfile, &pComputeShader);
  533. #endif
  534. }
  535. else {
  536. CompileFromText(pShader, L"main", pTargetProfile, &pComputeShader, pOptions, numOptions);
  537. }
  538. // Describe and create the compute pipeline state object (PSO).
  539. D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
  540. computePsoDesc.pRootSignature = pRootSignature;
  541. computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
  542. VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
  543. }
  544. bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice,
  545. D3D_SHADER_MODEL testModel = D3D_SHADER_MODEL_6_0, bool skipUnsupported = true,
  546. bool enableRayTracing = false) {
  547. if (testModel > HIGHEST_SHADER_MODEL) {
  548. UINT minor = (UINT)testModel & 0x0f;
  549. LogCommentFmt(L"Installed SDK does not support "
  550. L"shader model 6.%1u", minor);
  551. if (skipUnsupported) {
  552. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  553. }
  554. return false;
  555. }
  556. const D3D_FEATURE_LEVEL FeatureLevelRequired = enableRayTracing ? D3D_FEATURE_LEVEL_12_0 : D3D_FEATURE_LEVEL_11_0;
  557. CComPtr<IDXGIFactory4> factory;
  558. CComPtr<ID3D12Device> pDevice;
  559. *ppDevice = nullptr;
  560. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  561. if (GetTestParamUseWARP(UseWarpByDefault())) {
  562. CComPtr<IDXGIAdapter> warpAdapter;
  563. VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
  564. HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
  565. IID_PPV_ARGS(&pDevice));
  566. if (FAILED(createHR)) {
  567. LogCommentFmt(L"The available version of WARP does not support d3d12.");
  568. if (skipUnsupported) {
  569. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  570. }
  571. return false;
  572. }
  573. } else {
  574. CComPtr<IDXGIAdapter1> hardwareAdapter;
  575. WEX::Common::String AdapterValue;
  576. HRESULT hr = WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
  577. AdapterValue);
  578. if (SUCCEEDED(hr)) {
  579. GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
  580. } else {
  581. WEX::Logging::Log::Comment(
  582. L"Using default hardware adapter with D3D12 support.");
  583. }
  584. VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
  585. IID_PPV_ARGS(&pDevice)));
  586. }
  587. // retrieve adapter information
  588. LUID adapterID = pDevice->GetAdapterLuid();
  589. CComPtr<IDXGIAdapter> adapter;
  590. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  591. DXGI_ADAPTER_DESC AdapterDesc;
  592. VERIFY_SUCCEEDED(adapter->GetDesc(&AdapterDesc));
  593. LogCommentFmt(L"Using Adapter:%s", AdapterDesc.Description);
  594. if (pDevice == nullptr)
  595. return false;
  596. if (!UseDxbc()) {
  597. // Check for DXIL support.
  598. typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
  599. _Inout_ D3D_SHADER_MODEL HighestShaderModel;
  600. } D3D12_FEATURE_DATA_SHADER_MODEL;
  601. const UINT D3D12_FEATURE_SHADER_MODEL = 7;
  602. D3D12_FEATURE_DATA_SHADER_MODEL SMData;
  603. SMData.HighestShaderModel = testModel;
  604. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
  605. (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
  606. if (SMData.HighestShaderModel < testModel) {
  607. UINT minor = (UINT)testModel & 0x0f;
  608. LogCommentFmt(L"The selected device does not support "
  609. L"shader model 6.%1u", minor);
  610. if (skipUnsupported) {
  611. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  612. }
  613. return false;
  614. }
  615. }
  616. if (UseDebugIfaces()) {
  617. CComPtr<ID3D12InfoQueue> pInfoQueue;
  618. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  619. pInfoQueue->SetMuteDebugOutput(FALSE);
  620. }
  621. }
  622. *ppDevice = pDevice.Detach();
  623. return true;
  624. }
  625. void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
  626. D3D12_COMMAND_QUEUE_DESC queueDesc = {};
  627. queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  628. queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
  629. VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
  630. }
  631. void CreateGraphicsCommandQueueAndList(
  632. ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
  633. ID3D12CommandAllocator **ppAllocator,
  634. ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
  635. CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
  636. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
  637. D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
  638. VERIFY_SUCCEEDED(pDevice->CreateCommandList(
  639. 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
  640. IID_PPV_ARGS(ppCommandList)));
  641. }
  642. void CreateGraphicsPSO(ID3D12Device *pDevice,
  643. D3D12_INPUT_LAYOUT_DESC *pInputLayout,
  644. ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
  645. ID3D12PipelineState **ppPSO) {
  646. CComPtr<ID3DBlob> vertexShader;
  647. CComPtr<ID3DBlob> pixelShader;
  648. if (UseDxbc()) {
  649. #ifndef _HLK_CONF
  650. DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  651. DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  652. #endif
  653. } else {
  654. CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
  655. CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
  656. }
  657. // Describe and create the graphics pipeline state object (PSO).
  658. D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
  659. psoDesc.InputLayout = *pInputLayout;
  660. psoDesc.pRootSignature = pRootSignature;
  661. psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
  662. psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
  663. psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
  664. psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
  665. psoDesc.DepthStencilState.DepthEnable = FALSE;
  666. psoDesc.DepthStencilState.StencilEnable = FALSE;
  667. psoDesc.SampleMask = UINT_MAX;
  668. psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
  669. psoDesc.NumRenderTargets = 1;
  670. psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
  671. psoDesc.SampleDesc.Count = 1;
  672. VERIFY_SUCCEEDED(
  673. pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
  674. }
  675. void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
  676. ID3D12DescriptorHeap *pHeap, UINT width,
  677. UINT height,
  678. ID3D12Resource **ppRenderTarget,
  679. ID3D12Resource **ppBuffer) {
  680. const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
  681. const size_t formatElementSize = 4;
  682. CComPtr<ID3D12Resource> pRenderTarget;
  683. CComPtr<ID3D12Resource> pBuffer;
  684. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
  685. pHeap->GetCPUDescriptorHandleForHeapStart());
  686. CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
  687. CD3DX12_RESOURCE_DESC rtDesc(
  688. CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
  689. CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
  690. rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
  691. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  692. &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
  693. &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
  694. pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
  695. // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
  696. // resource.
  697. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  698. CD3DX12_RESOURCE_DESC readDesc(
  699. CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
  700. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  701. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  702. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
  703. *ppRenderTarget = pRenderTarget.Detach();
  704. *ppBuffer = pBuffer.Detach();
  705. }
  706. void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
  707. const D3D12_ROOT_SIGNATURE_DESC *pDesc,
  708. ID3D12RootSignature **pRootSig) {
  709. CComPtr<ID3DBlob> signature;
  710. CComPtr<ID3DBlob> error;
  711. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  712. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
  713. 0, signature->GetBufferPointer(), signature->GetBufferSize(),
  714. IID_PPV_ARGS(pRootSig)));
  715. }
  716. void CreateRootSignatureFromRanges(ID3D12Device *pDevice, ID3D12RootSignature **pRootSig,
  717. CD3DX12_DESCRIPTOR_RANGE *resRanges, UINT resCt,
  718. CD3DX12_DESCRIPTOR_RANGE *sampRanges = nullptr, UINT sampCt = 0,
  719. D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
  720. CD3DX12_ROOT_PARAMETER rootParameters[2];
  721. rootParameters[0].InitAsDescriptorTable(resCt, resRanges, D3D12_SHADER_VISIBILITY_ALL);
  722. rootParameters[1].InitAsDescriptorTable(sampCt, sampRanges, D3D12_SHADER_VISIBILITY_ALL);
  723. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  724. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, flags);
  725. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, pRootSig);
  726. }
  727. void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
  728. ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
  729. D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
  730. rtvHeapDesc.NumDescriptors = numDescriptors;
  731. rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  732. rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  733. VERIFY_SUCCEEDED(
  734. pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
  735. if (rtvDescriptorSize != nullptr) {
  736. *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
  737. D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  738. }
  739. }
  740. void CreateTestResources(ID3D12Device *pDevice,
  741. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  742. UINT32 valueSizeInBytes, D3D12_RESOURCE_DESC resDesc,
  743. ID3D12Resource **ppResource,
  744. ID3D12Resource **ppUploadResource,
  745. ID3D12Resource **ppReadBuffer = nullptr) {
  746. CComPtr<ID3D12Resource> pResource;
  747. CComPtr<ID3D12Resource> pReadBuffer;
  748. CComPtr<ID3D12Resource> pUploadResource;
  749. D3D12_SUBRESOURCE_DATA transferData;
  750. D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
  751. D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
  752. D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  753. CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
  754. CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
  755. pDevice->GetCopyableFootprints(&resDesc, 0, 1/*mipleveles*/, 0, nullptr, nullptr, nullptr, &uploadBufferDesc.Width);
  756. uploadBufferDesc.Height = 1;
  757. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  758. &defaultHeapProperties,
  759. D3D12_HEAP_FLAG_NONE,
  760. &resDesc,
  761. D3D12_RESOURCE_STATE_COPY_DEST,
  762. nullptr,
  763. IID_PPV_ARGS(&pResource)));
  764. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  765. &uploadHeapProperties,
  766. D3D12_HEAP_FLAG_NONE,
  767. &uploadBufferDesc,
  768. D3D12_RESOURCE_STATE_GENERIC_READ,
  769. nullptr,
  770. IID_PPV_ARGS(&pUploadResource)));
  771. if (ppReadBuffer)
  772. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  773. &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
  774. D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
  775. transferData.pData = values;
  776. transferData.RowPitch = valueSizeInBytes/resDesc.Height;
  777. transferData.SlicePitch = valueSizeInBytes;
  778. UpdateSubresources<1>(pCommandList, pResource.p, pUploadResource.p, 0, 0, 1, &transferData);
  779. if (resDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS)
  780. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
  781. else
  782. RecordTransitionBarrier(pCommandList, pResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
  783. *ppResource = pResource.Detach();
  784. *ppUploadResource = pUploadResource.Detach();
  785. if (ppReadBuffer)
  786. *ppReadBuffer = pReadBuffer.Detach();
  787. }
  788. void CreateTestUavs(ID3D12Device *pDevice,
  789. ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
  790. UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
  791. ID3D12Resource **ppUploadResource = nullptr,
  792. ID3D12Resource **ppReadBuffer = nullptr) {
  793. D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  794. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufferDesc,
  795. ppUavResource, ppUploadResource, ppReadBuffer);
  796. }
  797. // Create and return descriptor heaps for the given device
  798. // with the given number of resources and samples.
  799. // using some reasonable defaults
  800. void CreateDefaultDescHeaps(ID3D12Device *pDevice,
  801. int NumResources, int NumSamplers,
  802. ID3D12DescriptorHeap **ppResHeap, ID3D12DescriptorHeap **ppSampHeap) {
  803. // Describe and create descriptor heaps.
  804. ID3D12DescriptorHeap *pResHeap, *pSampHeap;
  805. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  806. heapDesc.NumDescriptors = NumResources;
  807. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  808. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  809. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pResHeap)));
  810. heapDesc.NumDescriptors = NumSamplers;
  811. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
  812. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pSampHeap)));
  813. *ppResHeap = pResHeap;
  814. *ppSampHeap = pSampHeap;
  815. }
  816. void CreateSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  817. DXGI_FORMAT format, D3D12_SRV_DIMENSION viewDimension, UINT numElements, UINT stride,
  818. const CComPtr<ID3D12Resource> pResource) {
  819. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  820. // Create SRV
  821. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  822. srvDesc.Format = format;
  823. srvDesc.ViewDimension = viewDimension;
  824. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  825. switch (viewDimension) {
  826. case D3D12_SRV_DIMENSION_BUFFER:
  827. srvDesc.Buffer.FirstElement = 0;
  828. srvDesc.Buffer.NumElements = numElements;
  829. srvDesc.Buffer.StructureByteStride = stride;
  830. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  831. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_RAW;
  832. else
  833. srvDesc.Buffer.Flags = D3D12_BUFFER_SRV_FLAG_NONE;
  834. break;
  835. case D3D12_SRV_DIMENSION_TEXTURE1D:
  836. srvDesc.Texture1D.MostDetailedMip = 0;
  837. srvDesc.Texture1D.MipLevels = 1;
  838. srvDesc.Texture1D.ResourceMinLODClamp = 0;
  839. break;
  840. case D3D12_SRV_DIMENSION_TEXTURE2D:
  841. srvDesc.Texture2D.MostDetailedMip = 0;
  842. srvDesc.Texture2D.MipLevels = 1;
  843. srvDesc.Texture2D.PlaneSlice = 0;
  844. srvDesc.Texture2D.ResourceMinLODClamp = 0;
  845. break;
  846. }
  847. pDevice->CreateShaderResourceView(pResource, &srvDesc, baseHandle);
  848. baseHandle.Offset(descriptorSize);
  849. }
  850. void CreateRawSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  851. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  852. CreateSRV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  853. }
  854. void CreateStructSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  855. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  856. CreateSRV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_SRV_DIMENSION_BUFFER, numElements, stride, pResource);
  857. }
  858. void CreateTypedSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  859. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  860. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_BUFFER, numElements, 0, pResource);
  861. }
  862. void CreateTex1DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  863. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  864. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  865. }
  866. void CreateTex2DSRV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  867. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  868. CreateSRV(pDevice, heapStart, format, D3D12_SRV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  869. }
  870. void CreateUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &baseHandle,
  871. DXGI_FORMAT format, D3D12_UAV_DIMENSION viewDimension, UINT numElements, UINT stride,
  872. const CComPtr<ID3D12Resource> pResource) {
  873. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
  874. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  875. uavDesc.Format = format;
  876. uavDesc.ViewDimension = viewDimension;
  877. switch (viewDimension) {
  878. case D3D12_UAV_DIMENSION_BUFFER:
  879. uavDesc.Buffer.FirstElement = 0;
  880. uavDesc.Buffer.NumElements = numElements;
  881. uavDesc.Buffer.StructureByteStride = stride;
  882. if (format == DXGI_FORMAT_R32_TYPELESS && stride == 0)
  883. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  884. else
  885. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  886. break;
  887. case D3D12_UAV_DIMENSION_TEXTURE1D:
  888. uavDesc.Texture1D.MipSlice = 0;
  889. break;
  890. case D3D12_UAV_DIMENSION_TEXTURE2D:
  891. uavDesc.Texture2D.MipSlice = 0;
  892. uavDesc.Texture2D.PlaneSlice = 0;
  893. break;
  894. }
  895. pDevice->CreateUnorderedAccessView(pResource, nullptr, &uavDesc, baseHandle);
  896. baseHandle.Offset(descriptorSize);
  897. }
  898. void CreateRawUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  899. UINT numElements, const CComPtr<ID3D12Resource> pResource) {
  900. CreateUAV(pDevice, heapStart, DXGI_FORMAT_R32_TYPELESS, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  901. }
  902. void CreateStructUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  903. UINT numElements, UINT stride, const CComPtr<ID3D12Resource> pResource) {
  904. CreateUAV(pDevice, heapStart, DXGI_FORMAT_UNKNOWN, D3D12_UAV_DIMENSION_BUFFER, numElements, stride, pResource);
  905. }
  906. void CreateTypedUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  907. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  908. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_BUFFER, numElements, 0, pResource);
  909. }
  910. void CreateTex1DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  911. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  912. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE1D, numElements, 0, pResource);
  913. }
  914. void CreateTex2DUAV(ID3D12Device *pDevice, CD3DX12_CPU_DESCRIPTOR_HANDLE &heapStart,
  915. UINT numElements, DXGI_FORMAT format, const CComPtr<ID3D12Resource> pResource) {
  916. CreateUAV(pDevice, heapStart, format, D3D12_UAV_DIMENSION_TEXTURE2D, numElements, 0, pResource);
  917. }
  918. // Create Samplers for <pDevice> given the filter and border color information provided
  919. // using some reasonable defaults
  920. void CreateDefaultSamplers(ID3D12Device *pDevice, D3D12_CPU_DESCRIPTOR_HANDLE heapStart,
  921. D3D12_FILTER filters[], float BorderColors[], int NumSamplers) {
  922. CD3DX12_CPU_DESCRIPTOR_HANDLE sampHandle(heapStart);
  923. UINT descriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
  924. D3D12_SAMPLER_DESC sampDesc = {};
  925. sampDesc.Filter = D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  926. sampDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  927. sampDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  928. sampDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER;
  929. sampDesc.MipLODBias = 0;
  930. sampDesc.MaxAnisotropy = 1;
  931. sampDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_EQUAL;
  932. sampDesc.MinLOD = 0;
  933. sampDesc.MaxLOD = 0;
  934. for (int i = 0; i < NumSamplers; i++) {
  935. sampDesc.Filter = filters[i];
  936. for (int j = 0; j < 4; j++)
  937. sampDesc.BorderColor[j] = BorderColors[i];
  938. pDevice->CreateSampler(&sampDesc, sampHandle);
  939. sampHandle = sampHandle.Offset(descriptorSize);
  940. }
  941. }
  942. template <typename TVertex, int len>
  943. void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
  944. ID3D12Resource **ppVertexBuffer,
  945. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
  946. size_t vertexBufferSize = sizeof(vertices);
  947. CComPtr<ID3D12Resource> pVertexBuffer;
  948. CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
  949. CD3DX12_RESOURCE_DESC bufferDesc(
  950. CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
  951. VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
  952. &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
  953. D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
  954. IID_PPV_ARGS(&pVertexBuffer)));
  955. UINT8 *pVertexDataBegin;
  956. CD3DX12_RANGE readRange(0, 0);
  957. VERIFY_SUCCEEDED(pVertexBuffer->Map(
  958. 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
  959. memcpy(pVertexDataBegin, vertices, vertexBufferSize);
  960. pVertexBuffer->Unmap(0, nullptr);
  961. // Initialize the vertex buffer view.
  962. pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
  963. pVertexBufferView->StrideInBytes = sizeof(TVertex);
  964. pVertexBufferView->SizeInBytes = (UINT)vertexBufferSize;
  965. *ppVertexBuffer = pVertexBuffer.Detach();
  966. }
  967. // Requires Anniversary Edition headers, so simplifying things for current setup.
  968. const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
  969. struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
  970. BOOL WaveOps;
  971. UINT WaveLaneCountMin;
  972. UINT WaveLaneCountMax;
  973. UINT TotalLaneCount;
  974. BOOL ExpandedComputeResourceStates;
  975. BOOL Int64ShaderOps;
  976. };
  977. bool IsDeviceBasicAdapter(ID3D12Device *pDevice) {
  978. CComPtr<IDXGIFactory4> factory;
  979. VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
  980. LUID adapterID = pDevice->GetAdapterLuid();
  981. CComPtr<IDXGIAdapter1> adapter;
  982. factory->EnumAdapterByLuid(adapterID, IID_PPV_ARGS(&adapter));
  983. DXGI_ADAPTER_DESC1 AdapterDesc;
  984. VERIFY_SUCCEEDED(adapter->GetDesc1(&AdapterDesc));
  985. return (AdapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE);
  986. }
  987. bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
  988. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  989. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  990. return false;
  991. return O.Int64ShaderOps != FALSE;
  992. }
  993. bool DoesDeviceSupportDouble(ID3D12Device *pDevice) {
  994. D3D12_FEATURE_DATA_D3D12_OPTIONS O;
  995. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS, &O, sizeof(O))))
  996. return false;
  997. return O.DoublePrecisionFloatShaderOps != FALSE;
  998. }
  999. bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
  1000. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1001. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1002. return false;
  1003. return O.WaveOps != FALSE;
  1004. }
  1005. bool DoesDeviceSupportBarycentrics(ID3D12Device *pDevice) {
  1006. D3D12_FEATURE_DATA_D3D12_OPTIONS3 O;
  1007. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS3, &O, sizeof(O))))
  1008. return false;
  1009. return O.BarycentricsSupported != FALSE;
  1010. }
  1011. bool DoesDeviceSupportNative16bitOps(ID3D12Device *pDevice) {
  1012. D3D12_FEATURE_DATA_D3D12_OPTIONS4 O;
  1013. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS4, &O, sizeof(O))))
  1014. return false;
  1015. return O.Native16BitShaderOpsSupported != FALSE;
  1016. }
  1017. bool DoesDeviceSupportMeshShaders(ID3D12Device *pDevice) {
  1018. #if defined(NTDDI_WIN10_VB) && WDK_NTDDI_VERSION >= NTDDI_WIN10_VB
  1019. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1020. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))))
  1021. return false;
  1022. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
  1023. #else
  1024. UNREFERENCED_PARAMETER(pDevice);
  1025. return false;
  1026. #endif
  1027. }
  1028. bool DoesDeviceSupportRayTracing(ID3D12Device *pDevice) {
  1029. #if WDK_NTDDI_VERSION > NTDDI_WIN10_RS4
  1030. D3D12_FEATURE_DATA_D3D12_OPTIONS5 O5;
  1031. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS5, &O5, sizeof(O5))))
  1032. return false;
  1033. return O5.RaytracingTier != D3D12_RAYTRACING_TIER_NOT_SUPPORTED;
  1034. #else
  1035. UNREFERENCED_PARAMETER(pDevice);
  1036. return false;
  1037. #endif
  1038. }
  1039. bool DoesDeviceSupportMeshAmpDerivatives(ID3D12Device *pDevice) {
  1040. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1041. D3D12_FEATURE_DATA_D3D12_OPTIONS7 O7;
  1042. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1043. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS7, &O7, sizeof(O7))) ||
  1044. FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1045. return false;
  1046. return O7.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED &&
  1047. O9.DerivativesInMeshAndAmplificationShadersSupported != FALSE;
  1048. #else
  1049. UNREFERENCED_PARAMETER(pDevice);
  1050. return false;
  1051. #endif
  1052. }
  1053. bool DoesDeviceSupportTyped64Atomics(ID3D12Device *pDevice) {
  1054. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1055. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1056. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1057. return false;
  1058. return O9.AtomicInt64OnTypedResourceSupported != FALSE;
  1059. #else
  1060. UNREFERENCED_PARAMETER(pDevice);
  1061. return false;
  1062. #endif
  1063. }
  1064. bool DoesDeviceSupportShared64Atomics(ID3D12Device *pDevice) {
  1065. #if defined(NTDDI_WIN10_FE) && WDK_NTDDI_VERSION >= NTDDI_WIN10_FE
  1066. D3D12_FEATURE_DATA_D3D12_OPTIONS9 O9;
  1067. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS9, &O9, sizeof(O9))))
  1068. return false;
  1069. return O9.AtomicInt64OnGroupSharedSupported != FALSE;
  1070. #else
  1071. UNREFERENCED_PARAMETER(pDevice);
  1072. return false;
  1073. #endif
  1074. }
  1075. #ifndef _HLK_CONF
  1076. void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
  1077. CW2A pEntryPointA(pEntryPoint, CP_UTF8);
  1078. CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
  1079. CComPtr<ID3DBlob> pErrors;
  1080. D3D_SHADER_MACRO d3dMacro[2];
  1081. ZeroMemory(d3dMacro, sizeof(d3dMacro));
  1082. d3dMacro[0].Definition = "1";
  1083. d3dMacro[0].Name = "USING_DXBC";
  1084. HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
  1085. if (pErrors != nullptr) {
  1086. CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
  1087. LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
  1088. }
  1089. VERIFY_SUCCEEDED(hr);
  1090. }
  1091. #endif
  1092. HRESULT EnableDebugLayer() {
  1093. // The debug layer does net yet validate DXIL programs that require rewriting,
  1094. // but basic logging should work properly.
  1095. HRESULT hr = S_FALSE;
  1096. if (UseDebugIfaces()) {
  1097. CComPtr<ID3D12Debug> debugController;
  1098. hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
  1099. if (SUCCEEDED(hr)) {
  1100. debugController->EnableDebugLayer();
  1101. hr = S_OK;
  1102. }
  1103. }
  1104. return hr;
  1105. }
  1106. #ifndef _HLK_CONF
  1107. HRESULT EnableExperimentalMode() {
  1108. if (m_ExperimentalModeEnabled) {
  1109. return S_OK;
  1110. }
  1111. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1112. return S_FALSE;
  1113. }
  1114. HRESULT hr = EnableExperimentalShaderModels();
  1115. if (SUCCEEDED(hr)) {
  1116. m_ExperimentalModeEnabled = true;
  1117. }
  1118. return hr;
  1119. }
  1120. #endif
  1121. struct FenceObj {
  1122. HANDLE m_fenceEvent = NULL;
  1123. CComPtr<ID3D12Fence> m_fence;
  1124. UINT64 m_fenceValue;
  1125. ~FenceObj() {
  1126. if (m_fenceEvent) CloseHandle(m_fenceEvent);
  1127. }
  1128. };
  1129. void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
  1130. pObj->m_fenceValue = 1;
  1131. VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
  1132. IID_PPV_ARGS(&pObj->m_fence)));
  1133. // Create an event handle to use for frame synchronization.
  1134. pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
  1135. if (pObj->m_fenceEvent == nullptr) {
  1136. VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
  1137. }
  1138. }
  1139. void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
  1140. VERIFY_SUCCEEDED(m_support.Initialize());
  1141. CComPtr<IDxcLibrary> pLibrary;
  1142. CComPtr<IDxcBlobEncoding> pBlob;
  1143. CComPtr<IStream> pStream;
  1144. std::wstring path = GetPathToHlslDataFile(relativePath);
  1145. VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  1146. VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
  1147. VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
  1148. *ppStream = pStream.Detach();
  1149. }
  1150. void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
  1151. ID3D12DescriptorHeap *pRtvHeap,
  1152. UINT rtvDescriptorSize,
  1153. UINT instanceCount,
  1154. D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
  1155. ID3D12RootSignature *pRootSig,
  1156. ID3D12Resource *pRenderTarget,
  1157. ID3D12Resource *pReadBuffer) {
  1158. D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
  1159. D3D12_VIEWPORT viewport;
  1160. D3D12_RECT scissorRect;
  1161. memset(&viewport, 0, sizeof(viewport));
  1162. viewport.Height = (float)rtDesc.Height;
  1163. viewport.Width = (float)rtDesc.Width;
  1164. viewport.MaxDepth = 1.0f;
  1165. memset(&scissorRect, 0, sizeof(scissorRect));
  1166. scissorRect.right = (long)rtDesc.Width;
  1167. scissorRect.bottom = rtDesc.Height;
  1168. if (pRootSig != nullptr) {
  1169. pList->SetGraphicsRootSignature(pRootSig);
  1170. }
  1171. pList->RSSetViewports(1, &viewport);
  1172. pList->RSSetScissorRects(1, &scissorRect);
  1173. // Indicate that the buffer will be used as a render target.
  1174. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
  1175. CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
  1176. pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
  1177. pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
  1178. pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
  1179. pList->IASetVertexBuffers(0, 1, pVertexBufferView);
  1180. pList->DrawInstanced(3, instanceCount, 0, 0);
  1181. // Transition to copy source and copy into read-back buffer.
  1182. RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1183. // Copy into read-back buffer.
  1184. UINT64 rowPitch = rtDesc.Width * 4;
  1185. if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
  1186. rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
  1187. D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
  1188. Footprint.Offset = 0;
  1189. Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)rtDesc.Width, rtDesc.Height, 1, (UINT)rowPitch);
  1190. CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
  1191. CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
  1192. pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
  1193. }
  1194. void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
  1195. void RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR shader, D3D_SHADER_MODEL shaderModel, bool useLibTarget, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1196. void RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1197. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values);
  1198. void RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1199. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions);
  1200. void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
  1201. ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
  1202. pCommandList->SetDescriptorHeaps(1, pHeaps);
  1203. }
  1204. void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
  1205. ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
  1206. }
  1207. };
  1208. #define WAVE_INTRINSIC_DXBC_GUARD \
  1209. "#ifdef USING_DXBC\r\n" \
  1210. "uint WaveGetLaneIndex() { return 1; }\r\n" \
  1211. "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
  1212. "bool WaveIsFirstLane() { return true; }\r\n" \
  1213. "uint WaveGetLaneCount() { return 1; }\r\n" \
  1214. "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
  1215. "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
  1216. "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
  1217. "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
  1218. "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
  1219. "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
  1220. "uint WaveActiveSum(uint u) { return 1; }\r\n" \
  1221. "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
  1222. "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
  1223. "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
  1224. "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
  1225. "uint WaveActiveMin(uint u) { return 1; }\r\n" \
  1226. "uint WaveActiveMax(uint u) { return 1; }\r\n" \
  1227. "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
  1228. "uint WavePrefixSum(uint u) { return 1; }\r\n" \
  1229. "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
  1230. "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
  1231. "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
  1232. "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
  1233. "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
  1234. "#endif\r\n"
  1235. static void SetupComputeValuePattern(std::vector<uint32_t> &values,
  1236. size_t count) {
  1237. values.resize(count); // one element per dispatch group, in bytes
  1238. for (size_t i = 0; i < count; ++i) {
  1239. values[i] = (uint32_t)i;
  1240. }
  1241. }
  1242. bool ExecutionTest::ExecutionTestClassSetup() {
  1243. #ifdef _HLK_CONF
  1244. // TODO: Enabling the D3D driver verifier. Check out the logic in the D3DConf_12_Core test.
  1245. VERIFY_SUCCEEDED(m_support.Initialize());
  1246. m_UseWarp = hlsl_test::GetTestParamUseWARP(false);
  1247. m_EnableDebugLayer = hlsl_test::GetTestParamBool(L"DebugLayer");
  1248. if (m_EnableDebugLayer) {
  1249. EnableDebugLayer();
  1250. }
  1251. return true;
  1252. #else
  1253. HRESULT hr = EnableExperimentalMode();
  1254. if (FAILED(hr)) {
  1255. LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
  1256. }
  1257. else if (hr == S_FALSE) {
  1258. LogCommentFmt(L"Experimental mode not enabled.");
  1259. }
  1260. else {
  1261. LogCommentFmt(L"Experimental mode enabled.");
  1262. }
  1263. hr = EnableDebugLayer();
  1264. if (FAILED(hr)) {
  1265. LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
  1266. }
  1267. else {
  1268. LogCommentFmt(L"Debug layer enabled.");
  1269. }
  1270. return true;
  1271. #endif
  1272. }
  1273. void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
  1274. static const int DispatchGroupX = 1;
  1275. static const int DispatchGroupY = 1;
  1276. static const int DispatchGroupZ = 1;
  1277. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1278. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1279. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1280. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1281. UINT uavDescriptorSize;
  1282. FenceObj FO;
  1283. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1284. CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
  1285. InitFenceObj(pDevice, &FO);
  1286. // Describe and create a UAV descriptor heap.
  1287. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1288. heapDesc.NumDescriptors = 1;
  1289. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1290. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1291. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1292. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1293. // Create root signature.
  1294. CComPtr<ID3D12RootSignature> pRootSignature;
  1295. {
  1296. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1297. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1298. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1299. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1300. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1301. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1302. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1303. }
  1304. // Create pipeline state object.
  1305. CComPtr<ID3D12PipelineState> pComputeState;
  1306. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1307. // Create a command allocator and list for compute.
  1308. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1309. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1310. pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
  1311. // Set up UAV resource.
  1312. CComPtr<ID3D12Resource> pUavResource;
  1313. CComPtr<ID3D12Resource> pReadBuffer;
  1314. CComPtr<ID3D12Resource> pUploadResource;
  1315. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1316. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
  1317. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
  1318. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
  1319. // Close the command list and execute it to perform the GPU setup.
  1320. pCommandList->Close();
  1321. ExecuteCommandList(pCommandQueue, pCommandList);
  1322. WaitForSignal(pCommandQueue, FO);
  1323. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1324. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1325. // Run the compute shader and copy the results back to readable memory.
  1326. {
  1327. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1328. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1329. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1330. uavDesc.Buffer.FirstElement = 0;
  1331. uavDesc.Buffer.NumElements = (UINT)values.size();
  1332. uavDesc.Buffer.StructureByteStride = 0;
  1333. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1334. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1335. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1336. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1337. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1338. SetDescriptorHeap(pCommandList, pUavHeap);
  1339. pCommandList->SetComputeRootSignature(pRootSignature);
  1340. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1341. }
  1342. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1343. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1344. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1345. pCommandList->Close();
  1346. ExecuteCommandList(pCommandQueue, pCommandList);
  1347. WaitForSignal(pCommandQueue, FO);
  1348. {
  1349. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1350. uint32_t *pData = (uint32_t *)mappedData.data();
  1351. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1352. }
  1353. WaitForSignal(pCommandQueue, FO);
  1354. }
  1355. void ExecutionTest::RunLifetimeIntrinsicComputeTest(ID3D12Device *pDevice, LPCSTR pShader, CComPtr<ID3D12DescriptorHeap>& pUavHeap, CComPtr<ID3D12RootSignature>& pRootSignature,
  1356. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1357. // Create command queue.
  1358. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1359. CreateComputeCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue);
  1360. FenceObj FO;
  1361. InitFenceObj(pDevice, &FO);
  1362. // Compile shader "main" and create pipeline state object.
  1363. CComPtr<ID3D12PipelineState> pComputeState;
  1364. CreateComputePSO(pDevice, pRootSignature, pShader, pTargetProfile, &pComputeState, pOptions, numOptions);
  1365. // Create a command allocator and list for compute.
  1366. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1367. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1368. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1369. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1370. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1371. // Set up UAV resource.
  1372. const UINT valueSizeInBytes = (UINT)values.size() * sizeof(uint32_t);
  1373. CComPtr<ID3D12Resource> pUavResource;
  1374. CComPtr<ID3D12Resource> pReadBuffer;
  1375. CComPtr<ID3D12Resource> pUploadResource;
  1376. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1377. VERIFY_SUCCEEDED(pUavResource->SetName(L"RunLifetimeIntrinsicTest UAV"));
  1378. VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunLifetimeIntrinsicTest UAV Read Buffer"));
  1379. VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunLifetimeIntrinsicTest UAV Upload Buffer"));
  1380. // Close the command list and execute it to perform the GPU setup.
  1381. pCommandList->Close();
  1382. ExecuteCommandList(pCommandQueue, pCommandList);
  1383. WaitForSignal(pCommandQueue, FO);
  1384. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1385. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1386. // Run the compute shader and copy the results back to readable memory.
  1387. {
  1388. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1389. uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
  1390. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1391. uavDesc.Buffer.FirstElement = 0;
  1392. uavDesc.Buffer.NumElements = (UINT)values.size();
  1393. uavDesc.Buffer.StructureByteStride = 0;
  1394. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1395. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
  1396. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1397. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1398. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1399. SetDescriptorHeap(pCommandList, pUavHeap);
  1400. pCommandList->SetComputeRootSignature(pRootSignature);
  1401. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1402. }
  1403. static const int DispatchGroupX = 1;
  1404. static const int DispatchGroupY = 1;
  1405. static const int DispatchGroupZ = 1;
  1406. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  1407. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  1408. pCommandList->CopyResource(pReadBuffer, pUavResource);
  1409. pCommandList->Close();
  1410. ExecuteCommandList(pCommandQueue, pCommandList);
  1411. WaitForSignal(pCommandQueue, FO);
  1412. {
  1413. MappedData mappedData(pReadBuffer, valueSizeInBytes);
  1414. uint32_t *pData = (uint32_t *)mappedData.data();
  1415. memcpy(values.data(), pData, (size_t)valueSizeInBytes);
  1416. }
  1417. WaitForSignal(pCommandQueue, FO);
  1418. }
  1419. void ExecutionTest::RunLifetimeIntrinsicLibTest(ID3D12Device5 *pDevice, LPCSTR pShader, CComPtr<ID3D12RootSignature>& pRootSignature,
  1420. LPCWSTR pTargetProfile, LPCWSTR *pOptions, int numOptions) {
  1421. // Create command queue.
  1422. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1423. CreateCommandQueue(pDevice, L"RunLifetimeIntrinsicTest Command Queue", &pCommandQueue, D3D12_COMMAND_LIST_TYPE_DIRECT);
  1424. FenceObj FO;
  1425. InitFenceObj(pDevice, &FO);
  1426. // Compile raygen shader.
  1427. CComPtr<ID3DBlob> pShaderLib;
  1428. CompileFromText(pShader, L"RayGen", pTargetProfile, &pShaderLib, pOptions, numOptions);
  1429. // Describe and create the RT pipeline state object (RTPSO).
  1430. CD3DX12_STATE_OBJECT_DESC stateObjectDesc(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
  1431. auto lib = stateObjectDesc.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
  1432. CD3DX12_SHADER_BYTECODE byteCode(pShaderLib);
  1433. lib->SetDXILLibrary(&byteCode);
  1434. lib->DefineExport(L"RayGen");
  1435. const int payloadCount = 4;
  1436. const int attributeCount = 2;
  1437. const int maxRecursion = 2;
  1438. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT>()->Config(payloadCount * sizeof(float), attributeCount * sizeof(float));
  1439. stateObjectDesc.CreateSubobject<CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT>()->Config(maxRecursion);
  1440. // Create (local!) root sig subobject and associate with shader.
  1441. auto localRootSigSubObj = stateObjectDesc.CreateSubobject<CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT>();
  1442. localRootSigSubObj->SetRootSignature(pRootSignature);
  1443. auto x = stateObjectDesc.CreateSubobject<CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT>();
  1444. x->SetSubobjectToAssociate(*localRootSigSubObj);
  1445. x->AddExport(L"RayGen");
  1446. CComPtr<ID3D12StateObject> pStateObject;
  1447. VERIFY_SUCCEEDED(pDevice->CreateStateObject(stateObjectDesc, IID_PPV_ARGS(&pStateObject)));
  1448. // Create a command allocator and list.
  1449. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1450. CComPtr<ID3D12GraphicsCommandList4> pCommandList;
  1451. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&pCommandAllocator)));
  1452. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, pCommandAllocator, nullptr, IID_PPV_ARGS(&pCommandList)));
  1453. pCommandList->SetPipelineState1(pStateObject);
  1454. pCommandList->SetName(L"ExecutionTest::RunLifetimeIntrinsicTest Command List");
  1455. // Close the command list and execute it to kick-off compilation in the driver.
  1456. // NOTE: We don't care about anything else, so we're not setting up any resources and don't actually execute the shader.
  1457. pCommandList->Close();
  1458. ExecuteCommandList(pCommandQueue, pCommandList);
  1459. WaitForSignal(pCommandQueue, FO);
  1460. }
  1461. void ExecutionTest::RunLifetimeIntrinsicTest(ID3D12Device *pDevice, LPCSTR pShader, D3D_SHADER_MODEL shaderModel, bool useLibTarget,
  1462. LPCWSTR *pOptions, int numOptions, std::vector<uint32_t> &values) {
  1463. LPCWSTR pTargetProfile;
  1464. switch (shaderModel) {
  1465. default: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_0"; break; // Default to 6.3 for lib, 6.0 otherwise.
  1466. case D3D_SHADER_MODEL_6_0: pTargetProfile = useLibTarget ? L"lib_6_0" : L"cs_6_0"; break;
  1467. case D3D_SHADER_MODEL_6_3: pTargetProfile = useLibTarget ? L"lib_6_3" : L"cs_6_3"; break;
  1468. case D3D_SHADER_MODEL_6_5: pTargetProfile = useLibTarget ? L"lib_6_5" : L"cs_6_5"; break;
  1469. case D3D_SHADER_MODEL_6_6: pTargetProfile = useLibTarget ? L"lib_6_6" : L"cs_6_6"; break;
  1470. }
  1471. // Describe a UAV descriptor heap.
  1472. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1473. heapDesc.NumDescriptors = 1;
  1474. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1475. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1476. // Create the UAV descriptor heap.
  1477. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1478. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1479. // Create root signature.
  1480. CComPtr<ID3D12RootSignature> pRootSignature;
  1481. {
  1482. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1483. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1484. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1485. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1486. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1487. D3D12_ROOT_SIGNATURE_FLAGS rootSigFlag = useLibTarget ? D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE : D3D12_ROOT_SIGNATURE_FLAG_NONE;
  1488. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, rootSigFlag);
  1489. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  1490. }
  1491. if (useLibTarget)
  1492. RunLifetimeIntrinsicLibTest(reinterpret_cast<ID3D12Device5*>(pDevice), pShader, pRootSignature, pTargetProfile, pOptions, numOptions);
  1493. else
  1494. RunLifetimeIntrinsicComputeTest(pDevice, pShader, pUavHeap, pRootSignature, pTargetProfile, pOptions, numOptions, values);
  1495. }
  1496. TEST_F(ExecutionTest, LifetimeIntrinsicTest) {
  1497. // The only thing we test here is that existence of lifetime intrinsics or
  1498. // their fallback replacement (store undef or store zeroinitializer) do not
  1499. // cause any issues in the runtime and driver stack.
  1500. // The easiest way to force placement of intrinsics is to create an array in
  1501. // a local scope that is dynamically indexed. It must not be optimized away,
  1502. // so we do some bogus initialization that prevents this. Since all the code
  1503. // is guarded by a conditional that is dynamically always false, the actual
  1504. // effect of the shader is that the same value that was read is written back.
  1505. static const char* pShader = R"(
  1506. RWByteAddressBuffer g_bab : register(u0);
  1507. void fn(uint GI) {
  1508. const uint addr = GI * 4;
  1509. const int val = g_bab.Load(addr);
  1510. int res = val;
  1511. if (val < 0) { // Never true.
  1512. int arr[200];
  1513. for (int i = 0; i < 200; ++i) {
  1514. arr[i] = arr[val - i];
  1515. }
  1516. res += arr[val];
  1517. }
  1518. g_bab.Store(addr, (uint)res);
  1519. }
  1520. [numthreads(8,8,1)]
  1521. void main(uint GI : SV_GroupIndex) {
  1522. fn(GI);
  1523. }
  1524. [shader("raygeneration")]
  1525. void RayGen() {
  1526. const uint d = DispatchRaysIndex().x;
  1527. const uint g = g > 64 ? 63 : g;
  1528. fn(g);
  1529. }
  1530. )";
  1531. static const int NumThreadsX = 8;
  1532. static const int NumThreadsY = 8;
  1533. static const int NumThreadsZ = 1;
  1534. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1535. static const int DispatchGroupCount = 1;
  1536. // TODO: There's probably a lot of things in the rest of this test that could be stripped away.
  1537. CComPtr<ID3D12Device5> pDevice;
  1538. if (!CreateDevice(reinterpret_cast<ID3D12Device**>(&pDevice), D3D_SHADER_MODEL_6_6, true, true)) {
  1539. WEX::Logging::Log::Comment(L"Lifetime test not run pre 6.6");
  1540. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  1541. return;
  1542. }
  1543. std::vector<uint32_t> values;
  1544. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1545. // Run a number of tests for different configurations that will cause
  1546. // lifetime intrinsics to be placed directly, be replaced by a zeroinitializer
  1547. // store, or be replaced by an undef store.
  1548. LPCWSTR pOptions15[] = {L"/validator-version 1.5"};
  1549. LPCWSTR pOptions16[] = {L"/validator-version 1.6", L"/Vd"};
  1550. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1551. // Test regular shader with zeroinitializer store.
  1552. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions15, _countof(pOptions15), values);
  1553. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1554. if (DoesDeviceSupportRayTracing(pDevice)) {
  1555. // Test library with zeroinitializer store.
  1556. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions15, _countof(pOptions15), values);
  1557. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1558. }
  1559. // Testing SM 6.6 and validator version 1.6 requires experimental shaders
  1560. // being turned on.
  1561. if (!m_ExperimentalModeEnabled)
  1562. return;
  1563. // Test regular shader with undef store.
  1564. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_0, false, pOptions16, _countof(pOptions16), values);
  1565. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1566. if (DoesDeviceSupportRayTracing(pDevice)) {
  1567. // Test library with undef store.
  1568. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_3, true, pOptions16, _countof(pOptions16), values);
  1569. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1570. }
  1571. // Test regular shader with lifetime intrinsics.
  1572. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, false, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1573. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1574. if (DoesDeviceSupportRayTracing(pDevice)) {
  1575. // Test library with lifetime intrinsics.
  1576. RunLifetimeIntrinsicTest(pDevice, pShader, D3D_SHADER_MODEL_6_5, true, pOptions16, _countof(pOptions16), values); // TODO: Test 6.6 here!
  1577. VERIFY_ARE_EQUAL(values[1], (uint32_t)1);
  1578. }
  1579. }
  1580. TEST_F(ExecutionTest, BasicComputeTest) {
  1581. #ifndef _HLK_CONF
  1582. //
  1583. // BasicComputeTest is a simple compute shader that can be used as the basis
  1584. // for more interesting compute execution tests.
  1585. // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
  1586. // rendering code paths for comparison.
  1587. //
  1588. static const char pShader[] =
  1589. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1590. "[numthreads(8,8,1)]\r\n"
  1591. "void main(uint GI : SV_GroupIndex) {"
  1592. " uint addr = GI * 4;\r\n"
  1593. " uint val = g_bab.Load(addr);\r\n"
  1594. " DeviceMemoryBarrierWithGroupSync();\r\n"
  1595. " g_bab.Store(addr, val + 1);\r\n"
  1596. "}";
  1597. static const int NumThreadsX = 8;
  1598. static const int NumThreadsY = 8;
  1599. static const int NumThreadsZ = 1;
  1600. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1601. static const int DispatchGroupCount = 1;
  1602. CComPtr<ID3D12Device> pDevice;
  1603. if (!CreateDevice(&pDevice))
  1604. return;
  1605. std::vector<uint32_t> values;
  1606. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1607. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1608. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1609. VERIFY_ARE_EQUAL(values[0], (uint32_t)1);
  1610. #endif
  1611. }
  1612. TEST_F(ExecutionTest, BasicTriangleTest) {
  1613. #ifndef _HLK_CONF
  1614. static const UINT FrameCount = 2;
  1615. static const UINT m_width = 320;
  1616. static const UINT m_height = 200;
  1617. static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
  1618. struct Vertex {
  1619. XMFLOAT3 position;
  1620. XMFLOAT4 color;
  1621. };
  1622. // Pipeline objects.
  1623. CComPtr<ID3D12Device> pDevice;
  1624. CComPtr<ID3D12Resource> pRenderTarget;
  1625. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1626. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1627. CComPtr<ID3D12RootSignature> pRootSig;
  1628. CComPtr<ID3D12DescriptorHeap> pRtvHeap;
  1629. CComPtr<ID3D12PipelineState> pPipelineState;
  1630. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1631. CComPtr<ID3D12Resource> pReadBuffer;
  1632. UINT rtvDescriptorSize;
  1633. CComPtr<ID3D12Resource> pVertexBuffer;
  1634. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  1635. // Synchronization objects.
  1636. FenceObj FO;
  1637. // Shaders.
  1638. static const char pShaders[] =
  1639. "struct PSInput {\r\n"
  1640. " float4 position : SV_POSITION;\r\n"
  1641. " float4 color : COLOR;\r\n"
  1642. "};\r\n\r\n"
  1643. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  1644. " PSInput result;\r\n"
  1645. "\r\n"
  1646. " result.position = position;\r\n"
  1647. " result.color = color;\r\n"
  1648. " return result;\r\n"
  1649. "}\r\n\r\n"
  1650. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  1651. " return 1; //input.color;\r\n"
  1652. "};\r\n";
  1653. if (!CreateDevice(&pDevice))
  1654. return;
  1655. struct BasicTestChecker {
  1656. CComPtr<ID3D12Device> m_pDevice;
  1657. CComPtr<ID3D12InfoQueue> m_pInfoQueue;
  1658. bool m_OK = false;
  1659. void SetOK(bool value) { m_OK = value; }
  1660. BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
  1661. if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
  1662. return;
  1663. m_pInfoQueue->PushEmptyStorageFilter();
  1664. m_pInfoQueue->PushEmptyRetrievalFilter();
  1665. }
  1666. ~BasicTestChecker() {
  1667. if (!m_OK && m_pInfoQueue != nullptr) {
  1668. UINT64 count = m_pInfoQueue->GetNumStoredMessages();
  1669. bool invalidBytecodeFound = false;
  1670. CAtlArray<BYTE> m_pBytes;
  1671. for (UINT64 i = 0; i < count; ++i) {
  1672. SIZE_T len = 0;
  1673. if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
  1674. continue;
  1675. if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
  1676. continue;
  1677. D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
  1678. if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
  1679. continue;
  1680. if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
  1681. pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
  1682. invalidBytecodeFound = true;
  1683. break;
  1684. }
  1685. }
  1686. if (invalidBytecodeFound) {
  1687. LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
  1688. L"typically indicates that experimental mode "
  1689. L"is not set up properly.");
  1690. if (!GetTestParamBool(L"ExperimentalShaders")) {
  1691. LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
  1692. }
  1693. }
  1694. else {
  1695. LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
  1696. L"queue - dumping complete queue.");
  1697. WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
  1698. }
  1699. }
  1700. }
  1701. static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
  1702. UNREFERENCED_PARAMETER(pCtx);
  1703. LogCommentFmt(L"%s", pMsg);
  1704. }
  1705. };
  1706. BasicTestChecker BTC(pDevice);
  1707. {
  1708. InitFenceObj(pDevice, &FO);
  1709. CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
  1710. CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
  1711. // Create an empty root signature.
  1712. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1713. rootSignatureDesc.Init(
  1714. 0, nullptr, 0, nullptr,
  1715. D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  1716. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
  1717. // Create the pipeline state, which includes compiling and loading shaders.
  1718. // Define the vertex input layout.
  1719. D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
  1720. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  1721. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
  1722. {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
  1723. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  1724. D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
  1725. CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
  1726. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
  1727. &pCommandAllocator, &pCommandList,
  1728. pPipelineState);
  1729. // Define the geometry for a triangle.
  1730. Vertex triangleVertices[] = {
  1731. { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
  1732. { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
  1733. { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
  1734. CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
  1735. WaitForSignal(pCommandQueue, FO);
  1736. }
  1737. // Render and execute the command list.
  1738. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
  1739. &vertexBufferView, pRootSig, pRenderTarget,
  1740. pReadBuffer);
  1741. VERIFY_SUCCEEDED(pCommandList->Close());
  1742. ExecuteCommandList(pCommandQueue, pCommandList);
  1743. // Wait for previous frame.
  1744. WaitForSignal(pCommandQueue, FO);
  1745. // At this point, we've verified that execution succeeded with DXIL.
  1746. BTC.SetOK(true);
  1747. // Read back to CPU and examine contents.
  1748. {
  1749. MappedData data(pReadBuffer, m_width * m_height * 4);
  1750. const uint32_t *pPixels = (uint32_t *)data.data();
  1751. if (SaveImages()) {
  1752. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
  1753. }
  1754. uint32_t top = pPixels[m_width / 2]; // Top center.
  1755. uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
  1756. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  1757. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  1758. }
  1759. #endif
  1760. }
  1761. TEST_F(ExecutionTest, Int64Test) {
  1762. static const char pShader[] =
  1763. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1764. "[numthreads(8,8,1)]\r\n"
  1765. "void main(uint GI : SV_GroupIndex) {"
  1766. " uint addr = GI * 4;\r\n"
  1767. " uint val = g_bab.Load(addr);\r\n"
  1768. " uint64_t u64 = val;\r\n"
  1769. " u64 *= val;\r\n"
  1770. " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
  1771. "}";
  1772. static const int NumThreadsX = 8;
  1773. static const int NumThreadsY = 8;
  1774. static const int NumThreadsZ = 1;
  1775. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1776. static const int DispatchGroupCount = 1;
  1777. CComPtr<ID3D12Device> pDevice;
  1778. if (!CreateDevice(&pDevice))
  1779. return;
  1780. if (!DoesDeviceSupportInt64(pDevice)) {
  1781. // Optional feature, so it's correct to not support it if declared as such.
  1782. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  1783. return;
  1784. }
  1785. std::vector<uint32_t> values;
  1786. SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
  1787. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1788. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1789. VERIFY_ARE_EQUAL(values[0], (uint32_t)0);
  1790. }
  1791. TEST_F(ExecutionTest, SignTest) {
  1792. static const char pShader[] =
  1793. "RWByteAddressBuffer g_bab : register(u0);\r\n"
  1794. "[numthreads(8,1,1)]\r\n"
  1795. "void main(uint GI : SV_GroupIndex) {"
  1796. " uint addr = GI * 4;\r\n"
  1797. " int val = g_bab.Load(addr);\r\n"
  1798. " g_bab.Store(addr, (uint)(sign(val)));\r\n"
  1799. "}";
  1800. static const int NumThreadsX = 8;
  1801. static const int NumThreadsY = 1;
  1802. static const int NumThreadsZ = 1;
  1803. static const int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  1804. static const int DispatchGroupCount = 1;
  1805. CComPtr<ID3D12Device> pDevice;
  1806. if (!CreateDevice(&pDevice))
  1807. return;
  1808. const uint32_t neg1 = (uint32_t)-1;
  1809. uint32_t origValues[] = { (uint32_t)-3, (uint32_t)-2, neg1, 0, 1, 2, 3, 4 };
  1810. std::vector<uint32_t> values(origValues, origValues + _countof(origValues));
  1811. RunRWByteBufferComputeTest(pDevice, pShader, values);
  1812. VERIFY_ARE_EQUAL(values[0], neg1);
  1813. VERIFY_ARE_EQUAL(values[1], neg1);
  1814. VERIFY_ARE_EQUAL(values[2], neg1);
  1815. VERIFY_ARE_EQUAL(values[3], (uint32_t)0);
  1816. VERIFY_ARE_EQUAL(values[4], (uint32_t)1);
  1817. VERIFY_ARE_EQUAL(values[5], (uint32_t)1);
  1818. VERIFY_ARE_EQUAL(values[6], (uint32_t)1);
  1819. VERIFY_ARE_EQUAL(values[7], (uint32_t)1);
  1820. }
  1821. TEST_F(ExecutionTest, WaveIntrinsicsDDITest) {
  1822. #ifndef _HLK_CONF
  1823. CComPtr<ID3D12Device> pDevice;
  1824. if (!CreateDevice(&pDevice))
  1825. return;
  1826. D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
  1827. if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
  1828. return;
  1829. bool waveSupported = O.WaveOps;
  1830. UINT laneCountMin = O.WaveLaneCountMin;
  1831. UINT laneCountMax = O.WaveLaneCountMax;
  1832. LogCommentFmt(L"WaveOps %i, WaveLaneCountMin %u, WaveLaneCountMax %u", waveSupported, laneCountMin, laneCountMax);
  1833. VERIFY_IS_TRUE(laneCountMin <= laneCountMax);
  1834. if (waveSupported) {
  1835. VERIFY_IS_TRUE(laneCountMin > 0 && laneCountMax > 0);
  1836. }
  1837. else {
  1838. VERIFY_IS_TRUE(laneCountMin == 0 && laneCountMax == 0);
  1839. }
  1840. #endif
  1841. }
  1842. TEST_F(ExecutionTest, WaveIntrinsicsTest) {
  1843. #ifndef _HLK_CONF
  1844. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1845. struct PerThreadData {
  1846. uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
  1847. uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
  1848. uint32_t pfBC, pfSum, pfProd;
  1849. uint32_t ballot[4];
  1850. uint32_t diver; // divergent value, used in calculation
  1851. int32_t i_diver; // divergent value, used in calculation
  1852. int32_t i_allMax, i_allMin, i_allSum, i_allProd;
  1853. int32_t i_pfSum, i_pfProd;
  1854. };
  1855. static const char pShader[] =
  1856. WAVE_INTRINSIC_DXBC_GUARD
  1857. "struct PerThreadData {\r\n"
  1858. " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
  1859. " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
  1860. " uint pfBC, pfSum, pfProd;\r\n"
  1861. " uint4 ballot;\r\n"
  1862. " uint diver;\r\n"
  1863. " int i_diver;\r\n"
  1864. " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
  1865. " int i_pfSum, i_pfProd;\r\n"
  1866. "};\r\n"
  1867. "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
  1868. "[numthreads(8,8,1)]\r\n"
  1869. "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
  1870. " PerThreadData pts = g_sb[GI];\r\n"
  1871. " uint diver = GTID.x + 2;\r\n"
  1872. " pts.diver = diver;\r\n"
  1873. " pts.flags = 0;\r\n"
  1874. " pts.preds = 0;\r\n"
  1875. " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
  1876. " pts.laneIndex = WaveGetLaneIndex();\r\n"
  1877. " pts.laneCount = WaveGetLaneCount();\r\n"
  1878. " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
  1879. " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
  1880. " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
  1881. " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
  1882. " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
  1883. " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
  1884. " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  1885. " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
  1886. " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
  1887. "\r\n"
  1888. " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
  1889. " pts.allSum = WaveActiveSum(diver);\r\n"
  1890. " pts.allProd = WaveActiveProduct(diver);\r\n"
  1891. " pts.allAND = WaveActiveBitAnd(diver);\r\n"
  1892. " pts.allOR = WaveActiveBitOr(diver);\r\n"
  1893. " pts.allXOR = WaveActiveBitXor(diver);\r\n"
  1894. " pts.allMin = WaveActiveMin(diver);\r\n"
  1895. " pts.allMax = WaveActiveMax(diver);\r\n"
  1896. "\r\n"
  1897. " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
  1898. " pts.pfSum = WavePrefixSum(diver);\r\n"
  1899. " pts.pfProd = WavePrefixProduct(diver);\r\n"
  1900. "\r\n"
  1901. " int i_diver = pts.i_diver;\r\n"
  1902. " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
  1903. " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
  1904. " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
  1905. " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
  1906. " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
  1907. " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
  1908. "\r\n"
  1909. " g_sb[GI] = pts;\r\n"
  1910. "}";
  1911. static const int NumtheadsX = 8;
  1912. static const int NumtheadsY = 8;
  1913. static const int NumtheadsZ = 1;
  1914. static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
  1915. static const int DispatchGroupCount = 1;
  1916. CComPtr<ID3D12Device> pDevice;
  1917. if (!CreateDevice(&pDevice))
  1918. return;
  1919. if (!DoesDeviceSupportWaveOps(pDevice)) {
  1920. // Optional feature, so it's correct to not support it if declared as such.
  1921. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  1922. return;
  1923. }
  1924. std::vector<PerThreadData> values;
  1925. values.resize(ThreadsPerGroup * DispatchGroupCount);
  1926. for (size_t i = 0; i < values.size(); ++i) {
  1927. memset(&values[i], 0, sizeof(PerThreadData));
  1928. values[i].id = (uint32_t)i;
  1929. values[i].i_diver = (int)i;
  1930. values[i].i_diver *= (i % 2) ? 1 : -1;
  1931. }
  1932. static const int DispatchGroupX = 1;
  1933. static const int DispatchGroupY = 1;
  1934. static const int DispatchGroupZ = 1;
  1935. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  1936. CComPtr<ID3D12CommandQueue> pCommandQueue;
  1937. CComPtr<ID3D12DescriptorHeap> pUavHeap;
  1938. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  1939. UINT uavDescriptorSize;
  1940. FenceObj FO;
  1941. bool dxbc = UseDxbc();
  1942. const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
  1943. CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
  1944. InitFenceObj(pDevice, &FO);
  1945. // Describe and create a UAV descriptor heap.
  1946. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  1947. heapDesc.NumDescriptors = 1;
  1948. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  1949. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  1950. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  1951. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  1952. // Create root signature.
  1953. CComPtr<ID3D12RootSignature> pRootSignature;
  1954. {
  1955. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  1956. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
  1957. CD3DX12_ROOT_PARAMETER rootParameters[1];
  1958. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  1959. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  1960. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
  1961. CComPtr<ID3DBlob> signature;
  1962. CComPtr<ID3DBlob> error;
  1963. VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
  1964. VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
  1965. }
  1966. // Create pipeline state object.
  1967. CComPtr<ID3D12PipelineState> pComputeState;
  1968. CreateComputePSO(pDevice, pRootSignature, pShader, L"cs_6_0", &pComputeState);
  1969. // Create a command allocator and list for compute.
  1970. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  1971. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  1972. // Set up UAV resource.
  1973. CComPtr<ID3D12Resource> pUavResource;
  1974. CComPtr<ID3D12Resource> pReadBuffer;
  1975. CComPtr<ID3D12Resource> pUploadResource;
  1976. CreateTestUavs(pDevice, pCommandList, values.data(), (UINT)valueSizeInBytes, &pUavResource, &pUploadResource, &pReadBuffer);
  1977. // Close the command list and execute it to perform the GPU setup.
  1978. pCommandList->Close();
  1979. ExecuteCommandList(pCommandQueue, pCommandList);
  1980. WaitForSignal(pCommandQueue, FO);
  1981. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  1982. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  1983. // Run the compute shader and copy the results back to readable memory.
  1984. {
  1985. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  1986. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  1987. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  1988. uavDesc.Buffer.FirstElement = 0;
  1989. uavDesc.Buffer.NumElements = (UINT)values.size();
  1990. uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
  1991. uavDesc.Buffer.CounterOffsetInBytes = 0;
  1992. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  1993. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  1994. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  1995. pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
  1996. SetDescriptorHeap(pCommandList, pUavHeap);
  1997. pCommandList->SetComputeRootSignature(pRootSignature);
  1998. pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
  1999. }
  2000. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  2001. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2002. pCommandList->CopyResource(pReadBuffer, pUavResource);
  2003. pCommandList->Close();
  2004. ExecuteCommandList(pCommandQueue, pCommandList);
  2005. WaitForSignal(pCommandQueue, FO);
  2006. {
  2007. MappedData mappedData(pReadBuffer, (UINT)valueSizeInBytes);
  2008. PerThreadData *pData = (PerThreadData *)mappedData.data();
  2009. memcpy(values.data(), pData, valueSizeInBytes);
  2010. // Gather some general data.
  2011. // The 'firstLaneId' captures a unique number per first-lane per wave.
  2012. // Counting the number distinct firstLaneIds gives us the number of waves.
  2013. std::vector<uint32_t> firstLaneIds;
  2014. for (size_t i = 0; i < values.size(); ++i) {
  2015. PerThreadData &pts = values[i];
  2016. uint32_t firstLaneId = pts.firstLaneId;
  2017. if (!contains(firstLaneIds, firstLaneId)) {
  2018. firstLaneIds.push_back(firstLaneId);
  2019. }
  2020. }
  2021. // Waves should cover 4 threads or more.
  2022. LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
  2023. if (!dxbc) {
  2024. VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
  2025. }
  2026. // Now, group threads into waves.
  2027. std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
  2028. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  2029. waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
  2030. }
  2031. for (size_t i = 0; i < values.size(); ++i) {
  2032. PerThreadData &pts = values[i];
  2033. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2034. wave->push_back(&pts);
  2035. }
  2036. // Verify that all the wave values are coherent across the wave.
  2037. for (size_t i = 0; i < values.size(); ++i) {
  2038. PerThreadData &pts = values[i];
  2039. std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
  2040. // Sort the lanes by increasing lane ID.
  2041. struct LaneIdOrderPred {
  2042. bool operator()(PerThreadData *a, PerThreadData *b) {
  2043. return a->laneIndex < b->laneIndex;
  2044. }
  2045. };
  2046. std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
  2047. // Verify some interesting properties of the first lane.
  2048. uint32_t pfBC, pfSum, pfProd;
  2049. int32_t i_pfSum, i_pfProd;
  2050. int32_t i_allMax, i_allMin;
  2051. {
  2052. PerThreadData *ptdFirst = wave->front();
  2053. VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
  2054. VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
  2055. VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
  2056. VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
  2057. VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
  2058. VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
  2059. pfBC = (ptdFirst->diver > 3) ? 1 : 0;
  2060. pfSum = ptdFirst->diver;
  2061. pfProd = ptdFirst->diver;
  2062. i_pfSum = ptdFirst->i_diver;
  2063. i_pfProd = ptdFirst->i_diver;
  2064. i_allMax = i_allMin = ptdFirst->i_diver;
  2065. }
  2066. // Calculate values which take into consideration all lanes.
  2067. uint32_t preds = 0;
  2068. preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
  2069. preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
  2070. preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
  2071. preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
  2072. uint32_t ballot[4] = { 0, 0, 0, 0 };
  2073. int32_t i_allSum = 0, i_allProd = 1;
  2074. for (size_t n = 0; n < wave->size(); ++n) {
  2075. std::vector<PerThreadData *> &lanes = *wave.get();
  2076. // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
  2077. if (lanes[n]->diver == 1) preds |= (1 << 0);
  2078. // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
  2079. if (lanes[n]->diver != 1) preds &= ~(1 << 1);
  2080. // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
  2081. if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
  2082. // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
  2083. if (lanes[n]->diver > 3) {
  2084. // This is the uint4 result layout:
  2085. // .x -> bits 0 .. 31
  2086. // .y -> bits 32 .. 63
  2087. // .z -> bits 64 .. 95
  2088. // .w -> bits 96 ..127
  2089. uint32_t component = lanes[n]->laneIndex / 32;
  2090. uint32_t bit = lanes[n]->laneIndex % 32;
  2091. ballot[component] |= 1 << bit;
  2092. }
  2093. i_allMax = std::max(lanes[n]->i_diver, i_allMax);
  2094. i_allMin = std::min(lanes[n]->i_diver, i_allMin);
  2095. i_allProd *= lanes[n]->i_diver;
  2096. i_allSum += lanes[n]->i_diver;
  2097. }
  2098. for (size_t n = 1; n < wave->size(); ++n) {
  2099. // 'All' operations are uniform across the wave.
  2100. std::vector<PerThreadData *> &lanes = *wave.get();
  2101. VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
  2102. VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
  2103. VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
  2104. VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
  2105. VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
  2106. VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
  2107. VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
  2108. VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
  2109. VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
  2110. VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
  2111. VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
  2112. VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
  2113. VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
  2114. // first-lane reads and uniform reads are uniform across the wave.
  2115. VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
  2116. VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
  2117. // the lane count is uniform across the wave.
  2118. VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
  2119. // The predicates are uniform across the wave.
  2120. VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
  2121. // the lane index is distinct per thread.
  2122. for (size_t prior = 0; prior < n; ++prior) {
  2123. VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
  2124. }
  2125. // Ballot results are uniform across the wave.
  2126. VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
  2127. // Keep running total of prefix calculation. Prefix values are exclusive to
  2128. // the executing lane.
  2129. VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
  2130. VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
  2131. VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
  2132. VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
  2133. VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
  2134. pfBC += (lanes[n]->diver > 3) ? 1 : 0;
  2135. pfSum += lanes[n]->diver;
  2136. pfProd *= lanes[n]->diver;
  2137. i_pfSum += lanes[n]->i_diver;
  2138. i_pfProd *= lanes[n]->i_diver;
  2139. }
  2140. // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
  2141. }
  2142. // Compare each value of each per-thread element.
  2143. for (size_t i = 0; i < values.size(); ++i) {
  2144. PerThreadData &pts = values[i];
  2145. VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
  2146. }
  2147. }
  2148. #endif
  2149. }
  2150. // This test is assuming that the adapter implements WaveReadLaneFirst correctly
  2151. TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
  2152. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2153. struct Vertex {
  2154. XMFLOAT3 position;
  2155. };
  2156. struct PerPixelData {
  2157. XMFLOAT4 position;
  2158. uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
  2159. uint32_t id0, id1, id2, id3;
  2160. uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
  2161. };
  2162. const UINT RTWidth = 128;
  2163. const UINT RTHeight = 128;
  2164. // Shaders.
  2165. static const char pShaders[] =
  2166. WAVE_INTRINSIC_DXBC_GUARD
  2167. "struct PSInput {\r\n"
  2168. " float4 position : SV_POSITION;\r\n"
  2169. "};\r\n\r\n"
  2170. "PSInput VSMain(float4 position : POSITION) {\r\n"
  2171. " PSInput result;\r\n"
  2172. "\r\n"
  2173. " result.position = position;\r\n"
  2174. " return result;\r\n"
  2175. "}\r\n\r\n"
  2176. "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
  2177. "struct PerPixelData {\r\n"
  2178. " float4 position;\r\n"
  2179. " uint id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
  2180. " uint id0, id1, id2, id3;\r\n"
  2181. " uint acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
  2182. "};\r\n"
  2183. "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
  2184. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  2185. " uint one = 1;\r\n"
  2186. " PerPixelData d;\r\n"
  2187. " d.position = input.position;\r\n"
  2188. " d.id = pos_to_id(input.position);\r\n"
  2189. " d.flags = 0;\r\n"
  2190. " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
  2191. " d.laneIndex = WaveGetLaneIndex();\r\n"
  2192. " d.laneCount = WaveGetLaneCount();\r\n"
  2193. " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
  2194. " d.sum1 = WaveActiveSum(one);\r\n"
  2195. " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
  2196. " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
  2197. " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
  2198. " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
  2199. " d.acrossX = QuadReadAcrossX(d.id);\r\n"
  2200. " d.acrossY = QuadReadAcrossY(d.id);\r\n"
  2201. " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
  2202. " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
  2203. " g_sb.Append(d);\r\n"
  2204. " return 1;\r\n"
  2205. "};\r\n";
  2206. CComPtr<ID3D12Device> pDevice;
  2207. CComPtr<ID3D12CommandQueue> pCommandQueue;
  2208. CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
  2209. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  2210. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  2211. CComPtr<ID3D12PipelineState> pPSO;
  2212. CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
  2213. UINT uavDescriptorSize, rtvDescriptorSize;
  2214. CComPtr<ID3D12Resource> pVertexBuffer;
  2215. D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
  2216. if (!CreateDevice(&pDevice))
  2217. return;
  2218. if (!DoesDeviceSupportWaveOps(pDevice)) {
  2219. // Optional feature, so it's correct to not support it if declared as such.
  2220. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  2221. return;
  2222. }
  2223. FenceObj FO;
  2224. InitFenceObj(pDevice, &FO);
  2225. // Describe and create a UAV descriptor heap.
  2226. D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
  2227. heapDesc.NumDescriptors = 1;
  2228. heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  2229. heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  2230. VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
  2231. uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
  2232. CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
  2233. CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
  2234. // Create root signature: one UAV.
  2235. CComPtr<ID3D12RootSignature> pRootSignature;
  2236. {
  2237. CD3DX12_DESCRIPTOR_RANGE ranges[1];
  2238. ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
  2239. CD3DX12_ROOT_PARAMETER rootParameters[1];
  2240. rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
  2241. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  2242. rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  2243. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  2244. }
  2245. D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
  2246. {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
  2247. D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
  2248. D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
  2249. CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
  2250. CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
  2251. &pCommandList, pPSO);
  2252. // Single triangle covering half the target.
  2253. Vertex vertices[] = {
  2254. { { -1.0f, 1.0f, 0.0f } },
  2255. { { 1.0f, 1.0f, 0.0f } },
  2256. { { -1.0f, -1.0f, 0.0f } } };
  2257. const UINT TriangleCount = _countof(vertices) / 3;
  2258. CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
  2259. bool dxbc = UseDxbc();
  2260. // Set up UAV resource.
  2261. std::vector<PerPixelData> values;
  2262. values.resize(RTWidth * RTHeight * 2);
  2263. UINT valueSizeInBytes = (UINT)values.size() * sizeof(PerPixelData);
  2264. memset(values.data(), 0, valueSizeInBytes);
  2265. CComPtr<ID3D12Resource> pUavResource;
  2266. CComPtr<ID3D12Resource> pUavReadBuffer;
  2267. CComPtr<ID3D12Resource> pUploadResource;
  2268. CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUploadResource, &pUavReadBuffer);
  2269. // Set up the append counter resource.
  2270. CComPtr<ID3D12Resource> pUavCounterResource;
  2271. CComPtr<ID3D12Resource> pReadCounterBuffer;
  2272. CComPtr<ID3D12Resource> pUploadCounterResource;
  2273. BYTE zero[sizeof(UINT)] = { 0 };
  2274. CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pUploadCounterResource, &pReadCounterBuffer);
  2275. // Close the command list and execute it to perform the GPU setup.
  2276. pCommandList->Close();
  2277. ExecuteCommandList(pCommandQueue, pCommandList);
  2278. WaitForSignal(pCommandQueue, FO);
  2279. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  2280. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
  2281. pCommandList->SetGraphicsRootSignature(pRootSignature);
  2282. SetDescriptorHeap(pCommandList, pUavHeap);
  2283. {
  2284. D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
  2285. uavDesc.Format = DXGI_FORMAT_UNKNOWN;
  2286. uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
  2287. uavDesc.Buffer.FirstElement = 0;
  2288. uavDesc.Buffer.NumElements = (UINT)values.size();
  2289. uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
  2290. uavDesc.Buffer.CounterOffsetInBytes = 0;
  2291. uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
  2292. CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
  2293. CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
  2294. pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
  2295. pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
  2296. }
  2297. RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
  2298. RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2299. RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  2300. pCommandList->CopyResource(pUavReadBuffer, pUavResource);
  2301. pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
  2302. VERIFY_SUCCEEDED(pCommandList->Close());
  2303. LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
  2304. ExecuteCommandList(pCommandQueue, pCommandList);
  2305. WaitForSignal(pCommandQueue, FO);
  2306. {
  2307. MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
  2308. const uint32_t *pPixels = (uint32_t *)data.data();
  2309. if (SaveImages()) {
  2310. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
  2311. }
  2312. }
  2313. uint32_t appendCount;
  2314. {
  2315. MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
  2316. appendCount = *((uint32_t *)mappedData.data());
  2317. LogCommentFmt(L"%u elements in append buffer", appendCount);
  2318. }
  2319. {
  2320. MappedData mappedData(pUavReadBuffer, (UINT32)values.size());
  2321. PerPixelData *pData = (PerPixelData *)mappedData.data();
  2322. memcpy(values.data(), pData, valueSizeInBytes);
  2323. // DXBC is handy to test pipeline setup, but interesting functions are
  2324. // stubbed out, so there is no point in further validation.
  2325. if (dxbc)
  2326. return;
  2327. uint32_t maxActiveLaneCount = 0;
  2328. uint32_t maxLaneCount = 0;
  2329. for (uint32_t i = 0; i < appendCount; ++i) {
  2330. maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
  2331. maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
  2332. }
  2333. uint32_t peerOfHelperLanes = 0;
  2334. for (uint32_t i = 0; i < appendCount; ++i) {
  2335. if (values[i].sum1 != maxActiveLaneCount) {
  2336. ++peerOfHelperLanes;
  2337. }
  2338. }
  2339. LogCommentFmt(
  2340. L"Found: %u threads. Waves reported up to %u total lanes, up "
  2341. L"to %u active lanes, and %u threads had helper/inactive lanes.",
  2342. appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
  2343. // Group threads into quad invocations.
  2344. uint32_t singlePixelCount = 0;
  2345. uint32_t multiPixelCount = 0;
  2346. std::unordered_set<uint32_t> ids;
  2347. std::multimap<uint32_t, PerPixelData *> idGroups;
  2348. std::multimap<uint32_t, PerPixelData *> firstIdGroups;
  2349. for (uint32_t i = 0; i < appendCount; ++i) {
  2350. ids.insert(values[i].id);
  2351. idGroups.insert(std::make_pair(values[i].id, &values[i]));
  2352. firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
  2353. }
  2354. for (uint32_t id : ids) {
  2355. if (idGroups.count(id) == 1)
  2356. ++singlePixelCount;
  2357. else
  2358. ++multiPixelCount;
  2359. }
  2360. LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
  2361. singlePixelCount, multiPixelCount);
  2362. // Multiple threads may have tried to shade the same pixel. (Is this true even if we have only one triangle?)
  2363. // Where every pixel is distinct, it's very straightforward to validate.
  2364. {
  2365. auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
  2366. while (cur != end) {
  2367. bool simpleWave = true;
  2368. uint32_t firstId = (*cur).first;
  2369. auto groupEnd = cur;
  2370. while (groupEnd != end && (*groupEnd).first == firstId) {
  2371. if (idGroups.count((*groupEnd).second->id) > 1)
  2372. simpleWave = false;
  2373. ++groupEnd;
  2374. }
  2375. if (simpleWave) {
  2376. // Break the wave into quads.
  2377. struct QuadData {
  2378. unsigned count;
  2379. PerPixelData *data[4];
  2380. };
  2381. std::map<uint32_t, QuadData> quads;
  2382. for (auto i = cur; i != groupEnd; ++i) {
  2383. // assuming that it is a simple wave, idGroups has a unique id for each entry.
  2384. uint32_t laneId = (*i).second->id;
  2385. uint32_t laneIds[4] = {(*i).second->id0, (*i).second->id1,
  2386. (*i).second->id2, (*i).second->id3};
  2387. // Since this is a simple wave, each lane has an unique id and
  2388. // therefore should not have any ids in there.
  2389. VERIFY_IS_TRUE(quads.find(laneId) == quads.end());
  2390. // check if QuadReadLaneAt is returning same values in a single quad.
  2391. bool newQuad = true;
  2392. for (unsigned quadIndex = 0; quadIndex < 4; ++quadIndex) {
  2393. auto match = quads.find(laneIds[quadIndex]);
  2394. if (match != quads.end()) {
  2395. (*match).second.data[(*match).second.count++] = (*i).second;
  2396. newQuad = false;
  2397. break;
  2398. }
  2399. auto quadMemberData = idGroups.find(laneIds[quadIndex]);
  2400. if (quadMemberData != idGroups.end()) {
  2401. VERIFY_IS_TRUE((*quadMemberData).second->id0 == laneIds[0]);
  2402. VERIFY_IS_TRUE((*quadMemberData).second->id1 == laneIds[1]);
  2403. VERIFY_IS_TRUE((*quadMemberData).second->id2 == laneIds[2]);
  2404. VERIFY_IS_TRUE((*quadMemberData).second->id3 == laneIds[3]);
  2405. }
  2406. }
  2407. if (newQuad) {
  2408. QuadData qdata;
  2409. qdata.count = 1;
  2410. qdata.data[0] = (*i).second;
  2411. quads.insert(std::make_pair(laneId, qdata));
  2412. }
  2413. }
  2414. for (auto quadPair : quads) {
  2415. unsigned count = quadPair.second.count;
  2416. // There could be only one pixel data on the edge of the triangle
  2417. if (count < 2) continue;
  2418. PerPixelData **data = quadPair.second.data;
  2419. bool isTop[4];
  2420. bool isLeft[4];
  2421. PerPixelData helperData;
  2422. memset(&helperData, sizeof(helperData), 0);
  2423. PerPixelData *layout[4]; // tl,tr,bl,br
  2424. memset(layout, sizeof(layout), 0);
  2425. auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
  2426. int idx = top ? 0 : 2;
  2427. idx += left ? 0 : 1;
  2428. return &layout[idx];
  2429. };
  2430. auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
  2431. PerPixelData **pResult = fnToLayout(top, left);
  2432. if (*pResult == nullptr) return &helperData;
  2433. return *pResult;
  2434. };
  2435. VERIFY_IS_TRUE(count <= 4);
  2436. if (count == 2) {
  2437. isTop[0] = data[0]->position.y < data[1]->position.y;
  2438. isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
  2439. isLeft[0] = data[0]->position.x < data[1]->position.x;
  2440. isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
  2441. }
  2442. else {
  2443. // with at least three samples, we have distinct x and y coordinates.
  2444. float left = std::min(data[0]->position.x, data[1]->position.x);
  2445. left = std::min(data[2]->position.x, left);
  2446. float top = std::min(data[0]->position.y, data[1]->position.y);
  2447. top = std::min(data[2]->position.y, top);
  2448. for (unsigned i = 0; i < count; ++i) {
  2449. isTop[i] = data[i]->position.y == top;
  2450. isLeft[i] = data[i]->position.x == left;
  2451. }
  2452. }
  2453. for (unsigned i = 0; i < count; ++i) {
  2454. *(fnToLayout(isTop[i], isLeft[i])) = data[i];
  2455. }
  2456. // Finally, we have a proper quad reconstructed. Validate.
  2457. for (unsigned i = 0; i < count; ++i) {
  2458. PerPixelData *d = data[i];
  2459. VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
  2460. VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
  2461. VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
  2462. VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
  2463. VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
  2464. VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
  2465. VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
  2466. VERIFY_ARE_EQUAL(d->quadActiveCount, count);
  2467. }
  2468. }
  2469. }
  2470. cur = groupEnd;
  2471. }
  2472. }
  2473. // TODO: provide validation for quads where the same pixel was shaded multiple times
  2474. //
  2475. // Consider: for pixels that were shaded multiple times, check whether
  2476. // some grouping of threads into quads satisfies all value requirements.
  2477. }
  2478. }
  2479. struct ShaderOpTestResult {
  2480. st::ShaderOp *ShaderOp;
  2481. std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
  2482. std::shared_ptr<st::ShaderOpTest> Test;
  2483. };
  2484. struct SPrimitives {
  2485. float f_float;
  2486. float f_float2;
  2487. float f_float_o;
  2488. float f_float2_o;
  2489. };
  2490. std::shared_ptr<ShaderOpTestResult>
  2491. RunShaderOpTestAfterParse(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2492. LPCSTR pName,
  2493. st::ShaderOpTest::TInitCallbackFn pInitCallback,
  2494. std::shared_ptr<st::ShaderOpSet> ShaderOpSet) {
  2495. st::ShaderOp *pShaderOp;
  2496. if (pName == nullptr) {
  2497. if (ShaderOpSet->ShaderOps.size() != 1) {
  2498. VERIFY_FAIL(L"Expected a single shader operation.");
  2499. }
  2500. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  2501. }
  2502. else {
  2503. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  2504. }
  2505. if (pShaderOp == nullptr) {
  2506. std::string msg = "Unable to find shader op ";
  2507. msg += pName;
  2508. msg += "; available ops";
  2509. const char sep = ':';
  2510. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  2511. msg += sep;
  2512. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  2513. }
  2514. CA2W msgWide(msg.c_str());
  2515. VERIFY_FAIL(msgWide.m_psz);
  2516. }
  2517. // This won't actually be used since we're supplying the device,
  2518. // but let's make it consistent.
  2519. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2520. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2521. test->SetDxcSupport(&support);
  2522. test->SetInitCallback(pInitCallback);
  2523. test->SetDevice(pDevice);
  2524. test->RunShaderOp(pShaderOp);
  2525. std::shared_ptr<ShaderOpTestResult> result =
  2526. std::make_shared<ShaderOpTestResult>();
  2527. result->ShaderOpSet = ShaderOpSet;
  2528. result->Test = test;
  2529. result->ShaderOp = pShaderOp;
  2530. return result;
  2531. }
  2532. std::shared_ptr<ShaderOpTestResult>
  2533. RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2534. IStream *pStream, LPCSTR pName,
  2535. st::ShaderOpTest::TInitCallbackFn pInitCallback) {
  2536. DXASSERT_NOMSG(pStream != nullptr);
  2537. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2538. std::make_shared<st::ShaderOpSet>();
  2539. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2540. return RunShaderOpTestAfterParse(pDevice, support, pName, pInitCallback, ShaderOpSet);
  2541. }
  2542. TEST_F(ExecutionTest, OutOfBoundsTest) {
  2543. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2544. CComPtr<IStream> pStream;
  2545. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2546. // Single operation test at the moment.
  2547. CComPtr<ID3D12Device> pDevice;
  2548. if (!CreateDevice(&pDevice))
  2549. return;
  2550. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
  2551. MappedData data;
  2552. // Read back to CPU and examine contents - should get pure red.
  2553. {
  2554. MappedData data;
  2555. test->Test->GetReadBackData("RTarget", &data);
  2556. const uint32_t *pPixels = (uint32_t *)data.data();
  2557. uint32_t first = *pPixels;
  2558. VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
  2559. }
  2560. }
  2561. TEST_F(ExecutionTest, SaturateTest) {
  2562. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2563. CComPtr<IStream> pStream;
  2564. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2565. // Single operation test at the moment.
  2566. CComPtr<ID3D12Device> pDevice;
  2567. if (!CreateDevice(&pDevice))
  2568. return;
  2569. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
  2570. MappedData data;
  2571. test->Test->GetReadBackData("U0", &data);
  2572. const float *pValues = (float *)data.data();
  2573. // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
  2574. const float ExpectedCases[9] = {
  2575. 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
  2576. 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
  2577. 0.0f // nan
  2578. };
  2579. for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
  2580. VERIFY_IS_TRUE(ifdenorm_flushf_eq(*pValues, ExpectedCases[i]));
  2581. ++pValues;
  2582. }
  2583. }
  2584. void ExecutionTest::BasicTriangleTestSetup(LPCSTR ShaderOpName, LPCWSTR FileName, D3D_SHADER_MODEL testModel) {
  2585. #ifdef _HLK_CONF
  2586. UNREFERENCED_PARAMETER(ShaderOpName);
  2587. UNREFERENCED_PARAMETER(FileName);
  2588. UNREFERENCED_PARAMETER(testModel);
  2589. #else
  2590. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2591. CComPtr<IStream> pStream;
  2592. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2593. // Single operation test at the moment.
  2594. CComPtr<ID3D12Device> pDevice;
  2595. if (!CreateDevice(&pDevice, testModel))
  2596. return;
  2597. // As this is used, 6.2 requirement always comes with requiring native 16-bit ops
  2598. if (testModel == D3D_SHADER_MODEL_6_2 && !DoesDeviceSupportNative16bitOps(pDevice)) {
  2599. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  2600. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2601. return;
  2602. }
  2603. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, ShaderOpName, nullptr);
  2604. MappedData data;
  2605. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2606. UINT width = (UINT)D.Width;
  2607. UINT height = D.Height;
  2608. test->Test->GetReadBackData("RTarget", &data);
  2609. const uint32_t *pPixels = (uint32_t *)data.data();
  2610. if (SaveImages()) {
  2611. SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, FileName);
  2612. }
  2613. uint32_t top = pPixels[width / 2]; // Top center.
  2614. uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
  2615. VERIFY_ARE_EQUAL(0xff663300, top); // clear color
  2616. VERIFY_ARE_EQUAL(0xffffffff, mid); // white
  2617. // This is the basic validation test for shader operations, so it's good to
  2618. // check this here at least for this one test case.
  2619. data.reset();
  2620. test.reset();
  2621. ReportLiveObjects();
  2622. #endif
  2623. }
  2624. TEST_F(ExecutionTest, BasicTriangleOpTest) {
  2625. BasicTriangleTestSetup("Triangle", L"basic-triangle.bmp", D3D_SHADER_MODEL_6_0);
  2626. }
  2627. TEST_F(ExecutionTest, BasicTriangleOpTestHalf) {
  2628. BasicTriangleTestSetup("TriangleHalf", L"basic-triangle-half.bmp", D3D_SHADER_MODEL_6_2);
  2629. }
  2630. void VerifyDerivResults(const float *pPixels, UINT offsetCenter) {
  2631. // pixel at the center
  2632. float CenterDDXFine = pPixels[offsetCenter];
  2633. float CenterDDYFine = pPixels[offsetCenter + 1];
  2634. float CenterDDXCoarse = pPixels[offsetCenter + 2];
  2635. float CenterDDYCoarse = pPixels[offsetCenter + 3];
  2636. LogCommentFmt(
  2637. L"center ddx_fine: %8f, ddy_fine: %8f, ddx_coarse: %8f, ddy_coarse: %8f",
  2638. CenterDDXFine, CenterDDYFine, CenterDDXCoarse, CenterDDYCoarse);
  2639. // The texture for the 9 pixels in the center should look like the following
  2640. // 256 32 64
  2641. // 2048 256 512
  2642. // 1 .125 .25
  2643. // In D3D12 there is no guarantee of how the adapter is grouping 2x2 pixels
  2644. // So for fine derivatives there can be up to two possible results for the center pixel,
  2645. // while for coarse derivatives there can be up to six possible results.
  2646. int ulpTolerance = 1;
  2647. // 512 - 256 or 2048 - 256
  2648. bool left = CompareFloatULP(CenterDDXFine, -1792.0f, ulpTolerance);
  2649. VERIFY_IS_TRUE(left || CompareFloatULP(CenterDDXFine, 256.0f, ulpTolerance));
  2650. // 256 - 32 or 256 - .125
  2651. bool top = CompareFloatULP(CenterDDYFine, 224.0f, ulpTolerance);
  2652. VERIFY_IS_TRUE(top || CompareFloatULP(CenterDDYFine, -255.875, ulpTolerance));
  2653. if (top && left) {
  2654. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -224.0f, ulpTolerance) ||
  2655. CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance)) &&
  2656. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2657. CompareFloatULP(CenterDDYCoarse, 1792.0f, ulpTolerance)));
  2658. }
  2659. else if (top) { // top right quad
  2660. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2661. CompareFloatULP(CenterDDXCoarse, 32.0f, ulpTolerance)) &&
  2662. (CompareFloatULP(CenterDDYCoarse, 224.0f, ulpTolerance) ||
  2663. CompareFloatULP(CenterDDYCoarse, 448.0f, ulpTolerance)));
  2664. }
  2665. else if (left) { // bottom left quad
  2666. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, -1792.0f, ulpTolerance) ||
  2667. CompareFloatULP(CenterDDXCoarse, -.875f, ulpTolerance)) &&
  2668. (CompareFloatULP(CenterDDYCoarse, -2047.0f, ulpTolerance) ||
  2669. CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance)));
  2670. }
  2671. else { // bottom right
  2672. VERIFY_IS_TRUE((CompareFloatULP(CenterDDXCoarse, 256.0f, ulpTolerance) ||
  2673. CompareFloatULP(CenterDDXCoarse, .125f, ulpTolerance)) &&
  2674. (CompareFloatULP(CenterDDYCoarse, -255.875f, ulpTolerance) ||
  2675. CompareFloatULP(CenterDDYCoarse, -511.75f, ulpTolerance)));
  2676. }
  2677. }
  2678. // Rendering two right triangles forming a square and assigning a texture value
  2679. // for each pixel to calculate derivates.
  2680. TEST_F(ExecutionTest, PartialDerivTest) {
  2681. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2682. CComPtr<IStream> pStream;
  2683. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2684. CComPtr<ID3D12Device> pDevice;
  2685. if (!CreateDevice(&pDevice))
  2686. return;
  2687. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "DerivFine", nullptr);
  2688. MappedData data;
  2689. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  2690. UINT width = (UINT)D.Width;
  2691. UINT height = D.Height;
  2692. UINT pixelSize = GetByteSizeForFormat(D.Format) / 4;
  2693. test->Test->GetReadBackData("RTarget", &data);
  2694. const float *pPixels = (float *)data.data();
  2695. UINT centerIndex = (UINT64)width * height / 2 - width / 2;
  2696. UINT offsetCenter = centerIndex * pixelSize;
  2697. VerifyDerivResults(pPixels, offsetCenter);
  2698. }
  2699. struct Dispatch {
  2700. int width, height, depth;
  2701. };
  2702. std::shared_ptr<st::ShaderOpTest>
  2703. RunDispatch(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
  2704. st::ShaderOp *pShaderOp, const Dispatch D) {
  2705. char compilerOptions[256];
  2706. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  2707. test->SetDxcSupport(&support);
  2708. test->SetInitCallback(nullptr);
  2709. test->SetDevice(pDevice);
  2710. // format compiler args
  2711. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2712. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d ",
  2713. D.width, D.height, D.depth));
  2714. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2715. S.Arguments = compilerOptions;
  2716. pShaderOp->DispatchX = D.width;
  2717. pShaderOp->DispatchY = D.height;
  2718. pShaderOp->DispatchZ = D.depth;
  2719. test->RunShaderOp(pShaderOp);
  2720. return test;
  2721. }
  2722. TEST_F(ExecutionTest, DerivativesTest) {
  2723. const UINT pixelSize = 4; // always float4
  2724. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2725. CComPtr<IStream> pStream;
  2726. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2727. CComPtr<ID3D12Device> pDevice;
  2728. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2729. return;
  2730. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2731. std::make_shared<st::ShaderOpSet>();
  2732. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2733. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Derivatives");
  2734. std::vector<Dispatch> dispatches =
  2735. {
  2736. {40, 1, 1},
  2737. {1000, 1, 1},
  2738. {32, 32, 1},
  2739. {16, 64, 1},
  2740. {4, 12, 4},
  2741. {4, 64, 1},
  2742. {16, 16, 3},
  2743. {32, 8, 2}
  2744. };
  2745. std::vector<Dispatch> meshDispatches =
  2746. {
  2747. {60, 1, 1},
  2748. {128, 1, 1},
  2749. {8, 8, 1},
  2750. {32, 8, 1},
  2751. {8, 16, 4},
  2752. {8, 64, 1},
  2753. {8, 8, 3},
  2754. };
  2755. std::vector<Dispatch> badDispatches =
  2756. {
  2757. {16, 3, 1},
  2758. {2, 16, 1},
  2759. {33, 1, 1}
  2760. };
  2761. pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
  2762. LPCSTR CS = pShaderOp->CS;
  2763. MappedData data;
  2764. for (Dispatch &D : dispatches) {
  2765. // Test Compute Shader
  2766. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2767. test->GetReadBackData("U0", &data);
  2768. float *pPixels = (float *)data.data();;
  2769. UINT centerIndex = 0;
  2770. if (D.height == 1) {
  2771. centerIndex = (((UINT64)(D.width * D.height * D.depth) / 2) & ~0xF) + 10;
  2772. } else {
  2773. // To find roughly the center for compute, divide the height and width in half,
  2774. // truncate to the previous multiple of 4 to get to the start of the repeating pattern
  2775. // and then add 2 rows to get to the second row of quads and 2 to get to the first texel
  2776. // of the second row of that quad row
  2777. UINT centerRow = ((D.height/2UL) & ~0x3) + 2;
  2778. UINT centerCol = ((D.width/2UL) & ~0x3) + 2;
  2779. centerIndex = centerRow * D.width + centerCol;
  2780. }
  2781. UINT offsetCenter = centerIndex * pixelSize;
  2782. LogCommentFmt(L"Verifying derivatives in compute shader results");
  2783. VerifyDerivResults(pPixels, offsetCenter);
  2784. }
  2785. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2786. // Disable CS so mesh goes forward
  2787. pShaderOp->CS = nullptr;
  2788. for (Dispatch &D : meshDispatches) {
  2789. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2790. test->GetReadBackData("U1", &data);
  2791. const float *pPixels = (float *)data.data();
  2792. UINT centerIndex = (((UINT64)(D.width * D.height * D.depth)/2) & ~0xF) + 10;
  2793. UINT offsetCenter = centerIndex * pixelSize;
  2794. LogCommentFmt(L"Verifying derivatives in mesh shader results");
  2795. VerifyDerivResults(pPixels, offsetCenter);
  2796. test->GetReadBackData("U2", &data);
  2797. pPixels = (float *)data.data();
  2798. LogCommentFmt(L"Verifying derivatives in amplification shader results");
  2799. VerifyDerivResults(pPixels, offsetCenter);
  2800. }
  2801. }
  2802. // Final tests with invalid dispatch size just to make sure they run
  2803. for (Dispatch &D : badDispatches) {
  2804. // Test Compute Shader
  2805. pShaderOp->CS = CS;
  2806. std::shared_ptr<st::ShaderOpTest> test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2807. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2808. pShaderOp->CS = nullptr;
  2809. test = RunDispatch(pDevice, m_support, pShaderOp, D);
  2810. }
  2811. }
  2812. }
  2813. // Verify the results for the quad starting with the given index
  2814. void VerifyQuadReadResults(const UINT *pPixels, UINT quadIndex) {
  2815. for (UINT i = 0; i < 4; i++) {
  2816. UINT ix = quadIndex + i;
  2817. VERIFY_ARE_EQUAL(pPixels[4*ix + 0], ix); // ReadLaneAt own quad index
  2818. VERIFY_ARE_EQUAL(pPixels[4*ix + 1], (ix^1));// ReadAcrossX
  2819. VERIFY_ARE_EQUAL(pPixels[4*ix + 2], (ix^2));// ReadAcrossY
  2820. VERIFY_ARE_EQUAL(pPixels[4*ix + 3], (ix^3));// ReadAcrossDiagonal
  2821. }
  2822. }
  2823. TEST_F(ExecutionTest, QuadReadTest) {
  2824. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2825. CComPtr<IStream> pStream;
  2826. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2827. CComPtr<ID3D12Device> pDevice;
  2828. if (!CreateDevice(&pDevice))
  2829. return;
  2830. if (GetTestParamUseWARP(UseWarpByDefault()) || IsDeviceBasicAdapter(pDevice)) {
  2831. WEX::Logging::Log::Comment(L"WARP does not support QuadRead in compute shaders.");
  2832. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  2833. return;
  2834. }
  2835. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2836. std::make_shared<st::ShaderOpSet>();
  2837. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2838. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("QuadRead");
  2839. LPCSTR CS = pShaderOp->CS;
  2840. struct Dispatch {
  2841. int x, y, z;
  2842. int mx, my, mz;
  2843. };
  2844. //std::vector<std::tuple<int, int, int, int, int>> dispatches =
  2845. std::vector<Dispatch> dispatches =
  2846. {
  2847. {32, 32, 1, 8, 8, 1},
  2848. {64, 4, 1, 64, 2, 1},
  2849. {1, 4, 64, 1, 4, 32},
  2850. {64, 1, 1, 64, 1, 1},
  2851. {1, 64, 1, 1, 64, 1},
  2852. {1, 1, 64, 1, 1, 64},
  2853. {16, 16, 3, 4, 4, 3},
  2854. {32, 3, 8, 8, 3, 2},
  2855. {3, 1, 64, 3, 1, 32}
  2856. };
  2857. for (Dispatch &D : dispatches) {
  2858. UINT width = D.x;
  2859. UINT height = D.y;
  2860. UINT depth = D.z;
  2861. UINT mwidth = D.mx;
  2862. UINT mheight = D.my;
  2863. UINT mdepth = D.mz;
  2864. // format compiler args
  2865. char compilerOptions[256];
  2866. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions),
  2867. "-D DISPATCHX=%d -D DISPATCHY=%d -D DISPATCHZ=%d "
  2868. "-D MESHDISPATCHX=%d -D MESHDISPATCHY=%d -D MESHDISPATCHZ=%d",
  2869. width, height, depth, mwidth, mheight, mdepth));
  2870. for (st::ShaderOpShader &S : pShaderOp->Shaders)
  2871. S.Arguments = compilerOptions;
  2872. pShaderOp->DispatchX = width;
  2873. pShaderOp->DispatchY = height;
  2874. pShaderOp->DispatchZ = depth;
  2875. // Test Compute Shader
  2876. pShaderOp->CS = CS;
  2877. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2878. MappedData data;
  2879. test->Test->GetReadBackData("U0", &data);
  2880. const UINT *pPixels = (UINT *)data.data();
  2881. // To find roughly the center for compute, divide the pixel count in half
  2882. // and truncate to next lowest power of 4 to start at a quad
  2883. UINT offsetCenter = ((UINT64)(width * height * depth)/2) & ~0x3;
  2884. // Test first, second and center quads
  2885. LogCommentFmt(L"Verifying QuadRead* in compute shader results");
  2886. VerifyQuadReadResults(pPixels, 0);
  2887. VerifyQuadReadResults(pPixels, 4);
  2888. VerifyQuadReadResults(pPixels, offsetCenter);
  2889. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2890. offsetCenter = ((UINT64)(mwidth * mheight * mdepth)/2) & ~0x3;
  2891. // Disable CS so mesh goes forward
  2892. pShaderOp->CS = nullptr;
  2893. test = RunShaderOpTestAfterParse(pDevice, m_support, "QuadRead", nullptr, ShaderOpSet);
  2894. test->Test->GetReadBackData("U1", &data);
  2895. pPixels = (UINT *)data.data();
  2896. // Test first, second and center quads
  2897. LogCommentFmt(L"Verifying QuadRead* in mesh shader results");
  2898. VerifyQuadReadResults(pPixels, 0);
  2899. VerifyQuadReadResults(pPixels, 4);
  2900. VerifyQuadReadResults(pPixels, offsetCenter);
  2901. test->Test->GetReadBackData("U2", &data);
  2902. pPixels = (UINT *)data.data();
  2903. // Test first, second and center quads
  2904. LogCommentFmt(L"Verifying QuadRead* in amplification shader results");
  2905. VerifyQuadReadResults(pPixels, 0);
  2906. VerifyQuadReadResults(pPixels, 4);
  2907. VerifyQuadReadResults(pPixels, offsetCenter);
  2908. }
  2909. }
  2910. }
  2911. void VerifySampleResults(const UINT *pPixels, UINT width) {
  2912. UINT xlod = 0;
  2913. UINT ylod = 0;
  2914. // Each pixel contains 4 samples and 4 LOD calculations.
  2915. // 2 of these (called 'left' and 'right') have X values that vary and a constant Y
  2916. // 2 others (called 'top' and 'bot') have Y values that vary and a constant X
  2917. // Only of the X variant sample results and one of the Y variant results
  2918. // are actually reported for the pixel.
  2919. // The other 2 serve as "helpers" to the other pixels in the quad.
  2920. // On the left side of the quad, the 'left' samples are reported.
  2921. // Op the top of the quad, the 'top' samples are reported and so on.
  2922. // The varying coordinate values alternate between zero and a
  2923. // value whose magnitude increases with the index.
  2924. // As a result, the LOD level should steadily increas.
  2925. // Due to vagaries of implementation, the same derivatives
  2926. // in both directions might result in different levels for different locations
  2927. // in the quad. So only comparisons between sample results and LOD calculations
  2928. // and ensuring that the LOD increased and reaches the max can be tested reliably.
  2929. for (unsigned i = 0; i < width; i++) {
  2930. // CalculateLOD and Sample from texture with mip levels containing LOD index should match
  2931. VERIFY_ARE_EQUAL(pPixels[4*i + 0], pPixels[4*i + 1]);
  2932. VERIFY_ARE_EQUAL(pPixels[4*i + 2], pPixels[4*i + 3]);
  2933. // Make sure LODs are ever climbing as magnitudes increase
  2934. VERIFY_IS_TRUE(pPixels[4*i] >= xlod);
  2935. xlod = pPixels[4*i];
  2936. VERIFY_IS_TRUE(pPixels[4*i + 2] >= ylod);
  2937. ylod = pPixels[4*i + 2];
  2938. }
  2939. // Make sure we reached the max lod level for both tracks
  2940. VERIFY_ARE_EQUAL(xlod, 6u);
  2941. VERIFY_ARE_EQUAL(ylod, 6u);
  2942. }
  2943. TEST_F(ExecutionTest, ComputeSampleTest) {
  2944. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  2945. CComPtr<IStream> pStream;
  2946. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  2947. CComPtr<ID3D12Device> pDevice;
  2948. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  2949. return;
  2950. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  2951. std::make_shared<st::ShaderOpSet>();
  2952. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  2953. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("ComputeSample");
  2954. // Initialize texture with the LOD number in each corresponding mip level
  2955. auto SampleInitFn = [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  2956. UNREFERENCED_PARAMETER(pShaderOp);
  2957. VERIFY_ARE_EQUAL(0, _stricmp(Name, "T0"));
  2958. D3D12_RESOURCE_DESC &texDesc = pShaderOp->GetResourceByName("T0")->Desc;
  2959. UINT texWidth = (UINT)texDesc.Width;
  2960. UINT texHeight = (UINT)texDesc.Height;
  2961. size_t size = sizeof(float) * texWidth * texHeight * 2;
  2962. Data.resize(size);
  2963. float *pPrimitives = (float *)Data.data();
  2964. float lod = 0.0;
  2965. int ix = 0;
  2966. while (texHeight > 0 && texWidth > 0) {
  2967. if(!texHeight) texHeight = 1;
  2968. if(!texWidth) texWidth = 1;
  2969. for (size_t j = 0; j < texHeight; ++j) {
  2970. for (size_t i = 0; i < texWidth; ++i) {
  2971. pPrimitives[ix++] = lod;
  2972. }
  2973. }
  2974. lod += 1.0;
  2975. texHeight >>= 1;
  2976. texWidth >>= 1;
  2977. }
  2978. };
  2979. LPCSTR CS2 = nullptr, AS2 = nullptr, MS2 = nullptr;
  2980. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  2981. if (!strcmp(S.Name, "CS2")) CS2 = S.Name;
  2982. if (!strcmp(S.Name, "AS2")) AS2 = S.Name;
  2983. if (!strcmp(S.Name, "MS2")) MS2 = S.Name;
  2984. }
  2985. // Test 1D compute shader
  2986. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2987. MappedData data;
  2988. test->Test->GetReadBackData("U0", &data);
  2989. const UINT *pPixels = (UINT *)data.data();
  2990. VerifySampleResults(pPixels, 84*4);
  2991. // Test 2D compute shader
  2992. pShaderOp->CS = CS2;
  2993. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  2994. test->Test->GetReadBackData("U0", &data);
  2995. pPixels = (UINT *)data.data();
  2996. VerifySampleResults(pPixels, 84*4);
  2997. if (DoesDeviceSupportMeshAmpDerivatives(pDevice)) {
  2998. // Disable CS so mesh goes forward
  2999. pShaderOp->CS = nullptr;
  3000. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3001. test->Test->GetReadBackData("U1", &data);
  3002. pPixels = (UINT *)data.data();
  3003. VerifySampleResults(pPixels, 116);
  3004. test->Test->GetReadBackData("U2", &data);
  3005. pPixels = (UINT *)data.data();
  3006. VerifySampleResults(pPixels, 84);
  3007. pShaderOp->AS = AS2;
  3008. pShaderOp->MS = MS2;
  3009. test = RunShaderOpTestAfterParse(pDevice, m_support, "ComputeSample", SampleInitFn, ShaderOpSet);
  3010. test->Test->GetReadBackData("U1", &data);
  3011. pPixels = (UINT *)data.data();
  3012. VerifySampleResults(pPixels, 116);
  3013. test->Test->GetReadBackData("U2", &data);
  3014. pPixels = (UINT *)data.data();
  3015. VerifySampleResults(pPixels, 84);
  3016. }
  3017. }
  3018. // Executing a simple binop to verify shadel model 6.1 support; runs with
  3019. // ShaderModel61.CoreRequirement
  3020. TEST_F(ExecutionTest, BasicShaderModel61) {
  3021. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_1);
  3022. }
  3023. // Executing a simple binop to verify shadel model 6.3 support; runs with
  3024. // ShaderModel63.CoreRequirement
  3025. TEST_F(ExecutionTest, BasicShaderModel63) {
  3026. RunBasicShaderModelTest(D3D_SHADER_MODEL_6_3);
  3027. }
  3028. void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
  3029. WEX::TestExecution::SetVerifyOutput verifySettings(
  3030. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  3031. CComPtr<ID3D12Device> pDevice;
  3032. if (!CreateDevice(&pDevice, shaderModel)) {
  3033. return;
  3034. }
  3035. char *pShaderModelStr;
  3036. if (shaderModel == D3D_SHADER_MODEL_6_1) {
  3037. pShaderModelStr = "cs_6_1";
  3038. } else if (shaderModel == D3D_SHADER_MODEL_6_3) {
  3039. pShaderModelStr = "cs_6_3";
  3040. } else {
  3041. DXASSERT_NOMSG("Invalid Shader Model Parameter");
  3042. pShaderModelStr = nullptr;
  3043. }
  3044. const char shaderTemplate[] =
  3045. "struct SBinaryOp { %s input1; %s input2; %s output; };"
  3046. "RWStructuredBuffer<SBinaryOp> g_buf : register(u0);"
  3047. "[numthreads(8,8,1)]"
  3048. "void main(uint GI : SV_GroupIndex) {"
  3049. " SBinaryOp l = g_buf[GI];"
  3050. " l.output = l.input1 + l.input2;"
  3051. " g_buf[GI] = l;"
  3052. "}";
  3053. char shader[sizeof(shaderTemplate) + 50];
  3054. // Run simple shader with float data types
  3055. char* sTy = "float";
  3056. float inputFloatPairs[] = { 1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f };
  3057. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3058. WEX::Logging::Log::Comment(L"BasicShaderModel float");
  3059. RunBasicShaderModelTest<float>(pDevice, pShaderModelStr, shader, inputFloatPairs, sizeof(inputFloatPairs) / (2 * sizeof(float)));
  3060. // Run simple shader with double data types
  3061. if (DoesDeviceSupportDouble(pDevice)) {
  3062. sTy = "double";
  3063. double inputDoublePairs[] = { 1.5891020, -2.8, 3.23e-5, 1 / 3, 181.91621, 14.654978 };
  3064. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3065. WEX::Logging::Log::Comment(L"BasicShaderModel double");
  3066. RunBasicShaderModelTest<double>(pDevice, pShaderModelStr, shader, inputDoublePairs, sizeof(inputDoublePairs) / (2 * sizeof(double)));
  3067. }
  3068. else {
  3069. // Optional feature, so it's correct to not support it if declared as such.
  3070. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  3071. }
  3072. // Run simple shader with int64 types
  3073. if (DoesDeviceSupportInt64(pDevice)) {
  3074. sTy = "int64_t";
  3075. int64_t inputInt64Pairs[] = { 1, -100, 6814684, -9814810, 654, 1021248900 };
  3076. VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
  3077. WEX::Logging::Log::Comment(L"BasicShaderModel int64_t");
  3078. RunBasicShaderModelTest<int64_t>(pDevice, pShaderModelStr, shader, inputInt64Pairs, sizeof(inputInt64Pairs) / (2 * sizeof(int64_t)));
  3079. }
  3080. else {
  3081. // Optional feature, so it's correct to not support it if declared as such.
  3082. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  3083. }
  3084. }
  3085. template <class Ty>
  3086. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString() {
  3087. DXASSERT_NOMSG("Unsupported type");
  3088. return "";
  3089. }
  3090. template <>
  3091. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<float>() {
  3092. return L"element #%u: input1 = %6.8f, input1 = %6.8f, output = %6.8f, expected = %6.8f";
  3093. }
  3094. template <>
  3095. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<double>() {
  3096. return BasicShaderModelTest_GetFormatString<float>();
  3097. }
  3098. template <>
  3099. const wchar_t* ExecutionTest::BasicShaderModelTest_GetFormatString<int64_t>() {
  3100. return L"element #%u: input1 = %ld, input1 = %ld, output = %ld, expected = %ld";
  3101. }
  3102. template <class Ty>
  3103. void ExecutionTest::RunBasicShaderModelTest(CComPtr<ID3D12Device> pDevice, const char *pShaderModelStr, const char *pShader,
  3104. Ty *pInputDataPairs, unsigned inputDataCount) {
  3105. struct SBinaryOp {
  3106. Ty input1;
  3107. Ty input2;
  3108. Ty output;
  3109. };
  3110. CComPtr<IStream> pStream;
  3111. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  3112. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  3113. pDevice, m_support, pStream, "BinaryFPOp",
  3114. // this callbacked is called when the test is creating the resource to run the test
  3115. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  3116. UNREFERENCED_PARAMETER(Name);
  3117. pShaderOp->Shaders.at(0).Target = pShaderModelStr;
  3118. pShaderOp->Shaders.at(0).Text = pShader;
  3119. size_t size = sizeof(SBinaryOp) * inputDataCount;
  3120. Data.resize(size);
  3121. SBinaryOp *pPrimitives = (SBinaryOp*)Data.data();
  3122. Ty *pIn = pInputDataPairs;
  3123. for (size_t i = 0; i < inputDataCount; i++, pIn += 2) {
  3124. SBinaryOp *p = &pPrimitives[i];
  3125. p->input1 = pIn[0];
  3126. p->input2 = pIn[1];
  3127. }
  3128. });
  3129. VERIFY_SUCCEEDED(S_OK);
  3130. MappedData data;
  3131. test->Test->GetReadBackData("SBinaryFPOp", &data);
  3132. SBinaryOp *pPrimitives = (SBinaryOp*)data.data();
  3133. const wchar_t* formatStr = BasicShaderModelTest_GetFormatString<Ty>();
  3134. Ty *pIn = pInputDataPairs;
  3135. for (unsigned i = 0; i < inputDataCount; i++, pIn += 2) {
  3136. Ty expValue = pIn[0] + pIn[1];
  3137. SBinaryOp *p = &pPrimitives[i];
  3138. LogCommentFmt(formatStr, i, pIn[0], pIn[1], p->output, expValue);
  3139. VERIFY_ARE_EQUAL(p->output, expValue);
  3140. }
  3141. }
  3142. // Resource structure for data-driven tests.
  3143. struct SUnaryFPOp {
  3144. float input;
  3145. float output;
  3146. };
  3147. struct SBinaryFPOp {
  3148. float input1;
  3149. float input2;
  3150. float output1;
  3151. float output2;
  3152. };
  3153. struct STertiaryFPOp {
  3154. float input1;
  3155. float input2;
  3156. float input3;
  3157. float output;
  3158. };
  3159. struct SUnaryHalfOp {
  3160. uint16_t input;
  3161. uint16_t output;
  3162. };
  3163. struct SBinaryHalfOp {
  3164. uint16_t input1;
  3165. uint16_t input2;
  3166. uint16_t output1;
  3167. uint16_t output2;
  3168. };
  3169. struct STertiaryHalfOp {
  3170. uint16_t input1;
  3171. uint16_t input2;
  3172. uint16_t input3;
  3173. uint16_t output;
  3174. };
  3175. struct SUnaryIntOp {
  3176. int input;
  3177. int output;
  3178. };
  3179. struct SUnaryUintOp {
  3180. unsigned int input;
  3181. unsigned int output;
  3182. };
  3183. struct SBinaryIntOp {
  3184. int input1;
  3185. int input2;
  3186. int output1;
  3187. int output2;
  3188. };
  3189. struct STertiaryIntOp {
  3190. int input1;
  3191. int input2;
  3192. int input3;
  3193. int output;
  3194. };
  3195. struct SBinaryUintOp {
  3196. unsigned int input1;
  3197. unsigned int input2;
  3198. unsigned int output1;
  3199. unsigned int output2;
  3200. };
  3201. struct STertiaryUintOp {
  3202. unsigned int input1;
  3203. unsigned int input2;
  3204. unsigned int input3;
  3205. unsigned int output;
  3206. };
  3207. struct SUnaryInt16Op {
  3208. short input;
  3209. short output;
  3210. };
  3211. struct SUnaryUint16Op {
  3212. unsigned short input;
  3213. unsigned short output;
  3214. };
  3215. struct SBinaryInt16Op {
  3216. short input1;
  3217. short input2;
  3218. short output1;
  3219. short output2;
  3220. };
  3221. struct STertiaryInt16Op {
  3222. short input1;
  3223. short input2;
  3224. short input3;
  3225. short output;
  3226. };
  3227. struct SBinaryUint16Op {
  3228. unsigned short input1;
  3229. unsigned short input2;
  3230. unsigned short output1;
  3231. unsigned short output2;
  3232. };
  3233. struct STertiaryUint16Op {
  3234. unsigned short input1;
  3235. unsigned short input2;
  3236. unsigned short input3;
  3237. unsigned short output;
  3238. };
  3239. // representation for HLSL float vectors
  3240. struct SDotOp {
  3241. XMFLOAT4 input1;
  3242. XMFLOAT4 input2;
  3243. float o_dot2;
  3244. float o_dot3;
  3245. float o_dot4;
  3246. };
  3247. struct Half2
  3248. {
  3249. uint16_t x;
  3250. uint16_t y;
  3251. Half2() = default;
  3252. Half2(const Half2&) = default;
  3253. Half2& operator=(const Half2&) = default;
  3254. Half2(Half2&&) = default;
  3255. Half2& operator=(Half2&&) = default;
  3256. constexpr Half2(uint16_t _x, uint16_t _y) : x(_x), y(_y) {}
  3257. explicit Half2(_In_reads_(2) const uint16_t *pArray) : x(pArray[0]), y(pArray[1]) {}
  3258. };
  3259. struct SDot2AddHalfOp {
  3260. Half2 input1;
  3261. Half2 input2;
  3262. float acc;
  3263. float result;
  3264. };
  3265. struct SDot4AddI8PackedOp {
  3266. uint32_t input1;
  3267. uint32_t input2;
  3268. int32_t acc;
  3269. int32_t result;
  3270. };
  3271. struct SDot4AddU8PackedOp {
  3272. uint32_t input1;
  3273. uint32_t input2;
  3274. uint32_t acc;
  3275. uint32_t result;
  3276. };
  3277. struct SMsad4 {
  3278. unsigned int ref;
  3279. XMUINT2 src;
  3280. XMUINT4 accum;
  3281. XMUINT4 result;
  3282. };
  3283. struct SPackUnpackOpOutPacked
  3284. {
  3285. uint32_t packedUint32;
  3286. uint32_t packedInt32;
  3287. uint32_t packedUint16;
  3288. uint32_t packedInt16;
  3289. uint32_t packedClampedUint32;
  3290. uint32_t packedClampedInt32;
  3291. uint32_t packedClampedUint16;
  3292. uint32_t packedClampedInt16;
  3293. };
  3294. struct SPackUnpackOpOutUnpacked {
  3295. std::array<uint32_t, 4> outputUint32;
  3296. std::array<int32_t, 4> outputInt32;
  3297. std::array<uint16_t, 4> outputUint16;
  3298. std::array<int16_t, 4> outputInt16;
  3299. std::array<uint32_t, 4> outputClampedUint32;
  3300. std::array<int32_t, 4> outputClampedInt32;
  3301. std::array<uint16_t, 4> outputClampedUint16;
  3302. std::array<int16_t, 4> outputClampedInt16;
  3303. };
  3304. // Parameter representation for taef data-driven tests
  3305. struct TableParameter {
  3306. LPCWSTR m_name;
  3307. enum TableParameterType {
  3308. INT8,
  3309. INT16,
  3310. INT32,
  3311. UINT,
  3312. FLOAT,
  3313. HALF,
  3314. DOUBLE,
  3315. STRING,
  3316. BOOL,
  3317. INT8_TABLE,
  3318. INT16_TABLE,
  3319. INT32_TABLE,
  3320. FLOAT_TABLE,
  3321. HALF_TABLE,
  3322. DOUBLE_TABLE,
  3323. STRING_TABLE,
  3324. UINT8_TABLE,
  3325. UINT16_TABLE,
  3326. UINT32_TABLE,
  3327. BOOL_TABLE
  3328. };
  3329. TableParameterType m_type;
  3330. bool m_required; // required parameter
  3331. int8_t m_int8;
  3332. int16_t m_int16;
  3333. int m_int32;
  3334. unsigned int m_uint;
  3335. float m_float;
  3336. uint16_t m_half; // no such thing as half type in c++. Use int16 instead
  3337. double m_double;
  3338. bool m_bool;
  3339. WEX::Common::String m_str;
  3340. std::vector<int8_t> m_int8Table;
  3341. std::vector<int16_t> m_int16Table;
  3342. std::vector<int> m_int32Table;
  3343. std::vector<uint8_t> m_uint8Table;
  3344. std::vector<uint16_t> m_uint16Table;
  3345. std::vector<unsigned int> m_uint32Table;
  3346. std::vector<float> m_floatTable;
  3347. std::vector<uint16_t> m_halfTable; // no such thing as half type in c++
  3348. std::vector<double> m_doubleTable;
  3349. std::vector<bool> m_boolTable;
  3350. std::vector<WEX::Common::String> m_StringTable;
  3351. };
  3352. class TableParameterHandler {
  3353. private:
  3354. HRESULT ParseTableRow();
  3355. public:
  3356. TableParameter* m_table;
  3357. size_t m_tableSize;
  3358. TableParameterHandler(TableParameter *pTable, size_t size) : m_table(pTable), m_tableSize(size) {
  3359. clearTableParameter();
  3360. VERIFY_SUCCEEDED(ParseTableRow());
  3361. }
  3362. TableParameter* GetTableParamByName(LPCWSTR name) {
  3363. for (size_t i = 0; i < m_tableSize; ++i) {
  3364. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3365. return &m_table[i];
  3366. }
  3367. }
  3368. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3369. return nullptr;
  3370. }
  3371. void clearTableParameter() {
  3372. for (size_t i = 0; i < m_tableSize; ++i) {
  3373. m_table[i].m_int32 = 0;
  3374. m_table[i].m_uint = 0;
  3375. m_table[i].m_double = 0;
  3376. m_table[i].m_bool = false;
  3377. m_table[i].m_str = WEX::Common::String();
  3378. }
  3379. }
  3380. template <class T1>
  3381. std::vector<T1> *GetDataArray(LPCWSTR name) {
  3382. return nullptr;
  3383. }
  3384. template <>
  3385. std::vector<int> *GetDataArray(LPCWSTR name) {
  3386. for (size_t i = 0; i < m_tableSize; ++i) {
  3387. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3388. return &(m_table[i].m_int32Table);
  3389. }
  3390. }
  3391. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3392. return nullptr;
  3393. }
  3394. template <>
  3395. std::vector<int8_t> *GetDataArray(LPCWSTR name) {
  3396. for (size_t i = 0; i < m_tableSize; ++i) {
  3397. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3398. return &(m_table[i].m_int8Table);
  3399. }
  3400. }
  3401. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3402. return nullptr;
  3403. }
  3404. template <>
  3405. std::vector<int16_t> *GetDataArray(LPCWSTR name) {
  3406. for (size_t i = 0; i < m_tableSize; ++i) {
  3407. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3408. return &(m_table[i].m_int16Table);
  3409. }
  3410. }
  3411. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3412. return nullptr;
  3413. }
  3414. template <>
  3415. std::vector<unsigned int> *GetDataArray(LPCWSTR name) {
  3416. for (size_t i = 0; i < m_tableSize; ++i) {
  3417. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3418. return &(m_table[i].m_uint32Table);
  3419. }
  3420. }
  3421. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3422. return nullptr;
  3423. }
  3424. template <>
  3425. std::vector<float> *GetDataArray(LPCWSTR name) {
  3426. for (size_t i = 0; i < m_tableSize; ++i) {
  3427. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3428. return &(m_table[i].m_floatTable);
  3429. }
  3430. }
  3431. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3432. return nullptr;
  3433. }
  3434. // TODO: uin16_t may be used to represent two different types when we introduce uint16
  3435. template <>
  3436. std::vector<uint16_t> *GetDataArray(LPCWSTR name) {
  3437. for (size_t i = 0; i < m_tableSize; ++i) {
  3438. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3439. return &(m_table[i].m_halfTable);
  3440. }
  3441. }
  3442. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3443. return nullptr;
  3444. }
  3445. template <>
  3446. std::vector<double> *GetDataArray(LPCWSTR name) {
  3447. for (size_t i = 0; i < m_tableSize; ++i) {
  3448. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3449. return &(m_table[i].m_doubleTable);
  3450. }
  3451. }
  3452. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3453. return nullptr;
  3454. }
  3455. template <>
  3456. std::vector<bool> *GetDataArray(LPCWSTR name) {
  3457. for (size_t i = 0; i < m_tableSize; ++i) {
  3458. if (_wcsicmp(name, m_table[i].m_name) == 0) {
  3459. return &(m_table[i].m_boolTable);
  3460. }
  3461. }
  3462. DXASSERT_ARGS(false, "Invalid Table Parameter Name %s", name);
  3463. return nullptr;
  3464. }
  3465. };
  3466. static TableParameter UnaryFPOpParameters[] = {
  3467. { L"ShaderOp.Target", TableParameter::STRING, true },
  3468. { L"ShaderOp.Text", TableParameter::STRING, true },
  3469. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3470. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3471. { L"Validation.Type", TableParameter::STRING, true },
  3472. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3473. { L"Warp.Version", TableParameter::UINT, false }
  3474. };
  3475. static TableParameter BinaryFPOpParameters[] = {
  3476. { L"ShaderOp.Target", TableParameter::STRING, true },
  3477. { L"ShaderOp.Text", TableParameter::STRING, true },
  3478. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3479. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3480. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3481. { L"Validation.Expected2", TableParameter::FLOAT_TABLE, false },
  3482. { L"Validation.Type", TableParameter::STRING, true },
  3483. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3484. };
  3485. static TableParameter TertiaryFPOpParameters[] = {
  3486. { L"ShaderOp.Target", TableParameter::STRING, true },
  3487. { L"ShaderOp.Text", TableParameter::STRING, true },
  3488. { L"Validation.Input1", TableParameter::FLOAT_TABLE, true },
  3489. { L"Validation.Input2", TableParameter::FLOAT_TABLE, true },
  3490. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3491. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3492. { L"Validation.Type", TableParameter::STRING, true },
  3493. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3494. };
  3495. static TableParameter UnaryHalfOpParameters[] = {
  3496. { L"ShaderOp.Target", TableParameter::STRING, true },
  3497. { L"ShaderOp.Text", TableParameter::STRING, true },
  3498. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3499. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3500. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3501. { L"Validation.Type", TableParameter::STRING, true },
  3502. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3503. { L"Warp.Version", TableParameter::UINT, false }
  3504. };
  3505. static TableParameter BinaryHalfOpParameters[] = {
  3506. { L"ShaderOp.Target", TableParameter::STRING, true },
  3507. { L"ShaderOp.Text", TableParameter::STRING, true },
  3508. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3509. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3510. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3511. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3512. { L"Validation.Expected2", TableParameter::HALF_TABLE, false },
  3513. { L"Validation.Type", TableParameter::STRING, true },
  3514. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3515. };
  3516. static TableParameter TertiaryHalfOpParameters[] = {
  3517. { L"ShaderOp.Target", TableParameter::STRING, true },
  3518. { L"ShaderOp.Text", TableParameter::STRING, true },
  3519. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3520. { L"Validation.Input1", TableParameter::HALF_TABLE, true },
  3521. { L"Validation.Input2", TableParameter::HALF_TABLE, true },
  3522. { L"Validation.Input3", TableParameter::HALF_TABLE, true },
  3523. { L"Validation.Expected1", TableParameter::HALF_TABLE, true },
  3524. { L"Validation.Type", TableParameter::STRING, true },
  3525. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3526. };
  3527. static TableParameter UnaryIntOpParameters[] = {
  3528. { L"ShaderOp.Target", TableParameter::STRING, true },
  3529. { L"ShaderOp.Text", TableParameter::STRING, true },
  3530. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3531. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3532. { L"Validation.Tolerance", TableParameter::INT32, true },
  3533. };
  3534. static TableParameter UnaryUintOpParameters[] = {
  3535. { L"ShaderOp.Target", TableParameter::STRING, true },
  3536. { L"ShaderOp.Text", TableParameter::STRING, true },
  3537. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3538. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3539. { L"Validation.Tolerance", TableParameter::INT32, true },
  3540. };
  3541. static TableParameter BinaryIntOpParameters[] = {
  3542. { L"ShaderOp.Target", TableParameter::STRING, true },
  3543. { L"ShaderOp.Text", TableParameter::STRING, true },
  3544. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3545. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3546. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3547. { L"Validation.Expected2", TableParameter::INT32_TABLE, false },
  3548. { L"Validation.Tolerance", TableParameter::INT32, true },
  3549. };
  3550. static TableParameter TertiaryIntOpParameters[] = {
  3551. { L"ShaderOp.Target", TableParameter::STRING, true },
  3552. { L"ShaderOp.Text", TableParameter::STRING, true },
  3553. { L"Validation.Input1", TableParameter::INT32_TABLE, true },
  3554. { L"Validation.Input2", TableParameter::INT32_TABLE, true },
  3555. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3556. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3557. { L"Validation.Tolerance", TableParameter::INT32, true },
  3558. };
  3559. static TableParameter BinaryUintOpParameters[] = {
  3560. { L"ShaderOp.Target", TableParameter::STRING, true },
  3561. { L"ShaderOp.Text", TableParameter::STRING, true },
  3562. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3563. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3564. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3565. { L"Validation.Expected2", TableParameter::UINT32_TABLE, false },
  3566. { L"Validation.Tolerance", TableParameter::INT32, true },
  3567. };
  3568. static TableParameter TertiaryUintOpParameters[] = {
  3569. { L"ShaderOp.Target", TableParameter::STRING, true },
  3570. { L"ShaderOp.Text", TableParameter::STRING, true },
  3571. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3572. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3573. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3574. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3575. { L"Validation.Tolerance", TableParameter::INT32, true },
  3576. };
  3577. static TableParameter UnaryInt16OpParameters[] = {
  3578. { L"ShaderOp.Target", TableParameter::STRING, true },
  3579. { L"ShaderOp.Text", TableParameter::STRING, true },
  3580. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3581. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3582. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3583. { L"Validation.Tolerance", TableParameter::INT32, true },
  3584. };
  3585. static TableParameter UnaryUint16OpParameters[] = {
  3586. { L"ShaderOp.Target", TableParameter::STRING, true },
  3587. { L"ShaderOp.Text", TableParameter::STRING, true },
  3588. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3589. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3590. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3591. { L"Validation.Tolerance", TableParameter::INT32, true },
  3592. };
  3593. static TableParameter BinaryInt16OpParameters[] = {
  3594. { L"ShaderOp.Target", TableParameter::STRING, true },
  3595. { L"ShaderOp.Text", TableParameter::STRING, true },
  3596. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3597. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3598. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3599. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3600. { L"Validation.Expected2", TableParameter::INT16_TABLE, false },
  3601. { L"Validation.Tolerance", TableParameter::INT32, true },
  3602. };
  3603. static TableParameter TertiaryInt16OpParameters[] = {
  3604. { L"ShaderOp.Target", TableParameter::STRING, true },
  3605. { L"ShaderOp.Text", TableParameter::STRING, true },
  3606. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3607. { L"Validation.Input1", TableParameter::INT16_TABLE, true },
  3608. { L"Validation.Input2", TableParameter::INT16_TABLE, true },
  3609. { L"Validation.Input3", TableParameter::INT16_TABLE, true },
  3610. { L"Validation.Expected1", TableParameter::INT16_TABLE, true },
  3611. { L"Validation.Tolerance", TableParameter::INT32, true },
  3612. };
  3613. static TableParameter BinaryUint16OpParameters[] = {
  3614. { L"ShaderOp.Target", TableParameter::STRING, true },
  3615. { L"ShaderOp.Text", TableParameter::STRING, true },
  3616. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3617. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3618. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3619. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3620. { L"Validation.Expected2", TableParameter::UINT16_TABLE, false },
  3621. { L"Validation.Tolerance", TableParameter::INT32, true },
  3622. };
  3623. static TableParameter TertiaryUint16OpParameters[] = {
  3624. { L"ShaderOp.Target", TableParameter::STRING, true },
  3625. { L"ShaderOp.Text", TableParameter::STRING, true },
  3626. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3627. { L"Validation.Input1", TableParameter::UINT16_TABLE, true },
  3628. { L"Validation.Input2", TableParameter::UINT16_TABLE, true },
  3629. { L"Validation.Input3", TableParameter::UINT16_TABLE, true },
  3630. { L"Validation.Expected1", TableParameter::UINT16_TABLE, true },
  3631. { L"Validation.Tolerance", TableParameter::INT32, true },
  3632. };
  3633. static TableParameter DotOpParameters[] = {
  3634. { L"ShaderOp.Target", TableParameter::STRING, true },
  3635. { L"ShaderOp.Text", TableParameter::STRING, true },
  3636. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3637. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3638. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3639. { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
  3640. { L"Validation.Expected3", TableParameter::STRING_TABLE, true },
  3641. { L"Validation.Type", TableParameter::STRING, true },
  3642. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3643. };
  3644. static TableParameter Dot2AddHalfOpParameters[] = {
  3645. { L"ShaderOp.Target", TableParameter::STRING, true },
  3646. { L"ShaderOp.Text", TableParameter::STRING, true },
  3647. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3648. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3649. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3650. { L"Validation.Input3", TableParameter::FLOAT_TABLE, true },
  3651. { L"Validation.Expected1", TableParameter::FLOAT_TABLE, true },
  3652. { L"Validation.Type", TableParameter::STRING, true },
  3653. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3654. };
  3655. static TableParameter Dot4AddI8PackedOpParameters[] = {
  3656. { L"ShaderOp.Target", TableParameter::STRING, true },
  3657. { L"ShaderOp.Text", TableParameter::STRING, true },
  3658. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3659. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3660. { L"Validation.Input3", TableParameter::INT32_TABLE, true },
  3661. { L"Validation.Expected1", TableParameter::INT32_TABLE, true },
  3662. };
  3663. static TableParameter Dot4AddU8PackedOpParameters[] = {
  3664. { L"ShaderOp.Target", TableParameter::STRING, true },
  3665. { L"ShaderOp.Text", TableParameter::STRING, true },
  3666. { L"Validation.Input1", TableParameter::UINT32_TABLE, true },
  3667. { L"Validation.Input2", TableParameter::UINT32_TABLE, true },
  3668. { L"Validation.Input3", TableParameter::UINT32_TABLE, true },
  3669. { L"Validation.Expected1", TableParameter::UINT32_TABLE, true },
  3670. };
  3671. static TableParameter Msad4OpParameters[] = {
  3672. { L"ShaderOp.Text", TableParameter::STRING, true },
  3673. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3674. { L"Validation.Input1", TableParameter::UINT32_TABLE, true},
  3675. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3676. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3677. { L"Validation.Expected1", TableParameter::STRING_TABLE, true }
  3678. };
  3679. static TableParameter WaveIntrinsicsActiveIntParameters[] = {
  3680. { L"ShaderOp.Name", TableParameter::STRING, true },
  3681. { L"ShaderOp.Text", TableParameter::STRING, true },
  3682. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3683. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3684. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3685. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3686. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3687. };
  3688. static TableParameter WaveIntrinsicsPrefixIntParameters[] = {
  3689. { L"ShaderOp.Name", TableParameter::STRING, true },
  3690. { L"ShaderOp.Text", TableParameter::STRING, true },
  3691. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3692. { L"Validation.InputSet1", TableParameter::INT32_TABLE, true },
  3693. { L"Validation.InputSet2", TableParameter::INT32_TABLE, false },
  3694. { L"Validation.InputSet3", TableParameter::INT32_TABLE, false },
  3695. { L"Validation.InputSet4", TableParameter::INT32_TABLE, false }
  3696. };
  3697. static TableParameter WaveIntrinsicsActiveUintParameters[] = {
  3698. { L"ShaderOp.Name", TableParameter::STRING, true },
  3699. { L"ShaderOp.Text", TableParameter::STRING, true },
  3700. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3701. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3702. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3703. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3704. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3705. };
  3706. static TableParameter WaveIntrinsicsPrefixUintParameters[] = {
  3707. { L"ShaderOp.Name", TableParameter::STRING, true },
  3708. { L"ShaderOp.Text", TableParameter::STRING, true },
  3709. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3710. { L"Validation.InputSet1", TableParameter::UINT32_TABLE, true },
  3711. { L"Validation.InputSet2", TableParameter::UINT32_TABLE, false },
  3712. { L"Validation.InputSet3", TableParameter::UINT32_TABLE, false },
  3713. { L"Validation.InputSet4", TableParameter::UINT32_TABLE, false }
  3714. };
  3715. static TableParameter WaveIntrinsicsMultiPrefixIntParameters[] = {
  3716. { L"ShaderOp.Name", TableParameter::STRING, true },
  3717. { L"ShaderOp.Target", TableParameter::STRING, true },
  3718. { L"ShaderOp.Text", TableParameter::STRING, true },
  3719. { L"Validation.Keys", TableParameter::INT32_TABLE, true },
  3720. { L"Validation.Values", TableParameter::INT32_TABLE, true },
  3721. };
  3722. static TableParameter WaveIntrinsicsMultiPrefixUintParameters[] = {
  3723. { L"ShaderOp.Name", TableParameter::STRING, true },
  3724. { L"ShaderOp.Target", TableParameter::STRING, true },
  3725. { L"ShaderOp.Text", TableParameter::STRING, true },
  3726. { L"Validation.Keys", TableParameter::UINT32_TABLE, true },
  3727. { L"Validation.Values", TableParameter::UINT32_TABLE, true },
  3728. };
  3729. static TableParameter WaveIntrinsicsActiveBoolParameters[] = {
  3730. { L"ShaderOp.Name", TableParameter::STRING, true },
  3731. { L"ShaderOp.Text", TableParameter::STRING, true },
  3732. { L"Validation.NumInputSet", TableParameter::UINT, true },
  3733. { L"Validation.InputSet1", TableParameter::BOOL_TABLE, true },
  3734. { L"Validation.InputSet2", TableParameter::BOOL_TABLE, false },
  3735. { L"Validation.InputSet3", TableParameter::BOOL_TABLE, false },
  3736. };
  3737. static TableParameter CBufferTestHalfParameters[] = {
  3738. { L"Validation.InputSet", TableParameter::HALF_TABLE, true },
  3739. };
  3740. static TableParameter DenormBinaryFPOpParameters[] = {
  3741. { L"ShaderOp.Target", TableParameter::STRING, true },
  3742. { L"ShaderOp.Text", TableParameter::STRING, true },
  3743. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3744. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3745. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3746. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3747. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3748. { L"Validation.Type", TableParameter::STRING, true },
  3749. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3750. };
  3751. static TableParameter DenormTertiaryFPOpParameters[] = {
  3752. { L"ShaderOp.Target", TableParameter::STRING, true },
  3753. { L"ShaderOp.Text", TableParameter::STRING, true },
  3754. { L"ShaderOp.Arguments", TableParameter::STRING, true },
  3755. { L"Validation.Input1", TableParameter::STRING_TABLE, true },
  3756. { L"Validation.Input2", TableParameter::STRING_TABLE, true },
  3757. { L"Validation.Input3", TableParameter::STRING_TABLE, true },
  3758. { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
  3759. { L"Validation.Expected2", TableParameter::STRING_TABLE, false },
  3760. { L"Validation.Type", TableParameter::STRING, true },
  3761. { L"Validation.Tolerance", TableParameter::DOUBLE, true },
  3762. };
  3763. static TableParameter PackUnpackOpParameters[] = {
  3764. { L"ShaderOp.Text", TableParameter::STRING, true },
  3765. { L"Validation.Type", TableParameter::STRING, true },
  3766. { L"Validation.Tolerance", TableParameter::UINT, true },
  3767. { L"Validation.Input", TableParameter::UINT32_TABLE, true },
  3768. };
  3769. static bool IsHexString(PCWSTR str, uint16_t *value) {
  3770. std::wstring wString(str);
  3771. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3772. LPCWSTR wstr = wString.c_str();
  3773. if (wcsncmp(wstr, L"0x", 2) == 0 || wcsncmp(wstr, L"0b", 2) == 0) {
  3774. *value = (uint16_t)wcstol(wstr, NULL, 0);
  3775. return true;
  3776. }
  3777. return false;
  3778. }
  3779. static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
  3780. std::wstring wString(str);
  3781. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3782. PCWSTR wstr = wString.data();
  3783. if (_wcsicmp(wstr, L"NaN") == 0) {
  3784. value = NAN;
  3785. } else if (_wcsicmp(wstr, L"-inf") == 0) {
  3786. value = -(INFINITY);
  3787. } else if (_wcsicmp(wstr, L"inf") == 0) {
  3788. value = INFINITY;
  3789. } else if (_wcsicmp(wstr, L"-denorm") == 0) {
  3790. value = -(FLT_MIN / 2);
  3791. } else if (_wcsicmp(wstr, L"denorm") == 0) {
  3792. value = FLT_MIN / 2;
  3793. } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
  3794. _wcsicmp(wstr, L"-0") == 0) {
  3795. value = -0.0f;
  3796. } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
  3797. _wcsicmp(wstr, L"0") == 0) {
  3798. value = 0.0f;
  3799. } else if (_wcsnicmp(wstr, L"0x", 2) == 0) { // For hex values, take values literally
  3800. unsigned temp_i = std::stoul(wstr, nullptr, 16);
  3801. value = (float&)temp_i;
  3802. }
  3803. else {
  3804. // evaluate the expression of wstring
  3805. double val = _wtof(wstr);
  3806. if (val == 0) {
  3807. LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
  3808. return E_FAIL;
  3809. }
  3810. value = (float)val;
  3811. }
  3812. return S_OK;
  3813. }
  3814. static HRESULT ParseDataToInt(PCWSTR str, int &value) {
  3815. std::wstring wString(str);
  3816. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3817. PCWSTR wstr = wString.data();
  3818. // evaluate the expression of string
  3819. if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
  3820. value = 0;
  3821. return S_OK;
  3822. }
  3823. int val = _wtoi(wstr);
  3824. if (val == 0) {
  3825. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3826. return E_FAIL;
  3827. }
  3828. value = val;
  3829. return S_OK;
  3830. }
  3831. static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
  3832. std::wstring wString(str);
  3833. wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
  3834. PCWSTR wstr = wString.data();
  3835. // evaluate the expression of string
  3836. if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
  3837. value = 0;
  3838. return S_OK;
  3839. }
  3840. wchar_t *end;
  3841. unsigned int val = std::wcstoul(wstr, &end, 0);
  3842. if (val == 0) {
  3843. LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
  3844. return E_FAIL;
  3845. }
  3846. value = val;
  3847. return S_OK;
  3848. }
  3849. static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
  3850. std::wstring wstr(str);
  3851. size_t curPosition = 0;
  3852. // parse a string of dot product separated by commas
  3853. for (size_t i = 0; i < count; ++i) {
  3854. size_t nextPosition = wstr.find(L",", curPosition);
  3855. if (FAILED(ParseDataToFloat(
  3856. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3857. *(ptr + i)))) {
  3858. return E_FAIL;
  3859. }
  3860. curPosition = nextPosition + 1;
  3861. }
  3862. return S_OK;
  3863. }
  3864. static HRESULT ParseDataToVectorHalf(PCWSTR str, uint16_t *ptr, size_t count) {
  3865. std::wstring wstr(str);
  3866. size_t curPosition = 0;
  3867. // parse a string of dot product separated by commas
  3868. for (size_t i = 0; i < count; ++i) {
  3869. size_t nextPosition = wstr.find(L",", curPosition);
  3870. float floatValue;
  3871. if (FAILED(ParseDataToFloat(
  3872. wstr.substr(curPosition, nextPosition - curPosition).data(), floatValue))) {
  3873. return E_FAIL;
  3874. }
  3875. *(ptr + i) = ConvertFloat32ToFloat16(floatValue);
  3876. curPosition = nextPosition + 1;
  3877. }
  3878. return S_OK;
  3879. }
  3880. static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
  3881. std::wstring wstr(str);
  3882. size_t curPosition = 0;
  3883. // parse a string of dot product separated by commas
  3884. for (size_t i = 0; i < count; ++i) {
  3885. size_t nextPosition = wstr.find(L",", curPosition);
  3886. if (FAILED(ParseDataToUint(
  3887. wstr.substr(curPosition, nextPosition - curPosition).data(),
  3888. *(ptr + i)))) {
  3889. return E_FAIL;
  3890. }
  3891. curPosition = nextPosition + 1;
  3892. }
  3893. return S_OK;
  3894. }
  3895. HRESULT TableParameterHandler::ParseTableRow() {
  3896. TableParameter *table = m_table;
  3897. for (unsigned int i = 0; i < m_tableSize; ++i) {
  3898. switch (table[i].m_type) {
  3899. case TableParameter::INT8:
  3900. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3901. table[i].m_int32)) && table[i].m_required) {
  3902. // TryGetValue does not suppport reading from int16
  3903. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3904. return E_FAIL;
  3905. }
  3906. table[i].m_int8 = (int8_t)(table[i].m_int32);
  3907. break;
  3908. case TableParameter::INT16:
  3909. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3910. table[i].m_int32)) && table[i].m_required) {
  3911. // TryGetValue does not suppport reading from int16
  3912. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3913. return E_FAIL;
  3914. }
  3915. table[i].m_int16 = (short)(table[i].m_int32);
  3916. break;
  3917. case TableParameter::INT32:
  3918. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3919. table[i].m_int32)) && table[i].m_required) {
  3920. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3921. return E_FAIL;
  3922. }
  3923. break;
  3924. case TableParameter::UINT:
  3925. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3926. table[i].m_uint)) && table[i].m_required) {
  3927. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3928. return E_FAIL;
  3929. }
  3930. break;
  3931. case TableParameter::DOUBLE:
  3932. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3933. table[i].m_name, table[i].m_double)) && table[i].m_required) {
  3934. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3935. return E_FAIL;
  3936. }
  3937. break;
  3938. case TableParameter::STRING:
  3939. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3940. table[i].m_str)) && table[i].m_required) {
  3941. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3942. return E_FAIL;
  3943. }
  3944. break;
  3945. case TableParameter::BOOL:
  3946. if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
  3947. table[i].m_str)) && table[i].m_bool) {
  3948. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3949. return E_FAIL;
  3950. }
  3951. break;
  3952. case TableParameter::INT8_TABLE: {
  3953. WEX::TestExecution::TestDataArray<int> tempTable;
  3954. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3955. table[i].m_name, tempTable)) && table[i].m_required) {
  3956. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3957. return E_FAIL;
  3958. }
  3959. // TryGetValue does not suppport reading from int8
  3960. table[i].m_int8Table.resize(tempTable.GetSize());
  3961. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3962. table[i].m_int8Table[j] = (int8_t)tempTable[j];
  3963. }
  3964. break;
  3965. }
  3966. case TableParameter::INT16_TABLE: {
  3967. WEX::TestExecution::TestDataArray<int> tempTable;
  3968. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3969. table[i].m_name, tempTable)) && table[i].m_required) {
  3970. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3971. return E_FAIL;
  3972. }
  3973. // TryGetValue does not suppport reading from int8
  3974. table[i].m_int16Table.resize(tempTable.GetSize());
  3975. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3976. table[i].m_int16Table[j] = (int16_t)tempTable[j];
  3977. }
  3978. break;
  3979. }case TableParameter::INT32_TABLE: {
  3980. WEX::TestExecution::TestDataArray<int> tempTable;
  3981. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3982. table[i].m_name, tempTable)) && table[i].m_required) {
  3983. // TryGetValue does not suppport reading from int8
  3984. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3985. return E_FAIL;
  3986. }
  3987. table[i].m_int32Table.resize(tempTable.GetSize());
  3988. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  3989. table[i].m_int32Table[j] = tempTable[j];
  3990. }
  3991. break;
  3992. }
  3993. case TableParameter::UINT8_TABLE: {
  3994. WEX::TestExecution::TestDataArray<int> tempTable;
  3995. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  3996. table[i].m_name, tempTable)) && table[i].m_required) {
  3997. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  3998. return E_FAIL;
  3999. }
  4000. // TryGetValue does not suppport reading from int8
  4001. table[i].m_int8Table.resize(tempTable.GetSize());
  4002. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4003. table[i].m_int8Table[j] = (uint8_t)tempTable[j];
  4004. }
  4005. break;
  4006. }
  4007. case TableParameter::UINT16_TABLE: {
  4008. WEX::TestExecution::TestDataArray<int> tempTable;
  4009. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4010. table[i].m_name, tempTable)) && table[i].m_required) {
  4011. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4012. return E_FAIL;
  4013. }
  4014. // TryGetValue does not suppport reading from int8
  4015. table[i].m_uint16Table.resize(tempTable.GetSize());
  4016. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4017. table[i].m_uint16Table[j] = (uint16_t)tempTable[j];
  4018. }
  4019. break;
  4020. }
  4021. case TableParameter::UINT32_TABLE: {
  4022. WEX::TestExecution::TestDataArray<unsigned int> tempTable;
  4023. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4024. table[i].m_name, tempTable)) && table[i].m_required) {
  4025. // TryGetValue does not suppport reading from int8
  4026. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4027. return E_FAIL;
  4028. }
  4029. table[i].m_uint32Table.resize(tempTable.GetSize());
  4030. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4031. table[i].m_uint32Table[j] = tempTable[j];
  4032. }
  4033. break;
  4034. }
  4035. case TableParameter::FLOAT_TABLE: {
  4036. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4037. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4038. table[i].m_name, tempTable)) && table[i].m_required) {
  4039. // TryGetValue does not suppport reading from int8
  4040. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4041. return E_FAIL;
  4042. }
  4043. table[i].m_floatTable.resize(tempTable.GetSize());
  4044. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4045. ParseDataToFloat(tempTable[j], table[i].m_floatTable[j]);
  4046. }
  4047. break;
  4048. }
  4049. case TableParameter::HALF_TABLE: {
  4050. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4051. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4052. table[i].m_name, tempTable)) && table[i].m_required) {
  4053. // TryGetValue does not suppport reading from int8
  4054. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4055. return E_FAIL;
  4056. }
  4057. table[i].m_halfTable.resize(tempTable.GetSize());
  4058. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4059. uint16_t value = 0;
  4060. if (IsHexString(tempTable[j], &value)) {
  4061. table[i].m_halfTable[j] = value;
  4062. }
  4063. else {
  4064. float val;
  4065. ParseDataToFloat(tempTable[j], val);
  4066. if (isdenorm(val))
  4067. table[i].m_halfTable[j] = signbit(val) ? Float16NegDenorm : Float16PosDenorm;
  4068. else
  4069. table[i].m_halfTable[j] = ConvertFloat32ToFloat16(val);
  4070. }
  4071. }
  4072. break;
  4073. }
  4074. case TableParameter::DOUBLE_TABLE: {
  4075. WEX::TestExecution::TestDataArray<double> tempTable;
  4076. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4077. table[i].m_name, tempTable)) && table[i].m_required) {
  4078. // TryGetValue does not suppport reading from int8
  4079. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4080. return E_FAIL;
  4081. }
  4082. table[i].m_doubleTable.resize(tempTable.GetSize());
  4083. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4084. table[i].m_doubleTable[j] = tempTable[j];
  4085. }
  4086. break;
  4087. }
  4088. case TableParameter::BOOL_TABLE: {
  4089. WEX::TestExecution::TestDataArray<bool> tempTable;
  4090. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4091. table[i].m_name, tempTable)) && table[i].m_required) {
  4092. // TryGetValue does not suppport reading from int8
  4093. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4094. return E_FAIL;
  4095. }
  4096. table[i].m_boolTable.resize(tempTable.GetSize());
  4097. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4098. table[i].m_boolTable[j] = tempTable[j];
  4099. }
  4100. break;
  4101. }
  4102. case TableParameter::STRING_TABLE: {
  4103. WEX::TestExecution::TestDataArray<WEX::Common::String> tempTable;
  4104. if (FAILED(WEX::TestExecution::TestData::TryGetValue(
  4105. table[i].m_name, tempTable)) && table[i].m_required) {
  4106. // TryGetValue does not suppport reading from int8
  4107. LogErrorFmt(L"Failed to get %s", table[i].m_name);
  4108. return E_FAIL;
  4109. }
  4110. table[i].m_StringTable.resize(tempTable.GetSize());
  4111. for (size_t j = 0, end = tempTable.GetSize(); j != end; ++j) {
  4112. table[i].m_StringTable[j] = tempTable[j];
  4113. }
  4114. break;
  4115. }
  4116. default:
  4117. DXASSERT_NOMSG("Invalid Parameter Type");
  4118. }
  4119. if (errno == ERANGE) {
  4120. LogErrorFmt(L"got out of range value for table %s", table[i].m_name);
  4121. return E_FAIL;
  4122. }
  4123. }
  4124. return S_OK;
  4125. }
  4126. static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
  4127. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4128. }
  4129. static void VerifyOutputWithExpectedValueUInt(uint32_t output, uint32_t ref, uint32_t tolerance) {
  4130. VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
  4131. }
  4132. static void VerifyOutputWithExpectedValueUInt4(XMUINT4 output, XMUINT4 ref) {
  4133. VERIFY_ARE_EQUAL(output.x, ref.x);
  4134. VERIFY_ARE_EQUAL(output.y, ref.y);
  4135. VERIFY_ARE_EQUAL(output.z, ref.z);
  4136. VERIFY_ARE_EQUAL(output.w, ref.w);
  4137. }
  4138. static void VerifyOutputWithExpectedValueFloat(
  4139. float output, float ref, LPCWSTR type, double tolerance,
  4140. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4141. if (_wcsicmp(type, L"Relative") == 0) {
  4142. VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode));
  4143. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4144. VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, (float)tolerance, mode));
  4145. } else if (_wcsicmp(type, L"ULP") == 0) {
  4146. VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance, mode));
  4147. } else {
  4148. LogErrorFmt(L"Failed to read comparison type %S", type);
  4149. }
  4150. }
  4151. static bool CompareOutputWithExpectedValueFloat(
  4152. float output, float ref, LPCWSTR type, double tolerance,
  4153. hlsl::DXIL::Float32DenormMode mode = hlsl::DXIL::Float32DenormMode::Any) {
  4154. if (_wcsicmp(type, L"Relative") == 0) {
  4155. return CompareFloatRelativeEpsilon(output, ref, (int)tolerance, mode);
  4156. } else if (_wcsicmp(type, L"Epsilon") == 0) {
  4157. return CompareFloatEpsilon(output, ref, (float)tolerance, mode);
  4158. } else if (_wcsicmp(type, L"ULP") == 0) {
  4159. return CompareFloatULP(output, ref, (int)tolerance, mode);
  4160. } else {
  4161. LogErrorFmt(L"Failed to read comparison type %S", type);
  4162. return false;
  4163. }
  4164. }
  4165. static void VerifyOutputWithExpectedValueHalf(
  4166. uint16_t output, uint16_t ref, LPCWSTR type, double tolerance) {
  4167. if (_wcsicmp(type, L"Relative") == 0) {
  4168. VERIFY_IS_TRUE(CompareHalfRelativeEpsilon(output, ref, (int)tolerance));
  4169. }
  4170. else if (_wcsicmp(type, L"Epsilon") == 0) {
  4171. VERIFY_IS_TRUE(CompareHalfEpsilon(output, ref, (float)tolerance));
  4172. }
  4173. else if (_wcsicmp(type, L"ULP") == 0) {
  4174. VERIFY_IS_TRUE(CompareHalfULP(output, ref, (float)tolerance));
  4175. }
  4176. else {
  4177. LogErrorFmt(L"Failed to read comparison type %S", type);
  4178. }
  4179. }
  4180. TEST_F(ExecutionTest, UnaryFloatOpTest) {
  4181. WEX::TestExecution::SetVerifyOutput verifySettings(
  4182. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4183. CComPtr<IStream> pStream;
  4184. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4185. CComPtr<ID3D12Device> pDevice;
  4186. if (!CreateDevice(&pDevice)) {
  4187. return;
  4188. }
  4189. // Read data from the table
  4190. int tableSize = sizeof(UnaryFPOpParameters) / sizeof(TableParameter);
  4191. TableParameterHandler handler(UnaryFPOpParameters, tableSize);
  4192. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4193. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4194. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4195. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4196. return;
  4197. }
  4198. std::vector<float> *Validation_Input =
  4199. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4200. std::vector<float> *Validation_Expected =
  4201. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4202. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4203. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4204. size_t count = Validation_Input->size();
  4205. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4206. pDevice, m_support, pStream, "UnaryFPOp",
  4207. // this callbacked is called when the test
  4208. // is creating the resource to run the test
  4209. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4210. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4211. size_t size = sizeof(SUnaryFPOp) * count;
  4212. Data.resize(size);
  4213. SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
  4214. for (size_t i = 0; i < count; ++i) {
  4215. SUnaryFPOp *p = &pPrimitives[i];
  4216. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4217. }
  4218. // use shader from data table
  4219. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4220. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4221. });
  4222. MappedData data;
  4223. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4224. SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
  4225. WEX::TestExecution::DisableVerifyExceptions dve;
  4226. for (unsigned i = 0; i < count; ++i) {
  4227. SUnaryFPOp *p = &pPrimitives[i];
  4228. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4229. LogCommentFmt(
  4230. L"element #%u, input = %6.8f, output = %6.8f, expected = %6.8f", i,
  4231. p->input, p->output, val);
  4232. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
  4233. }
  4234. }
  4235. TEST_F(ExecutionTest, BinaryFloatOpTest) {
  4236. WEX::TestExecution::SetVerifyOutput verifySettings(
  4237. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4238. CComPtr<IStream> pStream;
  4239. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4240. CComPtr<ID3D12Device> pDevice;
  4241. if (!CreateDevice(&pDevice)) {
  4242. return;
  4243. }
  4244. // Read data from the table
  4245. int tableSize = sizeof(BinaryFPOpParameters) / sizeof(TableParameter);
  4246. TableParameterHandler handler(BinaryFPOpParameters, tableSize);
  4247. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4248. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4249. std::vector<float> *Validation_Input1 =
  4250. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4251. std::vector<float> *Validation_Input2 =
  4252. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4253. std::vector<float> *Validation_Expected1 =
  4254. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4255. std::vector<float> *Validation_Expected2 =
  4256. &(handler.GetTableParamByName(L"Validation.Expected2")->m_floatTable);
  4257. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4258. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4259. size_t count = Validation_Input1->size();
  4260. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4261. pDevice, m_support, pStream, "BinaryFPOp",
  4262. // this callbacked is called when the test
  4263. // is creating the resource to run the test
  4264. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4265. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4266. size_t size = sizeof(SBinaryFPOp) * count;
  4267. Data.resize(size);
  4268. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  4269. for (size_t i = 0; i < count; ++i) {
  4270. SBinaryFPOp *p = &pPrimitives[i];
  4271. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4272. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4273. }
  4274. // use shader from data table
  4275. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4276. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4277. });
  4278. MappedData data;
  4279. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4280. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  4281. WEX::TestExecution::DisableVerifyExceptions dve;
  4282. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4283. if (numExpected == 2) {
  4284. for (unsigned i = 0; i < count; ++i) {
  4285. SBinaryFPOp *p = &pPrimitives[i];
  4286. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4287. float val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4288. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4289. L"%6.8f, expected1 = %6.8f, output2 = %6.8f, expected2 = %6.8f",
  4290. i, p->input1, p->input2, p->output1, val1, p->output2,
  4291. val2);
  4292. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4293. Validation_Tolerance);
  4294. VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
  4295. Validation_Tolerance);
  4296. }
  4297. }
  4298. else if (numExpected == 1) {
  4299. for (unsigned i = 0; i < count; ++i) {
  4300. SBinaryFPOp *p = &pPrimitives[i];
  4301. float val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4302. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output1 = "
  4303. L"%6.8f, expected1 = %6.8f",
  4304. i, p->input1, p->input2, p->output1, val1);
  4305. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  4306. Validation_Tolerance);
  4307. }
  4308. }
  4309. else {
  4310. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4311. }
  4312. }
  4313. TEST_F(ExecutionTest, TertiaryFloatOpTest) {
  4314. WEX::TestExecution::SetVerifyOutput verifySettings(
  4315. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4316. CComPtr<IStream> pStream;
  4317. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4318. CComPtr<ID3D12Device> pDevice;
  4319. if (!CreateDevice(&pDevice)) {
  4320. return;
  4321. }
  4322. // Read data from the table
  4323. int tableSize = sizeof(TertiaryFPOpParameters) / sizeof(TableParameter);
  4324. TableParameterHandler handler(TertiaryFPOpParameters, tableSize);
  4325. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4326. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4327. std::vector<float> *Validation_Input1 =
  4328. &(handler.GetTableParamByName(L"Validation.Input1")->m_floatTable);
  4329. std::vector<float> *Validation_Input2 =
  4330. &(handler.GetTableParamByName(L"Validation.Input2")->m_floatTable);
  4331. std::vector<float> *Validation_Input3 =
  4332. &(handler.GetTableParamByName(L"Validation.Input3")->m_floatTable);
  4333. std::vector<float> *Validation_Expected =
  4334. &(handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable);
  4335. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4336. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4337. size_t count = Validation_Input1->size();
  4338. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4339. pDevice, m_support, pStream, "TertiaryFPOp",
  4340. // this callbacked is called when the test
  4341. // is creating the resource to run the test
  4342. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4343. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4344. size_t size = sizeof(STertiaryFPOp) * count;
  4345. Data.resize(size);
  4346. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  4347. for (size_t i = 0; i < count; ++i) {
  4348. STertiaryFPOp *p = &pPrimitives[i];
  4349. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4350. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4351. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4352. }
  4353. // use shader from data table
  4354. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4355. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4356. });
  4357. MappedData data;
  4358. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4359. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  4360. WEX::TestExecution::DisableVerifyExceptions dve;
  4361. for (unsigned i = 0; i < count; ++i) {
  4362. STertiaryFPOp *p = &pPrimitives[i];
  4363. float val = (*Validation_Expected)[i % Validation_Expected->size()];
  4364. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output1 = "
  4365. L"%6.8f, expected = %6.8f",
  4366. i, p->input1, p->input2, p->input3, p->output, val);
  4367. VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
  4368. Validation_Tolerance);
  4369. }
  4370. }
  4371. TEST_F(ExecutionTest, UnaryHalfOpTest) {
  4372. WEX::TestExecution::SetVerifyOutput verifySettings(
  4373. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4374. CComPtr<IStream> pStream;
  4375. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4376. CComPtr<ID3D12Device> pDevice;
  4377. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4378. return;
  4379. }
  4380. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4381. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4382. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4383. return;
  4384. }
  4385. // Read data from the table
  4386. int tableSize = sizeof(UnaryHalfOpParameters) / sizeof(TableParameter);
  4387. TableParameterHandler handler(UnaryHalfOpParameters, tableSize);
  4388. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4389. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4390. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4391. unsigned int WarpVersion = handler.GetTableParamByName(L"Warp.Version")->m_uint;
  4392. if (GetTestParamUseWARP(true) && !IsValidWarpDllVersion(WarpVersion)) {
  4393. return;
  4394. }
  4395. std::vector<uint16_t> *Validation_Input =
  4396. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4397. std::vector<uint16_t> *Validation_Expected =
  4398. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4399. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4400. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4401. size_t count = Validation_Input->size();
  4402. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4403. pDevice, m_support, pStream, "UnaryFPOp",
  4404. // this callbacked is called when the test
  4405. // is creating the resource to run the test
  4406. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4407. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
  4408. size_t size = sizeof(SUnaryHalfOp) * count;
  4409. Data.resize(size);
  4410. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp *)Data.data();
  4411. for (size_t i = 0; i < count; ++i) {
  4412. SUnaryHalfOp *p = &pPrimitives[i];
  4413. p->input = (*Validation_Input)[i % Validation_Input->size()];
  4414. }
  4415. // use shader from data table
  4416. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4417. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4418. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4419. });
  4420. MappedData data;
  4421. test->Test->GetReadBackData("SUnaryFPOp", &data);
  4422. SUnaryHalfOp *pPrimitives = (SUnaryHalfOp*)data.data();
  4423. WEX::TestExecution::DisableVerifyExceptions dve;
  4424. for (unsigned i = 0; i < count; ++i) {
  4425. SUnaryHalfOp *p = &pPrimitives[i];
  4426. uint16_t expected = (*Validation_Expected)[i % Validation_Input->size()];
  4427. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4428. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4429. i, ConvertFloat16ToFloat32(p->input), p->input,
  4430. ConvertFloat16ToFloat32(p->output), p->output,
  4431. ConvertFloat16ToFloat32(expected), expected);
  4432. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4433. }
  4434. }
  4435. TEST_F(ExecutionTest, BinaryHalfOpTest) {
  4436. WEX::TestExecution::SetVerifyOutput verifySettings(
  4437. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4438. CComPtr<IStream> pStream;
  4439. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4440. CComPtr<ID3D12Device> pDevice;
  4441. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4442. return;
  4443. }
  4444. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4445. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4446. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4447. return;
  4448. }
  4449. // Read data from the table
  4450. int tableSize = sizeof(BinaryHalfOpParameters) / sizeof(TableParameter);
  4451. TableParameterHandler handler(BinaryHalfOpParameters, tableSize);
  4452. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4453. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4454. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4455. std::vector<uint16_t> *Validation_Input1 =
  4456. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4457. std::vector<uint16_t> *Validation_Input2 =
  4458. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4459. std::vector<uint16_t> *Validation_Expected1 =
  4460. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4461. std::vector<uint16_t> *Validation_Expected2 =
  4462. &(handler.GetTableParamByName(L"Validation.Expected2")->m_halfTable);
  4463. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4464. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4465. size_t count = Validation_Input1->size();
  4466. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4467. pDevice, m_support, pStream, "BinaryFPOp",
  4468. // this callbacked is called when the test
  4469. // is creating the resource to run the test
  4470. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4471. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  4472. size_t size = sizeof(SBinaryHalfOp) * count;
  4473. Data.resize(size);
  4474. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)Data.data();
  4475. for (size_t i = 0; i < count; ++i) {
  4476. SBinaryHalfOp *p = &pPrimitives[i];
  4477. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4478. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4479. }
  4480. // use shader from data table
  4481. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4482. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4483. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4484. });
  4485. MappedData data;
  4486. test->Test->GetReadBackData("SBinaryFPOp", &data);
  4487. SBinaryHalfOp *pPrimitives = (SBinaryHalfOp *)data.data();
  4488. WEX::TestExecution::DisableVerifyExceptions dve;
  4489. unsigned numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4490. if (numExpected == 2) {
  4491. for (unsigned i = 0; i < count; ++i) {
  4492. SBinaryHalfOp *p = &pPrimitives[i];
  4493. uint16_t expected1 = (*Validation_Expected1)[i % Validation_Input1->size()];
  4494. uint16_t expected2 = (*Validation_Expected2)[i % Validation_Input2->size()];
  4495. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), output1 = "
  4496. L"%6.8f(0x%04x), expected1 = %6.8f(0x%04x), output2 = %6.8f(0x%04x), expected2 = %6.8f(0x%04x)",
  4497. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4498. ConvertFloat16ToFloat32(p->input2), p->input2,
  4499. ConvertFloat16ToFloat32(p->output1), p->output1,
  4500. ConvertFloat16ToFloat32(p->output2), p->output2,
  4501. ConvertFloat16ToFloat32(expected1), expected1,
  4502. ConvertFloat16ToFloat32(expected2), expected2);
  4503. VerifyOutputWithExpectedValueHalf(p->output1, expected1, Validation_Type, Validation_Tolerance);
  4504. VerifyOutputWithExpectedValueHalf(p->output2, expected2, Validation_Type, Validation_Tolerance);
  4505. }
  4506. }
  4507. else if (numExpected == 1) {
  4508. for (unsigned i = 0; i < count; ++i) {
  4509. uint16_t expected = (*Validation_Expected1)[i % Validation_Input1->size()];
  4510. SBinaryHalfOp *p = &pPrimitives[i];
  4511. LogCommentFmt(L"element #%u, input = %6.8f(0x%04x), output = "
  4512. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4513. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4514. ConvertFloat16ToFloat32(p->output1), p->output1,
  4515. ConvertFloat16ToFloat32(expected), expected);
  4516. VerifyOutputWithExpectedValueHalf(p->output1, expected, Validation_Type, Validation_Tolerance);
  4517. }
  4518. }
  4519. else {
  4520. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4521. }
  4522. }
  4523. TEST_F(ExecutionTest, TertiaryHalfOpTest) {
  4524. WEX::TestExecution::SetVerifyOutput verifySettings(
  4525. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4526. CComPtr<IStream> pStream;
  4527. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4528. CComPtr<ID3D12Device> pDevice;
  4529. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4530. return;
  4531. }
  4532. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4533. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4534. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4535. return;
  4536. }
  4537. // Read data from the table
  4538. int tableSize = sizeof(TertiaryHalfOpParameters) / sizeof(TableParameter);
  4539. TableParameterHandler handler(TertiaryHalfOpParameters, tableSize);
  4540. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4541. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4542. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4543. std::vector<uint16_t> *Validation_Input1 =
  4544. &(handler.GetTableParamByName(L"Validation.Input1")->m_halfTable);
  4545. std::vector<uint16_t> *Validation_Input2 =
  4546. &(handler.GetTableParamByName(L"Validation.Input2")->m_halfTable);
  4547. std::vector<uint16_t> *Validation_Input3 =
  4548. &(handler.GetTableParamByName(L"Validation.Input3")->m_halfTable);
  4549. std::vector<uint16_t> *Validation_Expected =
  4550. &(handler.GetTableParamByName(L"Validation.Expected1")->m_halfTable);
  4551. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  4552. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  4553. size_t count = Validation_Input1->size();
  4554. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4555. pDevice, m_support, pStream, "TertiaryFPOp",
  4556. // this callbacked is called when the test
  4557. // is creating the resource to run the test
  4558. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4559. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  4560. size_t size = sizeof(STertiaryHalfOp) * count;
  4561. Data.resize(size);
  4562. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)Data.data();
  4563. for (size_t i = 0; i < count; ++i) {
  4564. STertiaryHalfOp *p = &pPrimitives[i];
  4565. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4566. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4567. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4568. }
  4569. // use shader from data table
  4570. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4571. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4572. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  4573. });
  4574. MappedData data;
  4575. test->Test->GetReadBackData("STertiaryFPOp", &data);
  4576. STertiaryHalfOp *pPrimitives = (STertiaryHalfOp *)data.data();
  4577. WEX::TestExecution::DisableVerifyExceptions dve;
  4578. for (unsigned i = 0; i < count; ++i) {
  4579. STertiaryHalfOp *p = &pPrimitives[i];
  4580. uint16_t expected = (*Validation_Expected)[i % Validation_Expected->size()];
  4581. LogCommentFmt(L"element #%u, input1 = %6.8f(0x%04x), input2 = %6.8f(0x%04x), input3 = %6.8f(0x%04x), output = "
  4582. L"%6.8f(0x%04x), expected = %6.8f(0x%04x)",
  4583. i, ConvertFloat16ToFloat32(p->input1), p->input1,
  4584. ConvertFloat16ToFloat32(p->input2), p->input2,
  4585. ConvertFloat16ToFloat32(p->input3), p->input3,
  4586. ConvertFloat16ToFloat32(p->output), p->output,
  4587. ConvertFloat16ToFloat32(expected), expected);
  4588. VerifyOutputWithExpectedValueHalf(p->output, expected, Validation_Type, Validation_Tolerance);
  4589. }
  4590. }
  4591. TEST_F(ExecutionTest, UnaryIntOpTest) {
  4592. WEX::TestExecution::SetVerifyOutput verifySettings(
  4593. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4594. CComPtr<IStream> pStream;
  4595. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4596. CComPtr<ID3D12Device> pDevice;
  4597. if (!CreateDevice(&pDevice)) {
  4598. return;
  4599. }
  4600. // Read data from the table
  4601. int tableSize = sizeof(UnaryIntOpParameters) / sizeof(TableParameter);
  4602. TableParameterHandler handler(UnaryIntOpParameters, tableSize);
  4603. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4604. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4605. std::vector<int> *Validation_Input =
  4606. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4607. std::vector<int> *Validation_Expected =
  4608. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4609. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4610. size_t count = Validation_Input->size();
  4611. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4612. pDevice, m_support, pStream, "UnaryIntOp",
  4613. // this callbacked is called when the test
  4614. // is creating the resource to run the test
  4615. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4616. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  4617. size_t size = sizeof(SUnaryIntOp) * count;
  4618. Data.resize(size);
  4619. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
  4620. for (size_t i = 0; i < count; ++i) {
  4621. SUnaryIntOp *p = &pPrimitives[i];
  4622. int val = (*Validation_Input)[i % Validation_Input->size()];
  4623. p->input = val;
  4624. }
  4625. // use shader data table
  4626. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4627. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4628. });
  4629. MappedData data;
  4630. test->Test->GetReadBackData("SUnaryIntOp", &data);
  4631. SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
  4632. WEX::TestExecution::DisableVerifyExceptions dve;
  4633. for (unsigned i = 0; i < count; ++i) {
  4634. SUnaryIntOp *p = &pPrimitives[i];
  4635. int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4636. LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
  4637. L"expected = %11i(0x%08x)",
  4638. i, p->input, p->input, p->output, p->output, val, val);
  4639. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4640. }
  4641. }
  4642. TEST_F(ExecutionTest, UnaryUintOpTest) {
  4643. WEX::TestExecution::SetVerifyOutput verifySettings(
  4644. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4645. CComPtr<IStream> pStream;
  4646. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4647. CComPtr<ID3D12Device> pDevice;
  4648. if (!CreateDevice(&pDevice)) {
  4649. return;
  4650. }
  4651. // Read data from the table
  4652. int tableSize = sizeof(UnaryUintOpParameters) / sizeof(TableParameter);
  4653. TableParameterHandler handler(UnaryUintOpParameters, tableSize);
  4654. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4655. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4656. std::vector<unsigned int> *Validation_Input =
  4657. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4658. std::vector<unsigned int> *Validation_Expected =
  4659. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4660. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4661. size_t count = Validation_Input->size();
  4662. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4663. pDevice, m_support, pStream, "UnaryUintOp",
  4664. // this callbacked is called when the test
  4665. // is creating the resource to run the test
  4666. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4667. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  4668. size_t size = sizeof(SUnaryUintOp) * count;
  4669. Data.resize(size);
  4670. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
  4671. for (size_t i = 0; i < count; ++i) {
  4672. SUnaryUintOp *p = &pPrimitives[i];
  4673. unsigned int val = (*Validation_Input)[i % Validation_Input->size()];
  4674. p->input = val;
  4675. }
  4676. // use shader data table
  4677. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4678. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4679. });
  4680. MappedData data;
  4681. test->Test->GetReadBackData("SUnaryUintOp", &data);
  4682. SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
  4683. WEX::TestExecution::DisableVerifyExceptions dve;
  4684. for (unsigned i = 0; i < count; ++i) {
  4685. SUnaryUintOp *p = &pPrimitives[i];
  4686. unsigned int val = (*Validation_Expected)[i % Validation_Expected->size()];
  4687. LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
  4688. L"expected = %11u(0x%08x)",
  4689. i, p->input, p->input, p->output, p->output, val, val);
  4690. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  4691. }
  4692. }
  4693. TEST_F(ExecutionTest, BinaryIntOpTest) {
  4694. WEX::TestExecution::SetVerifyOutput verifySettings(
  4695. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4696. CComPtr<IStream> pStream;
  4697. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4698. CComPtr<ID3D12Device> pDevice;
  4699. if (!CreateDevice(&pDevice)) {
  4700. return;
  4701. }
  4702. // Read data from the table
  4703. size_t tableSize = sizeof(BinaryIntOpParameters) / sizeof(TableParameter);
  4704. TableParameterHandler handler(BinaryIntOpParameters, tableSize);
  4705. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4706. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4707. std::vector<int> *Validation_Input1 =
  4708. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4709. std::vector<int> *Validation_Input2 =
  4710. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4711. std::vector<int> *Validation_Expected1 =
  4712. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4713. std::vector<int> *Validation_Expected2 =
  4714. &handler.GetTableParamByName(L"Validation.Expected2")->m_int32Table;
  4715. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4716. size_t count = Validation_Input1->size();
  4717. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4718. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4719. pDevice, m_support, pStream, "BinaryIntOp",
  4720. // this callbacked is called when the test
  4721. // is creating the resource to run the test
  4722. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4723. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  4724. size_t size = sizeof(SBinaryIntOp) * count;
  4725. Data.resize(size);
  4726. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
  4727. for (size_t i = 0; i < count; ++i) {
  4728. SBinaryIntOp *p = &pPrimitives[i];
  4729. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4730. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4731. p->input1 = val1;
  4732. p->input2 = val2;
  4733. }
  4734. // use shader from data table
  4735. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4736. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4737. });
  4738. MappedData data;
  4739. test->Test->GetReadBackData("SBinaryIntOp", &data);
  4740. SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
  4741. WEX::TestExecution::DisableVerifyExceptions dve;
  4742. if (numExpected == 2) {
  4743. for (unsigned i = 0; i < count; ++i) {
  4744. SBinaryIntOp *p = &pPrimitives[i];
  4745. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4746. int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4747. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4748. L"%11i(0x%08x), output1 = "
  4749. L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
  4750. L"%11i(0x%08x), expected2 = %11i(0x%08x)",
  4751. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4752. p->output1, val1, val1, p->output2, p->output2, val2,
  4753. val2);
  4754. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4755. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4756. }
  4757. }
  4758. else if (numExpected == 1) {
  4759. for (unsigned i = 0; i < count; ++i) {
  4760. SBinaryIntOp *p = &pPrimitives[i];
  4761. int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4762. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4763. L"%11i(0x%08x), output = "
  4764. L"%11i(0x%08x), expected = %11i(0x%08x)", i,
  4765. p->input1, p->input1, p->input2, p->input2,
  4766. p->output1, p->output1, val1, val1);
  4767. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4768. }
  4769. }
  4770. else {
  4771. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4772. }
  4773. }
  4774. TEST_F(ExecutionTest, TertiaryIntOpTest) {
  4775. WEX::TestExecution::SetVerifyOutput verifySettings(
  4776. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4777. CComPtr<IStream> pStream;
  4778. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4779. CComPtr<ID3D12Device> pDevice;
  4780. if (!CreateDevice(&pDevice)) {
  4781. return;
  4782. }
  4783. // Read data from the table
  4784. size_t tableSize = sizeof(TertiaryIntOpParameters) / sizeof(TableParameter);
  4785. TableParameterHandler handler(TertiaryIntOpParameters, tableSize);
  4786. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4787. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4788. std::vector<int> *Validation_Input1 =
  4789. &handler.GetTableParamByName(L"Validation.Input1")->m_int32Table;
  4790. std::vector<int> *Validation_Input2 =
  4791. &handler.GetTableParamByName(L"Validation.Input2")->m_int32Table;
  4792. std::vector<int> *Validation_Input3 =
  4793. &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  4794. std::vector<int> *Validation_Expected =
  4795. &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  4796. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4797. size_t count = Validation_Input1->size();
  4798. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4799. pDevice, m_support, pStream, "TertiaryIntOp",
  4800. // this callbacked is called when the test
  4801. // is creating the resource to run the test
  4802. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4803. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  4804. size_t size = sizeof(STertiaryIntOp) * count;
  4805. Data.resize(size);
  4806. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
  4807. for (size_t i = 0; i < count; ++i) {
  4808. STertiaryIntOp *p = &pPrimitives[i];
  4809. int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4810. int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4811. int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4812. p->input1 = val1;
  4813. p->input2 = val2;
  4814. p->input3 = val3;
  4815. }
  4816. // use shader from data table
  4817. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4818. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4819. });
  4820. MappedData data;
  4821. test->Test->GetReadBackData("STertiaryIntOp", &data);
  4822. STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
  4823. WEX::TestExecution::DisableVerifyExceptions dve;
  4824. for (unsigned i = 0; i < count; ++i) {
  4825. STertiaryIntOp *p = &pPrimitives[i];
  4826. int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4827. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  4828. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  4829. L"%11i(0x%08x), expected = %11i(0x%08x)",
  4830. i, p->input1, p->input1, p->input2, p->input2,
  4831. p->input3, p->input3, p->output, p->output, val1,
  4832. val1);
  4833. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4834. }
  4835. }
  4836. TEST_F(ExecutionTest, BinaryUintOpTest) {
  4837. WEX::TestExecution::SetVerifyOutput verifySettings(
  4838. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4839. CComPtr<IStream> pStream;
  4840. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4841. CComPtr<ID3D12Device> pDevice;
  4842. if (!CreateDevice(&pDevice)) {
  4843. return;
  4844. }
  4845. // Read data from the table
  4846. size_t tableSize = sizeof(BinaryUintOpParameters) / sizeof(TableParameter);
  4847. TableParameterHandler handler(BinaryUintOpParameters, tableSize);
  4848. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4849. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4850. std::vector<unsigned int> *Validation_Input1 =
  4851. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4852. std::vector<unsigned int> *Validation_Input2 =
  4853. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4854. std::vector<unsigned int> *Validation_Expected1 =
  4855. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4856. std::vector<unsigned int> *Validation_Expected2 =
  4857. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint32Table;
  4858. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4859. size_t count = Validation_Input1->size();
  4860. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  4861. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4862. pDevice, m_support, pStream, "BinaryUintOp",
  4863. // this callbacked is called when the test
  4864. // is creating the resource to run the test
  4865. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4866. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  4867. size_t size = sizeof(SBinaryUintOp) * count;
  4868. Data.resize(size);
  4869. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
  4870. for (size_t i = 0; i < count; ++i) {
  4871. SBinaryUintOp *p = &pPrimitives[i];
  4872. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4873. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4874. p->input1 = val1;
  4875. p->input2 = val2;
  4876. }
  4877. // use shader from data table
  4878. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4879. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4880. });
  4881. MappedData data;
  4882. test->Test->GetReadBackData("SBinaryUintOp", &data);
  4883. SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
  4884. WEX::TestExecution::DisableVerifyExceptions dve;
  4885. if (numExpected == 2) {
  4886. for (unsigned i = 0; i < count; ++i) {
  4887. SBinaryUintOp *p = &pPrimitives[i];
  4888. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4889. unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  4890. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4891. L"%11u(0x%08x), output1 = "
  4892. L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
  4893. L"%11u(0x%08x), expected2 = %11u(0x%08x)",
  4894. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  4895. p->output1, val1, val1, p->output2, p->output2, val2,
  4896. val2);
  4897. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4898. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  4899. }
  4900. }
  4901. else if (numExpected == 1) {
  4902. for (unsigned i = 0; i < count; ++i) {
  4903. SBinaryUintOp *p = &pPrimitives[i];
  4904. unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  4905. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4906. L"%11u(0x%08x), output = "
  4907. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4908. p->input1, p->input1, p->input2, p->input2,
  4909. p->output1, p->output1, val1, val1);
  4910. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  4911. }
  4912. }
  4913. else {
  4914. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  4915. }
  4916. }
  4917. TEST_F(ExecutionTest, TertiaryUintOpTest) {
  4918. WEX::TestExecution::SetVerifyOutput verifySettings(
  4919. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4920. CComPtr<IStream> pStream;
  4921. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4922. CComPtr<ID3D12Device> pDevice;
  4923. if (!CreateDevice(&pDevice)) {
  4924. return;
  4925. }
  4926. // Read data from the table
  4927. size_t tableSize = sizeof(TertiaryUintOpParameters) / sizeof(TableParameter);
  4928. TableParameterHandler handler(TertiaryUintOpParameters, tableSize);
  4929. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4930. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4931. std::vector<unsigned int> *Validation_Input1 =
  4932. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  4933. std::vector<unsigned int> *Validation_Input2 =
  4934. &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  4935. std::vector<unsigned int> *Validation_Input3 =
  4936. &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  4937. std::vector<unsigned int> *Validation_Expected =
  4938. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  4939. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  4940. size_t count = Validation_Input1->size();
  4941. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  4942. pDevice, m_support, pStream, "TertiaryUintOp",
  4943. // this callbacked is called when the test
  4944. // is creating the resource to run the test
  4945. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  4946. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  4947. size_t size = sizeof(STertiaryUintOp) * count;
  4948. Data.resize(size);
  4949. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
  4950. for (size_t i = 0; i < count; ++i) {
  4951. STertiaryUintOp *p = &pPrimitives[i];
  4952. unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->size()];
  4953. unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->size()];
  4954. unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->size()];
  4955. p->input1 = val1;
  4956. p->input2 = val2;
  4957. p->input3 = val3;
  4958. }
  4959. // use shader from data table
  4960. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  4961. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  4962. });
  4963. MappedData data;
  4964. test->Test->GetReadBackData("STertiaryUintOp", &data);
  4965. STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
  4966. WEX::TestExecution::DisableVerifyExceptions dve;
  4967. for (unsigned i = 0; i < count; ++i) {
  4968. STertiaryUintOp *p = &pPrimitives[i];
  4969. unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  4970. LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
  4971. L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
  4972. L"%11u(0x%08x), expected = %11u(0x%08x)", i,
  4973. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  4974. p->output, p->output, val1, val1);
  4975. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  4976. }
  4977. }
  4978. // 16 bit integer type tests
  4979. TEST_F(ExecutionTest, UnaryInt16OpTest) {
  4980. WEX::TestExecution::SetVerifyOutput verifySettings(
  4981. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  4982. CComPtr<IStream> pStream;
  4983. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  4984. CComPtr<ID3D12Device> pDevice;
  4985. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  4986. return;
  4987. }
  4988. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  4989. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  4990. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  4991. return;
  4992. }
  4993. // Read data from the table
  4994. int tableSize = sizeof(UnaryInt16OpParameters) / sizeof(TableParameter);
  4995. TableParameterHandler handler(UnaryInt16OpParameters, tableSize);
  4996. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  4997. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  4998. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  4999. std::vector<short> *Validation_Input =
  5000. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5001. std::vector<short> *Validation_Expected =
  5002. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5003. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5004. size_t count = Validation_Input->size();
  5005. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5006. pDevice, m_support, pStream, "UnaryIntOp",
  5007. // this callbacked is called when the test
  5008. // is creating the resource to run the test
  5009. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5010. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
  5011. size_t size = sizeof(SUnaryInt16Op) * count;
  5012. Data.resize(size);
  5013. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)Data.data();
  5014. for (size_t i = 0; i < count; ++i) {
  5015. SUnaryInt16Op *p = &pPrimitives[i];
  5016. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5017. }
  5018. // use shader data table
  5019. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5020. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5021. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5022. });
  5023. MappedData data;
  5024. test->Test->GetReadBackData("SUnaryIntOp", &data);
  5025. SUnaryInt16Op *pPrimitives = (SUnaryInt16Op *)data.data();
  5026. WEX::TestExecution::DisableVerifyExceptions dve;
  5027. for (unsigned i = 0; i < count; ++i) {
  5028. SUnaryInt16Op *p = &pPrimitives[i];
  5029. short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5030. LogCommentFmt(L"element #%u, input = %5hi(0x%08x), output = %5hi(0x%08x), "
  5031. L"expected = %5hi(0x%08x)",
  5032. i, p->input, p->input, p->output, p->output, val, val);
  5033. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5034. }
  5035. }
  5036. TEST_F(ExecutionTest, UnaryUint16OpTest) {
  5037. WEX::TestExecution::SetVerifyOutput verifySettings(
  5038. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5039. CComPtr<IStream> pStream;
  5040. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5041. CComPtr<ID3D12Device> pDevice;
  5042. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5043. return;
  5044. }
  5045. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5046. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5047. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5048. return;
  5049. }
  5050. // Read data from the table
  5051. int tableSize = sizeof(UnaryUint16OpParameters) / sizeof(TableParameter);
  5052. TableParameterHandler handler(UnaryUint16OpParameters, tableSize);
  5053. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5054. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5055. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5056. std::vector<unsigned short> *Validation_Input =
  5057. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5058. std::vector<unsigned short> *Validation_Expected =
  5059. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5060. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5061. size_t count = Validation_Input->size();
  5062. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5063. pDevice, m_support, pStream, "UnaryUintOp",
  5064. // this callbacked is called when the test
  5065. // is creating the resource to run the test
  5066. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5067. VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
  5068. size_t size = sizeof(SUnaryUint16Op) * count;
  5069. Data.resize(size);
  5070. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)Data.data();
  5071. for (size_t i = 0; i < count; ++i) {
  5072. SUnaryUint16Op *p = &pPrimitives[i];
  5073. p->input = (*Validation_Input)[i % Validation_Input->size()];
  5074. }
  5075. // use shader data table
  5076. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5077. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5078. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5079. });
  5080. MappedData data;
  5081. test->Test->GetReadBackData("SUnaryUintOp", &data);
  5082. SUnaryUint16Op *pPrimitives = (SUnaryUint16Op *)data.data();
  5083. WEX::TestExecution::DisableVerifyExceptions dve;
  5084. for (unsigned i = 0; i < count; ++i) {
  5085. SUnaryUint16Op *p = &pPrimitives[i];
  5086. unsigned short val = (*Validation_Expected)[i % Validation_Expected->size()];
  5087. LogCommentFmt(L"element #%u, input = %5hu(0x%08x), output = %5hu(0x%08x), "
  5088. L"expected = %5hu(0x%08x)",
  5089. i, p->input, p->input, p->output, p->output, val, val);
  5090. VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
  5091. }
  5092. }
  5093. TEST_F(ExecutionTest, BinaryInt16OpTest) {
  5094. WEX::TestExecution::SetVerifyOutput verifySettings(
  5095. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5096. CComPtr<IStream> pStream;
  5097. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5098. CComPtr<ID3D12Device> pDevice;
  5099. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5100. return;
  5101. }
  5102. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5103. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5104. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5105. return;
  5106. }
  5107. // Read data from the table
  5108. size_t tableSize = sizeof(BinaryInt16OpParameters) / sizeof(TableParameter);
  5109. TableParameterHandler handler(BinaryInt16OpParameters, tableSize);
  5110. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5111. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5112. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5113. std::vector<short> *Validation_Input1 =
  5114. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5115. std::vector<short> *Validation_Input2 =
  5116. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5117. std::vector<short> *Validation_Expected1 =
  5118. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5119. std::vector<short> *Validation_Expected2 =
  5120. &handler.GetTableParamByName(L"Validation.Expected2")->m_int16Table;
  5121. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5122. size_t count = Validation_Input1->size();
  5123. size_t numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5124. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5125. pDevice, m_support, pStream, "BinaryIntOp",
  5126. // this callbacked is called when the test
  5127. // is creating the resource to run the test
  5128. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5129. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
  5130. size_t size = sizeof(SBinaryInt16Op) * count;
  5131. Data.resize(size);
  5132. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)Data.data();
  5133. for (size_t i = 0; i < count; ++i) {
  5134. SBinaryInt16Op *p = &pPrimitives[i];
  5135. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5136. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5137. }
  5138. // use shader from data table
  5139. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5140. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5141. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5142. });
  5143. MappedData data;
  5144. test->Test->GetReadBackData("SBinaryIntOp", &data);
  5145. SBinaryInt16Op *pPrimitives = (SBinaryInt16Op *)data.data();
  5146. WEX::TestExecution::DisableVerifyExceptions dve;
  5147. if (numExpected == 2) {
  5148. for (unsigned i = 0; i < count; ++i) {
  5149. SBinaryInt16Op *p = &pPrimitives[i];
  5150. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5151. short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5152. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5153. L"%5hi(0x%08x), output1 = "
  5154. L"%5hi(0x%08x), expected1 = %5hi(0x%08x), output2 = "
  5155. L"%5hi(0x%08x), expected2 = %5hi(0x%08x)",
  5156. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5157. p->output1, val1, val1, p->output2, p->output2, val2,
  5158. val2);
  5159. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5160. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5161. }
  5162. }
  5163. else if (numExpected == 1) {
  5164. for (unsigned i = 0; i < count; ++i) {
  5165. SBinaryInt16Op *p = &pPrimitives[i];
  5166. short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5167. LogCommentFmt(L"element #%u, input1 = %5hi(0x%08x), input2 = "
  5168. L"%5hi(0x%08x), output = "
  5169. L"%5hi(0x%08x), expected = %5hi(0x%08x)", i,
  5170. p->input1, p->input1, p->input2, p->input2,
  5171. p->output1, p->output1, val1, val1);
  5172. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5173. }
  5174. }
  5175. else {
  5176. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5177. }
  5178. }
  5179. TEST_F(ExecutionTest, TertiaryInt16OpTest) {
  5180. WEX::TestExecution::SetVerifyOutput verifySettings(
  5181. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5182. CComPtr<IStream> pStream;
  5183. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5184. CComPtr<ID3D12Device> pDevice;
  5185. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5186. return;
  5187. }
  5188. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5189. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5190. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5191. return;
  5192. }
  5193. // Read data from the table
  5194. size_t tableSize = sizeof(TertiaryInt16OpParameters) / sizeof(TableParameter);
  5195. TableParameterHandler handler(TertiaryInt16OpParameters, tableSize);
  5196. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5197. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5198. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5199. std::vector<short> *Validation_Input1 =
  5200. &handler.GetTableParamByName(L"Validation.Input1")->m_int16Table;
  5201. std::vector<short> *Validation_Input2 =
  5202. &handler.GetTableParamByName(L"Validation.Input2")->m_int16Table;
  5203. std::vector<short> *Validation_Input3 =
  5204. &handler.GetTableParamByName(L"Validation.Input3")->m_int16Table;
  5205. std::vector<short> *Validation_Expected =
  5206. &handler.GetTableParamByName(L"Validation.Expected1")->m_int16Table;
  5207. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5208. size_t count = Validation_Input1->size();
  5209. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5210. pDevice, m_support, pStream, "TertiaryIntOp",
  5211. // this callbacked is called when the test
  5212. // is creating the resource to run the test
  5213. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5214. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
  5215. size_t size = sizeof(STertiaryInt16Op) * count;
  5216. Data.resize(size);
  5217. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)Data.data();
  5218. for (size_t i = 0; i < count; ++i) {
  5219. STertiaryInt16Op *p = &pPrimitives[i];
  5220. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5221. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5222. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5223. }
  5224. // use shader from data table
  5225. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5226. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5227. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5228. });
  5229. MappedData data;
  5230. test->Test->GetReadBackData("STertiaryIntOp", &data);
  5231. STertiaryInt16Op *pPrimitives = (STertiaryInt16Op *)data.data();
  5232. WEX::TestExecution::DisableVerifyExceptions dve;
  5233. for (unsigned i = 0; i < count; ++i) {
  5234. STertiaryInt16Op *p = &pPrimitives[i];
  5235. short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5236. LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
  5237. L"%11i(0x%08x), input3= %11i(0x%08x), output = "
  5238. L"%11i(0x%08x), expected = %11i(0x%08x)",
  5239. i, p->input1, p->input1, p->input2, p->input2,
  5240. p->input3, p->input3, p->output, p->output, val1,
  5241. val1);
  5242. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5243. }
  5244. }
  5245. TEST_F(ExecutionTest, BinaryUint16OpTest) {
  5246. WEX::TestExecution::SetVerifyOutput verifySettings(
  5247. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5248. CComPtr<IStream> pStream;
  5249. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5250. CComPtr<ID3D12Device> pDevice;
  5251. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5252. return;
  5253. }
  5254. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5255. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5256. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5257. return;
  5258. }
  5259. // Read data from the table
  5260. size_t tableSize = sizeof(BinaryUint16OpParameters) / sizeof(TableParameter);
  5261. TableParameterHandler handler(BinaryUint16OpParameters, tableSize);
  5262. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5263. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5264. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5265. std::vector<unsigned short> *Validation_Input1 =
  5266. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5267. std::vector<unsigned short> *Validation_Input2 =
  5268. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5269. std::vector<unsigned short> *Validation_Expected1 =
  5270. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5271. std::vector<unsigned short> *Validation_Expected2 =
  5272. &handler.GetTableParamByName(L"Validation.Expected2")->m_uint16Table;
  5273. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5274. size_t count = Validation_Input1->size();
  5275. int numExpected = Validation_Expected2->size() == 0 ? 1 : 2;
  5276. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5277. pDevice, m_support, pStream, "BinaryUintOp",
  5278. // this callbacked is called when the test
  5279. // is creating the resource to run the test
  5280. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5281. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
  5282. size_t size = sizeof(SBinaryUint16Op) * count;
  5283. Data.resize(size);
  5284. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)Data.data();
  5285. for (size_t i = 0; i < count; ++i) {
  5286. SBinaryUint16Op *p = &pPrimitives[i];
  5287. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5288. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5289. }
  5290. // use shader from data table
  5291. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5292. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5293. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5294. });
  5295. MappedData data;
  5296. test->Test->GetReadBackData("SBinaryUintOp", &data);
  5297. SBinaryUint16Op *pPrimitives = (SBinaryUint16Op *)data.data();
  5298. WEX::TestExecution::DisableVerifyExceptions dve;
  5299. if (numExpected == 2) {
  5300. for (unsigned i = 0; i < count; ++i) {
  5301. SBinaryUint16Op *p = &pPrimitives[i];
  5302. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5303. unsigned short val2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5304. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5305. L"%5hu(0x%08x), output1 = "
  5306. L"%5hu(0x%08x), expected1 = %5hu(0x%08x), output2 = "
  5307. L"%5hu(0x%08x), expected2 = %5hu(0x%08x)",
  5308. i, p->input1, p->input1, p->input2, p->input2, p->output1,
  5309. p->output1, val1, val1, p->output2, p->output2, val2,
  5310. val2);
  5311. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5312. VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
  5313. }
  5314. }
  5315. else if (numExpected == 1) {
  5316. for (unsigned i = 0; i < count; ++i) {
  5317. SBinaryUint16Op *p = &pPrimitives[i];
  5318. unsigned short val1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5319. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5320. L"%5hu(0x%08x), output = "
  5321. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5322. p->input1, p->input1, p->input2, p->input2,
  5323. p->output1, p->output1, val1, val1);
  5324. VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
  5325. }
  5326. }
  5327. else {
  5328. LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
  5329. }
  5330. }
  5331. TEST_F(ExecutionTest, TertiaryUint16OpTest) {
  5332. WEX::TestExecution::SetVerifyOutput verifySettings(
  5333. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5334. CComPtr<IStream> pStream;
  5335. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5336. CComPtr<ID3D12Device> pDevice;
  5337. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5338. return;
  5339. }
  5340. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5341. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5342. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5343. return;
  5344. }
  5345. // Read data from the table
  5346. size_t tableSize = sizeof(TertiaryUint16OpParameters) / sizeof(TableParameter);
  5347. TableParameterHandler handler(TertiaryUint16OpParameters, tableSize);
  5348. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5349. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5350. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5351. std::vector<unsigned short> *Validation_Input1 =
  5352. &handler.GetTableParamByName(L"Validation.Input1")->m_uint16Table;
  5353. std::vector<unsigned short> *Validation_Input2 =
  5354. &handler.GetTableParamByName(L"Validation.Input2")->m_uint16Table;
  5355. std::vector<unsigned short> *Validation_Input3 =
  5356. &handler.GetTableParamByName(L"Validation.Input3")->m_uint16Table;
  5357. std::vector<unsigned short> *Validation_Expected =
  5358. &handler.GetTableParamByName(L"Validation.Expected1")->m_uint16Table;
  5359. int Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_int32;
  5360. size_t count = Validation_Input1->size();
  5361. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5362. pDevice, m_support, pStream, "TertiaryUintOp",
  5363. // this callbacked is called when the test
  5364. // is creating the resource to run the test
  5365. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5366. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
  5367. size_t size = sizeof(STertiaryUint16Op) * count;
  5368. Data.resize(size);
  5369. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)Data.data();
  5370. for (size_t i = 0; i < count; ++i) {
  5371. STertiaryUint16Op *p = &pPrimitives[i];
  5372. p->input1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5373. p->input2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5374. p->input3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5375. }
  5376. // use shader from data table
  5377. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5378. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5379. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5380. });
  5381. MappedData data;
  5382. test->Test->GetReadBackData("STertiaryUintOp", &data);
  5383. STertiaryUint16Op *pPrimitives = (STertiaryUint16Op *)data.data();
  5384. WEX::TestExecution::DisableVerifyExceptions dve;
  5385. for (unsigned i = 0; i < count; ++i) {
  5386. STertiaryUint16Op *p = &pPrimitives[i];
  5387. unsigned short val1 = (*Validation_Expected)[i % Validation_Expected->size()];
  5388. LogCommentFmt(L"element #%u, input1 = %5hu(0x%08x), input2 = "
  5389. L"%5hu(0x%08x), input3 = %5hu(0x%08x), output = "
  5390. L"%5hu(0x%08x), expected = %5hu(0x%08x)", i,
  5391. p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
  5392. p->output, p->output, val1, val1);
  5393. VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
  5394. }
  5395. }
  5396. TEST_F(ExecutionTest, DotTest) {
  5397. WEX::TestExecution::SetVerifyOutput verifySettings(
  5398. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5399. CComPtr<IStream> pStream;
  5400. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5401. CComPtr<ID3D12Device> pDevice;
  5402. if (!CreateDevice(&pDevice)) {
  5403. return;
  5404. }
  5405. int tableSize = sizeof(DotOpParameters) / sizeof(TableParameter);
  5406. TableParameterHandler handler(DotOpParameters, tableSize);
  5407. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5408. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5409. std::vector<WEX::Common::String> *Validation_Input1 =
  5410. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5411. std::vector<WEX::Common::String> *Validation_Input2 =
  5412. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5413. std::vector<WEX::Common::String> *Validation_dot2 =
  5414. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5415. std::vector<WEX::Common::String> *Validation_dot3 =
  5416. &handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable;
  5417. std::vector<WEX::Common::String> *Validation_dot4 =
  5418. &handler.GetTableParamByName(L"Validation.Expected3")->m_StringTable;
  5419. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5420. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5421. size_t count = Validation_Input1->size();
  5422. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5423. pDevice, m_support, pStream, "DotOp",
  5424. // this callbacked is called when the test
  5425. // is creating the resource to run the test
  5426. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5427. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
  5428. size_t size = sizeof(SDotOp) * count;
  5429. Data.resize(size);
  5430. SDotOp *pPrimitives = (SDotOp*)Data.data();
  5431. for (size_t i = 0; i < count; ++i) {
  5432. SDotOp *p = &pPrimitives[i];
  5433. XMFLOAT4 val1,val2;
  5434. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
  5435. (float *)&val1, 4));
  5436. VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
  5437. (float *)&val2, 4));
  5438. p->input1 = val1;
  5439. p->input2 = val2;
  5440. }
  5441. // use shader from data table
  5442. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5443. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5444. });
  5445. MappedData data;
  5446. test->Test->GetReadBackData("SDotOp", &data);
  5447. SDotOp *pPrimitives = (SDotOp*)data.data();
  5448. WEX::TestExecution::DisableVerifyExceptions dve;
  5449. for (size_t i = 0; i < count; ++i) {
  5450. SDotOp *p = &pPrimitives[i];
  5451. float dot2, dot3, dot4;
  5452. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
  5453. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
  5454. VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
  5455. LogCommentFmt(
  5456. L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
  5457. L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
  5458. L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
  5459. i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
  5460. p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
  5461. p->o_dot4, dot4);
  5462. VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
  5463. tolerance);
  5464. VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
  5465. tolerance);
  5466. VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
  5467. tolerance);
  5468. }
  5469. }
  5470. TEST_F(ExecutionTest, Dot2AddHalfTest) {
  5471. WEX::TestExecution::SetVerifyOutput verifySettings(
  5472. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5473. CComPtr<IStream> pStream;
  5474. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5475. CComPtr<ID3D12Device> pDevice;
  5476. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5477. return;
  5478. }
  5479. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  5480. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  5481. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  5482. return;
  5483. }
  5484. int tableSize = sizeof(Dot2AddHalfOpParameters) / sizeof(TableParameter);
  5485. TableParameterHandler handler(Dot2AddHalfOpParameters, tableSize);
  5486. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5487. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5488. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5489. std::vector<WEX::Common::String> *validation_input1 =
  5490. &handler.GetTableParamByName(L"Validation.Input1")->m_StringTable;
  5491. std::vector<WEX::Common::String> *validation_input2 =
  5492. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5493. std::vector<float> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_floatTable;
  5494. std::vector<float> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_floatTable;
  5495. PCWSTR Validation_type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5496. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5497. size_t count = validation_input1->size();
  5498. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5499. pDevice, m_support, pStream, "Dot2AddHalfOp",
  5500. // this callback is called when the test
  5501. // is creating the resource to run the test
  5502. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5503. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot2AddHalfOp"));
  5504. size_t size = sizeof(SDot2AddHalfOp) * count;
  5505. Data.resize(size);
  5506. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)Data.data();
  5507. for (size_t i = 0; i < count; ++i) {
  5508. SDot2AddHalfOp *p = &pPrimitives[i];
  5509. Half2 val1,val2;
  5510. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input1)[i],
  5511. (uint16_t *)&val1, 2));
  5512. VERIFY_SUCCEEDED(ParseDataToVectorHalf((*validation_input2)[i],
  5513. (uint16_t *)&val2, 2));
  5514. p->input1 = val1;
  5515. p->input2 = val2;
  5516. p->acc = (*validation_acc)[i];
  5517. }
  5518. // use shader from data table
  5519. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5520. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5521. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5522. });
  5523. MappedData data;
  5524. test->Test->GetReadBackData("SDot2AddHalfOp", &data);
  5525. SDot2AddHalfOp *pPrimitives = (SDot2AddHalfOp*)data.data();
  5526. WEX::TestExecution::DisableVerifyExceptions dve;
  5527. for (size_t i = 0; i < count; ++i) {
  5528. SDot2AddHalfOp *p = &pPrimitives[i];
  5529. float expectedResult = (*validation_result)[i];
  5530. float input1x = ConvertFloat16ToFloat32(p->input1.x);
  5531. float input1y = ConvertFloat16ToFloat32(p->input1.y);
  5532. float input2x = ConvertFloat16ToFloat32(p->input2.x);
  5533. float input2y = ConvertFloat16ToFloat32(p->input2.y);
  5534. LogCommentFmt(
  5535. L"element #%u, input1 = (%f, %f), input2 = (%f, %f), acc = %f\n"
  5536. L"result = %f, result_expected = %f",
  5537. i, input1x, input1y, input2x, input2y, p->acc, p->result, expectedResult);
  5538. VerifyOutputWithExpectedValueFloat(p->result, expectedResult, Validation_type, tolerance);
  5539. }
  5540. }
  5541. TEST_F(ExecutionTest, Dot4AddI8PackedTest) {
  5542. WEX::TestExecution::SetVerifyOutput verifySettings(
  5543. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5544. CComPtr<IStream> pStream;
  5545. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5546. CComPtr<ID3D12Device> pDevice;
  5547. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5548. return;
  5549. }
  5550. int tableSize = sizeof(Dot4AddI8PackedOpParameters) / sizeof(TableParameter);
  5551. TableParameterHandler handler(Dot4AddI8PackedOpParameters, tableSize);
  5552. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5553. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5554. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5555. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5556. std::vector<int32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_int32Table;
  5557. std::vector<int32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_int32Table;
  5558. size_t count = validation_input1->size();
  5559. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5560. pDevice, m_support, pStream, "Dot4AddI8PackedOp",
  5561. // this callback is called when the test
  5562. // is creating the resource to run the test
  5563. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5564. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddI8PackedOp"));
  5565. size_t size = sizeof(SDot4AddI8PackedOp) * count;
  5566. Data.resize(size);
  5567. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)Data.data();
  5568. for (size_t i = 0; i < count; ++i) {
  5569. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5570. p->input1 = (*validation_input1)[i];
  5571. p->input2 = (*validation_input2)[i];
  5572. p->acc = (*validation_acc)[i];
  5573. }
  5574. // use shader from data table
  5575. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5576. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5577. });
  5578. MappedData data;
  5579. test->Test->GetReadBackData("SDot4AddI8PackedOp", &data);
  5580. SDot4AddI8PackedOp *pPrimitives = (SDot4AddI8PackedOp*)data.data();
  5581. WEX::TestExecution::DisableVerifyExceptions dve;
  5582. for (size_t i = 0; i < count; ++i) {
  5583. SDot4AddI8PackedOp *p = &pPrimitives[i];
  5584. int32_t expectedResult = (*validation_result)[i];
  5585. LogCommentFmt(
  5586. L"element #%u, input1 = %u, input2 = %u, acc = %d \n"
  5587. L"result = %d, result_expected = %d",
  5588. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5589. VerifyOutputWithExpectedValueInt(p->result, expectedResult, 0);
  5590. }
  5591. }
  5592. TEST_F(ExecutionTest, Dot4AddU8PackedTest) {
  5593. WEX::TestExecution::SetVerifyOutput verifySettings(
  5594. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5595. CComPtr<IStream> pStream;
  5596. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5597. CComPtr<ID3D12Device> pDevice;
  5598. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_4, false)) {
  5599. return;
  5600. }
  5601. int tableSize = sizeof(Dot4AddU8PackedOpParameters) / sizeof(TableParameter);
  5602. TableParameterHandler handler(Dot4AddU8PackedOpParameters, tableSize);
  5603. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5604. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5605. std::vector<uint32_t> *validation_input1 = &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5606. std::vector<uint32_t> *validation_input2 = &handler.GetTableParamByName(L"Validation.Input2")->m_uint32Table;
  5607. std::vector<uint32_t> *validation_acc = &handler.GetTableParamByName(L"Validation.Input3")->m_uint32Table;
  5608. std::vector<uint32_t> *validation_result = &handler.GetTableParamByName(L"Validation.Expected1")->m_uint32Table;
  5609. size_t count = validation_input1->size();
  5610. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5611. pDevice, m_support, pStream, "Dot4AddU8PackedOp",
  5612. // this callback is called when the test
  5613. // is creating the resource to run the test
  5614. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5615. VERIFY_IS_TRUE(0 == _stricmp(Name, "SDot4AddU8PackedOp"));
  5616. size_t size = sizeof(SDot4AddU8PackedOp) * count;
  5617. Data.resize(size);
  5618. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)Data.data();
  5619. for (size_t i = 0; i < count; ++i) {
  5620. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5621. p->input1 = (*validation_input1)[i];
  5622. p->input2 = (*validation_input2)[i];
  5623. p->acc = (*validation_acc)[i];
  5624. }
  5625. // use shader from data table
  5626. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5627. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5628. });
  5629. MappedData data;
  5630. test->Test->GetReadBackData("SDot4AddU8PackedOp", &data);
  5631. SDot4AddU8PackedOp *pPrimitives = (SDot4AddU8PackedOp*)data.data();
  5632. WEX::TestExecution::DisableVerifyExceptions dve;
  5633. for (size_t i = 0; i < count; ++i) {
  5634. SDot4AddU8PackedOp *p = &pPrimitives[i];
  5635. uint32_t expectedResult = (*validation_result)[i];
  5636. LogCommentFmt(
  5637. L"element #%u, input1 = %u, input2 = %u, acc = %u \n"
  5638. L"result = %u, result_expected = %u, ",
  5639. i, p->input1, p->input2, p->acc, p->result, expectedResult);
  5640. VerifyOutputWithExpectedValueUInt(p->result, expectedResult, 0);
  5641. }
  5642. }
  5643. TEST_F(ExecutionTest, Msad4Test) {
  5644. WEX::TestExecution::SetVerifyOutput verifySettings(
  5645. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5646. CComPtr<IStream> pStream;
  5647. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5648. CComPtr<ID3D12Device> pDevice;
  5649. if (!CreateDevice(&pDevice)) {
  5650. return;
  5651. }
  5652. size_t tableSize = sizeof(Msad4OpParameters) / sizeof(TableParameter);
  5653. TableParameterHandler handler(Msad4OpParameters, tableSize);
  5654. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5655. double tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5656. std::vector<unsigned int> *Validation_Reference =
  5657. &handler.GetTableParamByName(L"Validation.Input1")->m_uint32Table;
  5658. std::vector<WEX::Common::String> *Validation_Source =
  5659. &handler.GetTableParamByName(L"Validation.Input2")->m_StringTable;
  5660. std::vector<WEX::Common::String> *Validation_Accum =
  5661. &handler.GetTableParamByName(L"Validation.Input3")->m_StringTable;
  5662. std::vector<WEX::Common::String> *Validation_Expected =
  5663. &handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable;
  5664. size_t count = Validation_Expected->size();
  5665. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5666. pDevice, m_support, pStream, "Msad4",
  5667. // this callbacked is called when the test
  5668. // is creating the resource to run the test
  5669. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5670. VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
  5671. size_t size = sizeof(SMsad4) * count;
  5672. Data.resize(size);
  5673. SMsad4 *pPrimitives = (SMsad4*)Data.data();
  5674. for (size_t i = 0; i < count; ++i) {
  5675. SMsad4 *p = &pPrimitives[i];
  5676. XMUINT2 src;
  5677. XMUINT4 accum;
  5678. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
  5679. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
  5680. p->ref = (*Validation_Reference)[i];
  5681. p->src = src;
  5682. p->accum = accum;
  5683. }
  5684. // use shader from data table
  5685. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5686. });
  5687. MappedData data;
  5688. test->Test->GetReadBackData("SMsad4", &data);
  5689. SMsad4 *pPrimitives = (SMsad4*)data.data();
  5690. WEX::TestExecution::DisableVerifyExceptions dve;
  5691. for (size_t i = 0; i < count; ++i) {
  5692. SMsad4 *p = &pPrimitives[i];
  5693. XMUINT4 result;
  5694. VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
  5695. (unsigned int *)&result, 4));
  5696. LogCommentFmt(
  5697. L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
  5698. L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5699. L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
  5700. L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
  5701. p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
  5702. p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
  5703. p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
  5704. p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
  5705. result.x, result.x, result.y, result.y, result.z, result.z,
  5706. result.w, result.w);
  5707. int toleranceInt = (int)tolerance;
  5708. VerifyOutputWithExpectedValueInt(p->result.x, result.x, toleranceInt);
  5709. VerifyOutputWithExpectedValueInt(p->result.y, result.y, toleranceInt);
  5710. VerifyOutputWithExpectedValueInt(p->result.z, result.z, toleranceInt);
  5711. VerifyOutputWithExpectedValueInt(p->result.w, result.w, toleranceInt);
  5712. }
  5713. }
  5714. TEST_F(ExecutionTest, DenormBinaryFloatOpTest) {
  5715. WEX::TestExecution::SetVerifyOutput verifySettings(
  5716. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5717. CComPtr<IStream> pStream;
  5718. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5719. CComPtr<ID3D12Device> pDevice;
  5720. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5721. return;
  5722. }
  5723. // Read data from the table
  5724. int tableSize = sizeof(DenormBinaryFPOpParameters) / sizeof(TableParameter);
  5725. TableParameterHandler handler(DenormBinaryFPOpParameters, tableSize);
  5726. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5727. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5728. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5729. std::vector<WEX::Common::String> *Validation_Input1 =
  5730. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5731. std::vector<WEX::Common::String> *Validation_Input2 =
  5732. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5733. std::vector<WEX::Common::String> *Validation_Expected1 =
  5734. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5735. // two expected outputs for any mode
  5736. std::vector<WEX::Common::String> *Validation_Expected2 =
  5737. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5738. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5739. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5740. size_t count = Validation_Input1->size();
  5741. using namespace hlsl::DXIL;
  5742. Float32DenormMode mode = Float32DenormMode::Any;
  5743. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5744. mode = Float32DenormMode::Preserve;
  5745. }
  5746. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5747. mode = Float32DenormMode::FTZ;
  5748. }
  5749. if (mode == Float32DenormMode::Any) {
  5750. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5751. "must have same number of expected values");
  5752. }
  5753. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5754. pDevice, m_support, pStream, "BinaryFPOp",
  5755. // this callbacked is called when the test
  5756. // is creating the resource to run the test
  5757. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5758. VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
  5759. size_t size = sizeof(SBinaryFPOp) * count;
  5760. Data.resize(size);
  5761. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
  5762. for (size_t i = 0; i < count; ++i) {
  5763. SBinaryFPOp *p = &pPrimitives[i];
  5764. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5765. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5766. float val1, val2;
  5767. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5768. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5769. p->input1 = val1;
  5770. p->input2 = val2;
  5771. }
  5772. // use shader from data table
  5773. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5774. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5775. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5776. });
  5777. MappedData data;
  5778. test->Test->GetReadBackData("SBinaryFPOp", &data);
  5779. SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
  5780. WEX::TestExecution::DisableVerifyExceptions dve;
  5781. for (unsigned i = 0; i < count; ++i) {
  5782. SBinaryFPOp *p = &pPrimitives[i];
  5783. if (mode == Float32DenormMode::Any) {
  5784. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5785. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5786. float val1;
  5787. float val2;
  5788. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5789. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5790. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5791. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5792. i, p->input1, p->input2, p->output1, val1, *(int *)&val1, val2, *(int *)&val2);
  5793. VERIFY_IS_TRUE(
  5794. CompareOutputWithExpectedValueFloat(
  5795. p->output1, val1, Validation_Type, Validation_Tolerance, mode) ||
  5796. CompareOutputWithExpectedValueFloat(
  5797. p->output1, val2, Validation_Type, Validation_Tolerance, mode));
  5798. }
  5799. else {
  5800. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5801. float val1;
  5802. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5803. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, output = "
  5804. L"%6.8f, expected = %6.8f(%a)",
  5805. i, p->input1, p->input2, p->output1, val1, *(int *)&val1);
  5806. VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
  5807. Validation_Tolerance, mode);
  5808. }
  5809. }
  5810. }
  5811. TEST_F(ExecutionTest, DenormTertiaryFloatOpTest) {
  5812. WEX::TestExecution::SetVerifyOutput verifySettings(
  5813. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  5814. CComPtr<IStream> pStream;
  5815. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  5816. CComPtr<ID3D12Device> pDevice;
  5817. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL::D3D_SHADER_MODEL_6_2)) {
  5818. return;
  5819. }
  5820. // Read data from the table
  5821. int tableSize = sizeof(DenormTertiaryFPOpParameters) / sizeof(TableParameter);
  5822. TableParameterHandler handler(DenormTertiaryFPOpParameters, tableSize);
  5823. CW2A Target(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  5824. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  5825. CW2A Arguments(handler.GetTableParamByName(L"ShaderOp.Arguments")->m_str);
  5826. std::vector<WEX::Common::String> *Validation_Input1 =
  5827. &(handler.GetTableParamByName(L"Validation.Input1")->m_StringTable);
  5828. std::vector<WEX::Common::String> *Validation_Input2 =
  5829. &(handler.GetTableParamByName(L"Validation.Input2")->m_StringTable);
  5830. std::vector<WEX::Common::String> *Validation_Input3 =
  5831. &(handler.GetTableParamByName(L"Validation.Input3")->m_StringTable);
  5832. std::vector<WEX::Common::String> *Validation_Expected1 =
  5833. &(handler.GetTableParamByName(L"Validation.Expected1")->m_StringTable);
  5834. // two expected outputs for any mode
  5835. std::vector<WEX::Common::String> *Validation_Expected2 =
  5836. &(handler.GetTableParamByName(L"Validation.Expected2")->m_StringTable);
  5837. LPCWSTR Validation_Type = handler.GetTableParamByName(L"Validation.Type")->m_str;
  5838. double Validation_Tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_double;
  5839. size_t count = Validation_Input1->size();
  5840. using namespace hlsl::DXIL;
  5841. Float32DenormMode mode = Float32DenormMode::Any;
  5842. if (strcmp(Arguments.m_psz, "-denorm preserve") == 0) {
  5843. mode = Float32DenormMode::Preserve;
  5844. }
  5845. else if (strcmp(Arguments.m_psz, "-denorm ftz") == 0) {
  5846. mode = Float32DenormMode::FTZ;
  5847. }
  5848. if (mode == Float32DenormMode::Any) {
  5849. DXASSERT(Validation_Expected2->size() == Validation_Expected1->size(),
  5850. "must have same number of expected values");
  5851. }
  5852. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  5853. pDevice, m_support, pStream, "TertiaryFPOp",
  5854. // this callbacked is called when the test
  5855. // is creating the resource to run the test
  5856. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  5857. VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
  5858. size_t size = sizeof(STertiaryFPOp) * count;
  5859. Data.resize(size);
  5860. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
  5861. for (size_t i = 0; i < count; ++i) {
  5862. STertiaryFPOp *p = &pPrimitives[i];
  5863. PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->size()];
  5864. PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->size()];
  5865. PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->size()];
  5866. float val1, val2, val3;
  5867. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5868. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5869. VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
  5870. p->input1 = val1;
  5871. p->input2 = val2;
  5872. p->input3 = val3;
  5873. }
  5874. // use shader from data table
  5875. pShaderOp->Shaders.at(0).Target = Target.m_psz;
  5876. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  5877. pShaderOp->Shaders.at(0).Arguments = Arguments.m_psz;
  5878. });
  5879. MappedData data;
  5880. test->Test->GetReadBackData("STertiaryFPOp", &data);
  5881. STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
  5882. WEX::TestExecution::DisableVerifyExceptions dve;
  5883. for (unsigned i = 0; i < count; ++i) {
  5884. STertiaryFPOp *p = &pPrimitives[i];
  5885. if (mode == Float32DenormMode::Any) {
  5886. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5887. LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->size()];
  5888. float val1;
  5889. float val2;
  5890. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5891. VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
  5892. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5893. L"%6.8f, expected = %6.8f(%x) or %6.8f(%x)",
  5894. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1, val2, *(int *)&val2);
  5895. VERIFY_IS_TRUE(
  5896. CompareOutputWithExpectedValueFloat(
  5897. p->output, val1, Validation_Type, Validation_Tolerance, mode) ||
  5898. CompareOutputWithExpectedValueFloat(
  5899. p->output, val2, Validation_Type, Validation_Tolerance, mode));
  5900. }
  5901. else {
  5902. LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->size()];
  5903. float val1;
  5904. VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
  5905. LogCommentFmt(L"element #%u, input1 = %6.8f, input2 = %6.8f, input3 = %6.8f, output = "
  5906. L"%6.8f, expected = %6.8f(%a)",
  5907. i, p->input1, p->input2, p->input3, p->output, val1, *(int *)&val1);
  5908. VerifyOutputWithExpectedValueFloat(p->output, val1, Validation_Type,
  5909. Validation_Tolerance, mode);
  5910. }
  5911. }
  5912. }
  5913. // Setup for wave intrinsics tests
  5914. enum class ShaderOpKind {
  5915. WaveSum,
  5916. WaveProduct,
  5917. WaveActiveMax,
  5918. WaveActiveMin,
  5919. WaveCountBits,
  5920. WaveActiveAllEqual,
  5921. WaveActiveAnyTrue,
  5922. WaveActiveAllTrue,
  5923. WaveActiveBitOr,
  5924. WaveActiveBitAnd,
  5925. WaveActiveBitXor,
  5926. ShaderOpInvalid
  5927. };
  5928. struct ShaderOpKindPair {
  5929. LPCWSTR name;
  5930. ShaderOpKind kind;
  5931. };
  5932. static ShaderOpKindPair ShaderOpKindTable[] = {
  5933. { L"WaveActiveSum", ShaderOpKind::WaveSum },
  5934. { L"WaveActiveUSum", ShaderOpKind::WaveSum },
  5935. { L"WaveActiveProduct", ShaderOpKind::WaveProduct },
  5936. { L"WaveActiveUProduct", ShaderOpKind::WaveProduct },
  5937. { L"WaveActiveMax", ShaderOpKind::WaveActiveMax },
  5938. { L"WaveActiveUMax", ShaderOpKind::WaveActiveMax },
  5939. { L"WaveActiveMin", ShaderOpKind::WaveActiveMin },
  5940. { L"WaveActiveUMin", ShaderOpKind::WaveActiveMin },
  5941. { L"WaveActiveCountBits", ShaderOpKind::WaveCountBits },
  5942. { L"WaveActiveAllEqual", ShaderOpKind::WaveActiveAllEqual },
  5943. { L"WaveActiveAnyTrue", ShaderOpKind::WaveActiveAnyTrue },
  5944. { L"WaveActiveAllTrue", ShaderOpKind::WaveActiveAllTrue },
  5945. { L"WaveActiveBitOr", ShaderOpKind::WaveActiveBitOr },
  5946. { L"WaveActiveBitAnd", ShaderOpKind::WaveActiveBitAnd },
  5947. { L"WaveActiveBitXor", ShaderOpKind::WaveActiveBitXor },
  5948. { L"WavePrefixSum", ShaderOpKind::WaveSum },
  5949. { L"WavePrefixUSum", ShaderOpKind::WaveSum },
  5950. { L"WavePrefixProduct", ShaderOpKind::WaveProduct },
  5951. { L"WavePrefixUProduct", ShaderOpKind::WaveProduct },
  5952. { L"WavePrefixMax", ShaderOpKind::WaveActiveMax },
  5953. { L"WavePrefixUMax", ShaderOpKind::WaveActiveMax },
  5954. { L"WavePrefixMin", ShaderOpKind::WaveActiveMin },
  5955. { L"WavePrefixUMin", ShaderOpKind::WaveActiveMin },
  5956. { L"WavePrefixCountBits", ShaderOpKind::WaveCountBits }
  5957. };
  5958. ShaderOpKind GetShaderOpKind(LPCWSTR str) {
  5959. for (size_t i = 0; i < sizeof(ShaderOpKindTable)/sizeof(ShaderOpKindPair); ++i) {
  5960. if (_wcsicmp(ShaderOpKindTable[i].name, str) == 0) {
  5961. return ShaderOpKindTable[i].kind;
  5962. }
  5963. }
  5964. DXASSERT_ARGS(false, "Invalid ShaderOp name: %s", str);
  5965. return ShaderOpKind::ShaderOpInvalid;
  5966. }
  5967. template <typename InType, typename OutType, ShaderOpKind kind>
  5968. struct computeExpected {
  5969. OutType operator()(const std::vector<InType> &inputs,
  5970. const std::vector<int> &masks, int maskValue,
  5971. unsigned int index) {
  5972. return 0;
  5973. }
  5974. };
  5975. template <typename InType, typename OutType>
  5976. struct computeExpected<InType, OutType, ShaderOpKind::WaveSum> {
  5977. OutType operator()(const std::vector<InType> &inputs,
  5978. const std::vector<int> &masks, int maskValue,
  5979. unsigned int index) {
  5980. OutType sum = 0;
  5981. for (size_t i = 0; i < index; ++i) {
  5982. if (masks.at(i) == maskValue) {
  5983. sum += inputs.at(i);
  5984. }
  5985. }
  5986. return sum;
  5987. }
  5988. };
  5989. template <typename InType, typename OutType>
  5990. struct computeExpected<InType, OutType, ShaderOpKind::WaveProduct> {
  5991. OutType operator()(const std::vector<InType> &inputs,
  5992. const std::vector<int> &masks, int maskValue,
  5993. unsigned int index) {
  5994. OutType prod = 1;
  5995. for (size_t i = 0; i < index; ++i) {
  5996. if (masks.at(i) == maskValue) {
  5997. prod *= inputs.at(i);
  5998. }
  5999. }
  6000. return prod;
  6001. }
  6002. };
  6003. template <typename InType, typename OutType>
  6004. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax> {
  6005. OutType operator()(const std::vector<InType> &inputs,
  6006. const std::vector<int> &masks, int maskValue,
  6007. unsigned int index) {
  6008. OutType maximum = std::numeric_limits<OutType>::min();
  6009. for (size_t i = 0; i < index; ++i) {
  6010. if (masks.at(i) == maskValue && inputs.at(i) > maximum)
  6011. maximum = inputs.at(i);
  6012. }
  6013. return maximum;
  6014. }
  6015. };
  6016. template <typename InType, typename OutType>
  6017. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin> {
  6018. OutType operator()(const std::vector<InType> &inputs,
  6019. const std::vector<int> &masks, int maskValue,
  6020. unsigned int index) {
  6021. OutType minimum = std::numeric_limits<OutType>::max();
  6022. for (size_t i = 0; i < index; ++i) {
  6023. if (masks.at(i) == maskValue && inputs.at(i) < minimum)
  6024. minimum = inputs.at(i);
  6025. }
  6026. return minimum;
  6027. }
  6028. };
  6029. template <typename InType, typename OutType>
  6030. struct computeExpected<InType, OutType, ShaderOpKind::WaveCountBits> {
  6031. OutType operator()(const std::vector<InType> &inputs,
  6032. const std::vector<int> &masks, int maskValue,
  6033. unsigned int index) {
  6034. OutType count = 0;
  6035. for (size_t i = 0; i < index; ++i) {
  6036. if (masks.at(i) == maskValue && inputs.at(i) > 3) {
  6037. count++;
  6038. }
  6039. }
  6040. return count;
  6041. }
  6042. };
  6043. // In HLSL, boolean is represented in a 4 byte (uint32) format,
  6044. // So we cannot use c++ bool type to represent bool in HLSL
  6045. // HLSL returns 0 for false and 1 for true
  6046. template <typename InType, typename OutType>
  6047. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue> {
  6048. OutType operator()(const std::vector<InType> &inputs,
  6049. const std::vector<int> &masks, int maskValue,
  6050. unsigned int index) {
  6051. for (size_t i = 0; i < index; ++i) {
  6052. if (masks.at(i) == maskValue && inputs.at(i) != 0) {
  6053. return 1;
  6054. }
  6055. }
  6056. return 0;
  6057. }
  6058. };
  6059. template <typename InType, typename OutType>
  6060. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue> {
  6061. OutType operator()(const std::vector<InType> &inputs,
  6062. const std::vector<int> &masks, int maskValue,
  6063. unsigned int index) {
  6064. for (size_t i = 0; i < index; ++i) {
  6065. if (masks.at(i) == maskValue && inputs.at(i) == 0) {
  6066. return 0;
  6067. }
  6068. }
  6069. return 1;
  6070. }
  6071. };
  6072. template <typename InType, typename OutType>
  6073. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual> {
  6074. OutType operator()(const std::vector<InType> &inputs,
  6075. const std::vector<int> &masks, int maskValue,
  6076. unsigned int index) {
  6077. const InType *val = nullptr;
  6078. for (size_t i = 0; i < index; ++i) {
  6079. if (masks.at(i) == maskValue) {
  6080. if (val && *val != inputs.at(i)) {
  6081. return 0;
  6082. }
  6083. val = &inputs.at(i);
  6084. }
  6085. }
  6086. return 1;
  6087. }
  6088. };
  6089. template <typename InType, typename OutType>
  6090. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr> {
  6091. OutType operator()(const std::vector<InType> &inputs,
  6092. const std::vector<int> &masks, int maskValue,
  6093. unsigned int index) {
  6094. OutType bits = 0x00000000;
  6095. for (size_t i = 0; i < index; ++i) {
  6096. if (masks.at(i) == maskValue) {
  6097. bits |= inputs.at(i);
  6098. }
  6099. }
  6100. return bits;
  6101. }
  6102. };
  6103. template <typename InType, typename OutType>
  6104. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd> {
  6105. OutType operator()(const std::vector<InType> &inputs,
  6106. const std::vector<int> &masks, int maskValue,
  6107. unsigned int index) {
  6108. OutType bits = 0xffffffff;
  6109. for (size_t i = 0; i < index; ++i) {
  6110. if (masks.at(i) == maskValue) {
  6111. bits &= inputs.at(i);
  6112. }
  6113. }
  6114. return bits;
  6115. }
  6116. };
  6117. template <typename InType, typename OutType>
  6118. struct computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor> {
  6119. OutType operator()(const std::vector<InType> &inputs,
  6120. const std::vector<int> &masks, int maskValue,
  6121. unsigned int index) {
  6122. OutType bits = 0x00000000;
  6123. for (size_t i = 0; i < index; ++i) {
  6124. if (masks.at(i) == maskValue) {
  6125. bits ^= inputs.at(i);
  6126. }
  6127. }
  6128. return bits;
  6129. }
  6130. };
  6131. // Mask functions used to control active lanes
  6132. static int MaskAll(int i) {
  6133. UNREFERENCED_PARAMETER(i);
  6134. return 1;
  6135. }
  6136. static int MaskEveryOther(int i) {
  6137. return i % 2 == 0 ? 1 : 0;
  6138. }
  6139. static int MaskEveryThird(int i) {
  6140. return i % 3 == 0 ? 1 : 0;
  6141. }
  6142. typedef int(*MaskFunction)(int);
  6143. static MaskFunction MaskFunctionTable[] = {
  6144. MaskAll, MaskEveryOther, MaskEveryThird
  6145. };
  6146. template <typename InType, typename OutType>
  6147. static OutType computeExpectedWithShaderOp(const std::vector<InType> &inputs,
  6148. const std::vector<int> &masks,
  6149. int maskValue, unsigned int index,
  6150. LPCWSTR str) {
  6151. ShaderOpKind kind = GetShaderOpKind(str);
  6152. switch (kind) {
  6153. case ShaderOpKind::WaveSum:
  6154. return computeExpected<InType, OutType, ShaderOpKind::WaveSum>()(inputs, masks, maskValue, index);
  6155. case ShaderOpKind::WaveProduct:
  6156. return computeExpected<InType, OutType, ShaderOpKind::WaveProduct>()(inputs, masks, maskValue, index);
  6157. case ShaderOpKind::WaveActiveMax:
  6158. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMax>()(inputs, masks, maskValue, index);
  6159. case ShaderOpKind::WaveActiveMin:
  6160. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveMin>()(inputs, masks, maskValue, index);
  6161. case ShaderOpKind::WaveCountBits:
  6162. return computeExpected<InType, OutType, ShaderOpKind::WaveCountBits>()(inputs, masks, maskValue, index);
  6163. case ShaderOpKind::WaveActiveBitOr:
  6164. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitOr>()(inputs, masks, maskValue, index);
  6165. case ShaderOpKind::WaveActiveBitAnd:
  6166. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitAnd>()(inputs, masks, maskValue, index);
  6167. case ShaderOpKind::WaveActiveBitXor:
  6168. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveBitXor>()(inputs, masks, maskValue, index);
  6169. case ShaderOpKind::WaveActiveAnyTrue:
  6170. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAnyTrue>()(inputs, masks, maskValue, index);
  6171. case ShaderOpKind::WaveActiveAllTrue:
  6172. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllTrue>()(inputs, masks, maskValue, index);
  6173. case ShaderOpKind::WaveActiveAllEqual:
  6174. return computeExpected<InType, OutType, ShaderOpKind::WaveActiveAllEqual>()(inputs, masks, maskValue, index);
  6175. default:
  6176. DXASSERT_ARGS(false, "Invalid ShaderOp Name: %s", str);
  6177. return (OutType) 0;
  6178. }
  6179. };
  6180. // A framework for testing individual wave intrinsics tests.
  6181. // This test case is assuming that functions 1) WaveIsFirstLane and 2) WaveGetLaneIndex are correct for all lanes.
  6182. template <class T1, class T2>
  6183. void ExecutionTest::WaveIntrinsicsActivePrefixTest(
  6184. TableParameter *pParameterList, size_t numParameter, bool isPrefix) {
  6185. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6186. // Resource representation for compute shader
  6187. // firstLaneId is used to group different waves
  6188. // laneIndex is used to identify lane within the wave.
  6189. // Lane ids are not necessarily in same order as thread ids.
  6190. struct PerThreadData {
  6191. unsigned firstLaneId;
  6192. unsigned laneIndex;
  6193. int mask;
  6194. T1 input;
  6195. T2 output;
  6196. };
  6197. unsigned int NumThreadsX = 8;
  6198. unsigned int NumThreadsY = 12;
  6199. unsigned int NumThreadsZ = 1;
  6200. static const unsigned int ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6201. static const unsigned int DispatchGroupCount = 1;
  6202. static const unsigned int ThreadCount = ThreadsPerGroup * DispatchGroupCount;
  6203. CComPtr<IStream> pStream;
  6204. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6205. CComPtr<ID3D12Device> pDevice;
  6206. if (!CreateDevice(&pDevice)) {
  6207. return;
  6208. }
  6209. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6210. // Optional feature, so it's correct to not support it if declared as such.
  6211. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6212. return;
  6213. }
  6214. TableParameterHandler handler(pParameterList, numParameter);
  6215. unsigned int numInputSet = handler.GetTableParamByName(L"Validation.NumInputSet")->m_uint;
  6216. // Obtain the list of input lists
  6217. std::vector<std::vector<T1>*> InputDataList;
  6218. for (unsigned int i = 0;
  6219. i < numInputSet; ++i) {
  6220. std::wstring inputName = L"Validation.InputSet";
  6221. inputName.append(std::to_wstring(i + 1));
  6222. InputDataList.push_back(handler.GetDataArray<T1>(inputName.data()));
  6223. }
  6224. CW2A Text(handler.GetTableParamByName(L"ShaderOp.text")->m_str);
  6225. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6226. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6227. // Running compute shader for each input set with different masks
  6228. for (size_t setIndex = 0; setIndex < numInputSet; ++setIndex) {
  6229. for (size_t maskIndex = 0; maskIndex < sizeof(MaskFunctionTable) / sizeof(MaskFunction); ++maskIndex) {
  6230. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(
  6231. pDevice, m_support, "WaveIntrinsicsOp",
  6232. // this callbacked is called when the test
  6233. // is creating the resource to run the test
  6234. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6235. VERIFY_IS_TRUE(0 == _stricmp(Name, "SWaveIntrinsicsOp"));
  6236. size_t size = sizeof(PerThreadData) * ThreadCount;
  6237. Data.resize(size);
  6238. PerThreadData *pPrimitives = (PerThreadData*)Data.data();
  6239. // 4 different inputs for each operation test
  6240. size_t index = 0;
  6241. std::vector<T1> *IntList = InputDataList[setIndex];
  6242. while (index < ThreadCount) {
  6243. PerThreadData *p = &pPrimitives[index];
  6244. p->firstLaneId = 0xFFFFBFFF;
  6245. p->laneIndex = 0xFFFFBFFF;
  6246. p->mask = MaskFunctionTable[maskIndex]((int)index);
  6247. p->input = (*IntList)[index % IntList->size()];
  6248. p->output = 0xFFFFBFFF;
  6249. index++;
  6250. }
  6251. // use shader from data table
  6252. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  6253. }, ShaderOpSet);
  6254. // Check the value
  6255. MappedData data;
  6256. test->Test->GetReadBackData("SWaveIntrinsicsOp", &data);
  6257. PerThreadData *pPrimitives = (PerThreadData*)data.data();
  6258. WEX::TestExecution::DisableVerifyExceptions dve;
  6259. // Grouping data by waves
  6260. std::vector<int> firstLaneIds;
  6261. for (size_t i = 0; i < ThreadCount; ++i) {
  6262. PerThreadData *p = &pPrimitives[i];
  6263. int firstLaneId = p->firstLaneId;
  6264. if (!contains(firstLaneIds, firstLaneId)) {
  6265. firstLaneIds.push_back(firstLaneId);
  6266. }
  6267. }
  6268. std::map<int, std::unique_ptr<std::vector<PerThreadData *>>> waves;
  6269. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6270. waves[firstLaneIds.at(i)] = std::make_unique<std::vector<PerThreadData*>>();
  6271. }
  6272. for (size_t i = 0; i < ThreadCount; ++i) {
  6273. PerThreadData *p = &pPrimitives[i];
  6274. waves[p->firstLaneId].get()->push_back(p);
  6275. }
  6276. // validate for each wave
  6277. for (size_t i = 0; i < firstLaneIds.size(); ++i) {
  6278. // collect inputs and masks for a given wave
  6279. std::vector<PerThreadData *> *waveData = waves[firstLaneIds.at(i)].get();
  6280. std::vector<T1> inputList(waveData->size());
  6281. std::vector<int> maskList(waveData->size(), -1);
  6282. std::vector<T2> outputList(waveData->size());
  6283. // sort inputList and masklist by lane id. input for each lane can be computed for its group index
  6284. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6285. unsigned laneID = waveData->at(j)->laneIndex;
  6286. // ensure that each lane ID is unique and within the range
  6287. VERIFY_IS_TRUE(0 <= laneID && laneID < waveData->size());
  6288. VERIFY_IS_TRUE(maskList.at(laneID) == -1);
  6289. maskList.at(laneID) = waveData->at(j)->mask;
  6290. inputList.at(laneID) = waveData->at(j)->input;
  6291. outputList.at(laneID) = waveData->at(j)->output;
  6292. }
  6293. std::wstring inputStr = L"Wave Inputs: ";
  6294. std::wstring maskStr = L"Wave Masks: ";
  6295. std::wstring outputStr = L"Wave Outputs: ";
  6296. // append input string and mask string in lane id order
  6297. for (size_t j = 0, end = waveData->size(); j < end; ++j) {
  6298. maskStr.append(std::to_wstring(maskList.at(j)));
  6299. maskStr.append(L" ");
  6300. inputStr.append(std::to_wstring(inputList.at(j)));
  6301. inputStr.append(L" ");
  6302. outputStr.append(std::to_wstring(outputList.at(j)));
  6303. outputStr.append(L" ");
  6304. }
  6305. LogCommentFmt(inputStr.data());
  6306. LogCommentFmt(maskStr.data());
  6307. LogCommentFmt(outputStr.data());
  6308. LogCommentFmt(L"\n");
  6309. // Compute expected output for a given inputs, masks, and index
  6310. for (size_t laneIndex = 0, laneEnd = inputList.size(); laneIndex < laneEnd; ++laneIndex) {
  6311. T2 expected;
  6312. // WaveActive is equivalent to WavePrefix lane # lane count
  6313. unsigned index = isPrefix ? (unsigned)laneIndex : (unsigned)inputList.size();
  6314. if (maskList.at(laneIndex) == 1) {
  6315. expected = computeExpectedWithShaderOp<T1, T2>(
  6316. inputList, maskList, 1, index,
  6317. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6318. }
  6319. else {
  6320. expected = computeExpectedWithShaderOp<T1, T2>(
  6321. inputList, maskList, 0, index,
  6322. handler.GetTableParamByName(L"ShaderOp.Name")->m_str);
  6323. }
  6324. // TODO: use different comparison for floating point inputs
  6325. bool equal = outputList.at(laneIndex) == expected;
  6326. if (!equal) {
  6327. LogCommentFmt(L"lane%d: %4d, Expected : %4d", laneIndex, outputList.at(laneIndex), expected);
  6328. }
  6329. VERIFY_IS_TRUE(equal);
  6330. }
  6331. }
  6332. }
  6333. }
  6334. }
  6335. static const unsigned int MinWarpVersionForWaveIntrinsics = 16202;
  6336. TEST_F(ExecutionTest, WaveIntrinsicsActiveIntTest) {
  6337. if (GetTestParamUseWARP(true) &&
  6338. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6339. return;
  6340. }
  6341. WaveIntrinsicsActivePrefixTest<int, int>(
  6342. WaveIntrinsicsActiveIntParameters,
  6343. sizeof(WaveIntrinsicsActiveIntParameters) / sizeof(TableParameter),
  6344. /*isPrefix*/ false);
  6345. }
  6346. TEST_F(ExecutionTest, WaveIntrinsicsActiveUintTest) {
  6347. if (GetTestParamUseWARP(true) &&
  6348. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6349. return;
  6350. }
  6351. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6352. WaveIntrinsicsActiveUintParameters,
  6353. sizeof(WaveIntrinsicsActiveUintParameters) / sizeof(TableParameter),
  6354. /*isPrefix*/ false);
  6355. }
  6356. TEST_F(ExecutionTest, WaveIntrinsicsPrefixIntTest) {
  6357. if (GetTestParamUseWARP(true) &&
  6358. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6359. return;
  6360. }
  6361. WaveIntrinsicsActivePrefixTest<int, int>(
  6362. WaveIntrinsicsPrefixIntParameters,
  6363. sizeof(WaveIntrinsicsPrefixIntParameters) / sizeof(TableParameter),
  6364. /*isPrefix*/ true);
  6365. }
  6366. TEST_F(ExecutionTest, WaveIntrinsicsPrefixUintTest) {
  6367. if (GetTestParamUseWARP(true) &&
  6368. !IsValidWarpDllVersion(MinWarpVersionForWaveIntrinsics)) {
  6369. return;
  6370. }
  6371. WaveIntrinsicsActivePrefixTest<unsigned int, unsigned int>(
  6372. WaveIntrinsicsPrefixUintParameters,
  6373. sizeof(WaveIntrinsicsPrefixUintParameters) / sizeof(TableParameter),
  6374. /*isPrefix*/ true);
  6375. }
  6376. template <typename T>
  6377. static T GetWaveMultiPrefixInitialAccumValue(LPCWSTR testName) {
  6378. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6379. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6380. return static_cast<T>(1);
  6381. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6382. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0 ||
  6383. _wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6384. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0 ||
  6385. _wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6386. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0 ||
  6387. _wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6388. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6389. return static_cast<T>(0);
  6390. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6391. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6392. return static_cast<T>(-1);
  6393. } else {
  6394. return static_cast<T>(0);
  6395. }
  6396. }
  6397. template <typename T>
  6398. std::function<T(T, T)> GetWaveMultiPrefixReferenceFunction(LPCWSTR testName) {
  6399. if (_wcsicmp(testName, L"WaveMultiPrefixProduct") == 0 ||
  6400. _wcsicmp(testName, L"WaveMultiPrefixUProduct") == 0) {
  6401. return [] (T lhs, T rhs) -> T { return lhs * rhs; };
  6402. } else if (_wcsicmp(testName, L"WaveMultiPrefixSum") == 0 ||
  6403. _wcsicmp(testName, L"WaveMultiPrefixUSum") == 0) {
  6404. return [] (T lhs, T rhs) -> T { return lhs + rhs; };
  6405. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitAnd") == 0 ||
  6406. _wcsicmp(testName, L"WaveMultiPrefixUBitAnd") == 0) {
  6407. return [] (T lhs, T rhs) -> T { return lhs & rhs; };
  6408. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitOr") == 0 ||
  6409. _wcsicmp(testName, L"WaveMultiPrefixUBitOr") == 0) {
  6410. return [] (T lhs, T rhs) -> T { return lhs | rhs; };
  6411. } else if (_wcsicmp(testName, L"WaveMultiPrefixBitXor") == 0 ||
  6412. _wcsicmp(testName, L"WaveMultiPrefixUBitXor") == 0) {
  6413. return [] (T lhs, T rhs) -> T { return lhs ^ rhs; };
  6414. } else if (_wcsicmp(testName, L"WaveMultiPrefixCountBits") == 0 ||
  6415. _wcsicmp(testName, L"WaveMultiPrefixUCountBits") == 0) {
  6416. // For CountBits, each lane contributes a boolean value. The test input is
  6417. // a zero or non-zero integer. If the input is a non-zero value then the
  6418. // condition is true, thus we contribute one to the bit count.
  6419. return [] (T lhs, T rhs) -> T { return lhs + (rhs ? 1 : 0); };
  6420. } else {
  6421. return [] (T lhs, T rhs) -> T { UNREFERENCED_PARAMETER(lhs); UNREFERENCED_PARAMETER(rhs); return 0; };
  6422. }
  6423. }
  6424. template <class T>
  6425. void
  6426. ExecutionTest::WaveIntrinsicsMultiPrefixOpTest(TableParameter *pParameterList,
  6427. size_t numParameters) {
  6428. WEX::TestExecution::SetVerifyOutput
  6429. verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6430. struct PerThreadData {
  6431. uint32_t key;
  6432. uint32_t firstLaneId;
  6433. uint32_t laneId;
  6434. uint32_t mask;
  6435. T value;
  6436. T result;
  6437. };
  6438. constexpr size_t NumThreadsX = 8;
  6439. constexpr size_t NumThreadsY = 12;
  6440. constexpr size_t NumThreadsZ = 1;
  6441. constexpr size_t ThreadsPerGroup = NumThreadsX * NumThreadsY * NumThreadsZ;
  6442. constexpr size_t DispatchGroupSize = 1;
  6443. constexpr size_t ThreadCount = ThreadsPerGroup * DispatchGroupSize;
  6444. CComPtr<IStream> pStream;
  6445. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6446. CComPtr<ID3D12Device> pDevice;
  6447. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_5)) {
  6448. return;
  6449. }
  6450. if (!DoesDeviceSupportWaveOps(pDevice)) {
  6451. // Optional feature, so it's correct to not support it if declared as such.
  6452. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  6453. return;
  6454. }
  6455. std::shared_ptr<st::ShaderOpSet>
  6456. ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  6457. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  6458. TableParameterHandler handler(pParameterList, numParameters);
  6459. CW2A shaderSource(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  6460. CW2A shaderProfile(handler.GetTableParamByName(L"ShaderOp.Target")->m_str);
  6461. auto testName = handler.GetTableParamByName(L"ShaderOp.Name")->m_str;
  6462. std::vector<T> *keys = handler.GetDataArray<T>(L"Validation.Keys");
  6463. std::vector<T> *values = handler.GetDataArray<T>(L"Validation.Values");
  6464. for (size_t maskIndex = 0; maskIndex < _countof(MaskFunctionTable); ++maskIndex) {
  6465. std::shared_ptr<ShaderOpTestResult> test =
  6466. RunShaderOpTestAfterParse(pDevice, m_support, "WaveIntrinsicsOp",
  6467. [&] (LPCSTR name, std::vector<BYTE> &data, st::ShaderOp *pShaderOp) {
  6468. UNREFERENCED_PARAMETER(name);
  6469. const size_t dataSize = sizeof(PerThreadData) * ThreadCount;
  6470. data.resize(dataSize);
  6471. PerThreadData *pThreadData = reinterpret_cast<PerThreadData *>(data.data());
  6472. for (size_t i = 0; i != ThreadCount; ++i) {
  6473. pThreadData[i].key = keys->at(i % keys->size());
  6474. pThreadData[i].value = values->at(i % values->size());
  6475. pThreadData[i].firstLaneId = 0xdeadbeef;
  6476. pThreadData[i].laneId = 0xdeadbeef;
  6477. pThreadData[i].mask = MaskFunctionTable[maskIndex]((int)i);
  6478. pThreadData[i].result = 0xdeadbeef;
  6479. }
  6480. pShaderOp->Shaders.at(0).Text = shaderSource;
  6481. pShaderOp->Shaders.at(0).Target = shaderProfile;
  6482. }, ShaderOpSet);
  6483. MappedData mappedData;
  6484. test->Test->GetReadBackData("SWaveIntrinsicsOp", &mappedData);
  6485. PerThreadData *resultData = reinterpret_cast<PerThreadData *>(mappedData.data());
  6486. // Partition our data into waves
  6487. std::map<uint32_t, std::vector<PerThreadData *>> waves;
  6488. for (size_t i = 0, e = ThreadCount; i != e; ++i) {
  6489. PerThreadData *elt = &resultData[i];
  6490. // Basic sanity checks
  6491. VERIFY_IS_TRUE(elt->firstLaneId != 0xdeadbeef);
  6492. VERIFY_IS_TRUE(elt->laneId != 0xdeadbeef);
  6493. waves[elt->firstLaneId].push_back(elt);
  6494. }
  6495. // Verify each wave
  6496. auto refFn = GetWaveMultiPrefixReferenceFunction<T>(testName);
  6497. for (auto &w : waves) {
  6498. std::vector<PerThreadData *> &waveData = w.second;
  6499. struct {
  6500. bool operator()(PerThreadData *a, PerThreadData *b) const {
  6501. return (a->laneId < b->laneId);
  6502. }
  6503. } compare;
  6504. // Need to sort based on the lane id
  6505. std::sort(waveData.begin(), waveData.end(), compare);
  6506. LogCommentFmt(L"LaneId Mask Key Value Result Expected");
  6507. LogCommentFmt(L"-------- -------- -------- -------- -------- --------");
  6508. for (size_t i = 0, e = waveData.size(); i != e; ++i) {
  6509. PerThreadData *data = waveData[i];
  6510. // Compute prefix operation over each previous lane element that has the
  6511. // same key value, and is part of the same active thread group
  6512. T accum = GetWaveMultiPrefixInitialAccumValue<T>(testName);
  6513. for (unsigned j = 0; j < i; ++j) {
  6514. if (waveData[j]->key == data->key && waveData[j]->mask == data->mask) {
  6515. accum = refFn(accum, waveData[j]->value);
  6516. }
  6517. }
  6518. LogCommentFmt(L"%08X %08X %08X %08X %08X %08X", data->laneId, data->mask, data->key, data->value, data->result, accum);
  6519. VERIFY_IS_TRUE(accum == data->result);
  6520. }
  6521. LogCommentFmt(L"\n");
  6522. }
  6523. }
  6524. }
  6525. TEST_F(ExecutionTest, WaveIntrinsicsSM65IntTest) {
  6526. WaveIntrinsicsMultiPrefixOpTest<int>(WaveIntrinsicsMultiPrefixIntParameters,
  6527. _countof(WaveIntrinsicsMultiPrefixIntParameters));
  6528. }
  6529. TEST_F(ExecutionTest, WaveIntrinsicsSM65UintTest) {
  6530. WaveIntrinsicsMultiPrefixOpTest<unsigned>(WaveIntrinsicsMultiPrefixUintParameters,
  6531. _countof(WaveIntrinsicsMultiPrefixUintParameters));
  6532. }
  6533. TEST_F(ExecutionTest, CBufferTestHalf) {
  6534. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6535. CComPtr<IStream> pStream;
  6536. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6537. // Single operation test at the moment.
  6538. CComPtr<ID3D12Device> pDevice;
  6539. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_2))
  6540. return;
  6541. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6542. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6543. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6544. return;
  6545. }
  6546. uint16_t InputData[] = { 0x3F80, 0x3F00, 0x3D80, 0x7BFF };
  6547. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "CBufferTestHalf",
  6548. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6549. UNREFERENCED_PARAMETER(pShaderOp);
  6550. VERIFY_IS_TRUE(0 == _stricmp(Name, "CB0"));
  6551. // use shader from data table.
  6552. Data.resize(sizeof(InputData));
  6553. uint16_t *pData = (uint16_t *)Data.data();
  6554. for (size_t i = 0; i < 4; ++i, ++pData) {
  6555. *pData = InputData[i];
  6556. }
  6557. });
  6558. {
  6559. MappedData data;
  6560. test->Test->GetReadBackData("RTarget", &data);
  6561. const uint16_t *pPixels = (uint16_t *)data.data();
  6562. for (int i = 0; i < 4; ++i) {
  6563. uint16_t output = *(pPixels + i);
  6564. float outputFloat = ConvertFloat16ToFloat32(output);
  6565. float inputFloat = ConvertFloat16ToFloat32(InputData[i]);
  6566. LogCommentFmt(L"element #%u: input = %6.8f(0x%04x), output = %6.8f(0x%04x)",
  6567. i, inputFloat, InputData[i], outputFloat, output);
  6568. VERIFY_ARE_EQUAL(inputFloat, outputFloat);
  6569. }
  6570. }
  6571. }
  6572. TEST_F(ExecutionTest, BarycentricsTest) {
  6573. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6574. CComPtr<IStream> pStream;
  6575. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6576. CComPtr<ID3D12Device> pDevice;
  6577. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_1))
  6578. return;
  6579. if (!DoesDeviceSupportBarycentrics(pDevice)) {
  6580. WEX::Logging::Log::Comment(L"Device does not support barycentrics.");
  6581. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6582. return;
  6583. }
  6584. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Barycentrics", nullptr);
  6585. MappedData data;
  6586. D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
  6587. UINT width = (UINT)D.Width;
  6588. UINT height = D.Height;
  6589. UINT pixelSize = GetByteSizeForFormat(D.Format);
  6590. test->Test->GetReadBackData("RTarget", &data);
  6591. //const uint8_t *pPixels = (uint8_t *)data.data();
  6592. const float *pPixels = (float *)data.data();
  6593. // Get the vertex of barycentric coordinate using VBuffer
  6594. MappedData triangleData;
  6595. test->Test->GetReadBackData("VBuffer", &triangleData);
  6596. const float *pTriangleData = (float*)triangleData.data();
  6597. // get the size of the input data
  6598. unsigned triangleVertexSizeInFloat = 0;
  6599. for (auto element : test->ShaderOp->InputElements)
  6600. triangleVertexSizeInFloat += GetByteSizeForFormat(element.Format) / 4;
  6601. XMFLOAT2 p0(pTriangleData[0], pTriangleData[1]);
  6602. XMFLOAT2 p1(pTriangleData[triangleVertexSizeInFloat], pTriangleData[triangleVertexSizeInFloat + 1]);
  6603. XMFLOAT2 p2(pTriangleData[triangleVertexSizeInFloat * 2], pTriangleData[triangleVertexSizeInFloat * 2 + 1]);
  6604. XMFLOAT3 barycentricWeights[4] = {
  6605. XMFLOAT3(0.3333f, 0.3333f, 0.3333f),
  6606. XMFLOAT3(0.5f, 0.25f, 0.25f),
  6607. XMFLOAT3(0.25f, 0.5f, 0.25f),
  6608. XMFLOAT3(0.25f, 0.25f, 0.50f)
  6609. };
  6610. float tolerance = 0.001f;
  6611. for (unsigned i = 0; i < sizeof(barycentricWeights) / sizeof(XMFLOAT3); ++i) {
  6612. float w0 = barycentricWeights[i].x;
  6613. float w1 = barycentricWeights[i].y;
  6614. float w2 = barycentricWeights[i].z;
  6615. float x1 = w0 * p0.x + w1 * p1.x + w2 * p2.x;
  6616. float y1 = w0 * p0.y + w1 * p1.y + w2 * p2.y;
  6617. // map from x1 y1 to rtv pixels
  6618. int pixelX = (int)((x1 + 1) * (width - 1) / 2);
  6619. int pixelY = (int)((1 - y1) * (height - 1) / 2);
  6620. int offset = pixelSize * (pixelX + pixelY * width) / sizeof(pPixels[0]);
  6621. LogCommentFmt(L"location %u %u, value %f, %f, %f", pixelX, pixelY, pPixels[offset], pPixels[offset + 1], pPixels[offset + 2]);
  6622. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset], w0, tolerance));
  6623. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 1], w1, tolerance));
  6624. VERIFY_IS_TRUE(CompareFloatEpsilon(pPixels[offset + 2], w2, tolerance));
  6625. }
  6626. //SavePixelsToFile(pPixels, DXGI_FORMAT_R32G32B32A32_FLOAT, width, height, L"barycentric.bmp");
  6627. }
  6628. static const char RawBufferTestShaderDeclarations[] =
  6629. "// Note: COMPONENT_TYPE and COMPONENT_SIZE will be defined via compiler option -D\r\n"
  6630. "typedef COMPONENT_TYPE scalar; \r\n"
  6631. "typedef vector<COMPONENT_TYPE, 2> vector2; \r\n"
  6632. "typedef vector<COMPONENT_TYPE, 3> vector3; \r\n"
  6633. "typedef vector<COMPONENT_TYPE, 4> vector4; \r\n"
  6634. "\r\n"
  6635. "struct TestData { \r\n"
  6636. " scalar v1; \r\n"
  6637. " vector2 v2; \r\n"
  6638. " vector3 v3; \r\n"
  6639. " vector4 v4; \r\n"
  6640. "}; \r\n"
  6641. "\r\n"
  6642. "struct UavData {\r\n"
  6643. " TestData input; \r\n"
  6644. " TestData output; \r\n"
  6645. " TestData srvOut; \r\n"
  6646. "}; \r\n"
  6647. "\r\n"
  6648. "ByteAddressBuffer srv0 : register(t0); \r\n"
  6649. "StructuredBuffer<TestData> srv1 : register(t1); \r\n"
  6650. "ByteAddressBuffer srv2 : register(t2); \r\n"
  6651. "StructuredBuffer<TestData> srv3 : register(t3); \r\n"
  6652. "\r\n"
  6653. "RWByteAddressBuffer uav0 : register(u0); \r\n"
  6654. "RWStructuredBuffer<UavData> uav1 : register(u1); \r\n"
  6655. "RWByteAddressBuffer uav2 : register(u2); \r\n"
  6656. "RWStructuredBuffer<UavData> uav3 : register(u3); \r\n";
  6657. static const char RawBufferTestShaderBody[] =
  6658. " // offset of 'out' in 'UavData'\r\n"
  6659. " const int out_offset = COMPONENT_SIZE * 10; \r\n"
  6660. "\r\n"
  6661. " // offset of 'srv_out' in 'UavData'\r\n"
  6662. " const int srv_out_offset = COMPONENT_SIZE * 10 * 2; \r\n"
  6663. "\r\n"
  6664. " // offsets within the 'Data' struct\r\n"
  6665. " const int v1_offset = 0; \r\n"
  6666. " const int v2_offset = COMPONENT_SIZE; \r\n"
  6667. " const int v3_offset = COMPONENT_SIZE * 3; \r\n"
  6668. " const int v4_offset = COMPONENT_SIZE * 6; \r\n"
  6669. "\r\n"
  6670. " uav0.Store(srv_out_offset + v1_offset, srv0.Load<scalar>(v1_offset)); \r\n"
  6671. " uav0.Store(srv_out_offset + v2_offset, srv0.Load<vector2>(v2_offset)); \r\n"
  6672. " uav0.Store(srv_out_offset + v3_offset, srv0.Load<vector3>(v3_offset)); \r\n"
  6673. " uav0.Store(srv_out_offset + v4_offset, srv0.Load<vector4>(v4_offset)); \r\n"
  6674. "\r\n"
  6675. " uav1[0].srvOut.v1 = srv1[0].v1; \r\n"
  6676. " uav1[0].srvOut.v2 = srv1[0].v2; \r\n"
  6677. " uav1[0].srvOut.v3 = srv1[0].v3; \r\n"
  6678. " uav1[0].srvOut.v4 = srv1[0].v4; \r\n"
  6679. "\r\n"
  6680. " uav2.Store(srv_out_offset + v1_offset, srv2.Load<scalar>(v1_offset)); \r\n"
  6681. " uav2.Store(srv_out_offset + v2_offset, srv2.Load<vector2>(v2_offset)); \r\n"
  6682. " uav2.Store(srv_out_offset + v3_offset, srv2.Load<vector3>(v3_offset)); \r\n"
  6683. " uav2.Store(srv_out_offset + v4_offset, srv2.Load<vector4>(v4_offset)); \r\n"
  6684. "\r\n"
  6685. " uav3[0].srvOut.v1 = srv3[0].v1; \r\n"
  6686. " uav3[0].srvOut.v2 = srv3[0].v2; \r\n"
  6687. " uav3[0].srvOut.v3 = srv3[0].v3; \r\n"
  6688. " uav3[0].srvOut.v4 = srv3[0].v4; \r\n"
  6689. "\r\n"
  6690. " uav0.Store(out_offset + v1_offset, uav0.Load<scalar>(v1_offset)); \r\n"
  6691. " uav0.Store(out_offset + v2_offset, uav0.Load<vector2>(v2_offset)); \r\n"
  6692. " uav0.Store(out_offset + v3_offset, uav0.Load<vector3>(v3_offset)); \r\n"
  6693. " uav0.Store(out_offset + v4_offset, uav0.Load<vector4>(v4_offset)); \r\n"
  6694. "\r\n"
  6695. " uav1[0].output.v1 = uav1[0].input.v1; \r\n"
  6696. " uav1[0].output.v2 = uav1[0].input.v2; \r\n"
  6697. " uav1[0].output.v3 = uav1[0].input.v3; \r\n"
  6698. " uav1[0].output.v4 = uav1[0].input.v4; \r\n"
  6699. "\r\n"
  6700. " uav2.Store(out_offset + v1_offset, uav2.Load<scalar>(v1_offset)); \r\n"
  6701. " uav2.Store(out_offset + v2_offset, uav2.Load<vector2>(v2_offset)); \r\n"
  6702. " uav2.Store(out_offset + v3_offset, uav2.Load<vector3>(v3_offset)); \r\n"
  6703. " uav2.Store(out_offset + v4_offset, uav2.Load<vector4>(v4_offset)); \r\n"
  6704. "\r\n"
  6705. " uav3[0].output.v1 = uav3[0].input.v1; \r\n"
  6706. " uav3[0].output.v2 = uav3[0].input.v2; \r\n"
  6707. " uav3[0].output.v3 = uav3[0].input.v3; \r\n"
  6708. " uav3[0].output.v4 = uav3[0].input.v4; \r\n";
  6709. static const char RawBufferTestComputeShaderTemplate[] =
  6710. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6711. "[numthreads(1, 1, 1)]\r\n"
  6712. "void main(uint GI : SV_GroupIndex) {\r\n"
  6713. "%s\r\n" // <- RawBufferTestShaderBody
  6714. "};";
  6715. static const char RawBufferTestGraphicsPixelShaderTemplate[] =
  6716. "%s\r\n" // <- RawBufferTestShaderDeclarations
  6717. "struct PSInput { \r\n"
  6718. " float4 pos : SV_POSITION; \r\n"
  6719. "}; \r\n"
  6720. "uint4 main(PSInput input) : SV_TARGET{ \r\n"
  6721. " if (input.pos.x + input.pos.y == 1.0f) { // pixel { 0.5, 0.5, 0 } \r\n"
  6722. "%s\r\n" // <- RawBufferTestShaderBody
  6723. " } \r\n"
  6724. " return uint4(1, 2, 3, 4); \r\n"
  6725. "};";
  6726. TEST_F(ExecutionTest, ComputeRawBufferLdStI32) {
  6727. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6728. RunComputeRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "ComputeRawBufferLdSt32Bit", data);
  6729. }
  6730. TEST_F(ExecutionTest, ComputeRawBufferLdStFloat) {
  6731. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6732. RunComputeRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "ComputeRawBufferLdSt32Bit", data);
  6733. }
  6734. TEST_F(ExecutionTest, ComputeRawBufferLdStI64) {
  6735. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6736. RunComputeRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6737. }
  6738. TEST_F(ExecutionTest, ComputeRawBufferLdStDouble) {
  6739. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6740. RunComputeRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "ComputeRawBufferLdSt64Bit", data);
  6741. }
  6742. TEST_F(ExecutionTest, ComputeRawBufferLdStI16) {
  6743. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6744. RunComputeRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "ComputeRawBufferLdSt16Bit", data);
  6745. }
  6746. TEST_F(ExecutionTest, ComputeRawBufferLdStHalf) {
  6747. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6748. RawBufferLdStTestData<uint16_t> halfData;
  6749. for (int i = 0; i < sizeof(floatData)/sizeof(float); i++) {
  6750. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6751. }
  6752. RunComputeRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "ComputeRawBufferLdSt16Bit", halfData);
  6753. }
  6754. TEST_F(ExecutionTest, GraphicsRawBufferLdStI32) {
  6755. RawBufferLdStTestData<int32_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT32 / 2 } };
  6756. RunGraphicsRawBufferLdStTest<int32_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I32, "GraphicsRawBufferLdSt32Bit", data);
  6757. }
  6758. TEST_F(ExecutionTest, GraphicsRawBufferLdStFloat) {
  6759. RawBufferLdStTestData<float> data = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, -105.17f, 980.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6760. RunGraphicsRawBufferLdStTest<float>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Float, "GraphicsRawBufferLdSt32Bit", data);
  6761. }
  6762. TEST_F(ExecutionTest, GraphicsRawBufferLdStI64) {
  6763. RawBufferLdStTestData<int64_t> data = { { 1 }, { 2, -1 }, { 256, -105171532, 980 }, { 465, 13, -89, MAXUINT64 / 2 } };
  6764. RunGraphicsRawBufferLdStTest<int64_t>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::I64, "GraphicsRawBufferLdSt64Bit", data);
  6765. }
  6766. TEST_F(ExecutionTest, GraphicsRawBufferLdStDouble) {
  6767. RawBufferLdStTestData<double> data = { { 3e-10 }, { 1.5, -1.99988 }, { 256.0, -105.17, 980.0 }, { 465.1652, -1.5694e2, -0.8543e-2, 1333.5 } };
  6768. RunGraphicsRawBufferLdStTest<double>(D3D_SHADER_MODEL_6_3, RawBufferLdStType::Double, "GraphicsRawBufferLdSt64Bit", data);
  6769. }
  6770. TEST_F(ExecutionTest, GraphicsRawBufferLdStI16) {
  6771. RawBufferLdStTestData<int16_t> data = { { 1 }, { 2, -1 }, { 256, -10517, 980 }, { 465, 13, -89, MAXUINT16 / 2 } };
  6772. RunGraphicsRawBufferLdStTest<int16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::I16, "GraphicsRawBufferLdSt16Bit", data);
  6773. }
  6774. TEST_F(ExecutionTest, GraphicsRawBufferLdStHalf) {
  6775. RawBufferLdStTestData<float> floatData = { { 3e-10f }, { 1.5f, -1.99988f }, { 256.0f, 105.17f, 0.0f }, { 465.1652f, -1.5694e2f, -0.8543e-2f, 1333.5f } };
  6776. RawBufferLdStTestData<uint16_t> halfData;
  6777. for (int i = 0; i < sizeof(floatData) / sizeof(float); i++) {
  6778. ((uint16_t*)&halfData)[i] = ConvertFloat32ToFloat16(((float*)&floatData)[i]);
  6779. }
  6780. RunGraphicsRawBufferLdStTest<uint16_t>(D3D_SHADER_MODEL_6_2, RawBufferLdStType::Half, "GraphicsRawBufferLdSt16Bit", halfData);
  6781. }
  6782. bool ExecutionTest::SetupRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6783. CComPtr<ID3D12Device> &pDevice, CComPtr<IStream> &pStream,
  6784. char *&sTy, char *&additionalOptions) {
  6785. if (!CreateDevice(&pDevice, shaderModel)) {
  6786. return false;
  6787. }
  6788. additionalOptions = "";
  6789. switch (dataType) {
  6790. case RawBufferLdStType::I64:
  6791. if (!DoesDeviceSupportInt64(pDevice)) {
  6792. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  6793. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6794. return false;
  6795. }
  6796. sTy = "int64_t";
  6797. break;
  6798. case RawBufferLdStType::Double:
  6799. if (!DoesDeviceSupportDouble(pDevice)) {
  6800. WEX::Logging::Log::Comment(L"Device does not support double operations.");
  6801. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6802. return false;
  6803. }
  6804. sTy = "double";
  6805. break;
  6806. case RawBufferLdStType::I16:
  6807. case RawBufferLdStType::Half:
  6808. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  6809. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  6810. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  6811. return false;
  6812. }
  6813. additionalOptions = "-enable-16bit-types";
  6814. sTy = (dataType == RawBufferLdStType::I16 ? "int16_t" : "half");
  6815. break;
  6816. case RawBufferLdStType::I32:
  6817. sTy = "int32_t";
  6818. break;
  6819. case RawBufferLdStType::Float:
  6820. sTy = "float";
  6821. break;
  6822. default:
  6823. DXASSERT_NOMSG("Invalid RawBufferLdStType");
  6824. }
  6825. // read shader config
  6826. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6827. return true;
  6828. }
  6829. template <class Ty>
  6830. void ExecutionTest::VerifyRawBufferLdStTestResults(const std::shared_ptr<st::ShaderOpTest> test, const RawBufferLdStTestData<Ty> &testData) {
  6831. // read buffers back & verify expected values
  6832. static const int UavBufferCount = 4;
  6833. char bufferName[11] = "UAVBufferX";
  6834. for (unsigned i = 0; i < UavBufferCount; i++) {
  6835. MappedData dataUav;
  6836. RawBufferLdStUavData<Ty> *pOutData;
  6837. bufferName[sizeof(bufferName) - 2] = (char)(i + '0');
  6838. test->GetReadBackData(bufferName, &dataUav);
  6839. VERIFY_ARE_EQUAL(sizeof(RawBufferLdStUavData<Ty>), dataUav.size());
  6840. pOutData = (RawBufferLdStUavData<Ty> *)dataUav.data();
  6841. LogCommentFmt(L"Verifying UAVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6842. // scalar
  6843. VERIFY_ARE_EQUAL(pOutData->output.v1, testData.v1);
  6844. // vector 2
  6845. VERIFY_ARE_EQUAL(pOutData->output.v2[0], testData.v2[0]);
  6846. VERIFY_ARE_EQUAL(pOutData->output.v2[1], testData.v2[1]);
  6847. // vector 3
  6848. VERIFY_ARE_EQUAL(pOutData->output.v3[0], testData.v3[0]);
  6849. VERIFY_ARE_EQUAL(pOutData->output.v3[1], testData.v3[1]);
  6850. VERIFY_ARE_EQUAL(pOutData->output.v3[2], testData.v3[2]);
  6851. // vector 4
  6852. VERIFY_ARE_EQUAL(pOutData->output.v4[0], testData.v4[0]);
  6853. VERIFY_ARE_EQUAL(pOutData->output.v4[1], testData.v4[1]);
  6854. VERIFY_ARE_EQUAL(pOutData->output.v4[2], testData.v4[2]);
  6855. VERIFY_ARE_EQUAL(pOutData->output.v4[3], testData.v4[3]);
  6856. // verify SRV Store
  6857. LogCommentFmt(L"Verifying SRVBuffer%d Load -> UAVBuffer%d Store", i, i);
  6858. // scalar
  6859. VERIFY_ARE_EQUAL(pOutData->srvOut.v1, testData.v1);
  6860. // vector 2
  6861. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[0], testData.v2[0]);
  6862. VERIFY_ARE_EQUAL(pOutData->srvOut.v2[1], testData.v2[1]);
  6863. // vector 3
  6864. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[0], testData.v3[0]);
  6865. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[1], testData.v3[1]);
  6866. VERIFY_ARE_EQUAL(pOutData->srvOut.v3[2], testData.v3[2]);
  6867. // vector 4
  6868. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[0], testData.v4[0]);
  6869. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[1], testData.v4[1]);
  6870. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[2], testData.v4[2]);
  6871. VERIFY_ARE_EQUAL(pOutData->srvOut.v4[3], testData.v4[3]);
  6872. }
  6873. }
  6874. template <class Ty>
  6875. void ExecutionTest::RunComputeRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6876. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6877. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6878. CComPtr<ID3D12Device> pDevice;
  6879. CComPtr<IStream> pStream;
  6880. char *sTy = nullptr, *additionalOptions = nullptr;
  6881. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6882. return;
  6883. }
  6884. // format shader source
  6885. char rawBufferTestShaderText[sizeof(RawBufferTestComputeShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6886. VERIFY_IS_TRUE(sprintf_s(rawBufferTestShaderText, sizeof(rawBufferTestShaderText),
  6887. RawBufferTestComputeShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6888. // format compiler args
  6889. char compilerOptions[256];
  6890. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6891. // run the shader
  6892. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6893. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6894. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6895. (Name[9] >= '0' && Name[9] <= '3'));
  6896. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  6897. pShaderOp->Shaders.at(0).Text = rawBufferTestShaderText;
  6898. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6899. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6900. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6901. });
  6902. // verify expected values
  6903. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6904. }
  6905. template <class Ty>
  6906. void ExecutionTest::RunGraphicsRawBufferLdStTest(D3D_SHADER_MODEL shaderModel, RawBufferLdStType dataType,
  6907. const char *shaderOpName, const RawBufferLdStTestData<Ty> &testData) {
  6908. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6909. CComPtr<ID3D12Device> pDevice;
  6910. CComPtr<IStream> pStream;
  6911. char *sTy = nullptr, *additionalOptions = nullptr;
  6912. if (!SetupRawBufferLdStTest(shaderModel, dataType, pDevice, pStream, sTy, additionalOptions)) {
  6913. return;
  6914. }
  6915. // format shader source
  6916. char rawBufferTestPixelShaderText[sizeof(RawBufferTestGraphicsPixelShaderTemplate) + sizeof(RawBufferTestShaderDeclarations) + sizeof(RawBufferTestShaderBody)];
  6917. VERIFY_IS_TRUE(sprintf_s(rawBufferTestPixelShaderText, sizeof(rawBufferTestPixelShaderText),
  6918. RawBufferTestGraphicsPixelShaderTemplate, RawBufferTestShaderDeclarations, RawBufferTestShaderBody) != -1);
  6919. // format compiler args
  6920. char compilerOptions[256];
  6921. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D COMPONENT_TYPE=%s -D COMPONENT_SIZE=%d %s", sTy, (int)sizeof(Ty), additionalOptions) != -1);
  6922. // run the shader
  6923. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, shaderOpName,
  6924. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  6925. VERIFY_IS_TRUE(((0 == strncmp(Name, "SRVBuffer", 9)) || (0 == strncmp(Name, "UAVBuffer", 9))) &&
  6926. (Name[9] >= '0' && Name[9] <= '3'));
  6927. // pixel shader is at index 1, vertex shader at index 0
  6928. pShaderOp->Shaders.at(1).Arguments = compilerOptions;
  6929. pShaderOp->Shaders.at(1).Text = rawBufferTestPixelShaderText;
  6930. VERIFY_IS_TRUE(sizeof(RawBufferLdStTestData<Ty>) <= Data.size());
  6931. RawBufferLdStTestData<Ty> *pInData = (RawBufferLdStTestData<Ty>*)Data.data();
  6932. memcpy(pInData, &testData, sizeof(RawBufferLdStTestData<Ty>));
  6933. });
  6934. // verify expected values
  6935. VerifyRawBufferLdStTestResults<Ty>(test->Test, testData);
  6936. }
  6937. template<typename T>
  6938. uint32_t pack(std::array<T, 4> unpackedVals)
  6939. {
  6940. uint32_t dst = 0;
  6941. constexpr uint32_t bitMask = 0xFF;
  6942. for (uint32_t i = 0U; i < 4U; ++i)
  6943. {
  6944. dst |= (unpackedVals[i] & bitMask) << (i * 8);
  6945. }
  6946. return dst;
  6947. }
  6948. template <typename T>
  6949. uint32_t pack_clamp_u8(std::array<T, 4> unpackedVals)
  6950. {
  6951. int32_t clamp_min = std::numeric_limits<uint8_t>::min();
  6952. int32_t clamp_max = std::numeric_limits<uint8_t>::max();
  6953. uint32_t dst = 0;
  6954. for (uint32_t i = 0U; i < 4U; ++i)
  6955. {
  6956. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6957. dst |= ((uint8_t)clamped) << (i * 8);
  6958. }
  6959. return dst;
  6960. }
  6961. template <typename T>
  6962. uint32_t pack_clamp_s8(std::array<T, 4> unpackedVals)
  6963. {
  6964. int32_t clamp_min = std::numeric_limits<int8_t>::min();
  6965. int32_t clamp_max = std::numeric_limits<int8_t>::max();
  6966. uint32_t dst = 0;
  6967. for (uint32_t i = 0U; i < 4U; ++i)
  6968. {
  6969. int32_t clamped = std::min(std::max((int32_t)unpackedVals[i], clamp_min), clamp_max);
  6970. dst |= ((uint8_t)clamped) << (i * 8);
  6971. }
  6972. return dst;
  6973. }
  6974. template<typename T>
  6975. std::array<T, 4> unpack_u(uint32_t packedVal)
  6976. {
  6977. std::array<T, 4> ret;
  6978. ret[0] = (uint8_t)((packedVal & 0x000000FF) >> 0 );
  6979. ret[1] = (uint8_t)((packedVal & 0x0000FF00) >> 8 );
  6980. ret[2] = (uint8_t)((packedVal & 0x00FF0000) >> 16);
  6981. ret[3] = (uint8_t)((packedVal & 0xFF000000) >> 24);
  6982. return ret;
  6983. }
  6984. template<typename T>
  6985. std::array<T, 4> unpack_s(uint32_t packedVal)
  6986. {
  6987. std::array<T, 4> ret;
  6988. ret[0] = (int8_t)((packedVal & 0x000000FF) >> 0 );
  6989. ret[1] = (int8_t)((packedVal & 0x0000FF00) >> 8 );
  6990. ret[2] = (int8_t)((packedVal & 0x00FF0000) >> 16);
  6991. ret[3] = (int8_t)((packedVal & 0xFF000000) >> 24);
  6992. return ret;
  6993. }
  6994. TEST_F(ExecutionTest, PackUnpackTest) {
  6995. WEX::TestExecution::SetVerifyOutput verifySettings(
  6996. WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  6997. CComPtr<IStream> pStream;
  6998. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  6999. CComPtr<ID3D12Device> pDevice;
  7000. #ifdef PACKUNPACK_PLACEHOLDER
  7001. string args = "-enable-16bit-types -DPACKUNPACK_PLACEHOLDER";
  7002. string target = "cs_6_2";
  7003. if (!CreateDevice(&pDevice)) {
  7004. return;
  7005. }
  7006. #else
  7007. string args = "-enable-16bit-types";
  7008. string target = "cs_6_6";
  7009. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7010. return;
  7011. }
  7012. #endif
  7013. if (!DoesDeviceSupportNative16bitOps(pDevice)) {
  7014. WEX::Logging::Log::Comment(L"Device does not support native 16-bit operations.");
  7015. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7016. return;
  7017. }
  7018. int tableSize = sizeof(PackUnpackOpParameters) / sizeof(TableParameter);
  7019. TableParameterHandler handler(PackUnpackOpParameters, tableSize);
  7020. CW2A Text(handler.GetTableParamByName(L"ShaderOp.Text")->m_str);
  7021. std::vector<uint32_t> *validation_input = &handler.GetTableParamByName(L"Validation.Input")->m_uint32Table;
  7022. uint32_t validation_tolerance = handler.GetTableParamByName(L"Validation.Tolerance")->m_uint;
  7023. size_t count = validation_input->size();
  7024. std::vector<SPackUnpackOpOutPacked> expectedPacked(count / 4);
  7025. std::vector<SPackUnpackOpOutUnpacked> expectedUnpacked(count / 4);
  7026. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
  7027. pDevice, m_support, pStream, "PackUnpackOp",
  7028. // this callback is called when the test
  7029. // is creating the resource to run the test
  7030. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7031. if (0 == _stricmp(Name, "g_bufIn"))
  7032. {
  7033. size_t size = sizeof(uint32_t) * 4 * count;
  7034. Data.resize(size);
  7035. uint32_t *pPrimitives = (uint32_t*)Data.data();
  7036. for (size_t i = 0; i < count / 4; ++i) {
  7037. uint32_t *p = &pPrimitives[i * 4];
  7038. uint32_t x = (*validation_input)[i * 4 + 0];
  7039. uint32_t y = (*validation_input)[i * 4 + 1];
  7040. uint32_t z = (*validation_input)[i * 4 + 2];
  7041. uint32_t w = (*validation_input)[i * 4 + 3];
  7042. p[0] = x;
  7043. p[1] = y;
  7044. p[2] = z;
  7045. p[3] = w;
  7046. std::array<uint32_t, 4> inputUint32 = { x, y, z, w };
  7047. std::array<int32_t, 4> inputInt32 = { (int32_t)x, (int32_t)y, (int32_t)z, (int32_t)w };
  7048. std::array<uint16_t, 4> inputUint16 = { (uint16_t)x, (uint16_t)y, (uint16_t)z, (uint16_t)w };
  7049. std::array<int16_t, 4> inputInt16 = { (int16_t)x, (int16_t)y, (int16_t)z, (int16_t)w };
  7050. // Pack unclamped
  7051. expectedPacked[i].packedUint32 = pack(inputUint32);
  7052. expectedPacked[i].packedInt32 = pack(inputInt32);
  7053. expectedPacked[i].packedUint16 = pack(inputUint16);
  7054. expectedPacked[i].packedInt16 = pack(inputInt16);
  7055. // pack clamped
  7056. expectedPacked[i].packedClampedUint32 = pack_clamp_u8(inputInt32);
  7057. expectedPacked[i].packedClampedInt32 = pack_clamp_s8(inputInt32);
  7058. expectedPacked[i].packedClampedUint16 = pack_clamp_u8(inputInt16);
  7059. expectedPacked[i].packedClampedInt16 = pack_clamp_s8(inputInt16);
  7060. // unpack
  7061. expectedUnpacked[i].outputUint32 = unpack_u<uint32_t>(expectedPacked[i].packedUint32);
  7062. expectedUnpacked[i].outputInt32 = unpack_s<int32_t >(expectedPacked[i].packedInt32 );
  7063. expectedUnpacked[i].outputUint16 = unpack_u<uint16_t>(expectedPacked[i].packedUint16);
  7064. expectedUnpacked[i].outputInt16 = unpack_s<int16_t >(expectedPacked[i].packedInt16 );
  7065. expectedUnpacked[i].outputClampedUint32 = unpack_u<uint32_t>(expectedPacked[i].packedClampedUint32);
  7066. expectedUnpacked[i].outputClampedInt32 = unpack_s<int32_t >(expectedPacked[i].packedClampedInt32 );
  7067. expectedUnpacked[i].outputClampedUint16 = unpack_u<uint16_t>(expectedPacked[i].packedClampedUint16);
  7068. expectedUnpacked[i].outputClampedInt16 = unpack_s<int16_t >(expectedPacked[i].packedClampedInt16 );
  7069. }
  7070. }
  7071. else
  7072. {
  7073. std::fill(Data.begin(), Data.end(), (BYTE)0);
  7074. }
  7075. // use shader from data table
  7076. pShaderOp->Shaders.at(0).Target = target.c_str();
  7077. pShaderOp->Shaders.at(0).Text = Text.m_psz;
  7078. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7079. });
  7080. MappedData packedData;
  7081. test->Test->GetReadBackData("g_bufOutPacked", &packedData);
  7082. SPackUnpackOpOutPacked *readBackPacked = (SPackUnpackOpOutPacked *)packedData.data();
  7083. MappedData unpackedData;
  7084. test->Test->GetReadBackData("g_bufOutPackedUnpacked", &unpackedData);
  7085. SPackUnpackOpOutUnpacked *readBackUnpacked = (SPackUnpackOpOutUnpacked *)unpackedData.data();
  7086. for (size_t i = 0; i < count / 4; ++i)
  7087. {
  7088. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint32, expectedPacked[i].packedUint32, validation_tolerance);
  7089. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt32 , expectedPacked[i].packedInt32 , validation_tolerance);
  7090. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedUint16, expectedPacked[i].packedUint16, validation_tolerance);
  7091. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedInt16 , expectedPacked[i].packedInt16 , validation_tolerance);
  7092. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint32, expectedPacked[i].packedClampedUint32, validation_tolerance);
  7093. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt32 , expectedPacked[i].packedClampedInt32 , validation_tolerance);
  7094. VerifyOutputWithExpectedValueUInt(readBackPacked[i].packedClampedUint16, expectedPacked[i].packedClampedUint16, validation_tolerance);
  7095. VerifyOutputWithExpectedValueInt (readBackPacked[i].packedClampedInt16 , expectedPacked[i].packedClampedInt16 , validation_tolerance);
  7096. for (uint32_t j = 0; j < 4; ++j)
  7097. {
  7098. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint32[j], expectedUnpacked[i].outputUint32[j], validation_tolerance);
  7099. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt32 [j], expectedUnpacked[i].outputInt32 [j], validation_tolerance);
  7100. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputUint16[j], expectedUnpacked[i].outputUint16[j], validation_tolerance);
  7101. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputInt16 [j], expectedUnpacked[i].outputInt16 [j], validation_tolerance);
  7102. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint32[j], expectedUnpacked[i].outputClampedUint32[j], validation_tolerance);
  7103. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt32 [j], expectedUnpacked[i].outputClampedInt32 [j], validation_tolerance);
  7104. VerifyOutputWithExpectedValueUInt(readBackUnpacked[i].outputClampedUint16[j], expectedUnpacked[i].outputClampedUint16[j], validation_tolerance);
  7105. VerifyOutputWithExpectedValueInt (readBackUnpacked[i].outputClampedInt16 [j], expectedUnpacked[i].outputClampedInt16 [j], validation_tolerance);
  7106. }
  7107. }
  7108. }
  7109. // This test expects a <pShader> that retrieves a signal value from each of a few
  7110. // resources that are initialized here. <isDynamic> determines if it uses the
  7111. // 6.6 Dynamic Resources feature.
  7112. // Values are read back from the result UAV and compared to the expected signals
  7113. void ExecutionTest::RunResourceTest(ID3D12Device *pDevice, const char *pShader,
  7114. const wchar_t *sm, bool isDynamic) {
  7115. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7116. const int NumSRVs = 3;
  7117. const int NumUAVs = 4;
  7118. const int NumResources = NumSRVs + NumUAVs;
  7119. const int NumSamplers = 2;
  7120. const int valueSize = 16;
  7121. static const int DispatchGroupX = 1;
  7122. static const int DispatchGroupY = 1;
  7123. static const int DispatchGroupZ = 1;
  7124. CComPtr<ID3D12GraphicsCommandList> pCommandList;
  7125. CComPtr<ID3D12CommandQueue> pCommandQueue;
  7126. CComPtr<ID3D12CommandAllocator> pCommandAllocator;
  7127. FenceObj FO;
  7128. UINT valueSizeInBytes = valueSize * sizeof(float);
  7129. CreateComputeCommandQueue(pDevice, L"DynamicResourcesTest Command Queue", &pCommandQueue);
  7130. InitFenceObj(pDevice, &FO);
  7131. // Create root signature.
  7132. CComPtr<ID3D12RootSignature> pRootSignature;
  7133. if (!isDynamic) {
  7134. // Not dynamic, create a range for each resource and from them, the root signature
  7135. CD3DX12_DESCRIPTOR_RANGE ranges[NumResources];
  7136. CD3DX12_DESCRIPTOR_RANGE srange[NumSamplers];
  7137. for (int i = 0; i < NumSRVs; i++)
  7138. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, i, 0);
  7139. for (int i = NumSRVs; i < NumResources; i++)
  7140. ranges[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, i - NumSRVs, 0);
  7141. for (int i = 0; i < NumSamplers; i++)
  7142. srange[i].Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, i, 0);
  7143. CreateRootSignatureFromRanges(pDevice, &pRootSignature, ranges, NumResources, srange, NumSamplers);
  7144. } else {
  7145. // Dynamic just requires the flags indicating that the builtin arrays should be accessible
  7146. #if !defined(D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)
  7147. #define D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x400
  7148. #define D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED (D3D12_ROOT_SIGNATURE_FLAGS)0x800
  7149. #endif
  7150. CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
  7151. rootSignatureDesc.Init(0, nullptr, 0, nullptr,
  7152. D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED |
  7153. D3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED);
  7154. CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
  7155. }
  7156. // Create pipeline state object.
  7157. CComPtr<ID3D12PipelineState> pComputeState;
  7158. CreateComputePSO(pDevice, pRootSignature, pShader, sm, &pComputeState);
  7159. // Create a command allocator and list for compute.
  7160. VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
  7161. VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
  7162. // Set up SRV resources
  7163. CComPtr<ID3D12Resource> pSRVResources[NumSRVs];
  7164. CComPtr<ID3D12Resource> pUAVResources[NumUAVs];
  7165. CComPtr<ID3D12Resource> pUploadResources[NumResources];
  7166. {
  7167. D3D12_RESOURCE_DESC bufDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
  7168. float values[valueSize];
  7169. for (int i = 0; i < NumSRVs - 1; i++) {
  7170. for (int j = 0; j < valueSize; j++)
  7171. values[j] = 10.0f + i;
  7172. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, bufDesc,
  7173. &pSRVResources[i], &pUploadResources[i]);
  7174. }
  7175. D3D12_RESOURCE_DESC tex2dDesc = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, 4, 4);
  7176. for (int j = 0; j < valueSize; j++)
  7177. values[j] = 10.0 + (NumSRVs - 1);
  7178. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex2dDesc,
  7179. &pSRVResources[NumSRVs - 1], &pUploadResources[NumSRVs - 1]);
  7180. }
  7181. // Set up UAV resources
  7182. CComPtr<ID3D12Resource> pReadBuffer;
  7183. float values[valueSize];
  7184. for (int i = 0; i < NumUAVs - 2; i++) {
  7185. for (int j = 0; j < valueSize; j++)
  7186. values[j] = 20.0f + i;
  7187. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7188. &pUAVResources[i], &pUploadResources[NumSRVs + i]);
  7189. }
  7190. for (int j = 0; j < valueSize; j++)
  7191. values[j] = 20.0 + (NumUAVs - 1);
  7192. CreateTestUavs(pDevice, pCommandList, values, valueSizeInBytes,
  7193. &pUAVResources[NumUAVs - 2], &pUploadResources[NumResources - 2], &pReadBuffer);
  7194. for (int j = 0; j < valueSize; j++)
  7195. values[j] = 20.0 + (NumUAVs - 2);
  7196. D3D12_RESOURCE_DESC tex1dDesc = CD3DX12_RESOURCE_DESC::Tex1D(DXGI_FORMAT_R32_FLOAT, valueSize, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
  7197. CreateTestResources(pDevice, pCommandList, values, valueSizeInBytes, tex1dDesc,
  7198. &pUAVResources[NumUAVs - 1], &pUploadResources[NumResources - 1]);
  7199. // Close the command list and execute it to perform the GPU setup.
  7200. pCommandList->Close();
  7201. ExecuteCommandList(pCommandQueue, pCommandList);
  7202. WaitForSignal(pCommandQueue, FO);
  7203. VERIFY_SUCCEEDED(pCommandAllocator->Reset());
  7204. VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
  7205. CComPtr<ID3D12DescriptorHeap> pResHeap;
  7206. CComPtr<ID3D12DescriptorHeap> pSampHeap;
  7207. CreateDefaultDescHeaps(pDevice, NumSRVs + NumUAVs, NumSamplers, &pResHeap, &pSampHeap);
  7208. // Create Rootsignature and descriptor tables
  7209. {
  7210. ID3D12DescriptorHeap *descHeaps[2] = {pResHeap, pSampHeap};
  7211. pCommandList->SetDescriptorHeaps(2, descHeaps);
  7212. pCommandList->SetComputeRootSignature(pRootSignature);
  7213. if (!isDynamic) {
  7214. // Only non-dynamic resources require descriptortables
  7215. pCommandList->SetComputeRootDescriptorTable(0, pResHeap->GetGPUDescriptorHandleForHeapStart());
  7216. pCommandList->SetComputeRootDescriptorTable(1, pSampHeap->GetGPUDescriptorHandleForHeapStart());
  7217. }
  7218. }
  7219. CD3DX12_CPU_DESCRIPTOR_HANDLE baseHandle(pResHeap->GetCPUDescriptorHandleForHeapStart());
  7220. // Create SRVs
  7221. CreateRawSRV(pDevice, baseHandle, valueSize, pSRVResources[0]);
  7222. CreateStructSRV(pDevice, baseHandle, valueSize, sizeof(float), pSRVResources[1]);
  7223. CreateTex2DSRV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pSRVResources[2]);
  7224. // Create UAVs
  7225. CreateRawUAV(pDevice, baseHandle, valueSize, pUAVResources[0]);
  7226. CreateStructUAV(pDevice, baseHandle, valueSize, sizeof(float), pUAVResources[1]);
  7227. CreateTypedUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[2]);
  7228. CreateTex1DUAV(pDevice, baseHandle, valueSize, DXGI_FORMAT_R32_FLOAT, pUAVResources[3]);
  7229. D3D12_FILTER filters[] = {D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT};
  7230. float borderColors[] = {30.0, 31.0};
  7231. CreateDefaultSamplers(pDevice, pSampHeap->GetCPUDescriptorHandleForHeapStart(),
  7232. filters, borderColors, NumSamplers);
  7233. // Run the compute shader and copy the results back to readable memory.
  7234. pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
  7235. RecordTransitionBarrier(pCommandList, pUAVResources[NumUAVs - 2], D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
  7236. pCommandList->CopyResource(pReadBuffer, pUAVResources[NumUAVs - 2]);
  7237. pCommandList->Close();
  7238. ExecuteCommandList(pCommandQueue, pCommandList);
  7239. WaitForSignal(pCommandQueue, FO);
  7240. MappedData data(pReadBuffer, valueSize*sizeof(float));
  7241. const float *pData = (float*)data.data();
  7242. LogCommentFmt(L"Verify bound resources are properly selected");
  7243. VERIFY_ARE_EQUAL(pData[0], 10);
  7244. VERIFY_ARE_EQUAL(pData[1], 11);
  7245. VERIFY_ARE_EQUAL(pData[2], 12);
  7246. VERIFY_ARE_EQUAL(pData[3], 20);
  7247. VERIFY_ARE_EQUAL(pData[4], 21);
  7248. VERIFY_ARE_EQUAL(pData[5], 22);
  7249. VERIFY_ARE_EQUAL(pData[6], 30);
  7250. VERIFY_ARE_EQUAL(pData[7], 1); // samplecmp 1 means it matched 31
  7251. }
  7252. TEST_F(ExecutionTest, SignatureResourcesTest) {
  7253. std::string pShader =
  7254. "ByteAddressBuffer g_rawBuf : register(t0);\n"
  7255. "StructuredBuffer<float> g_structBuf : register(t1);\n"
  7256. "Texture2D<float> g_tex : register(t2);\n"
  7257. "RWByteAddressBuffer g_rwRawBuf : register(u0);\n"
  7258. "RWStructuredBuffer<float> g_rwStructBuf : register(u1);\n"
  7259. "RWBuffer<float> g_result : register(u2);\n"
  7260. "RWTexture1D<float> g_rwTex : register(u3);\n"
  7261. "SamplerState g_samp : register(s0);\n"
  7262. "SamplerComparisonState g_sampCmp : register(s1);\n"
  7263. "[NumThreads(1, 1, 1)]\n"
  7264. "void main(uint ix : SV_GroupIndex) {\n"
  7265. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7266. " g_result[1] = g_structBuf.Load(0);\n"
  7267. " g_result[2] = g_tex.Load(0);\n"
  7268. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7269. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7270. " g_result[5] = g_rwTex.Load(0);\n"
  7271. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7272. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7273. "}\n";
  7274. CComPtr<ID3D12Device> pDevice;
  7275. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7276. return;
  7277. RunResourceTest(pDevice, pShader.c_str(), L"cs_6_6", /*isDynamic*/false);
  7278. }
  7279. TEST_F(ExecutionTest, DynamicResourcesTest) {
  7280. static const char pShader[] =
  7281. "static ByteAddressBuffer g_rawBuf = ResourceDescriptorHeap[0];\n"
  7282. "static StructuredBuffer<float> g_structBuf = ResourceDescriptorHeap[1];\n"
  7283. "static Texture2D<float> g_tex = ResourceDescriptorHeap[2];\n"
  7284. "static RWByteAddressBuffer g_rwRawBuf = ResourceDescriptorHeap[3];\n"
  7285. "static RWStructuredBuffer<float> g_rwStructBuf = ResourceDescriptorHeap[4];\n"
  7286. "static RWBuffer<float> g_result = ResourceDescriptorHeap[5];\n"
  7287. "static RWTexture1D<float> g_rwTex = ResourceDescriptorHeap[6];\n"
  7288. "static SamplerState g_samp = SamplerDescriptorHeap[0];\n"
  7289. "static SamplerComparisonState g_sampCmp = SamplerDescriptorHeap[1];\n"
  7290. "[NumThreads(1, 1, 1)]\n"
  7291. "void main(uint ix : SV_GroupIndex) {\n"
  7292. " g_result[0] = g_rawBuf.Load<float>(0);\n"
  7293. " g_result[1] = g_structBuf.Load(0);\n"
  7294. " g_result[2] = g_tex.Load(0);\n"
  7295. " g_result[3] = g_rwRawBuf.Load<float>(0);\n"
  7296. " g_result[4] = g_rwStructBuf.Load(0);\n"
  7297. " g_result[5] = g_rwTex.Load(0);\n"
  7298. " g_result[6] = g_tex.SampleLevel(g_samp, -0.5, 0);\n"
  7299. " g_result[7] = g_tex.SampleCmpLevelZero(g_sampCmp, -0.5, 31.0);\n"
  7300. "}\n";
  7301. CComPtr<ID3D12Device> pDevice;
  7302. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7303. return;
  7304. RunResourceTest(pDevice, pShader, L"cs_6_6", /*isDynamic*/true);
  7305. }
  7306. #define MAX_WAVESIZE 128
  7307. #define strinfigy2(arg) #arg
  7308. #define strinfigy(arg) strinfigy2(arg)
  7309. void ExecutionTest::WaveSizeTest() {
  7310. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7311. CComPtr<ID3D12Device> pDevice;
  7312. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6)) {
  7313. return;
  7314. }
  7315. // Check Wave support
  7316. if (!DoesDeviceSupportWaveOps(pDevice)) {
  7317. // Optional feature, so it's correct to not support it if declared as such.
  7318. WEX::Logging::Log::Comment(L"Device does not support wave operations.");
  7319. return;
  7320. }
  7321. // Get supported wave sizes
  7322. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waveOpts;
  7323. VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &waveOpts, sizeof(waveOpts)));
  7324. UINT minWaveSize = waveOpts.WaveLaneCountMin;
  7325. UINT maxWaveSize = waveOpts.WaveLaneCountMax;
  7326. DXASSERT_NOMSG(minWaveSize <= maxWaveSize);
  7327. DXASSERT((minWaveSize & (minWaveSize - 1)) == 0, "must be a power of 2");
  7328. DXASSERT((maxWaveSize & (maxWaveSize - 1)) == 0, "must be a power of 2");
  7329. // read shader config
  7330. CComPtr<IStream> pStream;
  7331. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  7332. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7333. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7334. // format shader source
  7335. const char waveSizeTestShader[] =
  7336. "struct TestData { \r\n"
  7337. " uint count; \r\n"
  7338. "}; \r\n"
  7339. "RWStructuredBuffer<TestData> data : register(u0); \r\n"
  7340. "\r\n"
  7341. "// Note: WAVESIZE will be defined via compiler option -D\r\n"
  7342. "[wavesize(WAVESIZE)]\r\n"
  7343. "[numthreads(" strinfigy(MAX_WAVESIZE) "*2,1,1)]\r\n"
  7344. "void main(uint3 tid : SV_DispatchThreadID ) { \r\n"
  7345. " data[tid.x].count = WaveActiveSum(1); \r\n"
  7346. "}\r\n";
  7347. struct WaveSizeTestData {
  7348. uint32_t count;
  7349. };
  7350. for (UINT waveSize = minWaveSize; waveSize <= maxWaveSize; waveSize *= 2) {
  7351. // format compiler args
  7352. char compilerOptions[32];
  7353. VERIFY_IS_TRUE(sprintf_s(compilerOptions, sizeof(compilerOptions), "-D WAVESIZE=%d", waveSize) != -1);
  7354. // run the shader
  7355. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "WaveSizeTest",
  7356. [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
  7357. VERIFY_IS_TRUE((0 == strncmp(Name, "UAVBuffer0", 10)));
  7358. pShaderOp->Shaders.at(0).Arguments = compilerOptions;
  7359. pShaderOp->Shaders.at(0).Text = waveSizeTestShader;
  7360. VERIFY_IS_TRUE(sizeof(WaveSizeTestData)*MAX_WAVESIZE <= Data.size());
  7361. WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
  7362. memset(&pInData, sizeof(WaveSizeTestData)*MAX_WAVESIZE, 0);
  7363. }, ShaderOpSet);
  7364. // verify expected values
  7365. MappedData dataUav;
  7366. WaveSizeTestData *pOutData;
  7367. test->Test->GetReadBackData("UAVBuffer0", &dataUav);
  7368. VERIFY_ARE_EQUAL(sizeof(WaveSizeTestData)*MAX_WAVESIZE, dataUav.size());
  7369. pOutData = (WaveSizeTestData*)dataUav.data();
  7370. LogCommentFmt(L"Verifying test result for wave size %d", waveSize);
  7371. for (unsigned i = 0; i < MAX_WAVESIZE; i++) {
  7372. if (!VERIFY_ARE_EQUAL(pOutData[i].count, waveSize))
  7373. break;
  7374. }
  7375. }
  7376. }
  7377. // Atomic operation testing
  7378. // Atomic tests take a single integer index as input and contort it into some
  7379. // kind of interesting contributor to the operation in question.
  7380. // So each vertex, pixel, thread, or other will have a unique index that produces
  7381. // a contributing value to the calculation which is stored in a small resource
  7382. // For arithmetic or bitwise operations, each contributor accumulates to the same
  7383. // location in the resource indexed by the operation type. Addition is in index 0
  7384. // umin/umax are in 1 and 2 and so on.
  7385. // To make sure that the most significant bits are involved in the calculation,
  7386. // particularly in the case of 64-bit values, each contributing value is duplicated
  7387. // to the lower and upper halves of the value. There is an exception to this when
  7388. // addition exceeds the available size and also for compare and exchange explained below.
  7389. // For compare and exchange operations, 64 output locations are shared by the various lanes.
  7390. // Each lane attempts to write to a location that is shared with several others.
  7391. // The first one to write to it determines its contents, which will be the lane index <ix>
  7392. // in the upper bits and the output location index in the lower bits.
  7393. // This ensures that the compare operations consider the upper bits in the comparison.
  7394. // The initial compare store is followed by a compare exchange that compares for the
  7395. // value the current lane would have assigned there. Finally, the output of the cmpxchg
  7396. // is used to determine if the current lane should perform the final unconditional exchange.
  7397. // The values are verified by checking the lower bits for the matching location index
  7398. // and ensuring that the upper bits undergoing the same transformation result in the location index.
  7399. // For lane index <ix> the location is calculated and final result assigned as if by this code:
  7400. // g_outputBuf[(ix/3)%64] = (ix << shBits) | ((ix/3)%64);
  7401. bool AtomicResultMatches(const BYTE *uResults, uint64_t gold, size_t size) {
  7402. if (memcmp(uResults, &gold, size)) {
  7403. if (size == 4)
  7404. LogCommentFmt(L" value %d is not %d", ((uint32_t*)uResults)[0], (uint32_t)gold);
  7405. else
  7406. LogCommentFmt(L" value %lld is not %lld", ((uint64_t*)uResults)[0], gold);
  7407. return false;
  7408. }
  7409. return true;
  7410. }
  7411. // Used to duplicate the lower half bits into the upper half bits of an integer
  7412. // To verify that the full value is being considered, many tests duplicate the results into the upper half
  7413. #define SHIFT(val, bits) (((val)&((1ULL<<(bits))-1ULL)) | ((uint64_t)(val) << (bits)))
  7414. // Symbolic constants for the results
  7415. #define ADD_IDX 0
  7416. #define UMIN_IDX 1
  7417. #define UMAX_IDX 2
  7418. #define AND_IDX 3
  7419. #define OR_IDX 4
  7420. #define XOR_IDX 5
  7421. #define SMIN_IDX 0
  7422. #define SMAX_IDX 1
  7423. // Verify results for atomic operations. <uResults> and <sResults> are pointers to
  7424. // the readback resource sections containing unsigned and signed integers respectively.
  7425. // <pXchg> is a poiner to the readback resource containing the results of the compare
  7426. // and exchange operations tests. <stride> is the number of bytes between results for
  7427. // all of the results pointers. <maxIdx> is the number of indices that went into the results
  7428. // which is used to determine what the results should be. <bitSize> is the size in bits of
  7429. // the produced results, either 32 or 64.
  7430. void VerifyAtomicResults(const BYTE *uResults, const BYTE *sResults,
  7431. const BYTE *pXchg, size_t stride, uint64_t maxIdx, size_t bitSize) {
  7432. // Each atomic test performs the test on the value in the lower half
  7433. // and also duplicated in the upper half of the value. The SHIFT macros account for this.
  7434. // This is to verify that the upper bits are considered
  7435. uint64_t shBits = bitSize/2;
  7436. size_t byteSize = bitSize/8;
  7437. // Test ADD Operation
  7438. // ADD just sums all the indices. The result should the sum of the highest and lowest indices
  7439. // multiplied by half the number of sums.
  7440. uint64_t addResult = (maxIdx)*(maxIdx-1)/2;
  7441. LogCommentFmt(L"Verifying %d-bit integer atomic add", bitSize);
  7442. // For 32-bit values, the sum exceeds the 16 bit limit, so we can't duplicate
  7443. // That's fine, the duplication is really for 64-bit values.
  7444. if (bitSize < 64)
  7445. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, addResult, byteSize));
  7446. else
  7447. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*ADD_IDX, SHIFT(addResult, shBits), byteSize));
  7448. // Test MIN and MAX Operations
  7449. // The result of a simple min and max of any sequence of indices would be fairly uninteresting
  7450. // and certain erroneous behavior might mistakenly produce the correct results.
  7451. // To make it interesting, the contributing values will change depending on the evenness of the index.
  7452. // On an even index, min and max operate on the bitflipped index. For signed compares, this is
  7453. // interpretted as a negative value and for unsigned, a very high value.
  7454. // For unsigned min/max, index 0 will be bitflipped to ~0, which is interpretted as the maximum
  7455. // Because zero is manipulated, this leaves 1 as the lowest value.
  7456. LogCommentFmt(L"Verifying %d-bit integer atomic umin", bitSize);
  7457. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMIN_IDX, SHIFT(1ULL, shBits), byteSize)); // UMin
  7458. LogCommentFmt(L"Verifying %d-bit integer atomic umax", bitSize);
  7459. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*UMAX_IDX, ~0ULL, byteSize)); // UMax
  7460. // For signed min/max, the index just before the last will be bitflipped (maxIndex is always even).
  7461. // This is interpretted as -(maxIndex-1) and will be the lowest
  7462. // The maxIndex will be unaltered and interpretted as the highest.
  7463. LogCommentFmt(L"Verifying %d-bit integer atomic smin", bitSize);
  7464. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMIN_IDX, SHIFT(-((int64_t)maxIdx-1), shBits), byteSize)); // SMin
  7465. LogCommentFmt(L"Verifying %d-bit integer atomic smax", bitSize);
  7466. VERIFY_IS_TRUE(AtomicResultMatches(sResults + stride*SMAX_IDX, SHIFT(maxIdx-1, shBits), byteSize)); // SMax
  7467. // Test AND and OR operations.
  7468. // For AND operations, all indices are bitflipped and ANDed to the previous result.
  7469. // This means that the highest bits, which are never set by the contributing indices will be set
  7470. // for all the indices, so they will be set in the final result.
  7471. // For OR operations, the indices are ORed to the previous result unaltered
  7472. // This means that any bit that is set in any index will be set in the final OR result.
  7473. // In practice, this means that the cumulative result of the AND and OR operations
  7474. // are bitflipped versions of each other.
  7475. // Finding the most significant set bit by the max index or next power of two (pot)
  7476. // gives us the pivot point for these results
  7477. uint64_t nextPot = 1ULL << (bitSize - 1);
  7478. for (;nextPot && !((maxIdx-1) & (nextPot)); nextPot >>= 1) {}
  7479. nextPot <<= 1;
  7480. LogCommentFmt(L"Verifying %d-bit integer atomic and", bitSize);
  7481. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*AND_IDX, ~SHIFT(nextPot-1, shBits), byteSize)); // And
  7482. LogCommentFmt(L"Verifying %d-bit integer atomic or", bitSize);
  7483. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*OR_IDX, SHIFT(nextPot-1, shBits), byteSize)); // Or
  7484. // Test XOR operation
  7485. // For XOR operations, a 1 is shifted by the number of spaces equal to the index and XORed
  7486. // to the previous result. Because this would rapidely shift off the end of the value,
  7487. // giving undefined and uninteresting results, the index is moduloed to a value that will
  7488. // fit within the type size.
  7489. // Because many of the tests use total numbers of lanes that can be evenly divisible by 32 or 64,
  7490. // these values aren't used for the modulo since the expected result might be zero,
  7491. // which could be encountered through erroneous behavior.
  7492. // Instead, one less than the type size in bits is used for the modulo.
  7493. // Even though we don't know the actual order these operations are performed,
  7494. // indices that make up a contiguous sequence of 31 or 63 values can be thought of as one of a series of "passes".
  7495. // Each "pass" sets or clears the bits depending on what's already there.
  7496. // if the number of the pass is odd, the bits are being unset and all above the mod position should be set.
  7497. // If even, the bits are in the process of being set and bits below the mod position should be set.
  7498. uint64_t xorResult = ((1ULL<<((maxIdx)%(bitSize-1))) -1);
  7499. if (((maxIdx/(bitSize-1))&1)) {
  7500. xorResult ^= ~0ULL;
  7501. // The XOR above may set uninvolved upper bits, messing up the compare. So AND off the uninvolved bits.
  7502. xorResult &= ((1ULL<<(bitSize-1)) - 1);
  7503. }
  7504. LogCommentFmt(L"Verifying %d-bit integer atomic xor", bitSize);
  7505. VERIFY_IS_TRUE(AtomicResultMatches(uResults + stride*XOR_IDX, xorResult, byteSize));
  7506. // Test CMP/XCHG Operations
  7507. // This tests CompareStore, CompareExchange, and Exchange operations.
  7508. // Unlike above, every lane isn't contributing to the same resource location
  7509. // Instead, every lane competes with a few others to update the same resource location.
  7510. // The first lane to find the contents of their location uninitialized will
  7511. // update it. To verify that upper bits are considered in the comparison and
  7512. // in the assignment, the value stored in the lowest bits is the location index.
  7513. // This ensures that part will be the same for each of the competing lanes.
  7514. // The uppermost bits are updated with the index of the lane that got there first.
  7515. // Subsequent calls to CompareExchange will verify this value matches and alter
  7516. // the content slightly. Finally, a simple check of the output value to what
  7517. // the current lane would expect and a call to exchange will update the value once more
  7518. // To verify this has gone through properly, the upper portion is converted as
  7519. // if to calculate the location index and compared with the location index.
  7520. // It could be the index of any of several lanes that assign to that location,
  7521. // but this ensures that it is not any lane outside of that group.
  7522. // The lower bits are compared to the location index as well.
  7523. LogCommentFmt(L"Verifying %d-bit integer atomic cmp/xchg results", bitSize);
  7524. for (size_t i = 0; i < 64; i++) {
  7525. uint64_t val = *((uint64_t*)(pXchg + i*stride));
  7526. // Verify lower bits match location index exactly
  7527. VERIFY_ARE_EQUAL(i, val & ((1ULL << shBits) - 1ULL));
  7528. // Verify that upper bits contain original index that transforms to location index
  7529. VERIFY_ARE_EQUAL(((val >> shBits)/3)%64, i);
  7530. }
  7531. }
  7532. void VerifyAtomicsRawTest(std::shared_ptr<ShaderOpTestResult> test,
  7533. uint64_t maxIdx, size_t bitSize) {
  7534. size_t stride = 8;
  7535. // struct mirroring that in the shader
  7536. struct AtomicStuff {
  7537. float prepad[2][3];
  7538. UINT uintEl[4];
  7539. int sintEl[4];
  7540. struct useless {
  7541. uint32_t unused[3];
  7542. } postpad;
  7543. float last;
  7544. };
  7545. MappedData uintData, xchgData;
  7546. test->Test->GetReadBackData("U0", &uintData);
  7547. test->Test->GetReadBackData("U1", &xchgData);
  7548. const AtomicStuff *pStruct = (AtomicStuff *)uintData.data();
  7549. const AtomicStuff *pStrXchg = (AtomicStuff *)xchgData.data();
  7550. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWStructuredBuffer resource", bitSize);
  7551. VerifyAtomicResults((const BYTE*)&(pStruct[0].uintEl[2]), (const BYTE*)&(pStruct[1].sintEl[2]),
  7552. (const BYTE*)&(pStrXchg[0].uintEl[2]), sizeof(AtomicStuff), maxIdx, bitSize);
  7553. const BYTE *pUint = nullptr;
  7554. const BYTE *pXchg = nullptr;
  7555. test->Test->GetReadBackData("U2", &uintData);
  7556. test->Test->GetReadBackData("U3", &xchgData);
  7557. pUint = (BYTE *)uintData.data();
  7558. pXchg = (BYTE *)xchgData.data();
  7559. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWByteAddressBuffer resource", bitSize);
  7560. VerifyAtomicResults(pUint, pUint + stride*6,
  7561. pXchg, stride, maxIdx, bitSize);
  7562. }
  7563. void VerifyAtomicsTypedTest(std::shared_ptr<ShaderOpTestResult> test,
  7564. uint64_t maxIdx, size_t bitSize) {
  7565. size_t stride = 8;
  7566. MappedData uintData, sintData, xchgData;
  7567. const BYTE *pUint = nullptr;
  7568. const BYTE *pSint = nullptr;
  7569. const BYTE *pXchg = nullptr;
  7570. // Typed resources can't share between 32 and 64 bits
  7571. if (bitSize == 32) {
  7572. test->Test->GetReadBackData("U4", &uintData);
  7573. test->Test->GetReadBackData("U5", &sintData);
  7574. test->Test->GetReadBackData("U6", &xchgData);
  7575. } else {
  7576. test->Test->GetReadBackData("U12", &uintData);
  7577. test->Test->GetReadBackData("U13", &sintData);
  7578. test->Test->GetReadBackData("U14", &xchgData);
  7579. }
  7580. pUint = (BYTE *)uintData.data();
  7581. pSint = (BYTE *)sintData.data();
  7582. pXchg = (BYTE *)xchgData.data();
  7583. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWBuffer resource", bitSize);
  7584. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7585. // Typed resources can't share between 32 and 64 bits
  7586. if (bitSize == 32) {
  7587. test->Test->GetReadBackData("U7", &uintData);
  7588. test->Test->GetReadBackData("U8", &sintData);
  7589. test->Test->GetReadBackData("U9", &xchgData);
  7590. } else {
  7591. test->Test->GetReadBackData("U15", &uintData);
  7592. test->Test->GetReadBackData("U16", &sintData);
  7593. test->Test->GetReadBackData("U17", &xchgData);
  7594. }
  7595. pUint = (BYTE *)uintData.data();
  7596. pSint = (BYTE *)sintData.data();
  7597. pXchg = (BYTE *)xchgData.data();
  7598. LogCommentFmt(L"Verifying %d-bit integer atomic operations on RWTexture resource", bitSize);
  7599. VerifyAtomicResults(pUint, pSint + stride, pXchg, stride, maxIdx, bitSize);
  7600. }
  7601. void VerifyAtomicsSharedTest(std::shared_ptr<ShaderOpTestResult> test,
  7602. uint64_t maxIdx, size_t bitSize) {
  7603. size_t stride = 8;
  7604. MappedData uintData, xchgData;
  7605. const BYTE *pUint = nullptr;
  7606. const BYTE *pXchg = nullptr;
  7607. test->Test->GetReadBackData("U10", &uintData);
  7608. test->Test->GetReadBackData("U11", &xchgData);
  7609. pUint = (BYTE *)uintData.data();
  7610. pXchg = (BYTE *)xchgData.data();
  7611. LogCommentFmt(L"Verifying %d-bit integer atomic operations on groupshared variables", bitSize);
  7612. VerifyAtomicResults(pUint, pUint + stride*6,
  7613. pXchg, stride, maxIdx, bitSize);
  7614. }
  7615. void VerifyAtomicsTest(std::shared_ptr<ShaderOpTestResult> test,
  7616. uint64_t maxIdx, size_t bitSize) {
  7617. VerifyAtomicsRawTest(test, maxIdx, bitSize);
  7618. VerifyAtomicsTypedTest(test, maxIdx, bitSize);
  7619. }
  7620. TEST_F(ExecutionTest, AtomicsTest) {
  7621. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7622. CComPtr<IStream> pStream;
  7623. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7624. CComPtr<ID3D12Device> pDevice;
  7625. if (!CreateDevice(&pDevice))
  7626. return;
  7627. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7628. std::make_shared<st::ShaderOpSet>();
  7629. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7630. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7631. // Test compute shader
  7632. LogCommentFmt(L"Verifying 32-bit integer atomic operations in compute shader");
  7633. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7634. VerifyAtomicsTest(test, 32*32, 32);
  7635. VerifyAtomicsSharedTest(test, 32*32, 32);
  7636. // Test mesh shader if available
  7637. pShaderOp->CS = nullptr;
  7638. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7639. LogCommentFmt(L"Verifying 32-bit integer atomic operations in amp/mesh/pixel shaders");
  7640. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7641. VerifyAtomicsTest(test, 8*8*2 + 8*8*2 + 64*64, 32);
  7642. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 32);
  7643. }
  7644. // Test Vertex + Pixel shader
  7645. pShaderOp->MS = nullptr;
  7646. LogCommentFmt(L"Verifying 32-bit integer atomic operations in vert/pixel shaders");
  7647. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7648. VerifyAtomicsTest(test, 64*64+6, 32);
  7649. }
  7650. TEST_F(ExecutionTest, Atomics64Test) {
  7651. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7652. CComPtr<IStream> pStream;
  7653. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7654. CComPtr<ID3D12Device> pDevice;
  7655. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7656. return;
  7657. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7658. std::make_shared<st::ShaderOpSet>();
  7659. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7660. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7661. // Reassign shader stages to 64-bit versions
  7662. // Collect 64-bit shaders
  7663. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7664. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7665. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7666. if (!strcmp(S.Name, "CS64")) CS64 = S.Name;
  7667. if (!strcmp(S.Name, "VS64")) VS64 = S.Name;
  7668. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7669. if (!strcmp(S.Name, "AS64")) AS64 = S.Name;
  7670. if (!strcmp(S.Name, "MS64")) MS64 = S.Name;
  7671. }
  7672. pShaderOp->CS = CS64;
  7673. pShaderOp->VS = VS64;
  7674. pShaderOp->PS = PS64;
  7675. pShaderOp->AS = AS64;
  7676. pShaderOp->MS = MS64;
  7677. // Test compute shader
  7678. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in compute shader");
  7679. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7680. VerifyAtomicsRawTest(test, 32*32, 64);
  7681. // Test mesh shader if available
  7682. pShaderOp->CS = nullptr;
  7683. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7684. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in amp/mesh/pixel shader");
  7685. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7686. VerifyAtomicsRawTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7687. }
  7688. // Test Vertex + Pixel shader
  7689. pShaderOp->MS = nullptr;
  7690. LogCommentFmt(L"Verifying 64-bit integer atomic operations on raw buffers in vert/pixel shader");
  7691. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7692. VerifyAtomicsRawTest(test, 64*64+6, 64);
  7693. }
  7694. TEST_F(ExecutionTest, AtomicsTyped64Test) {
  7695. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7696. CComPtr<IStream> pStream;
  7697. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7698. CComPtr<ID3D12Device> pDevice;
  7699. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7700. return;
  7701. if (!DoesDeviceSupportInt64(pDevice)) {
  7702. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7703. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7704. return;
  7705. }
  7706. if (!DoesDeviceSupportTyped64Atomics(pDevice)) {
  7707. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on typed resources.");
  7708. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7709. return;
  7710. }
  7711. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7712. std::make_shared<st::ShaderOpSet>();
  7713. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7714. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7715. // Reassign shader stages to 64-bit versions
  7716. // Collect 64-bit shaders
  7717. LPCSTR CS64 = nullptr, VS64 = nullptr, PS64 = nullptr;
  7718. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7719. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7720. if (!strcmp(S.Name, "CSTY64")) CS64 = S.Name;
  7721. if (!strcmp(S.Name, "VSTY64")) VS64 = S.Name;
  7722. if (!strcmp(S.Name, "PSTY64")) PS64 = S.Name;
  7723. if (!strcmp(S.Name, "ASTY64")) AS64 = S.Name;
  7724. if (!strcmp(S.Name, "MSTY64")) MS64 = S.Name;
  7725. }
  7726. pShaderOp->CS = CS64;
  7727. pShaderOp->VS = VS64;
  7728. pShaderOp->PS = PS64;
  7729. pShaderOp->AS = AS64;
  7730. pShaderOp->MS = MS64;
  7731. // Test compute shader
  7732. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in compute shader");
  7733. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7734. VerifyAtomicsTypedTest(test, 32*32, 64);
  7735. // Test mesh shader if available
  7736. pShaderOp->CS = nullptr;
  7737. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7738. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in amp/mesh/pixel shader");
  7739. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7740. VerifyAtomicsTypedTest(test, 8*8*2 + 8*8*2 + 64*64, 64);
  7741. }
  7742. // Test Vertex + Pixel shader
  7743. pShaderOp->MS = nullptr;
  7744. LogCommentFmt(L"Verifying 64-bit integer atomic operations on typed resources in vert/pixel shader");
  7745. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7746. VerifyAtomicsTypedTest(test, 64*64+6, 64);
  7747. }
  7748. TEST_F(ExecutionTest, AtomicsShared64Test) {
  7749. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7750. CComPtr<IStream> pStream;
  7751. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7752. CComPtr<ID3D12Device> pDevice;
  7753. if (!CreateDevice(&pDevice, D3D_SHADER_MODEL_6_6))
  7754. return;
  7755. if (!DoesDeviceSupportInt64(pDevice)) {
  7756. WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
  7757. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7758. return;
  7759. }
  7760. if (!DoesDeviceSupportShared64Atomics(pDevice)) {
  7761. WEX::Logging::Log::Comment(L"Device does not support int64 atomic operations on groupshared variables.");
  7762. WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped);
  7763. return;
  7764. }
  7765. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7766. std::make_shared<st::ShaderOpSet>();
  7767. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7768. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("Atomics");
  7769. // Reassign shader stages to 64-bit versions
  7770. // Collect 64-bit shaders
  7771. LPCSTR CS64 = nullptr, PS64 = nullptr;
  7772. LPCSTR AS64 = nullptr, MS64 = nullptr;
  7773. for (st::ShaderOpShader &S : pShaderOp->Shaders) {
  7774. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7775. if (!strcmp(S.Name, "CSSH64")) CS64 = S.Name;
  7776. if (!strcmp(S.Name, "PS64")) PS64 = S.Name;
  7777. if (!strcmp(S.Name, "ASSH64")) AS64 = S.Name;
  7778. if (!strcmp(S.Name, "MSSH64")) MS64 = S.Name;
  7779. }
  7780. pShaderOp->CS = CS64;
  7781. pShaderOp->PS = PS64;
  7782. pShaderOp->AS = AS64;
  7783. pShaderOp->MS = MS64;
  7784. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in compute shader");
  7785. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7786. VerifyAtomicsSharedTest(test, 32*32, 64);
  7787. // Test mesh shader if available
  7788. pShaderOp->CS = nullptr;
  7789. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7790. LogCommentFmt(L"Verifying 64-bit integer atomic operations on groupshared variables in amp/mesh/pixel shader");
  7791. test = RunShaderOpTestAfterParse(pDevice, m_support, "Atomics", nullptr, ShaderOpSet);
  7792. VerifyAtomicsSharedTest(test, 8*8*2 + 8*8*2, 64);
  7793. }
  7794. }
  7795. // Float Atomics
  7796. // These operations are almost the same as for the 32-bit and 64-bit integer tests
  7797. // The difference is that there is no need to verify the upper bits.
  7798. // So there is no storing of different parts in upper and lower halves.
  7799. // Additionally, the only operations that are supported on floats
  7800. // are compare and exchange operations. So that's all that is tested here.
  7801. // Just as above, a number of lanes are assigned the same output value.
  7802. // Unlike above, one location is needed for the result of the special NaN test
  7803. // For this reason, the conversion is reduced by one and shifted by one to leave
  7804. // the zero-indexed location available.
  7805. // Verify results for a particular set of atomics results
  7806. void VerifyAtomicFloatResults(const float *results) {
  7807. // The first entry is for NaN to ensure that compares between NaNs succeed
  7808. // The sentinal value is 0.123, for which this compare is sufficient.
  7809. VERIFY_IS_TRUE(results[0] >= 0.120 && results[0] < 0.125);
  7810. // Start at 1 because 0 is just for NaN tests
  7811. for (int i = 1; i < 64; i++) {
  7812. VERIFY_ARE_EQUAL((int(results[i])/3)%63 + 1, i);
  7813. }
  7814. }
  7815. void VerifyAtomicsFloatSharedTest(std::shared_ptr<ShaderOpTestResult> test) {
  7816. MappedData Data;
  7817. const float *pData = nullptr;
  7818. test->Test->GetReadBackData("U4", &Data);
  7819. pData = (float *)Data.data();
  7820. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on groupshared variables");
  7821. VerifyAtomicFloatResults(pData);
  7822. }
  7823. void VerifyAtomicsFloatTest(std::shared_ptr<ShaderOpTestResult> test) {
  7824. // struct mirroring that in the shader
  7825. struct AtomicStuff {
  7826. float prepad[2][3];
  7827. float fltEl[2];
  7828. struct useless {
  7829. uint32_t unused[3];
  7830. } postpad;
  7831. };
  7832. // Test Compute Shader
  7833. MappedData Data;
  7834. const float *pData = nullptr;
  7835. test->Test->GetReadBackData("U0", &Data);
  7836. const AtomicStuff *pStructData = (AtomicStuff *)Data.data();
  7837. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWStructuredBuffer resources");
  7838. VERIFY_IS_TRUE(pStructData[0].fltEl[1] >= 0.120 && pStructData[0].fltEl[1] < 0.125);
  7839. for (int i = 1; i < 64; i++) {
  7840. VERIFY_ARE_EQUAL((int(pStructData[i].fltEl[1])/3)%63 + 1, i);
  7841. }
  7842. test->Test->GetReadBackData("U1", &Data);
  7843. pData = (float *)Data.data();
  7844. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWByteAddressBuffer resources");
  7845. VerifyAtomicFloatResults(pData);
  7846. test->Test->GetReadBackData("U2", &Data);
  7847. pData = (float *)Data.data();
  7848. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWBuffer resources");
  7849. VerifyAtomicFloatResults(pData);
  7850. test->Test->GetReadBackData("U3", &Data);
  7851. pData = (float *)Data.data();
  7852. LogCommentFmt(L"Verifying float cmp/xchg atomic operations on RWTexture resources");
  7853. VerifyAtomicFloatResults(pData);
  7854. }
  7855. TEST_F(ExecutionTest, AtomicsFloatTest) {
  7856. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7857. CComPtr<IStream> pStream;
  7858. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7859. CComPtr<ID3D12Device> pDevice;
  7860. if (!CreateDevice(&pDevice))
  7861. return;
  7862. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  7863. std::make_shared<st::ShaderOpSet>();
  7864. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7865. st::ShaderOp *pShaderOp = ShaderOpSet->GetShaderOp("FloatAtomics");
  7866. // Test compute shader
  7867. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in compute shader");
  7868. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7869. VerifyAtomicsFloatTest(test);
  7870. VerifyAtomicsFloatSharedTest(test);
  7871. // Test mesh shader if available
  7872. pShaderOp->CS = nullptr;
  7873. if (DoesDeviceSupportMeshShaders(pDevice)) {
  7874. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in amp/mesh/pixel shaders");
  7875. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7876. VerifyAtomicsFloatTest(test);
  7877. VerifyAtomicsFloatSharedTest(test);
  7878. }
  7879. // Test Vertex + Pixel shader
  7880. pShaderOp->MS = nullptr;
  7881. LogCommentFmt(L"Verifying float cmp/xchg atomic operations in vert/pixel shaders");
  7882. test = RunShaderOpTestAfterParse(pDevice, m_support, "FloatAtomics", nullptr, ShaderOpSet);
  7883. VerifyAtomicsFloatTest(test);
  7884. }
  7885. // The IsHelperLane test renders 3-pixel triangle into 16x16 render target restricted
  7886. // to 2x2 viewport alligned at (0,0) which guarantees it will run in a single quad.
  7887. //
  7888. // Pixels to be rendered*
  7889. // (0,0)* (0,1)*
  7890. // (1,0) (1,1)*
  7891. //
  7892. // Pixel (1,0) is not rendered and is in helper lane.
  7893. //
  7894. // Each thread will use ddx_fine and ddy_fine to read the IsHelperLane() values from other threads.
  7895. // The bottom right pixel will write the results into the UAV buffer.
  7896. //
  7897. // Then the top level pixel (0,0) is discarded and the process above is repeated.
  7898. //
  7899. // Runs with shader models 6.0 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  7900. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6).
  7901. //
  7902. TEST_F(ExecutionTest, HelperLaneTest) {
  7903. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  7904. CComPtr<IStream> pStream;
  7905. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  7906. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  7907. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  7908. #ifdef ISHELPERLANE_PLACEHOLDER
  7909. string args = "-DISHELPERLANE_PLACEHOLDER";
  7910. #else
  7911. string args = "";
  7912. #endif
  7913. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_6 };
  7914. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  7915. D3D_SHADER_MODEL sm = TestShaderModels[i];
  7916. LogCommentFmt(L"Verifying IsHelperLane in shader model 6.%1u", ((UINT)sm & 0x0f));
  7917. CComPtr<ID3D12Device> pDevice;
  7918. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */))
  7919. continue;
  7920. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestNoWave",
  7921. // this callbacked is called when the test is creating the resource to run the test
  7922. [&](LPCSTR Name, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  7923. VERIFY_IS_TRUE(0 == _stricmp(Name, "UAVBuffer0"));
  7924. std::fill(Data.begin(), Data.end(), (BYTE)0xCC);
  7925. pShaderOp->Shaders.at(0).Arguments = args.c_str();
  7926. pShaderOp->Shaders.at(1).Arguments = args.c_str();
  7927. }, ShaderOpSet);
  7928. struct HelperLaneTestResult {
  7929. int32_t is_helper_00;
  7930. int32_t is_helper_10;
  7931. int32_t is_helper_01;
  7932. int32_t is_helper_11;
  7933. };
  7934. MappedData uavData;
  7935. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  7936. HelperLaneTestResult* pTestResults = (HelperLaneTestResult*)uavData.data();
  7937. MappedData renderData;
  7938. test->Test->GetReadBackData("RTarget", &renderData);
  7939. const uint32_t* pPixels = (uint32_t*)renderData.data();
  7940. // before discard
  7941. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_00, 0);
  7942. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_10, 0);
  7943. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_01, 1);
  7944. VERIFY_ARE_EQUAL(pTestResults[0].is_helper_11, 0);
  7945. // after discard
  7946. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_00, 1);
  7947. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_10, 0);
  7948. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_01, 1);
  7949. VERIFY_ARE_EQUAL(pTestResults[1].is_helper_11, 0);
  7950. UNREFERENCED_PARAMETER(pPixels);
  7951. }
  7952. }
  7953. struct HelperLaneWaveTestResult60 {
  7954. // 6.0 wave ops
  7955. int32_t anyTrue;
  7956. int32_t allTrue;
  7957. XMUINT4 ballot;
  7958. int32_t waterfallLoopCount;
  7959. int32_t allEqual;
  7960. int32_t countBits;
  7961. int32_t sum;
  7962. int32_t product;
  7963. int32_t bitAnd;
  7964. int32_t bitOr;
  7965. int32_t bitXor;
  7966. int32_t min;
  7967. int32_t max;
  7968. int32_t prefixCountBits;
  7969. int32_t prefixProduct;
  7970. int32_t prefixSum;
  7971. };
  7972. struct HelperLaneQuadTestResult {
  7973. int32_t is_helper_this;
  7974. int32_t is_helper_across_X;
  7975. int32_t is_helper_across_Y;
  7976. int32_t is_helper_across_Diag;
  7977. };
  7978. struct HelperLaneWaveTestResult65 {
  7979. // 6.5 wave ops
  7980. XMUINT4 match;
  7981. int32_t mpCountBits;
  7982. int32_t mpSum;
  7983. int32_t mpProduct;
  7984. int32_t mpBitAnd;
  7985. int32_t mpBitOr;
  7986. int32_t mpBitXor;
  7987. };
  7988. struct HelperLaneWaveTestResult {
  7989. HelperLaneWaveTestResult60 sm60;
  7990. HelperLaneQuadTestResult sm60_quad;
  7991. HelperLaneWaveTestResult65 sm65;
  7992. };
  7993. struct foo { int32_t a; int32_t b; int32_t c; };
  7994. struct bar { foo f; int32_t d; XMUINT4 g; };
  7995. foo f = {1, 2, 3};
  7996. bar b = { { 1, 2, 3 }, 0, { 1, 2, 3, 4 } };
  7997. HelperLaneWaveTestResult HelperLane_CS_ExpectedResults = {
  7998. // HelperLaneWaveTestResult60
  7999. { 0, 1, { 0x7, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  8000. // HelperLaneQuadTestResult
  8001. { 0, 0, 0, 0 },
  8002. // HelperLaneWaveTestResult65
  8003. { {0x7, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  8004. };
  8005. HelperLaneWaveTestResult HelperLane_VS_ExpectedResults = HelperLane_CS_ExpectedResults;
  8006. HelperLaneWaveTestResult HelperLane_PS_ExpectedResults = {
  8007. // HelperLaneWaveTestResult60
  8008. { 0, 1, { 0xB, 0, 0, 0 }, 3, 1, 3, 12, 64, 1, 0, 0, 10, 1, 2, 16, 4 },
  8009. // HelperLaneQuadTestResult
  8010. { 0, 1, 0, 0 },
  8011. // HelperLaneWaveTestResult65
  8012. { {0xB, 0, 0, 0}, 2, 4, 16, 1, 0, 0 }
  8013. };
  8014. HelperLaneWaveTestResult HelperLane_PSAfterDiscard_ExpectedResults = {
  8015. // HelperLaneWaveTestResult60
  8016. { 0, 1, { 0xA, 0, 0, 0 }, 2, 1, 2, 8, 16, 1, 0, 0, 10, 1, 1, 4, 2 },
  8017. // HelperLaneQuadTestResult
  8018. { 0, 1, 0, 1 },
  8019. // HelperLaneWaveTestResult65
  8020. { {0xA, 0, 0, 0}, 1, 2, 4, 1, 0, 0 }
  8021. };
  8022. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, uint32_t expectedValue, uint32_t actualValue) {
  8023. bool matches = (expectedValue == actualValue);
  8024. LogCommentFmt(L"%s%s, expected = %u, actual = %u", matches ? L" - " : L"FAILED: ", testDesc, expectedValue, actualValue);
  8025. return matches;
  8026. }
  8027. bool HelperLaneResultLogAndVerify(const wchar_t* testDesc, XMUINT4 expectedValue, XMUINT4 actualValue) {
  8028. bool matches = (expectedValue.x == actualValue.x && expectedValue.y == actualValue.y &&
  8029. expectedValue.z == actualValue.z && expectedValue.w == actualValue.w);
  8030. LogCommentFmt(L"%s%s, expected = (0x%X,0x%X,0x%X,0x%X), actual = (0x%X,0x%X,0x%X,0x%X)", matches ? L" - " : L"FAILED: ", testDesc,
  8031. expectedValue.x, expectedValue.y, expectedValue.z, expectedValue.w, actualValue.x, actualValue.y, actualValue.z, actualValue.w);
  8032. return matches;
  8033. }
  8034. bool VerifyHelperLaneWaveResults(ExecutionTest::D3D_SHADER_MODEL sm, HelperLaneWaveTestResult& testResults, HelperLaneWaveTestResult& expectedResults, bool verifyQuads) {
  8035. bool passed = true;
  8036. {
  8037. HelperLaneWaveTestResult60& tr60 = testResults.sm60;
  8038. HelperLaneWaveTestResult60& tr60exp = expectedResults.sm60;
  8039. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAnyTrue(IsHelperLane())", tr60exp.anyTrue, tr60.anyTrue);
  8040. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllTrue(!IsHelperLane())", tr60exp.allTrue, tr60.allTrue);
  8041. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBallot(true) has exactly 3 bits set", tr60exp.ballot, tr60.ballot);
  8042. passed &= HelperLaneResultLogAndVerify(L"!WaveReadLaneFirst(IsHelperLane()) && WaveIsFirstLane() in a waterfall loop", tr60exp.waterfallLoopCount, tr60.waterfallLoopCount);
  8043. passed &= HelperLaneResultLogAndVerify(L"WaveActiveAllEqual(IsHelperLane())", tr60exp.allEqual, tr60.allEqual);
  8044. passed &= HelperLaneResultLogAndVerify(L"WaveActiveCountBits(true)", tr60exp.countBits, tr60.countBits);
  8045. passed &= HelperLaneResultLogAndVerify(L"WaveActiveSum(4)", tr60exp.sum, tr60.sum);
  8046. passed &= HelperLaneResultLogAndVerify(L"WaveActiveProduct(4)", tr60exp.product, tr60.product);
  8047. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitAnd(!IsHelperLane())", tr60exp.bitAnd, tr60.bitAnd);
  8048. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitOr(IsHelperLane())", tr60exp.bitOr, tr60.bitOr);
  8049. passed &= HelperLaneResultLogAndVerify(L"WaveActiveBitXor(IsHelperLane())", tr60exp.bitXor, tr60.bitXor);
  8050. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMin(IsHelperLane() ? 1 : 10)", tr60exp.min, tr60.min);
  8051. passed &= HelperLaneResultLogAndVerify(L"WaveActiveMax(IsHelperLane() ? 10 : 1)", tr60exp.max, tr60.max);
  8052. passed &= HelperLaneResultLogAndVerify(L"WavePrefixCountBits(1)", tr60exp.prefixCountBits, tr60.prefixCountBits);
  8053. passed &= HelperLaneResultLogAndVerify(L"WavePrefixProduct(4)", tr60exp.prefixProduct, tr60.prefixProduct);
  8054. passed &= HelperLaneResultLogAndVerify(L"WavePrefixSum(2)", tr60exp.prefixSum, tr60.prefixSum);
  8055. }
  8056. if (verifyQuads) {
  8057. HelperLaneQuadTestResult& quad_tr = testResults.sm60_quad;
  8058. HelperLaneQuadTestResult& quad_tr_exp = expectedResults.sm60_quad;
  8059. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 3 / pixel (1,1) - IsHelperLane()", quad_tr_exp.is_helper_this, quad_tr.is_helper_this);
  8060. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 2 / pixel (0,1) - IsHelperLane()", quad_tr_exp.is_helper_across_X, quad_tr.is_helper_across_X);
  8061. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 1 / pixel (1,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Y, quad_tr.is_helper_across_Y);
  8062. passed &= HelperLaneResultLogAndVerify(L"QuadReadAcross* - lane 0 / pixel (0,0) - IsHelperLane()", quad_tr_exp.is_helper_across_Diag, quad_tr.is_helper_across_Diag);
  8063. }
  8064. if (sm >= D3D_SHADER_MODEL_6_5) {
  8065. HelperLaneWaveTestResult65& tr65 = testResults.sm65;
  8066. HelperLaneWaveTestResult65& tr65exp = expectedResults.sm65;
  8067. passed &= HelperLaneResultLogAndVerify(L"WaveMatch(true) has exactly 3 bits set", tr65exp.match, tr65.match);
  8068. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixCountBits(1, no_masked_bits)", tr65exp.mpCountBits, tr65.mpCountBits);
  8069. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixSum(2, no_masked_bits)", tr65exp.mpSum, tr65.mpSum);
  8070. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixProduct(4, no_masked_bits)", tr65exp.mpProduct, tr65.mpProduct);
  8071. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixAnd(IsHelperLane() ? 0 : 1, no_masked_bits)", tr65exp.mpBitAnd, tr65.mpBitAnd);
  8072. passed &= HelperLaneResultLogAndVerify(L"WaveMultiPrefixOr(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitOr, tr65.mpBitOr);
  8073. passed &= HelperLaneResultLogAndVerify(L"verify WaveMultiPrefixXor(IsHelperLane() ? 1 : 0, no_masked_bits)", tr65exp.mpBitXor, tr65.mpBitXor);
  8074. }
  8075. return passed;
  8076. }
  8077. void CleanUAVBuffer0Buffer(LPCSTR BufferName, std::vector<BYTE>& Data, st::ShaderOp* pShaderOp) {
  8078. UNREFERENCED_PARAMETER(pShaderOp);
  8079. VERIFY_IS_TRUE(0 == _stricmp(BufferName, "UAVBuffer0"));
  8080. std::fill(Data.begin(), Data.end(), (BYTE)0xCC);
  8081. }
  8082. //
  8083. // The IsHelperLane test that use Wave intrinsics to verify IsHelperLane() and Wave operations on active lanes.
  8084. //
  8085. // Runs with shader models 6.0, 6.5 and 6.6 to test both the HLSL built-in IsHelperLane fallback
  8086. // function (sm <= 6.5) and the IsHelperLane intrisics (sm >= 6.6) and the shader model 6.5 wave intrinsics (sm >= 6.5).
  8087. //
  8088. // For compute and vertex shaders IsHelperLane() always returns false and might be optimized away in the front end.
  8089. // However it can be exposed to the driver in CS/VS through an exported function in a library so drivers need
  8090. // to be prepared to handle it. For this reason the test is compiled with disabled optimizations (/Od).
  8091. // The tests are also validating that wave intrinsics operate correctly with 3 threads in a CS or 3 vertices
  8092. // in a VS where the rest of the lanes in the wave are not active (dead lanes).
  8093. //
  8094. TEST_F(ExecutionTest, HelperLaneTestWave) {
  8095. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  8096. CComPtr<IStream> pStream;
  8097. ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
  8098. std::shared_ptr<st::ShaderOpSet> ShaderOpSet = std::make_shared<st::ShaderOpSet>();
  8099. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8100. st::ShaderOp* pShaderOp = ShaderOpSet->GetShaderOp("HelperLaneTestWave");
  8101. #ifdef ISHELPERLANE_PLACEHOLDER
  8102. LPCSTR args = "/Od -DISHELPERLANE_PLACEHOLDER";
  8103. #else
  8104. LPCSTR args = "/Od";
  8105. #endif
  8106. if (args[0]) {
  8107. for (st::ShaderOpShader& S : pShaderOp->Shaders)
  8108. S.Arguments = args;
  8109. }
  8110. bool testPassed = true;
  8111. D3D_SHADER_MODEL TestShaderModels[] = { D3D_SHADER_MODEL_6_0, D3D_SHADER_MODEL_6_5, D3D_SHADER_MODEL_6_6 };
  8112. for (unsigned i = 0; i < _countof(TestShaderModels); i++) {
  8113. D3D_SHADER_MODEL sm = TestShaderModels[i];
  8114. LogCommentFmt(L"\r\nVerifying IsHelperLane using Wave intrinsics in shader model 6.%1u", ((UINT)sm & 0x0f));
  8115. bool smPassed = true;
  8116. CComPtr<ID3D12Device> pDevice;
  8117. if (!CreateDevice(&pDevice, sm, false /* skipUnsupported */)) {
  8118. continue;
  8119. }
  8120. if (!DoesDeviceSupportWaveOps(pDevice)) {
  8121. LogCommentFmt(L"Device does not support wave operations in shader model 6.%1u", ((UINT)sm & 0x0f));
  8122. continue;
  8123. }
  8124. if (sm == D3D_SHADER_MODEL_6_5) {
  8125. // Reassign shader stages to 6.5 versions
  8126. LPCSTR CS65 = nullptr, VS65 = nullptr, PS65 = nullptr;
  8127. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8128. if (!strcmp(S.Name, "CS65")) CS65 = S.Name;
  8129. if (!strcmp(S.Name, "VS65")) VS65 = S.Name;
  8130. if (!strcmp(S.Name, "PS65")) PS65 = S.Name;
  8131. }
  8132. pShaderOp->CS = CS65;
  8133. pShaderOp->VS = VS65;
  8134. pShaderOp->PS = PS65;
  8135. } else if (sm == D3D_SHADER_MODEL_6_6) {
  8136. // Reassign shader stages to 6.6 versions
  8137. LPCSTR CS66 = nullptr, VS66 = nullptr, PS66 = nullptr;
  8138. for (st::ShaderOpShader& S : pShaderOp->Shaders) {
  8139. if (!strcmp(S.Name, "CS66")) CS66 = S.Name;
  8140. if (!strcmp(S.Name, "VS66")) VS66 = S.Name;
  8141. if (!strcmp(S.Name, "PS66")) PS66 = S.Name;
  8142. }
  8143. pShaderOp->CS = CS66;
  8144. pShaderOp->VS = VS66;
  8145. pShaderOp->PS = PS66;
  8146. }
  8147. const unsigned CS_INDEX = 0, VS_INDEX = 0, PS_INDEX = 1, PS_INDEX_AFTER_DISCARD = 2;
  8148. // Test Compute shader
  8149. {
  8150. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave",
  8151. CleanUAVBuffer0Buffer, ShaderOpSet);
  8152. MappedData uavData;
  8153. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8154. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8155. LogCommentFmt(L"\r\nCompute shader");
  8156. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[CS_INDEX], HelperLane_CS_ExpectedResults, true);
  8157. }
  8158. // Test Vertex + Pixel shader
  8159. {
  8160. pShaderOp->CS = nullptr;
  8161. std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTestAfterParse(pDevice, m_support, "HelperLaneTestWave", CleanUAVBuffer0Buffer, ShaderOpSet);
  8162. MappedData uavData;
  8163. test->Test->GetReadBackData("UAVBuffer0", &uavData);
  8164. HelperLaneWaveTestResult* pTestResults = (HelperLaneWaveTestResult*)uavData.data();
  8165. LogCommentFmt(L"\r\nVertex shader");
  8166. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[VS_INDEX], HelperLane_VS_ExpectedResults, false);
  8167. LogCommentFmt(L"\r\nPixel shader");
  8168. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX], HelperLane_PS_ExpectedResults, true);
  8169. LogCommentFmt(L"\r\nPixel shader with discarded pixel");
  8170. smPassed &= VerifyHelperLaneWaveResults(sm, pTestResults[PS_INDEX_AFTER_DISCARD], HelperLane_PSAfterDiscard_ExpectedResults, true);
  8171. MappedData renderData;
  8172. test->Test->GetReadBackData("RTarget", &renderData);
  8173. const uint32_t* pPixels = (uint32_t*)renderData.data();
  8174. UNREFERENCED_PARAMETER(pPixels);
  8175. }
  8176. testPassed &= smPassed;
  8177. }
  8178. VERIFY_ARE_EQUAL(testPassed, true);
  8179. }
  8180. #ifndef _HLK_CONF
  8181. static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
  8182. char **pReadBackDump) {
  8183. std::stringstream str;
  8184. unsigned count = 0;
  8185. for (auto &R : pShaderOp->Resources) {
  8186. if (!R.ReadBack)
  8187. continue;
  8188. ++count;
  8189. str << "Resource: " << R.Name << "\r\n";
  8190. // Find a descriptor that can tell us how to dump this resource.
  8191. bool found = false;
  8192. for (auto &Heaps : pShaderOp->DescriptorHeaps) {
  8193. for (auto &D : Heaps.Descriptors) {
  8194. if (_stricmp(D.ResName, R.Name) != 0) {
  8195. continue;
  8196. }
  8197. found = true;
  8198. if (_stricmp(D.Kind, "UAV") != 0) {
  8199. str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
  8200. break;
  8201. }
  8202. if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
  8203. str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
  8204. break;
  8205. }
  8206. // We can map back to the structure if a structured buffer via the shader, but
  8207. // we'll keep this simple and simply dump out 32-bit uint/float representations.
  8208. MappedData data;
  8209. pTest->GetReadBackData(R.Name, &data);
  8210. uint32_t *pData = (uint32_t *)data.data();
  8211. size_t u32_count = ((size_t)R.Desc.Width) / sizeof(uint32_t);
  8212. for (size_t i = 0; i < u32_count; ++i) {
  8213. float f = *(float *)pData;
  8214. str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
  8215. << std::dec << " " << f << "\r\n";
  8216. ++pData;
  8217. }
  8218. break;
  8219. }
  8220. if (found) break;
  8221. }
  8222. if (!found) {
  8223. str << "Unable to find a view for the resource.\r\n";
  8224. }
  8225. }
  8226. str << "Resources read back: " << count << "\r\n";
  8227. std::string s(str.str());
  8228. CComHeapPtr<char> pDump;
  8229. if (!pDump.Allocate(s.size() + 1))
  8230. throw std::bad_alloc();
  8231. memcpy(pDump.m_pData, s.data(), s.size());
  8232. pDump.m_pData[s.size()] = '\0';
  8233. *pReadBackDump = pDump.Detach();
  8234. }
  8235. // This is the exported interface by use from HLSLHost.exe.
  8236. // It's exclusive with the use of the DLL as a TAEF target.
  8237. extern "C" {
  8238. __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
  8239. HRESULT hr = EnableExperimentalShaderModels();
  8240. if (FAILED(hr)) {
  8241. pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
  8242. }
  8243. return S_OK;
  8244. }
  8245. __declspec(dllexport) HRESULT WINAPI
  8246. RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
  8247. ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
  8248. ID3D12Resource *pRenderTarget, char **pReadBackDump) {
  8249. HRESULT hr;
  8250. if (pReadBackDump) *pReadBackDump = nullptr;
  8251. st::SetOutputFn(pStrCtx, pOutputStrFn);
  8252. CComPtr<ID3D12InfoQueue> pInfoQueue;
  8253. CComHeapPtr<char> pDump;
  8254. bool FilterCreation = false;
  8255. if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
  8256. // Creation is largely driven by inputs, so don't log create/destroy messages.
  8257. pInfoQueue->PushEmptyStorageFilter();
  8258. pInfoQueue->PushEmptyRetrievalFilter();
  8259. if (FilterCreation) {
  8260. D3D12_INFO_QUEUE_FILTER filter;
  8261. D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
  8262. ZeroMemory(&filter, sizeof(filter));
  8263. filter.DenyList.NumCategories = _countof(denyCategories);
  8264. filter.DenyList.pCategoryList = denyCategories;
  8265. pInfoQueue->PushStorageFilter(&filter);
  8266. }
  8267. }
  8268. else {
  8269. pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
  8270. }
  8271. try {
  8272. dxc::DxcDllSupport m_support;
  8273. m_support.Initialize();
  8274. const char *pName = nullptr;
  8275. CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, (UINT)strlen(pText));
  8276. std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
  8277. std::make_shared<st::ShaderOpSet>();
  8278. st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
  8279. st::ShaderOp *pShaderOp;
  8280. if (pName == nullptr) {
  8281. if (ShaderOpSet->ShaderOps.size() != 1) {
  8282. pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
  8283. return E_FAIL;
  8284. }
  8285. pShaderOp = ShaderOpSet->ShaderOps[0].get();
  8286. }
  8287. else {
  8288. pShaderOp = ShaderOpSet->GetShaderOp(pName);
  8289. }
  8290. if (pShaderOp == nullptr) {
  8291. std::string msg = "Unable to find shader op ";
  8292. msg += pName;
  8293. msg += "; available ops";
  8294. const char sep = ':';
  8295. for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
  8296. msg += sep;
  8297. msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
  8298. }
  8299. CA2W msgWide(msg.c_str());
  8300. pOutputStrFn(pStrCtx, msgWide);
  8301. return E_FAIL;
  8302. }
  8303. std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
  8304. test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
  8305. test->SetDxcSupport(&m_support);
  8306. test->RunShaderOp(pShaderOp);
  8307. test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
  8308. pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
  8309. if (!pShaderOp->IsCompute()) {
  8310. D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
  8311. test->GetPipelineStats(&stats);
  8312. wchar_t statsText[400];
  8313. StringCchPrintfW(statsText, _countof(statsText),
  8314. L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
  8315. L"Vertex shader invocations: %I64u\r\n"
  8316. L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
  8317. L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
  8318. L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
  8319. stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
  8320. stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
  8321. stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
  8322. stats.DSInvocations, stats.CSInvocations);
  8323. pOutputStrFn(pStrCtx, statsText);
  8324. }
  8325. if (pReadBackDump) {
  8326. WriteReadBackDump(pShaderOp, test.get(), &pDump);
  8327. }
  8328. hr = S_OK;
  8329. }
  8330. catch (const CAtlException &E)
  8331. {
  8332. hr = E.m_hr;
  8333. }
  8334. catch (const std::bad_alloc &)
  8335. {
  8336. hr = E_OUTOFMEMORY;
  8337. }
  8338. catch (const std::exception &)
  8339. {
  8340. hr = E_FAIL;
  8341. }
  8342. // Drain the device message queue if available.
  8343. if (pInfoQueue != nullptr) {
  8344. wchar_t buf[200];
  8345. StringCchPrintfW(buf, _countof(buf),
  8346. L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
  8347. L"allowed/denied by storage filter=%u/%u "
  8348. L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
  8349. (unsigned)pInfoQueue->GetNumStoredMessages(),
  8350. (unsigned)pInfoQueue->GetMessageCountLimit(),
  8351. (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
  8352. (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
  8353. (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
  8354. (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
  8355. pOutputStrFn(pStrCtx, buf);
  8356. WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
  8357. pInfoQueue->ClearStoredMessages();
  8358. pInfoQueue->PopRetrievalFilter();
  8359. pInfoQueue->PopStorageFilter();
  8360. if (FilterCreation) {
  8361. pInfoQueue->PopStorageFilter();
  8362. }
  8363. }
  8364. if (pReadBackDump) *pReadBackDump = pDump.Detach();
  8365. return hr;
  8366. }
  8367. }
  8368. #endif
  8369. // MARKER: ExecutionTest/DxilConf Shared Implementation End
  8370. // Do not remove the line above - it is used by TranslateExecutionTest.py